src/window.c

changeset 96
9e25f080a33e
parent 95
622887f7e954
--- a/src/window.c	Thu Apr 24 19:53:40 2025 +0200
+++ b/src/window.c	Fri Apr 25 18:38:08 2025 +0200
@@ -77,10 +77,10 @@
 
     if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) {
         asc_scene_init(&window->ui);
-        asc_dprintf("Window %u initialized", window->id);
+        asc_dprintf("Window %u initialized at index %u", window->id, index);
         asc_context.active_window = index;
     } else {
-        asc_error("Creating GL context failed for window %u", window->id);
+        asc_error("Creating GL context failed for window %u at index %u", window->id, index);
         // cleanup on error
         SDL_DestroyWindow(window->window);
         window->window = NULL;
@@ -104,6 +104,9 @@
     asc_gl_context_activate(&window->glctx);
 
     // destroy all scenes
+    for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) {
+        asc_scene_destroy(&window->scenes[i]);
+    }
     asc_scene_destroy(&window->ui);
 
     // release context related data
@@ -125,8 +128,13 @@
 }
 
 void asc_window_sync(unsigned int index) {
+    if (index > ASC_MAX_WINDOWS) {
+        asc_error("Index for syncing window out of bounds (%u/%u).", index, ASC_MAX_WINDOWS);
+        return;
+    }
+    AscWindow *window = &asc_context.windows[index];
     // necessary safeguard
-    if (asc_context.windows[index].id == 0) return;
+    if (window->id == 0) return;
 
     // active the window that shall be synced temporarily
     unsigned int active_index = asc_context.active_window;
@@ -135,22 +143,24 @@
     }
 
     // Clear the color buffer for the window frame
-    int window_width = asc_active_window->dimensions.width;
-    int window_height = asc_active_window->dimensions.height;
+    int window_width = window->dimensions.width;
+    int window_height = window->dimensions.height;
     glViewport(0, 0, window_width, window_height);
     glClear(GL_COLOR_BUFFER_BIT);
 
-    // Draw the UI
-    AscScene *ui = &asc_active_window->ui;
+    // Draw all scenes
     asc_recti viewport = {0, 0, window_width, window_height};
-    asc_camera_ortho(&ui->camera, viewport);
-    asc_scene_draw(ui, viewport);
+    for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) {
+        asc_scene_draw(&window->scenes[i], viewport);
+    }
+    asc_camera_ortho(&window->ui.camera, viewport);
+    asc_scene_draw(&window->ui, viewport);
 
     // Swap Buffers
-    SDL_GL_SwapWindow(asc_active_window->window);
+    SDL_GL_SwapWindow(window->window);
 
     // Clear Flags
-    asc_active_window->resized = false;
+    window->resized = false;
 
     if (index != active_index) {
         asc_window_activate(active_index);
@@ -173,3 +183,7 @@
 void asc_add_ui_node(AscSceneNode *node) {
     asc_scene_add_node(&asc_active_window->ui, node);
 }
+
+AscScene *asc_window_scene(unsigned int index) {
+    return &asc_active_window->scenes[index];
+}

mercurial