From f0e8af534db8fd25a97a58b57a625e478af6597d Mon Sep 17 00:00:00 2001 From: Slendi Date: Sat, 6 Dec 2025 20:11:59 +0200 Subject: [PATCH] Add fastgltf, mouse capture Signed-off-by: Slendi --- .gitmodules | 3 +++ meson.build | 14 +++++++++++++- src/Application.cpp | 34 +++++++++++++++++++++++++--------- src/Application.h | 5 +++++ subprojects/.wraplock | 0 subprojects/fastgltf | 1 + thirdparty/.wraplock | 0 7 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 subprojects/.wraplock create mode 160000 subprojects/fastgltf create mode 100644 thirdparty/.wraplock diff --git a/.gitmodules b/.gitmodules index f3c5f75..6571d42 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "thirdparty/smath"] path = thirdparty/smath url = https://github.com/slendidev/smath.git +[submodule "subprojects/fastgltf"] + path = subprojects/fastgltf + url = https://github.com/spnda/fastgltf.git diff --git a/meson.build b/meson.build index 6576d57..7578700 100644 --- a/meson.build +++ b/meson.build @@ -4,9 +4,18 @@ project('vr-compositor', 'cpp', 'cpp_std=c++26', 'warning_level=everything', 'werror=true', - ] + ], + subproject_dir: 'subprojects', ) +cmake = import('cmake') + +fastgltf_opts = cmake.subproject_options() +fastgltf_opts.set_override_option('cpp_std', 'c++23') +fastgltf_opts.set_override_option('warning_level', '0') +fastgltf_opts.set_override_option('werror', 'false') +fastgltf = cmake.subproject('fastgltf', options: fastgltf_opts) + cc = meson.get_compiler('cpp') wayland_dep = dependency('wayland-server') @@ -22,6 +31,7 @@ imgui_src = files( 'thirdparty/imgui/backends/imgui_impl_vulkan.cpp', 'thirdparty/imgui/backends/imgui_impl_sdl3.cpp', ) +fastgltf_dep = fastgltf.dependency('fastgltf') vkbootstrap_dev = get_option('vkbootstrap_dev') vkbootstrap_lib = get_option('vkbootstrap_lib') @@ -49,6 +59,7 @@ add_project_arguments( '-Wno-old-style-cast', '-Wno-implicit-int-float-conversion', '-Wno-implicit-float-conversion', + '-Wno-c++98-compat', ], language : 'cpp' ) @@ -104,6 +115,7 @@ exe = executable('vr-compositor', vkbootstrap_dep, zlib_dep, sdl3_dep, + fastgltf_dep, ], cpp_args: [ '--embed-dir=' + join_paths(meson.project_build_root(), 'shaders') diff --git a/src/Application.cpp b/src/Application.cpp index 4ab7b49..5a97d18 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -33,6 +33,8 @@ Application::Application() m_renderer = std::make_unique(m_window, m_logger); + mouse_captured(true); + m_logger.info("App init done!"); } @@ -71,6 +73,11 @@ auto Application::run() -> void SDL_GetWindowSize(m_window, &width, &height); m_renderer->resize(static_cast(width), static_cast(height)); + } else if (e.type == SDL_EVENT_KEY_DOWN && e.key.repeat == false) { + if (e.key.key == SDLK_F11 && e.key.mod & SDL_KMOD_LCTRL) { + mouse_captured(!mouse_captured()); + m_show_imgui = mouse_captured(); + } } ImGui_ImplSDL3_ProcessEvent(&e); @@ -81,18 +88,20 @@ auto Application::run() -> void ImGui::NewFrame(); - ImGui::ShowDemoWindow(); + if (m_show_imgui) { + ImGui::ShowDemoWindow(); - ImGui::SetNextWindowSize({ 100, 50 }); - ImGui::SetNextWindowPos({ 0, 0 }); - ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 { 0, 0, 0, 0.5f }); - if (ImGui::Begin("Debug Info", nullptr, - ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize)) { - defer(ImGui::End()); + ImGui::SetNextWindowSize({ 100, 50 }); + ImGui::SetNextWindowPos({ 0, 0 }); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4 { 0, 0, 0, 0.5f }); + if (ImGui::Begin("Debug Info", nullptr, + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize)) { + defer(ImGui::End()); - ImGui::Text("%s", std::format("FPS: {:.2f}", fps).c_str()); + ImGui::Text("%s", std::format("FPS: {:.2f}", fps).c_str()); + } + ImGui::PopStyleColor(); } - ImGui::PopStyleColor(); ImGui::Render(); @@ -100,4 +109,11 @@ auto Application::run() -> void } } +auto Application::mouse_captured(bool new_state) -> void +{ + SDL_CaptureMouse(new_state); + + m_mouse_captured = new_state; +} + } // namespace Lunar diff --git a/src/Application.h b/src/Application.h index 3acfbe6..fdcd2c9 100644 --- a/src/Application.h +++ b/src/Application.h @@ -17,6 +17,9 @@ struct Application { ~Application(); auto run() -> void; + auto mouse_captured(bool new_state) -> void; + auto mouse_captured() const -> bool { return m_mouse_captured; } + auto toggle_mouse_captured() -> void { mouse_captured(!m_mouse_captured); } private: SDL_Window *m_window { nullptr }; @@ -24,6 +27,8 @@ private: std::unique_ptr m_renderer; bool m_running { true }; + bool m_mouse_captured { false }; + bool m_show_imgui { false }; }; } // namespace Lunar diff --git a/subprojects/.wraplock b/subprojects/.wraplock new file mode 100644 index 0000000..e69de29 diff --git a/subprojects/fastgltf b/subprojects/fastgltf new file mode 160000 index 0000000..d3d6ee6 --- /dev/null +++ b/subprojects/fastgltf @@ -0,0 +1 @@ +Subproject commit d3d6ee651f878347e29352000a1f0fa1324236b4 diff --git a/thirdparty/.wraplock b/thirdparty/.wraplock new file mode 100644 index 0000000..e69de29