From dc8e5a54831e062736007d08b0dfe44c3c25ac65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Con=C3=A1l?= Date: Tue, 20 Feb 2024 15:57:38 -0500 Subject: [PATCH] Added a simple visibility toggle command, fixed some bugs on linux --- CMakeLists.txt | 2 +- Renderer/Renderer.hpp | 4 +++- UI/UI.cpp | 38 ++++++++++++++++++-------------------- UI/UI.hpp | 18 +----------------- pléascach.cpp | 4 +--- 5 files changed, 24 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f572d7..c331f08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) if(WIN32) set(CMAKE_CXX_FLAGS "-D_DEBUG") else() -set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall") +set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall -O3") endif() project(Pleascach) diff --git a/Renderer/Renderer.hpp b/Renderer/Renderer.hpp index 3cf13ce..8c5da50 100644 --- a/Renderer/Renderer.hpp +++ b/Renderer/Renderer.hpp @@ -70,15 +70,17 @@ struct Renderer { Camera cam{ .pos = glm::vec3(0.0, 5.0, 0.0), }; + + float fps; bool capture_mouse = false; bool flycam = false; /* time speed */ float time = 0.0; float speed = 1.0; bool paused = false; + bool visibility_testing = false; size_t n_indices; - bool visibility_testing; float near_plane = 2.0f; float far_plane = 10000.0f; diff --git a/UI/UI.cpp b/UI/UI.cpp index fffd32a..2a2e861 100644 --- a/UI/UI.cpp +++ b/UI/UI.cpp @@ -21,18 +21,12 @@ static csys::ItemLog& operator<<(csys::ItemLog& log, ImVector& vec) { return log << vec[vec.size() - 1] << " }"; } -static void vec_setter(ImVector& v, std::vector in) { +/*static void vec_setter(ImVector& v, std::vector in) { v.reserve(in.size()); std::memcpy(v.Data, in.data(), sizeof(float) * in.size()); -} +}*/ -UI::UI(Renderer* ren) : - info { - .flycam = ren->flycam, .visibility_testing = ren->visibility_testing, - .time = ren->time, .cam = ren->cam, .tess_factor = ren->tess_factor, - .tess_edge_size = ren->tess_edge_size, .n_indices = ren->n_indices, - .near_plane = ren->near_plane, .far_plane = ren->far_plane, .paused = ren->paused - }, dev(ren->dev) { +UI::UI(Renderer* ren) : ren(ren), dev(ren->dev) { IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -107,8 +101,13 @@ UI::UI(Renderer* ren) : console = std::make_unique("developer console"); console->System().RegisterCommand("pause", "Pauses or unpauses the engine", [this]() { - this->info.paused = !this->info.paused; - console->System().Log(csys::ItemType::INFO) << "Paused: " << (this->info.paused? "True" : "False") << csys::endl; + this->ren->paused = !this->ren->paused; + console->System().Log(csys::ItemType::INFO) << "Paused: " << (this->ren->paused? "True" : "False") << csys::endl; + }); + + console->System().RegisterCommand("toggle-visibility-testing", "Toggles visibility testings (using clusters and frustum culling)", [this]() { + this->ren->visibility_testing = !this->ren->visibility_testing; + console->System().Log(csys::ItemType::INFO) << "Visibility Testing: " << (this->ren->visibility_testing? "Enabled" : "Disabled") << csys::endl; }); console->System().Log(csys::ItemType::INFO) << "Welcome to Pleascach!" << csys::endl; @@ -122,15 +121,14 @@ void UI::newFrame() { ImGui::SetNextWindowBgAlpha(0.5f); ImGui::Begin("Rendering Info", nullptr); - ImGui::Text("# of Indices: %zu", info.n_indices); - ImGui::Text("FPS: %f", info.fps); - ImGui::Text("Time: %f", info.time); - ImGui::Checkbox("Fly Camera", &info.flycam); - ImGui::Checkbox("Visibility Testing", &info.visibility_testing); - ImGui::SliderFloat("Near Plane", &info.near_plane, 0.00, 0.20); - ImGui::SliderFloat("Far Plane", &info.far_plane, 1000.0, 10000.0); - ImGui::SliderFloat("Tessellation Factor", &info.tess_factor, 0.1, 10.0); - ImGui::SliderFloat("Edge Size", &info.tess_edge_size, 0.0, 40.0); + ImGui::Text("# of Indices: %zu", ren->n_indices); + ImGui::Text("FPS: %f", ren->fps); + ImGui::Text("Time: %f", ren->time); + ImGui::Checkbox("Fly Camera", &ren->flycam); + ImGui::SliderFloat("Near Plane", &ren->near_plane, 0.00, 0.20); + ImGui::SliderFloat("Far Plane", &ren->far_plane, 1000.0, 10000.0); + ImGui::SliderFloat("Tessellation Factor", &ren->tess_factor, 0.1, 10.0); + ImGui::SliderFloat("Edge Size", &ren->tess_edge_size, 0.0, 40.0); console->Draw(); diff --git a/UI/UI.hpp b/UI/UI.hpp index 059f2a9..78e2554 100644 --- a/UI/UI.hpp +++ b/UI/UI.hpp @@ -13,23 +13,7 @@ struct Renderer; struct Camera; struct UI { - struct UI_Info { - float fps = 0.0; - bool& flycam; - bool& visibility_testing; - float& time; - /* camera stuff */ - Camera& cam; - float& tess_factor; - float& tess_edge_size; - const size_t& n_indices; - float& near_plane; - float& far_plane; - bool& paused; - } info; - - - + Renderer* ren; vk::Device dev; vk::DescriptorPool desc_pool; diff --git a/pléascach.cpp b/pléascach.cpp index ad59321..d09e5c5 100644 --- a/pléascach.cpp +++ b/pléascach.cpp @@ -69,8 +69,6 @@ int main(int argc, char* argv[]) { ren.speed *= 10.0; } else if (event.key.key == GLFW_KEY_Y && event.key.state == GLFW_PRESS) { ren.speed /= 10.0; - } else if (event.key.key == GLFW_KEY_V && event.key.state == GLFW_PRESS) { - ren.visibility_testing = !ren.visibility_testing; } break; } @@ -79,7 +77,7 @@ int main(int argc, char* argv[]) { ren.draw(); ren.present(); const auto t = frame_timer.read(); - ren.ui->info.fps = 1000.0f / t; + ren.fps = 1000.0f / t; while (frame_timer.read() < 16.60) ;