75 ); |
75 ); |
76 window->resized = true; // count initial sizing as resize |
76 window->resized = true; // count initial sizing as resize |
77 |
77 |
78 if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { |
78 if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { |
79 asc_scene_init(&window->ui); |
79 asc_scene_init(&window->ui); |
80 asc_dprintf("Window %u initialized", window->id); |
80 asc_dprintf("Window %u initialized at index %u", window->id, index); |
81 asc_context.active_window = index; |
81 asc_context.active_window = index; |
82 } else { |
82 } else { |
83 asc_error("Creating GL context failed for window %u", window->id); |
83 asc_error("Creating GL context failed for window %u at index %u", window->id, index); |
84 // cleanup on error |
84 // cleanup on error |
85 SDL_DestroyWindow(window->window); |
85 SDL_DestroyWindow(window->window); |
86 window->window = NULL; |
86 window->window = NULL; |
87 window->id = 0; |
87 window->id = 0; |
88 } |
88 } |
102 |
102 |
103 // for releasing OpenGL resources, we need to make the context current |
103 // for releasing OpenGL resources, we need to make the context current |
104 asc_gl_context_activate(&window->glctx); |
104 asc_gl_context_activate(&window->glctx); |
105 |
105 |
106 // destroy all scenes |
106 // destroy all scenes |
|
107 for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) { |
|
108 asc_scene_destroy(&window->scenes[i]); |
|
109 } |
107 asc_scene_destroy(&window->ui); |
110 asc_scene_destroy(&window->ui); |
108 |
111 |
109 // release context related data |
112 // release context related data |
110 asc_gl_context_destroy(&window->glctx); |
113 asc_gl_context_destroy(&window->glctx); |
111 |
114 |
123 asc_dprintf("Window %u and its OpenGL context destroyed.", window->id); |
126 asc_dprintf("Window %u and its OpenGL context destroyed.", window->id); |
124 memset(window, 0, sizeof(AscWindow)); |
127 memset(window, 0, sizeof(AscWindow)); |
125 } |
128 } |
126 |
129 |
127 void asc_window_sync(unsigned int index) { |
130 void asc_window_sync(unsigned int index) { |
|
131 if (index > ASC_MAX_WINDOWS) { |
|
132 asc_error("Index for syncing window out of bounds (%u/%u).", index, ASC_MAX_WINDOWS); |
|
133 return; |
|
134 } |
|
135 AscWindow *window = &asc_context.windows[index]; |
128 // necessary safeguard |
136 // necessary safeguard |
129 if (asc_context.windows[index].id == 0) return; |
137 if (window->id == 0) return; |
130 |
138 |
131 // active the window that shall be synced temporarily |
139 // active the window that shall be synced temporarily |
132 unsigned int active_index = asc_context.active_window; |
140 unsigned int active_index = asc_context.active_window; |
133 if (index != active_index) { |
141 if (index != active_index) { |
134 asc_window_activate(index); |
142 asc_window_activate(index); |
135 } |
143 } |
136 |
144 |
137 // Clear the color buffer for the window frame |
145 // Clear the color buffer for the window frame |
138 int window_width = asc_active_window->dimensions.width; |
146 int window_width = window->dimensions.width; |
139 int window_height = asc_active_window->dimensions.height; |
147 int window_height = window->dimensions.height; |
140 glViewport(0, 0, window_width, window_height); |
148 glViewport(0, 0, window_width, window_height); |
141 glClear(GL_COLOR_BUFFER_BIT); |
149 glClear(GL_COLOR_BUFFER_BIT); |
142 |
150 |
143 // Draw the UI |
151 // Draw all scenes |
144 AscScene *ui = &asc_active_window->ui; |
|
145 asc_recti viewport = {0, 0, window_width, window_height}; |
152 asc_recti viewport = {0, 0, window_width, window_height}; |
146 asc_camera_ortho(&ui->camera, viewport); |
153 for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) { |
147 asc_scene_draw(ui, viewport); |
154 asc_scene_draw(&window->scenes[i], viewport); |
|
155 } |
|
156 asc_camera_ortho(&window->ui.camera, viewport); |
|
157 asc_scene_draw(&window->ui, viewport); |
148 |
158 |
149 // Swap Buffers |
159 // Swap Buffers |
150 SDL_GL_SwapWindow(asc_active_window->window); |
160 SDL_GL_SwapWindow(window->window); |
151 |
161 |
152 // Clear Flags |
162 // Clear Flags |
153 asc_active_window->resized = false; |
163 window->resized = false; |
154 |
164 |
155 if (index != active_index) { |
165 if (index != active_index) { |
156 asc_window_activate(active_index); |
166 asc_window_activate(active_index); |
157 } |
167 } |
158 } |
168 } |