Uniform colors
This commit is contained in:
@@ -37,14 +37,6 @@ get_aspect_ratio :: proc(renderer: ^Renderer) -> f32 {
|
||||
return f32(viewport.width) / f32(viewport.height)
|
||||
}
|
||||
|
||||
Color :: union {
|
||||
RGB_Color,
|
||||
RGBA_Color,
|
||||
}
|
||||
|
||||
RGB_Color :: [3]u8
|
||||
RGBA_Color :: [4]u8
|
||||
|
||||
create :: proc(surface_ptr: rawptr) -> (^Renderer, bool) {
|
||||
renderer := new(Renderer)
|
||||
renderer.surface_ptr = surface_ptr
|
||||
@@ -153,14 +145,14 @@ render_frame :: proc(renderer: ^Renderer, texture_to_present: ^Texture, clear_co
|
||||
return
|
||||
}
|
||||
|
||||
view_matrix, _ := get_camera_view_matrix(renderer.active_camera)
|
||||
projection_matrix, _ := get_camera_projection_matrix(renderer, renderer.active_camera)
|
||||
camera_view_matrix, _ := get_camera_view_matrix(renderer.active_camera)
|
||||
camera_projection_matrix, _ := get_camera_projection_matrix(renderer, renderer.active_camera)
|
||||
|
||||
set_clear_color(renderer, clear_color)
|
||||
clear_screen(renderer, true, true)
|
||||
|
||||
for i in 0 ..< renderer.pipeline.amount_of_passes {
|
||||
execute_pass(renderer, renderer.pipeline.passes[i], view_matrix, projection_matrix)
|
||||
execute_pass(renderer, renderer.pipeline.passes[i], camera_view_matrix, camera_projection_matrix)
|
||||
}
|
||||
|
||||
if texture_to_present != nil { // Present.
|
||||
@@ -243,7 +235,7 @@ execute_pass :: proc(renderer: ^Renderer, pass: ^Pass, view_matrix, projection_m
|
||||
scale := linalg.matrix4_scale(dc.scale)
|
||||
|
||||
model_matrix *= translation * rotation * scale
|
||||
|
||||
|
||||
activate_material(&dc.material, model_matrix, view_matrix, projection_matrix)
|
||||
|
||||
draw_mesh(&dc.mesh)
|
||||
@@ -295,11 +287,9 @@ execute_post_processing_node :: proc(renderer: ^Renderer, node: ^Post_Processing
|
||||
continue
|
||||
}
|
||||
|
||||
if set_shader_uniform(node.program, t) {
|
||||
mat.textures[mat.texture_count] = t.value
|
||||
mat.texture_count += 1
|
||||
}
|
||||
else {
|
||||
mat.textures[mat.texture_count] = t.value
|
||||
mat.texture_count += 1
|
||||
if !set_shader_uniform(node.program, t) {
|
||||
fmt.printfln("Failed to set uniform-texture %v in program (vs: '%s', fs: '%s').", t.index, vs_path, fs_path)
|
||||
}
|
||||
}
|
||||
@@ -318,6 +308,11 @@ execute_post_processing_node :: proc(renderer: ^Renderer, node: ^Post_Processing
|
||||
fmt.printfln("Failed to set uniform-vector3 '%s' in program (vs: '%s', fs: '%s').", t.name, vs_path, fs_path)
|
||||
}
|
||||
}
|
||||
case Uniform_Color: {
|
||||
if !set_shader_uniform(node.program, t) {
|
||||
fmt.printfln("Failed to set uniform-color '%s' in program (vs: '%s', fs: '%s').", t.name, vs_path, fs_path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,9 +329,52 @@ destroy :: proc(renderer: ^Renderer) {
|
||||
free(renderer)
|
||||
}
|
||||
|
||||
@(private) activate_shader_program :: proc(program: ^Shader_Program) {
|
||||
when RENDER_BACKEND_OPENGL {
|
||||
opengl_activate_shader_program(program)
|
||||
}
|
||||
}
|
||||
|
||||
@(private) activate_material :: proc(material: ^Material, model_matrix, view_matrix, projection_matrix: linalg.Matrix4x4f32, uv_scale: [2]f32 = { 1.0, 1.0 }) {
|
||||
assert(material != nil)
|
||||
|
||||
p := material.shader_program
|
||||
|
||||
activate_shader_program(p)
|
||||
|
||||
fs_path := p.fragment_shader != nil ? p.fragment_shader.path : "nil"
|
||||
vs_path := p.vertex_shader != nil ? p.vertex_shader.path : "nil"
|
||||
|
||||
for u in material.uniforms {
|
||||
switch &t in u {
|
||||
case Uniform_Texture: {
|
||||
if !set_shader_uniform(p, t) {
|
||||
fmt.printfln("Failed to set uniform-texture %v in program (vs: '%s', fs: '%s').", t.index, vs_path, fs_path)
|
||||
}
|
||||
}
|
||||
case Uniform_Float: {
|
||||
if !set_shader_uniform(p, t) {
|
||||
fmt.printfln("Failed to set uniform-float '%s' in program (vs: '%s', fs: '%s').", t.name, vs_path, fs_path)
|
||||
}
|
||||
}
|
||||
case Uniform_Matrix4f32: {
|
||||
if !set_shader_uniform(p, t) {
|
||||
fmt.printfln("Failed to set uniform-matrix4f32 '%s' in program (vs: '%s', fs: '%s').", t.name, vs_path, fs_path)
|
||||
}
|
||||
}
|
||||
case Uniform_Vector3: {
|
||||
if !set_shader_uniform(p, t) {
|
||||
fmt.printfln("Failed to set uniform-vector3 '%s' in program (vs: '%s', fs: '%s').", t.name, vs_path, fs_path)
|
||||
}
|
||||
}
|
||||
case Uniform_Color: {
|
||||
if !set_shader_uniform(p, t) {
|
||||
fmt.printfln("Failed to set uniform-color '%s' in program (vs: '%s', fs: '%s').", t.name, vs_path, fs_path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
when RENDER_BACKEND_OPENGL {
|
||||
opengl_activate_material(material, model_matrix, view_matrix, projection_matrix)
|
||||
}
|
||||
@@ -424,6 +462,11 @@ distance_to_camera :: proc(camera: ^Camera, position: [3]f32) -> f32 {
|
||||
|
||||
@(private) activate_fullscreen_material :: proc(renderer: ^Renderer, material: ^Material) { // TODO: SS - Maybe remove.
|
||||
assert(renderer != nil)
|
||||
assert(material != nil)
|
||||
assert(material.shader_program != nil)
|
||||
|
||||
activate_shader_program(material.shader_program)
|
||||
|
||||
when RENDER_BACKEND_OPENGL {
|
||||
opengl_activate_fullscreen_material(material)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user