src/window.c

changeset 288
8796f03aac26
parent 287
359eaf2a8bd2
equal deleted inserted replaced
287:359eaf2a8bd2 288:8796f03aac26
67 if (asc_gl_context_initialize(&window->glctx, window->window, &settings)) { 67 if (asc_gl_context_initialize(&window->glctx, window->window, &settings)) {
68 char ui_scene_name[16]; 68 char ui_scene_name[16];
69 snprintf(ui_scene_name, sizeof(ui_scene_name), "Window %u UI", index); 69 snprintf(ui_scene_name, sizeof(ui_scene_name), "Window %u UI", index);
70 asc_camera_init(&window->ui_camera, .type = ASC_CAMERA_ORTHO, 70 asc_camera_init(&window->ui_camera, .type = ASC_CAMERA_ORTHO,
71 .ortho.rect = ASC_RECT(0, 0, window->dimensions.width, window->dimensions.height), 71 .ortho.rect = ASC_RECT(0, 0, window->dimensions.width, window->dimensions.height),
72 .projection_update_func = asc_camera_ortho_update_size); 72 .viewport_update_func = asc_camera_ortho_update_size);
73 asc_scene_init(&window->ui, ui_scene_name, &window->ui_camera); 73 asc_scene_init(&window->ui, ui_scene_name, &window->ui_camera);
74 asc_dprintf("Window %u initialized at index %u", window->id, index); 74 asc_dprintf("Window %u initialized at index %u", window->id, index);
75 asc_context.active_window = index; 75 asc_context.active_window = index;
76 } else { 76 } else {
77 asc_error("Creating GL context failed for window %u at index %u", window->id, index); 77 asc_error("Creating GL context failed for window %u at index %u", window->id, index);
119 // clean the data 119 // clean the data
120 asc_dprintf("Window %u and its OpenGL context destroyed.", window->id); 120 asc_dprintf("Window %u and its OpenGL context destroyed.", window->id);
121 memset(window, 0, sizeof(AscWindow)); 121 memset(window, 0, sizeof(AscWindow));
122 } 122 }
123 123
124 static void asc_window_update_viewport(AscCamera *camera, asc_vec2u window_size) {
125 if (camera->viewport_update_func == NULL) {
126 // this assumes the viewport was initialized with zeros!
127 camera->viewport.size = window_size;
128 } else {
129 camera->viewport_update_func(camera, window_size);
130 }
131 }
132
133 static void asc_window_update_camera(AscCamera *camera) {
134 if (camera->update_func != NULL) {
135 camera->update_func(camera);
136 }
137 }
138
124 void asc_window_sync(unsigned int index) { 139 void asc_window_sync(unsigned int index) {
125 if (index > ASC_MAX_WINDOWS) { 140 if (index > ASC_MAX_WINDOWS) {
126 asc_error("Index for syncing window out of bounds (%u/%u).", index, ASC_MAX_WINDOWS); 141 asc_error("Index for syncing window out of bounds (%u/%u).", index, ASC_MAX_WINDOWS);
127 return; 142 return;
128 } 143 }
144 159
145 // Update the viewports when the window resized 160 // Update the viewports when the window resized
146 if (window->resized) { 161 if (window->resized) {
147 for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) { 162 for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) {
148 if (asc_scene_active(&window->scenes[i])) { 163 if (asc_scene_active(&window->scenes[i])) {
149 asc_camera_update_viewport(window->scenes[i].camera, window->dimensions); 164 asc_window_update_viewport(window->scenes[i].camera, window->dimensions);
150 } 165 }
151 } 166 }
152 asc_camera_update_viewport(window->ui.camera, window->dimensions); 167 asc_window_update_viewport(window->ui.camera, window->dimensions);
153 } 168 }
169
170 // Execute camera updates
171 for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) {
172 if (asc_scene_active(&window->scenes[i])) {
173 asc_window_update_camera(window->scenes[i].camera);
174 }
175 }
176 asc_window_update_camera(window->ui.camera);
154 177
155 // Execute all behaviors 178 // Execute all behaviors
156 // TODO: this can eventually be parallelized 179 // TODO: this can eventually be parallelized
157 for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) { 180 for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) {
158 asc_scene_execute_behaviors(&window->scenes[i]); 181 asc_scene_execute_behaviors(&window->scenes[i]);

mercurial