From 91f66ef952a40693662448bf161a351b21ecee53 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 11 Nov 2018 05:41:03 -0500 Subject: [PATCH] Only use imgui in debug builds --- CMakeLists.txt | 20 +++++++++++++++++--- include/renderer.h | 2 ++ src/main.cpp | 11 +++++++++-- src/renderer.cpp | 20 +++++++++++++------- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74afdb6..7dbb5bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,16 +44,25 @@ IMPORTED_LOCATION ${ASSIMP_IMPORTED_PATH}) INTERFACE_INCLUDE_DIRECTORIES ${ASSIMP_INCLUDE_DIRS}) endif() -add_executable(Graph +set(GRAPH_SRC src/main.cpp src/renderer.cpp src/worldpass.cpp src/postpass.cpp src/dofpass.cpp - src/imguipass.cpp src/skypass.cpp src/shadowpass.cpp src/config.cpp) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(GRAPH_SRC + ${GRAPH_SRC} + src/imguipass.cpp) +endif() + +add_executable(Graph + ${GRAPH_SRC}) + target_compile_options(Graph PUBLIC -fno-exceptions @@ -64,8 +73,13 @@ target_link_libraries(Graph Vulkan::Vulkan assimp::assimp nlohmann::json - stb::stb + stb::stb) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + target_link_libraries(Graph + PUBLIC imgui::imgui) +endif() target_include_directories(Graph PUBLIC diff --git a/include/renderer.h b/include/renderer.h index e6abba0..3134a3a 100644 --- a/include/renderer.h +++ b/include/renderer.h @@ -188,7 +188,9 @@ private: WorldPass* worldPass_ = nullptr; PostPass* postPass_ = nullptr; DoFPass* dofPass_ = nullptr; +#ifdef DEBUG ImGuiPass* imguiPass_ = nullptr; +#endif SkyPass* skyPass_ = nullptr; ShadowPass* shadowPass_ = nullptr; }; diff --git a/src/main.cpp b/src/main.cpp index cac1273..aeffffd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -221,13 +221,15 @@ int main(int argc, char* argv[]) { SDL_SetWindowFullscreen(window, windowFullscreen == 1 ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); +#ifdef DEBUG ImGui::CreateContext(); auto& io = ImGui::GetIO(); io.DisplaySize = ImVec2(windowWidth, windowHeight); ImGui::StyleColorsDark(); - +#endif + renderer = new Renderer(graphicsConfig); VkSurfaceKHR surface = nullptr; @@ -272,8 +274,10 @@ int main(int argc, char* argv[]) { if(event.type == SDL_WINDOWEVENT) { if(event.window.event == SDL_WINDOWEVENT_RESIZED) { +#ifdef DEBUG io.DisplaySize = ImVec2(event.window.data1, event.window.data2); - +#endif + target = renderer->createSurfaceRenderTarget(surface, target); } } @@ -349,6 +353,7 @@ int main(int argc, char* argv[]) { const float deltaTime = currentTime - lastTime; lastTime = currentTime; +#ifdef DEBUG ImGui::NewFrame(); io.DeltaTime = deltaTime; @@ -370,6 +375,8 @@ int main(int argc, char* argv[]) { ImGui::Text("dpack[2] = %f", (100 - camera.focusDistance) / 100.0f); ImGui::Render(); +#endif + renderer->render(world, camera, target); if(cinematicMode) { diff --git a/src/renderer.cpp b/src/renderer.cpp index 271841a..6e07f1a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -30,7 +30,9 @@ Renderer::Renderer(GraphicsConfig config) : config_(config) { worldPass_ = new WorldPass(*this); postPass_ = new PostPass(*this); dofPass_ = new DoFPass(*this); +#ifdef DEBUG imguiPass_ = new ImGuiPass(*this); +#endif skyPass_ = new SkyPass(*this); } @@ -38,7 +40,9 @@ Renderer::~Renderer() { vkDeviceWaitIdle(device_); delete skyPass_; +#ifdef DEBUG delete imguiPass_; +#endif delete dofPass_; delete postPass_; delete worldPass_; @@ -127,7 +131,9 @@ void Renderer::render(World& world, Camera& camera, RenderTarget* target) { vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); postPass_->render(commandBuffer, target); +#ifdef DEBUG imguiPass_->render(commandBuffer, target); +#endif vkCmdEndRenderPass(commandBuffer); @@ -1155,39 +1161,39 @@ void Renderer::destroyMeshBuffers(Mesh* mesh) { } void Renderer::createInstance() { + std::vector enabledLayers; +#ifdef DEBUG uint32_t layerCount = 0; vkEnumerateInstanceLayerProperties(&layerCount, nullptr); auto availableLayers = new VkLayerProperties[layerCount]; vkEnumerateInstanceLayerProperties(&layerCount, availableLayers); - std::vector enabledLayers; -#ifdef DEBUG for(uint32_t i = 0; i < layerCount; i++) { if(strcmp(availableLayers[i].layerName, "VK_LAYER_LUNARG_standard_validation") == 0) enabledLayers.push_back("VK_LAYER_LUNARG_standard_validation"); } + + delete[] availableLayers; #endif - delete[] availableLayers; - + std::vector enabledExtensions; +#ifdef DEBUG uint32_t extensionCount = 0; vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); auto availableExtensions = new VkExtensionProperties[extensionCount]; vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, availableExtensions); - std::vector enabledExtensions; -#ifdef DEBUG for(uint32_t i = 0; i < extensionCount; i++) { if(strcmp(availableExtensions[i].extensionName, "VK_EXT_debug_utils") == 0) { enabledExtensions.push_back("VK_EXT_debug_utils"); enableDebug = true; } } -#endif delete[] availableExtensions; +#endif auto requiredExtensions = platform::getRequiredExtensions(); enabledExtensions.insert(enabledExtensions.end(), requiredExtensions.begin(), requiredExtensions.end());