From 05927da1d4b9d8998a35ee3d3c951a2e20c66a75 Mon Sep 17 00:00:00 2001 From: connellpaxton Date: Thu, 22 Feb 2024 14:14:32 -0500 Subject: [PATCH] Made some more engine variables accessible to the console --- CMakeLists.txt | 4 ++-- Renderer/Pipeline.cpp | 7 ++++--- Renderer/Pipeline.hpp | 4 ++-- Renderer/Renderer.hpp | 1 + UI/UI.cpp | 8 +++++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8a6e47..2a28d8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(WIN32) -set(CMAKE_CXX_FLAGS "-D_DEBUG") +set(CMAKE_CXX_FLAGS "/O2") else() set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall") endif() @@ -43,7 +43,7 @@ foreach(SHADER_SOURCE ${SHADER_SOURCE_FILES}) set(SPIRV "${CMAKE_SOURCE_DIR}/assets/shaders/bin/${FILE_NAME}.spv") add_custom_command( OUTPUT ${SPIRV} - COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o ${SPIRV} ${SHADER_SOURCE} + COMMAND glslc -o ${SPIRV} ${SHADER_SOURCE} DEPENDS ${SHADER_SOURCE} ) list(APPEND SPIRV_BIN_FILES ${SPIRV}) diff --git a/Renderer/Pipeline.cpp b/Renderer/Pipeline.cpp index d3f494d..000f821 100644 --- a/Renderer/Pipeline.cpp +++ b/Renderer/Pipeline.cpp @@ -10,7 +10,7 @@ #include -GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector& shaders, const vk::Extent2D& extent, const RenderPass& render_pass, vk::ArrayProxy bindings, const vk::VertexInputBindingDescription& vertex_binding, const std::vector& vertex_attrs, enum Type type, bool wireframe) +GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector& shaders, const vk::Extent2D& extent, const RenderPass& render_pass, vk::ArrayProxy bindings, const vk::VertexInputBindingDescription& vertex_binding, const std::vector& vertex_attrs, enum Type type, bool wireframe, bool culling) : dev(dev), shaders(shaders), extent(extent), render_pass(render_pass), bindings(bindings), vertex_binding(vertex_binding), vertex_attrs(vertex_attrs), type(type) { /* create layout * Eventually add a graphicspipline constructor that allows specification of layouts etc @@ -106,7 +106,7 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector& sh raster_info = vk::PipelineRasterizationStateCreateInfo { .depthClampEnable = vk::False, .polygonMode = (type == eBOX || wireframe) ? vk::PolygonMode::eLine : vk::PolygonMode::eFill, - .cullMode = type == eBOX ? vk::CullModeFlagBits::eNone : vk::CullModeFlagBits::eNone, + .cullMode = (type == eBOX || !culling) ? vk::CullModeFlagBits::eNone : vk::CullModeFlagBits::eBack, .frontFace = vk::FrontFace::eCounterClockwise, .depthBiasEnable = type == eBOX, .depthBiasConstantFactor = 0.01, @@ -235,7 +235,7 @@ void GraphicsPipeline::update(uint32_t binding, const Texture& tex) { }, nullptr); } -void GraphicsPipeline::rebuild(bool wireframe) { +void GraphicsPipeline::rebuild(bool wireframe, bool culling) { vertex_input_info = vk::PipelineVertexInputStateCreateInfo { .vertexBindingDescriptionCount = static_cast(vertex_bindings.size()), .pVertexBindingDescriptions = vertex_bindings.data(), @@ -243,6 +243,7 @@ void GraphicsPipeline::rebuild(bool wireframe) { .pVertexAttributeDescriptions = vertex_attrs.data(), }; + raster_info.cullMode = culling ? vk::CullModeFlagBits::eBack : vk::CullModeFlagBits::eNone; raster_info.polygonMode = wireframe ? vk::PolygonMode::eLine : vk::PolygonMode::eFill; auto res = dev.createGraphicsPipeline(nullptr, pipeline_info); if (res.result != vk::Result::eSuccess) { diff --git a/Renderer/Pipeline.hpp b/Renderer/Pipeline.hpp index 12eaffc..49b0c6e 100644 --- a/Renderer/Pipeline.hpp +++ b/Renderer/Pipeline.hpp @@ -26,7 +26,7 @@ struct GraphicsPipeline { vk::ArrayProxy bindings, const vk::VertexInputBindingDescription& vertex_binding, const std::vector& vertex_attrs, - enum Type type = Type::eVERTEX, bool wireframe = false); + enum Type type = Type::eVERTEX, bool wireframe = false, bool culling = true); /* everything needed for recreation */ vk::Device dev; @@ -76,7 +76,7 @@ struct GraphicsPipeline { void update(uint32_t binding, const Texture& tex); - void rebuild(bool wireframe); + void rebuild(bool wireframe, bool culling); ~GraphicsPipeline(); }; diff --git a/Renderer/Renderer.hpp b/Renderer/Renderer.hpp index 283e193..bc6bd3b 100644 --- a/Renderer/Renderer.hpp +++ b/Renderer/Renderer.hpp @@ -80,6 +80,7 @@ struct Renderer { bool show_bboxes = false; bool should_close = false; bool wireframe_mode = false; + bool backface_culling = true; size_t n_indices; diff --git a/UI/UI.cpp b/UI/UI.cpp index 28b6008..b67ce24 100644 --- a/UI/UI.cpp +++ b/UI/UI.cpp @@ -24,11 +24,11 @@ static csys::ItemLog& operator<<(csys::ItemLog& log, ImVector& vec) { return log << vec[vec.size() - 1] << " }"; } -static void wireframe_setter(bool& v, bool in) { +static void pipeline_setter(bool& v, bool in) { if(v == in) return; v = in; - __ren->bsp->pipeline->rebuild(in); + __ren->bsp->pipeline->rebuild(__ren->wireframe_mode, __ren->backface_culling); } UI::UI(Renderer* ren) : ren(ren), dev(ren->dev) { @@ -124,6 +124,7 @@ UI::UI(Renderer* ren) : ren(ren), dev(ren->dev) { "speed", "max_fps", "wireframe", + "backface_culling", }; for(const auto& name : names) @@ -136,7 +137,8 @@ UI::UI(Renderer* ren) : ren(ren), dev(ren->dev) { console->System().RegisterVariable("speed", ren->speed, csys::Arg("value")); console->System().RegisterVariable("max_fps", ren->max_fps, csys::Arg("value")); - console->System().RegisterVariable("wireframe", ren->wireframe_mode, wireframe_setter); + console->System().RegisterVariable("wireframe", ren->wireframe_mode, pipeline_setter); + console->System().RegisterVariable("backface_culling", ren->backface_culling, pipeline_setter); console->System().Log(csys::ItemType::eINFO) << "Welcome to Pleascach!" << csys::endl; }