diff --git a/NothinFancy/src/client/render/RenderEngine.cpp b/NothinFancy/src/client/render/RenderEngine.cpp index 6968049..ac96b32 100644 --- a/NothinFancy/src/client/render/RenderEngine.cpp +++ b/NothinFancy/src/client/render/RenderEngine.cpp @@ -16,6 +16,7 @@ namespace nf::cli::render { , m_device() , m_queueGraphics() , m_queuePresent() + , m_renderPassOutput() { NFLog("Initializing render engine"); m_window->setDisplay(m_display); @@ -25,6 +26,7 @@ namespace nf::cli::render { createSurface(m_window->getHandle()); pickPhysicalDevice(); createDevice(); + createRenderPass(); } void RenderEngine::createInstance() { @@ -159,7 +161,37 @@ namespace nf::cli::render { vkGetDeviceQueue(m_device, m_queueFIPresent, 0, &m_queuePresent); } + void RenderEngine::createRenderPass() { + VkAttachmentDescription outputColorAttachment = {}; + outputColorAttachment.format = VK_FORMAT_R8G8B8A8_SRGB; + outputColorAttachment.samples = VK_SAMPLE_COUNT_1_BIT; + outputColorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + outputColorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + outputColorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + outputColorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + outputColorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + outputColorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference outputColorAttachmentReference = {}; + outputColorAttachmentReference.attachment = 0; + outputColorAttachmentReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription subpassDescription = {}; + subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + subpassDescription.colorAttachmentCount = 1; + subpassDescription.pColorAttachments = &outputColorAttachmentReference; + + VkRenderPassCreateInfo renderPassCI = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO }; + renderPassCI.attachmentCount = 1; + renderPassCI.pAttachments = &outputColorAttachment; + renderPassCI.subpassCount = 1; + renderPassCI.pSubpasses = &subpassDescription; + if (vkCreateRenderPass(m_device, &renderPassCI, nullptr, &m_renderPassOutput) != VK_SUCCESS) + NFError("Could not create Vulkan render pass"); + } + RenderEngine::~RenderEngine() { + vkDestroyRenderPass(m_device, m_renderPassOutput, nullptr); vkDestroyDevice(m_device, nullptr); vkDestroySurfaceKHR(m_instance, m_surface, nullptr); vkDestroyInstance(m_instance, nullptr); diff --git a/NothinFancy/src/client/render/RenderEngine.h b/NothinFancy/src/client/render/RenderEngine.h index 28222d9..c0f6654 100644 --- a/NothinFancy/src/client/render/RenderEngine.h +++ b/NothinFancy/src/client/render/RenderEngine.h @@ -15,6 +15,7 @@ namespace nf::cli::render { void createSurface(HWND window); void pickPhysicalDevice(); void createDevice(); + void createRenderPass(); std::shared_ptr m_window; DisplayConfig m_display; @@ -25,5 +26,6 @@ namespace nf::cli::render { uint32_t m_queueFIGraphics, m_queueFIPresent; VkDevice m_device; VkQueue m_queueGraphics, m_queuePresent; + VkRenderPass m_renderPassOutput; }; }