summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx/src/renderer/renderer.c26
-rw-r--r--gltfview/src/game.c7
2 files changed, 22 insertions, 11 deletions
diff --git a/gfx/src/renderer/renderer.c b/gfx/src/renderer/renderer.c
index bddde90..ac6a45f 100644
--- a/gfx/src/renderer/renderer.c
+++ b/gfx/src/renderer/renderer.c
@@ -264,7 +264,10 @@ static void draw_recursively(
264 gfx_set_mat4_uniform(shader, "CameraRotation", state->camera_rotation); 264 gfx_set_mat4_uniform(shader, "CameraRotation", state->camera_rotation);
265 gfx_set_float_uniform(shader, "Fovy", state->fovy); 265 gfx_set_float_uniform(shader, "Fovy", state->fovy);
266 gfx_set_float_uniform(shader, "Aspect", state->aspect); 266 gfx_set_float_uniform(shader, "Aspect", state->aspect);
267 gfx_set_vec3_uniform(shader, "CameraPosition", state->camera->spatial.p); 267 if (state->camera) {
268 gfx_set_vec3_uniform(
269 shader, "CameraPosition", state->camera->spatial.p);
270 }
268 if (state->num_joints > 0) { 271 if (state->num_joints > 0) {
269 gfx_set_mat4_array_uniform( 272 gfx_set_mat4_array_uniform(
270 shader, "JointMatrices", state->joint_matrices, state->num_joints); 273 shader, "JointMatrices", state->joint_matrices, state->num_joints);
@@ -309,7 +312,6 @@ void gfx_render_scene(Renderer* renderer, const RenderSceneParams* params) {
309 assert(renderer); 312 assert(renderer);
310 assert(params); 313 assert(params);
311 assert(params->scene); 314 assert(params->scene);
312 assert(params->camera);
313 315
314 ShaderProgram* const shader = load_shader(renderer, params->mode); 316 ShaderProgram* const shader = load_shader(renderer, params->mode);
315 317
@@ -318,11 +320,17 @@ void gfx_render_scene(Renderer* renderer, const RenderSceneParams* params) {
318 320
319 RenderBackend* render_backend = renderer->render_backend; 321 RenderBackend* render_backend = renderer->render_backend;
320 322
321 const mat4 projection = camera ? camera->camera.projection : mat4_id(); 323 mat4 projection, camera_rotation, view_matrix;
322 const mat4 camera_rotation = 324 if (camera) {
323 mat4_rotation(spatial3_transform(&camera->camera.spatial)); 325 projection = camera->camera.projection;
324 const mat4 view_matrix = 326 camera_rotation =
325 camera ? spatial3_inverse_transform(&camera->camera.spatial) : mat4_id(); 327 mat4_rotation(spatial3_transform(&camera->camera.spatial));
328 view_matrix = spatial3_inverse_transform(&camera->camera.spatial);
329 } else {
330 projection = mat4_id();
331 camera_rotation = mat4_id();
332 view_matrix = mat4_id();
333 }
326 334
327 int width, height; 335 int width, height;
328 gfx_get_viewport(render_backend, &width, &height); 336 gfx_get_viewport(render_backend, &width, &height);
@@ -341,8 +349,6 @@ void gfx_render_scene(Renderer* renderer, const RenderSceneParams* params) {
341 // Assuming a perspective matrix. 349 // Assuming a perspective matrix.
342 .fovy = atan(1.0 / (mat4_at(projection, 1, 1))) * 2, 350 .fovy = atan(1.0 / (mat4_at(projection, 1, 1))) * 2,
343 .aspect = aspect}; 351 .aspect = aspect};
344 352
345 gfx_start_frame(render_backend);
346 draw_recursively(&state, mat4_id(), scene->root); 353 draw_recursively(&state, mat4_id(), scene->root);
347 gfx_end_frame(render_backend);
348} 354}
diff --git a/gltfview/src/game.c b/gltfview/src/game.c
index d618447..5ca9ad4 100644
--- a/gltfview/src/game.c
+++ b/gltfview/src/game.c
@@ -130,7 +130,10 @@ void game_update(Game* game, double t, double dt) {
130} 130}
131 131
132void game_render(const Game* game) { 132void game_render(const Game* game) {
133 Renderer* renderer = gfx_get_renderer(game->gfx); 133 RenderBackend* render_backend = gfx_get_render_backend(game->gfx);
134 Renderer* renderer = gfx_get_renderer(game->gfx);
135
136 gfx_start_frame(render_backend);
134 137
135 gfx_render_scene( 138 gfx_render_scene(
136 renderer, 139 renderer,
@@ -142,6 +145,8 @@ void game_render(const Game* game) {
142 void* plugin_state = get_plugin_state(game->plugin); 145 void* plugin_state = get_plugin_state(game->plugin);
143 plugin_call(game->plugin, plugin_render, "render", plugin_state, game); 146 plugin_call(game->plugin, plugin_render, "render", plugin_state, game);
144 } 147 }
148
149 gfx_end_frame(render_backend);
145} 150}
146 151
147void game_set_viewport(Game* game, int width, int height) { 152void game_set_viewport(Game* game, int width, int height) {