Remove textures

This commit is contained in:
Hugo Mårdbrink 2025-08-27 21:03:35 +02:00
parent db75a10f2b
commit f658d040ed
14 changed files with 66 additions and 155 deletions

View file

@ -24,9 +24,12 @@ import program_config "../config"
import shaders "../shaders/out"
VertexData :: struct {
CubeVertexData :: struct {
pos: Vec3,
}
OutlineVertexData :: struct {
pos: Vec3,
uv: Vec2,
}
Mesh :: struct {
@ -37,8 +40,6 @@ Mesh :: struct {
Material :: struct {
pipeline: sg.Pipeline,
shader: sg.Shader,
image: sg.Image,
sampler: sg.Sampler,
}
RenderSystem :: struct {
@ -57,7 +58,6 @@ init_outline_material :: proc(render_system: ^RenderSystem) {
layout = {
attrs = {
shaders.ATTR_outline_pos = { format = .FLOAT3 },
shaders.ATTR_outline_uv = { format = .FLOAT2 },
},
},
index_type = .UINT16,
@ -73,12 +73,9 @@ init_outline_material :: proc(render_system: ^RenderSystem) {
sample_count = 4,
})
sampler := sg.make_sampler({})
render_system.materials[.Outline] = Material{
shader = shader,
pipeline = pipeline,
sampler = sampler,
}
}
@ -90,7 +87,6 @@ init_cube_material :: proc(render_system: ^RenderSystem) {
layout = {
attrs = {
shaders.ATTR_cube_pos = { format = .FLOAT3 },
shaders.ATTR_cube_uv = { format = .FLOAT2 },
},
},
index_type = .UINT16,
@ -106,69 +102,44 @@ init_cube_material :: proc(render_system: ^RenderSystem) {
sample_count = 4,
})
w, h: i32
pixels := stbi.load("res/white.png", &w, &h, nil, 4)
assert(pixels != nil)
defer(stbi.image_free(pixels))
image := sg.make_image({
width = w,
height = h,
pixel_format = .RGBA8,
data = {
subimage = {
0 = {
0 = {
ptr = pixels,
size = uint(w * h * 4)
}
}
}
},
})
sampler := sg.make_sampler({})
render_system.materials[.Cube] = Material{
shader = shader,
pipeline = pipeline,
image = image,
sampler = sampler,
}
}
@(private)
init_cube_mesh :: proc (render_system: ^RenderSystem) {
cube_vertices := []VertexData {
{ pos = { -0.5, -0.5, 0.5 }, uv = { 0, 0 } },
{ pos = { 0.5, -0.5, 0.5 }, uv = { 1, 0 } },
{ pos = { 0.5, 0.5, 0.5 }, uv = { 1, 1 } },
{ pos = { -0.5, 0.5, 0.5 }, uv = { 0, 1 } },
cube_vertices := []CubeVertexData {
{ pos = { -0.5, -0.5, 0.5 } },
{ pos = { 0.5, -0.5, 0.5 } },
{ pos = { 0.5, 0.5, 0.5 } },
{ pos = { -0.5, 0.5, 0.5 } },
{ pos = { -0.5, -0.5, -0.5 }, uv = { 1, 0 } },
{ pos = { 0.5, -0.5, -0.5 }, uv = { 0, 0 } },
{ pos = { 0.5, 0.5, -0.5 }, uv = { 0, 1 } },
{ pos = { -0.5, 0.5, -0.5 }, uv = { 1, 1 } },
{ pos = { -0.5, -0.5, -0.5 } },
{ pos = { 0.5, -0.5, -0.5 } },
{ pos = { 0.5, 0.5, -0.5 } },
{ pos = { -0.5, 0.5, -0.5 } },
{ pos = { -0.5, 0.5, 0.5 }, uv = { 0, 0 } },
{ pos = { 0.5, 0.5, 0.5 }, uv = { 1, 0 } },
{ pos = { 0.5, 0.5, -0.5 }, uv = { 1, 1 } },
{ pos = { -0.5, 0.5, -0.5 }, uv = { 0, 1 } },
{ pos = { -0.5, 0.5, 0.5 } },
{ pos = { 0.5, 0.5, 0.5 } },
{ pos = { 0.5, 0.5, -0.5 } },
{ pos = { -0.5, 0.5, -0.5 } },
{ pos = { -0.5, -0.5, 0.5 }, uv = { 0, 0 } },
{ pos = { 0.5, -0.5, 0.5 }, uv = { 1, 0 } },
{ pos = { 0.5, -0.5, -0.5 }, uv = { 1, 1 } },
{ pos = { -0.5, -0.5, -0.5 }, uv = { 0, 1 } },
{ pos = { -0.5, -0.5, 0.5 } },
{ pos = { 0.5, -0.5, 0.5 } },
{ pos = { 0.5, -0.5, -0.5 } },
{ pos = { -0.5, -0.5, -0.5 } },
{ pos = { 0.5, -0.5, 0.5 }, uv = { 0, 0 } },
{ pos = { 0.5, -0.5, -0.5 }, uv = { 1, 0 } },
{ pos = { 0.5, 0.5, -0.5 }, uv = { 1, 1 } },
{ pos = { 0.5, 0.5, 0.5 }, uv = { 0, 1 } },
{ pos = { 0.5, -0.5, 0.5 } },
{ pos = { 0.5, -0.5, -0.5 } },
{ pos = { 0.5, 0.5, -0.5 } },
{ pos = { 0.5, 0.5, 0.5 } },
{ pos = { -0.5, -0.5, 0.5 }, uv = { 1, 0 } },
{ pos = { -0.5, -0.5, -0.5 }, uv = { 0, 0 } },
{ pos = { -0.5, 0.5, -0.5 }, uv = { 0, 1 } },
{ pos = { -0.5, 0.5, 0.5 }, uv = { 1, 1 } },
{ pos = { -0.5, -0.5, 0.5 } },
{ pos = { -0.5, -0.5, -0.5 } },
{ pos = { -0.5, 0.5, -0.5 } },
{ pos = { -0.5, 0.5, 0.5 } },
}
vertex_buffer := sg.make_buffer({
data = sg_range(cube_vertices)
@ -225,13 +196,10 @@ render_system_delete :: proc(render_system: ^RenderSystem, coordinator: ^Coordin
sg.destroy_buffer(cube_mesh.vertex_buffer)
cube_material := render_system.materials[.Cube]
sg.destroy_image(cube_material.image)
sg.destroy_sampler(cube_material.sampler)
sg.destroy_pipeline(cube_material.pipeline)
sg.destroy_shader(cube_material.shader)
outline_material := render_system.materials[.Outline]
sg.destroy_sampler(outline_material.sampler)
sg.destroy_pipeline(outline_material.pipeline)
sg.destroy_shader(outline_material.shader)
@ -313,9 +281,6 @@ cube_pass :: proc(render_system: ^RenderSystem, coordinator: ^Coordinator, proj:
sg.apply_pipeline(material.pipeline)
sg.apply_bindings({
images = { shaders.IMG_tex = material.image },
samplers = { shaders.SMP_smp = material.sampler },
vertex_buffers = { 0 = mesh.vertex_buffer },
index_buffer = mesh.index_buffer,
})