Restructured passes

This commit is contained in:
2026-01-31 02:31:19 +01:00
parent bd4b81d434
commit b6a32ebe7f
6 changed files with 356 additions and 248 deletions

View File

@@ -85,19 +85,24 @@ when RENDER_BACKEND_OPENGL {
opengl_viewport_changed :: proc(renderer: ^Renderer) {
gl.Viewport(
i32(renderer.viewport.x),
i32(renderer.viewport.y),
i32(renderer.viewport.width),
i32(renderer.viewport.height)
i32(renderer.viewport.x), i32(renderer.viewport.y),
i32(renderer.viewport.width), i32(renderer.viewport.height)
)
}
opengl_set_clear_color :: proc(renderer: ^Renderer, color: RGB_Color) {
opengl_set_clear_color :: proc(renderer: ^Renderer, color: Color) {
r, g, b, a: u8 = max(u8), max(u8), max(u8), max(u8)
switch &c in color {
case RGB_Color: r, g, b = expand_values(c.rgb)
case RGBA_Color: r, g, b, a = expand_values(c.rgba)
}
gl.ClearColor(
f32(color.r) / f32(max(u8)),
f32(color.g) / f32(max(u8)),
f32(color.b) / f32(max(u8)),
1.0
f32(r) / f32(max(u8)),
f32(g) / f32(max(u8)),
f32(b) / f32(max(u8)),
f32(a) / f32(max(u8)),
)
}
@@ -253,33 +258,50 @@ when RENDER_BACKEND_OPENGL {
gl.DeleteProgram(shader_program.backend.handle)
}
opengl_activate_bind_textures_in_material :: proc(material: ^Material) {
assert(material != nil)
for t, i in material.textures[:material.texture_count] {
assert(t != nil)
gl.ActiveTexture(gl.TEXTURE0 + u32(i))
gl.BindTexture(gl.TEXTURE_2D, t.backend.handle)
loc := gl.GetUniformLocation(material.shader_program.backend.handle, fmt.ctprintf("texture%d", i))
gl.Uniform1i(loc, i32(i))
}
}
opengl_activate_material :: proc(material: ^Material, model_matrix, view_matrix, projection_matrix: linalg.Matrix4x4f32) {
gl.UseProgram(material.shader_program.backend.handle)
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, material.texture.backend.handle)
opengl_activate_bind_textures_in_material(material)
model_matrix_loc := gl.GetUniformLocation(material.shader_program.backend.handle, "in_model_matrix")
assert(model_matrix_loc >= 0)
model_matrix_as_f32_array := transmute([16]f32)(model_matrix)
gl.UniformMatrix4fv(model_matrix_loc, 1, false, &model_matrix_as_f32_array[0])
view_matrix_loc := gl.GetUniformLocation(material.shader_program.backend.handle, "in_view_matrix")
assert(view_matrix_loc >= 0)
view_matrix_as_f32_array := transmute([16]f32)(view_matrix)
gl.UniformMatrix4fv(view_matrix_loc, 1, false, &view_matrix_as_f32_array[0])
projection_matrix_loc := gl.GetUniformLocation(material.shader_program.backend.handle, "in_projection_matrix")
assert(projection_matrix_loc >= 0)
projection_matrix_as_f32_array := transmute([16]f32)(projection_matrix)
gl.UniformMatrix4fv(projection_matrix_loc, 1, false, &projection_matrix_as_f32_array[0])
}
opengl_activate_fullscreen_material :: proc(material: ^Material) {
opengl_activate_fullscreen_material :: proc(material: ^Material) { // TODO: SS - Maybe remove.
assert(material != nil)
gl.UseProgram(material.shader_program.backend.handle)
assert(material.texture_count > 0)
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, material.texture.backend.handle)
gl.BindTexture(gl.TEXTURE_2D, material.textures[0].backend.handle)
loc := gl.GetUniformLocation(material.shader_program.backend.handle, "texture0") // eller "uTex"
loc := gl.GetUniformLocation(material.shader_program.backend.handle, "texture0")
if loc != -1 {
gl.Uniform1i(loc, 0)
}
@@ -288,7 +310,7 @@ when RENDER_BACKEND_OPENGL {
gl.DepthMask(gl.FALSE)
}
opengl_deactivate_fullscreen_material :: proc() {
opengl_deactivate_fullscreen_material :: proc() { // TODO: SS - Maybe remove.
gl.DepthMask(gl.TRUE)
gl.Enable(gl.DEPTH_TEST)
}
@@ -486,6 +508,8 @@ when RENDER_BACKEND_OPENGL {
}
gl.BindFramebuffer(gl.FRAMEBUFFER, rt.backend.handle)
status := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)
assert(status == gl.FRAMEBUFFER_COMPLETE)
gl.Viewport(
0,
@@ -529,4 +553,13 @@ when RENDER_BACKEND_OPENGL {
return true
}
}
opengl_set_shader_value_texture :: proc(program: ^Shader_Program, value: ^Texture, index: u8) {
gl.UseProgram(program.backend.handle)
gl.ActiveTexture(gl.TEXTURE0 + u32(index))
gl.BindTexture(gl.TEXTURE_2D, value.backend.handle)
loc := gl.GetUniformLocation(program.backend.handle, fmt.ctprintf("texture%v", index))
gl.Uniform1i(loc, i32(index))
}
}