From 07a065ccb7e637472a1968d9edec0db7c3affe78 Mon Sep 17 00:00:00 2001 From: Jakub Domagala Date: Sun, 12 Nov 2023 23:57:23 +0100 Subject: [PATCH 1/2] [#146]: Add new UI option to render only selected render layer in Editor --- editor/editor.cpp | 28 ++++++++++++++++++++-------- editor/editor.hpp | 6 ++++++ editor/gui/editor_gui.cpp | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/editor/editor.cpp b/editor/editor.cpp index c0bcc56b..dbe49ed4 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -26,7 +26,7 @@ Editor::Editor(const glm::ivec2& screenSize) : gui_(*this) m_window = std::make_unique< renderer::Window >(screenSize, "Editor", true); InputManager::Init(m_window->GetWindowHandle()); - + renderer::VulkanRenderer::Initialize(m_window->GetWindowHandle(), renderer::ApplicationType::EDITOR); gui_.Init(); @@ -455,6 +455,19 @@ Editor::CheckIfObjectGotSelected(const glm::vec2& cursorPosition) } } +int32_t +Editor::GetRenderLayerToDraw() const +{ + return renderLayerToDraw_; +} + +void +Editor::SetRenderLayerToDraw(int32_t layer) +{ + renderLayerToDraw_ = layer; +} + + void Editor::SetupRendererData() { @@ -834,11 +847,11 @@ Editor::LoadLevel(const std::string& levelPath) { SCOPED_TIMER("Total level load"); - - m_levelFileName = levelPath; - m_currentLevel = std::make_shared< Level >(); - m_currentLevel->Load(this, levelPath); - + + m_levelFileName = levelPath; + m_currentLevel = std::make_shared< Level >(); + m_currentLevel->Load(this, levelPath); + SetupPathfinderNodes(); { @@ -875,9 +888,8 @@ Editor::LoadLevel(const std::string& levelPath) gui_.LevelLoaded(m_currentLevel); m_window->MakeFocus(); - } - + SetupRendererData(); } diff --git a/editor/editor.hpp b/editor/editor.hpp index 2d0f0062..d1bd6de9 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -168,6 +168,11 @@ class Editor : public Application bool IsAnyObjectSelected() const; + int32_t + GetRenderLayerToDraw() const; + + void SetRenderLayerToDraw(int32_t); + private: // [[nodiscard]] std::shared_ptr< EditorObject > // GetEditorObjectByID(Object::ID ID); @@ -253,6 +258,7 @@ class Editor : public Application bool m_drawGrid = false; int32_t m_gridCellSize = 128; + int32_t renderLayerToDraw_ = -1; // constructed in initializer list EditorGUI gui_; diff --git a/editor/gui/editor_gui.cpp b/editor/gui/editor_gui.cpp index 11ce30b7..a8c1606f 100644 --- a/editor/gui/editor_gui.cpp +++ b/editor/gui/editor_gui.cpp @@ -744,6 +744,24 @@ EditorGUI::RenderLevelMenu() // NOLINT } }); + CreateActionRowLabel("RenderLayer", [this] { + const auto items = std::to_array< std::string >( + {"All", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}); + const auto layer = parent_.GetRenderLayerToDraw(); + if (ImGui::BeginCombo( + "##combo", fmt::format("{}", layer == -1 ? "All" : std::to_string(layer)).c_str())) + { + for (const auto& item : items) + { + if (ImGui::Selectable(item.c_str())) + { + parent_.SetRenderLayerToDraw(item == "All" ? -1 : std::stoi(item)); + } + } + ImGui::EndCombo(); + } + }); + ImGui::EndTable(); } } From 8edaa9aedcd6cfa755801a5ffd558d967efa63a4 Mon Sep 17 00:00:00 2001 From: Jakub Domagala Date: Mon, 13 Nov 2023 00:03:18 +0100 Subject: [PATCH 2/2] [#146]: Implement logic to render selected layers in Editor --- editor/editor.cpp | 6 ++++-- editor/gui/editor_gui.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/editor/editor.cpp b/editor/editor.cpp index dbe49ed4..b6f5b549 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -593,8 +593,10 @@ Editor::Render(VkCommandBuffer cmdBuffer) { const auto idx = static_cast< size_t >(layer); const auto& numObjects = renderData.numMeshes.at(idx); - if (numObjects == 0 - or (idx == 9 and not m_renderPathfinderNodes) /* layer 9 means pathfinder nodes*/) + const auto renderThisLayer = renderLayerToDraw_ == -1 ? true : renderLayerToDraw_ == layer; + if (numObjects == 0 or !renderThisLayer + or (idx == 9 and not m_renderPathfinderNodes) /* layer 9 means pathfinder nodes*/ + ) { continue; } diff --git a/editor/gui/editor_gui.cpp b/editor/gui/editor_gui.cpp index a8c1606f..fefe3c0c 100644 --- a/editor/gui/editor_gui.cpp +++ b/editor/gui/editor_gui.cpp @@ -749,7 +749,8 @@ EditorGUI::RenderLevelMenu() // NOLINT {"All", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}); const auto layer = parent_.GetRenderLayerToDraw(); if (ImGui::BeginCombo( - "##combo", fmt::format("{}", layer == -1 ? "All" : std::to_string(layer)).c_str())) + "##combo", + fmt::format("{}", layer == -1 ? "All" : std::to_string(layer)).c_str())) { for (const auto& item : items) {