@@ -79,6 +79,23 @@ struct RenderPassKey {
7979 }
8080};
8181
82+ struct Resolution {
83+ int width;
84+ int height;
85+ const char * tag;
86+ };
87+
88+ std::vector<Resolution> preset_resolutions = {
89+ // clang-format off
90+ {640 , 480 , " 640 x 480 (480p)" },
91+ {800 , 600 , " 800 x 600" },
92+ {1280 , 720 , " 1280 x 720 (720p, HD)" },
93+ {1600 , 900 , " 1600 x 900" },
94+ {1920 , 1080 , " 1920 x 1080 (1080p, FHD)" },
95+ {2560 , 1440 , " 2560 x 1440 (1440p, QHD)" },
96+ // clang-format on
97+ };
98+
8299} // namespace
83100
84101class Engine ::Impl {
@@ -88,6 +105,11 @@ class Engine::Impl {
88105 GeometryShader,
89106 };
90107
108+ enum class DisplayMode {
109+ Windowed,
110+ WindowedFullscreen,
111+ };
112+
91113 public:
92114 Impl () {
93115 context_ = vk::Context (0 );
@@ -757,8 +779,7 @@ class Engine::Impl {
757779
758780 // draw ui
759781 {
760- viewer_.NewUiFrame ();
761- ImGui::NewFrame ();
782+ viewer_.BeginUi ();
762783
763784 const auto & io = ImGui::GetIO ();
764785
@@ -804,10 +825,68 @@ class Engine::Impl {
804825 if (ImGui::IsKeyDown (ImGuiKey_Space)) {
805826 camera_.Translate (0 .f , speed * dt);
806827 }
828+
829+ if (ImGui::IsKeyDown (ImGuiKey::ImGuiMod_Alt) && ImGui::IsKeyPressed (ImGuiKey_Enter, false )) {
830+ ToggleDisplayMode ();
831+ }
807832 }
808833
809834 if (ImGui::Begin (" vkgs" )) {
810835 ImGui::Text (" %s" , context_.device_name ().c_str ());
836+
837+ // Windowed or Windows Fullscreen
838+ std::vector<const char *> display_modes = {" Windowed" , " Windowed Fullscreen" };
839+ int display_mode_index = static_cast <int >(display_mode_);
840+ if (ImGui::Combo (" Display Mode" , &display_mode_index, display_modes.data (), display_modes.size ())) {
841+ switch (display_mode_index) {
842+ case 0 :
843+ SetWindowed ();
844+ break ;
845+ case 1 :
846+ SetWindowedFullscreen ();
847+ break ;
848+ }
849+ }
850+
851+ // Resolutions
852+ const auto [width, height] = viewer_.window_size ();
853+ std::string current_resolution;
854+ int resolution_index = 0 ;
855+ std::vector<const char *> resolutions;
856+ switch (display_mode_) {
857+ case DisplayMode::Windowed: {
858+ bool is_preset = false ;
859+ for (int i = 0 ; i < preset_resolutions.size (); ++i) {
860+ const auto & resolution = preset_resolutions[i];
861+ if (width == resolution.width && height == resolution.height ) {
862+ is_preset = true ;
863+ resolution_index = i;
864+ }
865+ resolutions.push_back (resolution.tag );
866+ }
867+
868+ if (!is_preset) {
869+ current_resolution = std::to_string (width) + " x " + std::to_string (height) + " (custom)" ;
870+ resolution_index = resolutions.size ();
871+ resolutions.push_back (current_resolution.c_str ());
872+ }
873+ } break ;
874+
875+ case DisplayMode::WindowedFullscreen:
876+ current_resolution = std::to_string (width) + " x " + std::to_string (height) + " (fullscreen)" ;
877+ resolution_index = resolutions.size ();
878+ resolutions.push_back (current_resolution.c_str ());
879+ break ;
880+ }
881+ ImGui::BeginDisabled (display_mode_index == 1 );
882+ if (ImGui::Combo (" Resolution" , &resolution_index, resolutions.data (), resolutions.size ())) {
883+ if (resolution_index < preset_resolutions.size ()) {
884+ const auto & resolution = preset_resolutions[resolution_index];
885+ viewer_.SetWindowSize (resolution.width , resolution.height );
886+ }
887+ }
888+ ImGui::EndDisabled ();
889+
811890 ImGui::Text (" %d total splats" , frame_info.total_point_count );
812891 ImGui::Text (" %d loaded splats" , frame_info.loaded_point_count );
813892
@@ -953,7 +1032,8 @@ class Engine::Impl {
9531032 ImGui::PopID ();
9541033 }
9551034 ImGui::End ();
956- ImGui::Render ();
1035+
1036+ viewer_.EndUi ();
9571037 }
9581038
9591039 model = ToScaleMatrix4 (scale_ * scale) * glm::toMat4 (gq) * ToTranslationMatrix4 (translation_ + gt) *
@@ -1437,6 +1517,33 @@ class Engine::Impl {
14371517 framebuffer_ = vk::Framebuffer (context_, framebuffer_info);
14381518 }
14391519
1520+ void ToggleDisplayMode () {
1521+ switch (display_mode_) {
1522+ case DisplayMode::Windowed:
1523+ SetWindowedFullscreen ();
1524+ break ;
1525+ case DisplayMode::WindowedFullscreen:
1526+ SetWindowed ();
1527+ break ;
1528+ }
1529+ }
1530+
1531+ void SetWindowed () {
1532+ if (display_mode_ == DisplayMode::WindowedFullscreen) {
1533+ display_mode_ = DisplayMode::Windowed;
1534+ viewer_.SetWindowed ();
1535+ }
1536+ }
1537+
1538+ void SetWindowedFullscreen () {
1539+ if (display_mode_ == DisplayMode::Windowed) {
1540+ display_mode_ = DisplayMode::WindowedFullscreen;
1541+ viewer_.SetWindowedFullscreen ();
1542+ }
1543+ }
1544+
1545+ DisplayMode display_mode_ = DisplayMode::Windowed;
1546+
14401547 std::atomic_bool terminate_ = false ;
14411548
14421549 std::mutex mutex_;
0 commit comments