Allowed setting uniforms in shader
This commit is contained in:
@@ -293,6 +293,11 @@ when RENDER_BACKEND_OPENGL {
|
||||
projection_matrix_as_f32_array := transmute([16]f32)(projection_matrix)
|
||||
gl.UniformMatrix4fv(projection_matrix_loc, 1, false, &projection_matrix_as_f32_array[0])
|
||||
}
|
||||
|
||||
uv_scale_loc := gl.GetUniformLocation(material.shader_program.backend.handle, "in_uv_scale")
|
||||
if uv_scale_loc >= 0 {
|
||||
gl.Uniform2fv(uv_scale_loc, 1, &material.uv_scale[0])
|
||||
}
|
||||
}
|
||||
|
||||
opengl_activate_fullscreen_material :: proc(material: ^Material) { // TODO: SS - Maybe remove.
|
||||
@@ -514,11 +519,13 @@ when RENDER_BACKEND_OPENGL {
|
||||
status := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)
|
||||
assert(status == gl.FRAMEBUFFER_COMPLETE)
|
||||
|
||||
assert(len(rt.color_textures) > 0)
|
||||
|
||||
gl.Viewport(
|
||||
0,
|
||||
0,
|
||||
i32(rt.color_texture.width),
|
||||
i32(rt.color_texture.height),
|
||||
i32(rt.color_textures[0].width),
|
||||
i32(rt.color_textures[0].height),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -527,13 +534,24 @@ when RENDER_BACKEND_OPENGL {
|
||||
gl.GenFramebuffers(1, &fb)
|
||||
gl.BindFramebuffer(gl.FRAMEBUFFER, fb)
|
||||
|
||||
gl.FramebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
gl.COLOR_ATTACHMENT0,
|
||||
gl.TEXTURE_2D,
|
||||
rt.color_texture.backend.handle,
|
||||
0
|
||||
)
|
||||
for texture, i in rt.color_textures {
|
||||
gl.FramebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
gl.COLOR_ATTACHMENT0 + u32(i),
|
||||
gl.TEXTURE_2D,
|
||||
texture.backend.handle,
|
||||
0
|
||||
)
|
||||
}
|
||||
|
||||
attachments: [MAX_COLOR_TEXTURES_IN_RENDER_TARGET]u32
|
||||
attachment_count := i32(0)
|
||||
for i in 0..<len(rt.color_textures) {
|
||||
attachments[i] = gl.COLOR_ATTACHMENT0 + u32(i)
|
||||
attachment_count += 1
|
||||
}
|
||||
gl.DrawBuffers(attachment_count, &attachments[0])
|
||||
|
||||
|
||||
if rt.depth_texture != nil {
|
||||
gl.FramebufferTexture2D(
|
||||
@@ -556,13 +574,71 @@ when RENDER_BACKEND_OPENGL {
|
||||
return true
|
||||
}
|
||||
|
||||
opengl_set_shader_value_texture :: proc(program: ^Shader_Program, value: ^Texture, index: u8) {
|
||||
opengl_destroy_render_target :: proc(renderer: ^Renderer, render_target: ^Render_Target) {
|
||||
gl.DeleteFramebuffers(1, &render_target.backend.handle)
|
||||
}
|
||||
|
||||
|
||||
opengl_set_shader_uniform_texture :: proc(program: ^Shader_Program, uniform: Uniform_Texture) -> bool {
|
||||
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))
|
||||
i := uniform.index
|
||||
|
||||
gl.ActiveTexture(gl.TEXTURE0 + u32(i))
|
||||
gl.BindTexture(gl.TEXTURE_2D, uniform.value.backend.handle)
|
||||
loc := gl.GetUniformLocation(program.backend.handle, fmt.ctprintf("texture%d", i))
|
||||
if loc < 0 {
|
||||
fmt.printfln("texture Loc: %v", loc)
|
||||
return false
|
||||
}
|
||||
|
||||
gl.Uniform1i(loc, i32(i))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
opengl_set_shader_uniform_float :: proc(program: ^Shader_Program, uniform: Uniform_Float) -> bool {
|
||||
gl.UseProgram(program.backend.handle)
|
||||
|
||||
loc := gl.GetUniformLocation(program.backend.handle, fmt.ctprintf("%v", uniform.name))
|
||||
if loc < 0 {
|
||||
fmt.printfln("float Loc: %v", loc)
|
||||
return false
|
||||
}
|
||||
|
||||
gl.Uniform1f(loc, uniform.value^)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// TODO: SS - This procedure and _float ^^ are very similar and will do pretty much the same thing but with calls to different gl.Uniform-- procedures. Make it generic instead then switch on the type?
|
||||
opengl_set_shader_uniform_matrix4f32 :: proc(program: ^Shader_Program, uniform: Uniform_Matrix4f32) -> bool {
|
||||
gl.UseProgram(program.backend.handle)
|
||||
|
||||
loc := gl.GetUniformLocation(program.backend.handle, fmt.ctprintf("%v", uniform.name))
|
||||
if loc < 0 {
|
||||
fmt.printfln("matrixf32 loc: %v", loc)
|
||||
return false
|
||||
}
|
||||
|
||||
data := transmute([16]f32)(uniform.value^)
|
||||
gl.UniformMatrix4fv(loc, 1, gl.FALSE, &data[0])
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
opengl_set_shader_uniform_vector3 :: proc(program: ^Shader_Program, uniform: Uniform_Vector3) -> bool {
|
||||
gl.UseProgram(program.backend.handle)
|
||||
|
||||
loc := gl.GetUniformLocation(program.backend.handle, fmt.ctprintf("%v", uniform.name))
|
||||
if loc < 0 {
|
||||
fmt.printfln("vector3 Loc: %v", loc)
|
||||
return false
|
||||
}
|
||||
|
||||
gl.Uniform3fv(loc, 1, &uniform.value[0])
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user