From bab42dba2ae5381a41201c5ebb675bc29802b29e Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Tue, 22 Aug 2023 16:58:07 -0400 Subject: first pass add present render pass --- src/window.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/window.cpp') diff --git a/src/window.cpp b/src/window.cpp index 0d94c47..f073df7 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,3 +1,4 @@ +#include #define GLFW_INCLUDE_NONE #define GLFW_INCLUDE_VULKAN @@ -40,6 +41,8 @@ VkPresentModeKHR vkPresentModeKHR; VkExtent2D extent; VkImage *swapchainImages = nullptr; VkImageView *swapchainImageViews = nullptr; +VkRenderPass renderPass; +VkPipelineLayout pipelineLayout; const std::vector REQUIRED_EXTENSIONS = std::vector { VK_KHR_SWAPCHAIN_EXTENSION_NAME @@ -443,6 +446,38 @@ void CreateSwapchain() { } } +void CreateRenderPass() { + VkAttachmentDescription colorAttachment{}; + colorAttachment.format = vkSurfaceFormatKHR.format; + colorAttachment.samples = VkSampleCountFlagBits::VK_SAMPLE_COUNT_1_BIT; + colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; + + VkAttachmentReference colorAttachmentRef{}; + colorAttachmentRef.attachment = 0; + colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + + VkSubpassDescription subpass{}; + subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + subpass.colorAttachmentCount = 1; + subpass.pColorAttachments = &colorAttachmentRef; + + VkRenderPassCreateInfo renderPassInfo{}; + renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + renderPassInfo.attachmentCount = 1; + renderPassInfo.pAttachments = &colorAttachment; + renderPassInfo.subpassCount = 1; + renderPassInfo.pSubpasses = &subpass; + + if (vkCreateRenderPass(vkDevice, &renderPassInfo, vkAllocator, &renderPass) != VK_SUCCESS) { + throw "failed to create render pass!"; + } +} + void DestroySwapchain() { if (swapchainImageViews!= nullptr && swapchainImageViews != CAFE_BABE(VkImageView)) { for (long i = 0; i < swapchainLength; ++i) { @@ -461,6 +496,8 @@ void FramebufferResizeCallback(GLFWwindow *window, int width, int height) { return; } DestroySwapchain(); + extent.width = width; + extent.height = height; CreateSwapchain(); } @@ -472,6 +509,7 @@ void CreateWindow(PKEWindowProperties *wp) { InitVulkan(); glfwSetFramebufferSizeCallback(window, FramebufferResizeCallback); CreateSwapchain(); + CreateRenderPass(); } void DestroyWindow() { @@ -480,6 +518,8 @@ void DestroyWindow() { auto vkDestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(vkInstance, "vkDestroyDebugReportCallbackEXT"); vkDestroyDebugReportCallbackEXT(vkInstance, vkDebugReport, nullptr); } + vkDestroyPipelineLayout(vkDevice, pipelineLayout, nullptr); + vkDestroyRenderPass(vkDevice, renderPass, nullptr); DestroySwapchain(); vkDestroySurfaceKHR(vkInstance, vkSurfaceKHR, vkAllocator); vkDestroyDevice(vkDevice, vkAllocator); -- cgit v1.2.3