From 52f167f6a889a05cb2767ce9e43e1b41cda35672 Mon Sep 17 00:00:00 2001 From: Ben Kyd Date: Wed, 29 Nov 2023 14:16:59 +0000 Subject: [PATCH] switch --- src/graphics/pipeline.cpp | 21 ++++++++++++++++++++- src/graphics/pipeline.hpp | 5 +++++ src/gui/gui.hpp | 13 +++++++------ src/inferno.cpp | 4 +++- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/graphics/pipeline.cpp b/src/graphics/pipeline.cpp index 35ff861..96ba7ef 100644 --- a/src/graphics/pipeline.cpp +++ b/src/graphics/pipeline.cpp @@ -22,6 +22,9 @@ Pipeline* pipeline_create(GraphicsDevice* device, SwapChain* swap, Shader* shade pipeline->Swap = swap; pipeline->RelaventShader = shader; + pipeline->DescriptorSetLayoutCount = descriptorSetLayoutCount; + pipeline->DescriptorSetLayouts = layouts; + auto bindingDescription = new VkVertexInputBindingDescription(scene::get_vert_binding_description()); auto attributeDescriptions = new std::array( @@ -56,7 +59,7 @@ Pipeline* pipeline_create(GraphicsDevice* device, SwapChain* swap, Shader* shade pipeline->Rasterizer.rasterizerDiscardEnable = VK_FALSE; pipeline->Rasterizer.polygonMode = VK_POLYGON_MODE_FILL; pipeline->Rasterizer.lineWidth = 1.f; - pipeline->Rasterizer.cullMode = VK_CULL_MODE_NONE; + pipeline->Rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; pipeline->Rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; pipeline->Rasterizer.depthBiasEnable = VK_FALSE; pipeline->Rasterizer.depthBiasConstantFactor = 0.f; // Optional @@ -187,4 +190,20 @@ void pipeline_cleanup(Pipeline* pipeline) delete pipeline; } +void pipeline_recreate(Pipeline* pipeline) +{ + vkDeviceWaitIdle(pipeline->Device->VulkanDevice); + GraphicsDevice* device = pipeline->Device; + SwapChain* swap = pipeline->Swap; + + swapchain_recreate(swap); + + Shader* shader = pipeline->RelaventShader; + uint32_t descriptorSetLayoutCount = pipeline->DescriptorSetLayoutCount; + VkDescriptorSetLayout* layouts = pipeline->DescriptorSetLayouts; + + pipeline_cleanup(pipeline); + pipeline = pipeline_create(device, swap, shader, descriptorSetLayoutCount, layouts); +} + } // namespace inferno::graphics diff --git a/src/graphics/pipeline.hpp b/src/graphics/pipeline.hpp index e6132c2..e29d9d1 100644 --- a/src/graphics/pipeline.hpp +++ b/src/graphics/pipeline.hpp @@ -14,6 +14,9 @@ typedef struct Pipeline { SwapChain* Swap; Shader* RelaventShader; + uint32_t DescriptorSetLayoutCount; + VkDescriptorSetLayout* DescriptorSetLayouts; + VkPipeline GraphicsPipeline; VkPipelineLayout Layout; @@ -32,4 +35,6 @@ Pipeline* pipeline_create(GraphicsDevice* device, SwapChain* swap, Shader* shade uint32_t descriptorSetLayoutCount, VkDescriptorSetLayout* layouts); void pipeline_cleanup(Pipeline* pipeline); +void pipeline_recreate(Pipeline* pipeline); + } diff --git a/src/gui/gui.hpp b/src/gui/gui.hpp index a86edba..156ade0 100644 --- a/src/gui/gui.hpp +++ b/src/gui/gui.hpp @@ -5,12 +5,12 @@ #include "graphics/device.hpp" #include "window.hpp" -namespace inferno { +#include "yolo/yolo.hpp" -inline void setupImGui(graphics::GraphicsDevice* device) +namespace inferno::gui { + +inline void imgui_init(graphics::GraphicsDevice* device) { - // 1: create descriptor pool for IMGUI - // the size of the pool is very oversize, but it's copied from imgui demo itself. VkDescriptorPoolSize pool_sizes[] = { { VK_DESCRIPTOR_TYPE_SAMPLER, 1000 }, { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000 }, @@ -38,8 +38,7 @@ inline void setupImGui(graphics::GraphicsDevice* device) // this initializes the core structures of imgui ImGui::CreateContext(); - // this initializes imgui for SDL - ImGui_ImplGlfw_InitForVulkan(graphics::Window, true); + ImGui_ImplGlfw_InitForVulkan(graphics::Window, false); // this initializes imgui for Vulkan ImGui_ImplVulkan_InitInfo init_info = {}; @@ -67,6 +66,8 @@ inline void setupImGui(graphics::GraphicsDevice* device) // vkDestroyDescriptorPool(_device, imguiPool, nullptr); // ImGui_ImplVulkan_Shutdown(); // }); + + yolo::info("Initialized ImGUI"); } } diff --git a/src/inferno.cpp b/src/inferno.cpp index 564dab1..901da96 100644 --- a/src/inferno.cpp +++ b/src/inferno.cpp @@ -3,7 +3,7 @@ #include #include -// #include "gui/layout.hpp" +#include "gui/gui.hpp" // #include "renderer/renderer.hpp" // #include "scene/scene.hpp" #include "graphics/buffer.hpp" @@ -97,6 +97,8 @@ InfernoApp* inferno_create() app->Renderer = graphics::renderer_create(app->Device); graphics::renderer_configure_command_buffer(app->Renderer); + gui::imgui_init(app->Device); + app->Shader = graphics::shader_create(app->Device, app->Renderer->Swap); graphics::shader_load(app->Shader, "res/shaders/basic"); graphics::shader_build(app->Shader);