diff options
author | Edward O'Callaghan <funfunctor@folklore1984.net> | 2017-02-07 23:09:38 +1100 |
---|---|---|
committer | Edward O'Callaghan <funfunctor@folklore1984.net> | 2017-02-07 23:09:38 +1100 |
commit | b4a0b0f3bb80925c2d4757d2f2c80e8443e42e87 (patch) | |
tree | 84e6546967d88183ff6d2349076b431ba1879d7c /src | |
parent | 69fb536dffe9fe6aa4b78921225db9ddc228ba51 (diff) |
src/main.cpp: Implement RenderPass
Signed-off-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index c558af8..fd444f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,7 @@ private: VDeleter<VkInstance> instance {vkDestroyInstance}; VDeleter<VkSurfaceKHR> surface{instance, vkDestroySurfaceKHR}; + VDeleter<VkRenderPass> renderPass{device, vkDestroyRenderPass}; VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; VDeleter<VkDevice> device{vkDestroyDevice}; @@ -87,9 +88,47 @@ private: createLogicalDevice(); createSwapChain(); createImageViews(); + createRenderPass(); createGraphicsPipeline(); } + void createRenderPass() { + VkAttachmentDescription colorAttachment = {}; + colorAttachment.format = swapChainImageFormat; + colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT; + + // no multisampling needed, use one sample + 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; + + // subpasses + 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; + + // render pass + 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(device, &renderPassInfo, nullptr, renderPass.replace()) != VK_SUCCESS) + throw std::runtime_error("failed to create render pass!"); + } + void createGraphicsPipeline() { auto vertShaderCode = readFile("shaders/vert.spv"); auto fragShaderCode = readFile("shaders/frag.spv"); |