The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

u/debug_gui: Refactor loop

+78 -49
+78 -49
src/xrt/auxiliary/util/u_debug_gui.c
··· 78 78 79 79 bool sdl_initialized; 80 80 char layout_file[1024]; 81 + 82 + #ifdef XRT_BUILD_DRIVER_QWERTY 83 + bool qwerty_enabled; 84 + #endif 81 85 }; 82 86 83 87 struct gui_imgui ··· 144 148 } 145 149 146 150 static void 151 + sdl2_loop_events(struct u_debug_gui *p) 152 + { 153 + SDL_Event event; 154 + 155 + while (SDL_PollEvent(&event)) { 156 + igImGui_ImplSDL2_ProcessEvent(&event); 157 + 158 + #ifdef XRT_BUILD_DRIVER_QWERTY 159 + // Caution here, qwerty driver is being accessed by the main thread as well 160 + if (p->qwerty_enabled) { 161 + qwerty_process_event(p->base.xsysd->xdevs, p->base.xsysd->xdev_count, event); 162 + } 163 + #endif 164 + 165 + if (event.type == SDL_QUIT) { 166 + p->base.stopped = true; 167 + } 168 + 169 + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && 170 + event.window.windowID == SDL_GetWindowID(p->win)) { 171 + p->base.stopped = true; 172 + } 173 + } 174 + } 175 + 176 + static void 177 + sdl2_loop_new_frame(struct u_debug_gui *p) 178 + { 179 + // Start the Dear ImGui frame 180 + igImGui_ImplOpenGL3_NewFrame(); 181 + igImGui_ImplSDL2_NewFrame(p->win); 182 + 183 + // Start new frame. 184 + igNewFrame(); 185 + } 186 + 187 + static void 188 + sdl2_loop_show_scene(struct u_debug_gui *p, struct gui_imgui *gui) 189 + { 190 + // Render the scene into it. 191 + gui_scene_manager_render(&p->base); 192 + 193 + // Handle this here. 194 + if (gui->show_imgui_demo) { 195 + igShowDemoWindow(&gui->show_imgui_demo); 196 + } 197 + 198 + // Handle this here. 199 + if (gui->show_implot_demo) { 200 + ImPlot_ShowDemoWindow(&gui->show_implot_demo); 201 + } 202 + } 203 + 204 + static void 205 + sdl2_loop_render(struct u_debug_gui *p, struct gui_imgui *gui, ImGuiIO *io) 206 + { 207 + // Build the DrawData (EndFrame). 208 + igRender(); 209 + 210 + // Clear the background. 211 + glViewport(0, 0, (int)io->DisplaySize.x, (int)io->DisplaySize.y); 212 + glClearColor(gui->clear.r, gui->clear.g, gui->clear.b, 1.0f); 213 + glClear(GL_COLOR_BUFFER_BIT); 214 + 215 + igImGui_ImplOpenGL3_RenderDrawData(igGetDrawData()); 216 + } 217 + 218 + static void 147 219 sdl2_loop(struct u_debug_gui *p) 148 220 { 149 221 // Need to call this before any other Imgui call. ··· 177 249 178 250 #ifdef XRT_BUILD_DRIVER_QWERTY 179 251 // Setup qwerty driver usage 180 - bool qwerty_enabled = debug_get_bool_option_qwerty_enable(); 252 + p->qwerty_enabled = debug_get_bool_option_qwerty_enable(); 181 253 #endif 182 254 183 255 // Main loop ··· 192 264 u_var_add_bool(&gui, &p->base.stopped, "Exit"); 193 265 194 266 while (!p->base.stopped) { 195 - SDL_Event event; 196 - 197 - while (SDL_PollEvent(&event)) { 198 - igImGui_ImplSDL2_ProcessEvent(&event); 267 + sdl2_loop_events(p); 199 268 200 - #ifdef XRT_BUILD_DRIVER_QWERTY 201 - // Caution here, qwerty driver is being accessed by the main thread as well 202 - if (qwerty_enabled) { 203 - qwerty_process_event(p->base.xsysd->xdevs, p->base.xsysd->xdev_count, event); 204 - } 205 - #endif 269 + sdl2_loop_new_frame(p); 206 270 207 - if (event.type == SDL_QUIT) { 208 - p->base.stopped = true; 209 - } 271 + sdl2_loop_show_scene(p, &gui); 210 272 211 - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && 212 - event.window.windowID == SDL_GetWindowID(p->win)) { 213 - p->base.stopped = true; 214 - } 215 - } 216 - 217 - // Start the Dear ImGui frame 218 - igImGui_ImplOpenGL3_NewFrame(); 219 - igImGui_ImplSDL2_NewFrame(p->win); 220 - 221 - // Start new frame. 222 - igNewFrame(); 223 - 224 - // Render the scene into it. 225 - gui_scene_manager_render(&p->base); 226 - 227 - // Handle this here. 228 - if (gui.show_imgui_demo) { 229 - igShowDemoWindow(&gui.show_imgui_demo); 230 - } 231 - 232 - // Handle this here. 233 - if (gui.show_implot_demo) { 234 - ImPlot_ShowDemoWindow(&gui.show_implot_demo); 235 - } 236 - 237 - // Build the DrawData (EndFrame). 238 - igRender(); 239 - 240 - // Clear the background. 241 - glViewport(0, 0, (int)io->DisplaySize.x, (int)io->DisplaySize.y); 242 - glClearColor(gui.clear.r, gui.clear.g, gui.clear.b, 1.0f); 243 - glClear(GL_COLOR_BUFFER_BIT); 244 - 245 - igImGui_ImplOpenGL3_RenderDrawData(igGetDrawData()); 273 + sdl2_loop_render(p, &gui, io); 246 274 247 275 SDL_GL_SwapWindow(p->win); 248 276 277 + // Update prober things. 249 278 gui_prober_update(&p->base); 250 279 } 251 280