The open source OpenXR runtime
0
fork

Configure Feed

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

t/gui: Add scene manager

authored by

Jakob Bornecrantz and committed by
Jakob Bornecrantz
71b3de9c c4741127

+149
+1
src/xrt/targets/gui/CMakeLists.txt
··· 18 18 gui_main.c 19 19 gui_ogl.c 20 20 gui_prober.c 21 + gui_scene.cpp 21 22 gui_sdl2.c 22 23 ../../../external/glad/gl.h 23 24 ../../../external/glad/gl.c
+52
src/xrt/targets/gui/gui_common.h
··· 28 28 struct xrt_device; 29 29 struct xrt_prober; 30 30 struct time_state; 31 + struct gui_scene_manager; 31 32 32 33 /*! 33 34 * Common struct holding state for the GUI interface. ··· 41 42 42 43 bool stopped; 43 44 bool initialized; 45 + 46 + struct gui_scene_manager *gsm; 44 47 45 48 struct 46 49 { ··· 57 60 struct xrt_prober *xp; 58 61 59 62 struct gui_ogl_texture *texs[256]; 63 + }; 64 + 65 + /*! 66 + * A single currently running scene. 67 + */ 68 + struct gui_scene 69 + { 70 + void (*render)(struct gui_scene *, struct program *); 71 + void (*destroy)(struct gui_scene *); 60 72 }; 61 73 62 74 /*! ··· 155 167 */ 156 168 void 157 169 gui_ogl_sink_update(struct gui_ogl_texture *); 170 + 171 + /*! 172 + * Push the scene to the top of the lists. 173 + * 174 + * @ingroup gui 175 + */ 176 + void 177 + gui_scene_push_front(struct program *p, struct gui_scene *me); 178 + 179 + /*! 180 + * Put a scene on the delete list, also removes it from any other list. 181 + * 182 + * @ingroup gui 183 + */ 184 + void 185 + gui_scene_delete_me(struct program *p, struct gui_scene *me); 186 + 187 + /*! 188 + * Render the scenes. 189 + * 190 + * @ingroup gui 191 + */ 192 + void 193 + gui_scene_manager_render(struct program *p); 194 + 195 + /*! 196 + * Initialize the scene manager. 197 + * 198 + * @ingroup gui 199 + */ 200 + void 201 + gui_scene_manager_init(struct program *p); 202 + 203 + /*! 204 + * Destroy the scene manager. 205 + * 206 + * @ingroup gui 207 + */ 208 + void 209 + gui_scene_manager_destroy(struct program *p); 158 210 159 211 160 212 #ifdef __cplusplus
+96
src/xrt/targets/gui/gui_scene.cpp
··· 1 + // Copyright 2019, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief SDL2 functions to drive the GUI. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup gui 8 + */ 9 + 10 + 11 + #include "gui_common.h" 12 + 13 + #include <vector> 14 + 15 + 16 + struct gui_scene_manager 17 + { 18 + public: 19 + std::vector<gui_scene *> scenes = {}; 20 + std::vector<gui_scene *> del = {}; 21 + }; 22 + 23 + extern "C" void 24 + gui_scene_push_front(struct program *p, struct gui_scene *me) 25 + { 26 + auto &gsm = *p->gsm; 27 + 28 + // Need to remove the scene if it is already on the list. 29 + auto index = gsm.scenes.begin(); 30 + for (auto scene : gsm.scenes) { 31 + if (scene != me) { 32 + index++; 33 + continue; 34 + } 35 + 36 + gsm.scenes.erase(index); 37 + break; 38 + } 39 + 40 + // Now push it to the front. 41 + gsm.scenes.push_back(me); 42 + } 43 + 44 + extern "C" void 45 + gui_scene_delete_me(struct program *p, struct gui_scene *me) 46 + { 47 + auto &gsm = *p->gsm; 48 + 49 + auto index = gsm.scenes.begin(); 50 + for (auto scene : gsm.scenes) { 51 + if (scene != me) { 52 + index++; 53 + continue; 54 + } 55 + 56 + gsm.scenes.erase(index); 57 + break; 58 + } 59 + 60 + gsm.del.push_back(me); 61 + } 62 + 63 + extern "C" void 64 + gui_scene_manager_render(struct program *p) 65 + { 66 + auto &gsm = *p->gsm; 67 + auto copy = gsm.scenes; 68 + 69 + for (auto scene : copy) { 70 + scene->render(scene, p); 71 + } 72 + 73 + copy = gsm.del; 74 + gsm.del.clear(); 75 + for (auto scene : copy) { 76 + scene->destroy(scene); 77 + } 78 + 79 + // If there are no scenes left stop the program. 80 + if (gsm.scenes.size() == 0) { 81 + p->stopped = true; 82 + } 83 + } 84 + 85 + extern "C" void 86 + gui_scene_manager_init(struct program *p) 87 + { 88 + p->gsm = new gui_scene_manager; 89 + } 90 + 91 + extern "C" void 92 + gui_scene_manager_destroy(struct program *p) 93 + { 94 + delete p->gsm; 95 + p->gsm = NULL; 96 + }