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