From 5a1abe6530cc4ade97ca5663a7ff99b5cd158c2c Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 14 Sep 2022 19:18:54 +0800 Subject: [PATCH] Auto stash before merge of "SP3-4-editor" and "origin/SP3-4-editor" --- .../Editor/Backend/SHImGuiVulkanBackend.cpp | 35 ++++++++++++++++++- .../src/Editor/Backend/SHImGuiVulkanBackend.h | 24 +++++++++++-- .../src/Graphics/Images/SHVkSampler.cpp | 6 ++++ .../src/Graphics/Images/SHVkSampler.h | 26 ++++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 SHADE_Engine/src/Graphics/Images/SHVkSampler.cpp create mode 100644 SHADE_Engine/src/Graphics/Images/SHVkSampler.h diff --git a/SHADE_Engine/src/Editor/Backend/SHImGuiVulkanBackend.cpp b/SHADE_Engine/src/Editor/Backend/SHImGuiVulkanBackend.cpp index 740ae683..676625bb 100644 --- a/SHADE_Engine/src/Editor/Backend/SHImGuiVulkanBackend.cpp +++ b/SHADE_Engine/src/Editor/Backend/SHImGuiVulkanBackend.cpp @@ -199,7 +199,7 @@ namespace SHADE viewport->PlatformHandle = io.UserData; } - void SHImGuiVulkanBackend::Render(void) noexcept + void SHImGuiVulkanBackend::Render(Handle const& commandBuffer) noexcept { GETINSTANCE ImGui::Render(); @@ -324,14 +324,22 @@ namespace SHADE fontsMipOffset.push_back(0); + // Create image. Data should be in staging only now fontsTexture = device->CreateImage(createParams, pixels, width * height * sizeof(uint32_t), fontsMipOffset, VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO, {}); + // TODO: Copy the image to device memory here + // 1. Start record + // 2. Do transfer + // 3. End record + // 4. execute cmd buffer + // We could put here the texture id if we wanted io.Fonts->TexID = nullptr; } void SHImGuiVulkanBackend::SHBreachInstance::InitializePipeline(ImGuiIO& io, Handle const& renderpass, uint32_t subpassIndex) noexcept { + // Vertex input state SHVertexInputState vInputState{}; vInputState.AddBinding(false, true, { @@ -341,9 +349,11 @@ namespace SHADE } ); + // Shaders Handle vs = device->CreateShaderModule(__glsl_shader_vert_spv, "main", vk::ShaderStageFlagBits::eVertex, "__glsl_shader_vert_spv"); Handle fs = device->CreateShaderModule(__glsl_shader_frag_spv, "main", vk::ShaderStageFlagBits::eFragment, "__glsl_shader_frag_spv"); + // pipeline layout initialize shaders SHPipelineLayoutParams pipelineLayoutParams { .shaderModules = std::move (std::vector> @@ -353,11 +363,34 @@ namespace SHADE }), }; + // Create pipeline layout Handle pipelineLayouot = device->CreatePipelineLayout(pipelineLayoutParams); + + // Create pipeline (but dont construct it yet) Handle newPipeline = device->CreatePipeline(pipelineLayouot, nullptr, renderpass, subpassIndex, SH_PIPELINE_TYPE::GRAPHICS); + + // Set the vertex input state newPipeline->GetPipelineState().SetVertexInputState(vInputState); + + // Actually construct the pipeline newPipeline->ConstructPipeline(); + SHVkDescriptorPool::Config config + { + .MaxSets = 10, + .Flags = {}, + }; + + // Create a descriptor pool + descriptorPool = device->CreateDescriptorPools(config); + + // Allocate descriptor sets required for the fonts + descriptorSetGroup = + } + + void SHImGuiVulkanBackend::SHBreachInstance::Render(Handle const& commandBuffer, ImGuiIO& io, ImDrawData* draw_data, Handle const& descriptorSetGroup) noexcept + { + } } \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/Backend/SHImGuiVulkanBackend.h b/SHADE_Engine/src/Editor/Backend/SHImGuiVulkanBackend.h index 65b88ccf..47f31e4c 100644 --- a/SHADE_Engine/src/Editor/Backend/SHImGuiVulkanBackend.h +++ b/SHADE_Engine/src/Editor/Backend/SHImGuiVulkanBackend.h @@ -23,8 +23,13 @@ namespace SHADE Handle vertexBuffer; Handle indicesBuffer; }; + //Required to create stuff Handle device; + + // Window of the imgui window SHWindow window; + + // Buffers required to draw the imgui entities std::array primitiveBuffers; public: @@ -34,18 +39,33 @@ namespace SHADE struct SHBreachInstance : public SHImGuiWindow { + // pipeline/shaders used to render imgui entities Handle pipeline; - Handle renderpass; + + // Last frame time std::chrono::time_point lastFrameTime; + + // Fonts texture Handle fontsTexture; + + // mip maps for font image (should just contain 1) std::vector fontsMipOffset; + + // Descriptor pool rquired to allocate descriptor sets + Handle descriptorPool; + + // Descriptor set required to store font texture + Handle descriptorSetGroup; + public: void CreateFontsTexture (Handle image, ImGuiIO& io) noexcept; void InitializePipeline(ImGuiIO& io, Handle const& renderpass, uint32_t subpassIndex) noexcept; + void Render (Handle const& commandBuffer, ImGuiIO& io, ImDrawData* draw_data, Handle const& descriptorSetGroup) noexcept; + }; public: static void CreateInstance(Handle const& logicalDevice, Handle const& renderpass, uint32_t subpassIndex, SHWindow& mainWindow) noexcept; - static void Render(void) noexcept; + static void Render(Handle const& commandBuffer) noexcept; static void EnableDocking(void) noexcept; diff --git a/SHADE_Engine/src/Graphics/Images/SHVkSampler.cpp b/SHADE_Engine/src/Graphics/Images/SHVkSampler.cpp new file mode 100644 index 00000000..f6117022 --- /dev/null +++ b/SHADE_Engine/src/Graphics/Images/SHVkSampler.cpp @@ -0,0 +1,6 @@ +#include "SHVkSampler.h" + +namespace SHADE +{ + +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/Images/SHVkSampler.h b/SHADE_Engine/src/Graphics/Images/SHVkSampler.h new file mode 100644 index 00000000..5c6fcaad --- /dev/null +++ b/SHADE_Engine/src/Graphics/Images/SHVkSampler.h @@ -0,0 +1,26 @@ +#pragma once + +#include "Graphics/SHVulkanIncludes.h" + +namespace SHADE +{ + struct SHVkSamplerParams + { + vk::Filter minFilter; + vk::Filter maxFilter; + }; + + class SHVkSampler + { + private: + //! The vulkan sampler handler + vk::Sampler vkSampler; + + public: + SHVkSampler () noexcept; + SHVkSampler (SHVkSampler&& rhs) noexcept; + SHVkSampler&& operator=(SHVkSampler&& rhs) noexcept; + + }; +} +