src/scene.c

changeset 99
ac143db979dc
parent 96
9e25f080a33e
--- a/src/scene.c	Sun Apr 27 13:27:27 2025 +0200
+++ b/src/scene.c	Sun Apr 27 15:17:12 2025 +0200
@@ -57,23 +57,30 @@
     asc_scene_node_free(scene->root);
 }
 
-void asc_scene_draw(AscScene *scene, asc_recti viewport) {
+void asc_scene_draw(AscScene *scene) {
     if (scene->root == NULL) return;
 
+    // if the window resized, we must update the viewport
+    if (asc_active_window->resized) {
+        if (scene->camera.viewport_update_func == NULL) {
+            // this assumes the viewport was initialized with zeros!
+            scene->camera.viewport.size = asc_active_window->dimensions;
+        } else {
+            scene->camera.viewport = scene->camera.viewport_update_func(asc_active_window->dimensions);
+        }
+    }
+
     // create render groups
     CxList *render_group[ASC_RENDER_GROUP_COUNT];
     cx_for_n(i, ASC_RENDER_GROUP_COUNT) {
         render_group[i] = cxArrayListCreateSimple(CX_STORE_POINTERS, 32);
     }
 
-    // skip the root node deliberately; we know it's just the container
+    // update the scene graph and add nodes to their render groups
     CxTreeVisitor iter = cx_tree_visitor(scene->root,
-            offsetof(AscSceneNode, children),
-            offsetof(AscSceneNode, next)
+        offsetof(AscSceneNode, children),
+        offsetof(AscSceneNode, next)
     );
-    cxIteratorNext(iter);
-
-    // update the children and add them to the render groups
     cx_foreach(AscSceneNode*, node, iter) {
         node->depth = iter.depth;
 
@@ -126,10 +133,10 @@
 
     // set the viewport (in OpenGL we need to invert the Y axis)
     glViewport(
-            viewport.pos.x,
-            -viewport.pos.y,
-            viewport.size.width,
-            viewport.size.height
+            scene->camera.viewport.pos.x,
+            -scene->camera.viewport.pos.y,
+            scene->camera.viewport.size.width,
+            scene->camera.viewport.size.height
     );
 
     // -------------------------

mercurial