diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-08-22 16:58:07 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-08-22 16:58:07 -0400 |
| commit | bab42dba2ae5381a41201c5ebb675bc29802b29e (patch) | |
| tree | b85d0b50688a1e0051d298c22d8f7409071c20fd /src | |
| parent | 51bc40dd03be65868095c1ff8ed185b109d29ede (diff) | |
first pass add present render pass
Diffstat (limited to 'src')
| -rw-r--r-- | src/.window.cpp.swp | bin | 0 -> 45056 bytes | |||
| -rw-r--r-- | src/window.cpp | 40 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/.window.cpp.swp b/src/.window.cpp.swp Binary files differnew file mode 100644 index 0000000..b47360a --- /dev/null +++ b/src/.window.cpp.swp 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 <vulkan/vulkan_core.h> #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<const char *> REQUIRED_EXTENSIONS = std::vector<const char *> { 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); |
