Added translations.
This commit is contained in:
@@ -15,6 +15,9 @@ Pass :: struct {
|
||||
Draw_Command :: struct {
|
||||
mesh: Mesh,
|
||||
material: Material,
|
||||
position: [3]f32,
|
||||
scale: [3]f32,
|
||||
// TODO: SS - Add rotation.
|
||||
}
|
||||
|
||||
add_command_to_pass :: proc(pass: ^Pass, command: Draw_Command) -> bool {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package renderer
|
||||
|
||||
import "core:math/linalg"
|
||||
import "core:fmt"
|
||||
import "core:log"
|
||||
|
||||
@@ -81,8 +82,23 @@ render_frame :: proc(renderer: ^Renderer) {
|
||||
|
||||
for i in 0..<pass.draw_command_count {
|
||||
command := &pass.draw_commands[i]
|
||||
|
||||
transform := linalg.identity(linalg.Matrix4x4f32)
|
||||
|
||||
activate_material(&command.material)
|
||||
scale := linalg.matrix4_scale(command.scale)
|
||||
rotation := linalg.matrix4_rotate(0, [3]f32 { 0, 0, 1 })
|
||||
translation := linalg.matrix4_translate(command.position)
|
||||
|
||||
// Scale.
|
||||
transform *= scale
|
||||
|
||||
// Rotate.
|
||||
transform *= rotation
|
||||
|
||||
// Translate.
|
||||
transform *= translation
|
||||
|
||||
activate_material(&command.material, transform)
|
||||
|
||||
draw_mesh(&command.mesh)
|
||||
}
|
||||
@@ -107,11 +123,11 @@ destroy :: proc(renderer: ^Renderer) {
|
||||
free(renderer)
|
||||
}
|
||||
|
||||
@(private) activate_material :: proc(material: ^Material) {
|
||||
@(private) activate_material :: proc(material: ^Material, transform: linalg.Matrix4x4f32) {
|
||||
assert(material != nil)
|
||||
|
||||
when RENDER_BACKEND_OPENGL {
|
||||
opengl_activate_material(material)
|
||||
opengl_activate_material(material, transform)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#+private
|
||||
package renderer
|
||||
|
||||
import "core:math/linalg"
|
||||
import "core:bytes"
|
||||
import "core:slice"
|
||||
import "core:image"
|
||||
@@ -238,11 +239,15 @@ when RENDER_BACKEND_OPENGL {
|
||||
gl.DeleteProgram(shader_program.backend.handle)
|
||||
}
|
||||
|
||||
opengl_activate_material :: proc(material: ^Material) {
|
||||
opengl_activate_material :: proc(material: ^Material, transform: linalg.Matrix4x4f32) {
|
||||
gl.UseProgram(material.shader_program.backend.handle)
|
||||
|
||||
|
||||
gl.ActiveTexture(gl.TEXTURE0)
|
||||
gl.BindTexture(gl.TEXTURE_2D, material.texture.backend.handle)
|
||||
|
||||
transform_loc := gl.GetUniformLocation(material.shader_program.backend.handle, "in_transform")
|
||||
transform_as_f32_array := transmute([16]f32)(transform)
|
||||
gl.UniformMatrix4fv(transform_loc, 1, false, &transform_as_f32_array[0])
|
||||
}
|
||||
|
||||
opengl_draw_mesh :: proc(mesh: ^Mesh) {
|
||||
|
||||
Reference in New Issue
Block a user