渲染流程
现在,我们已经设置好了附着和引用它的子流程,可以开车创建渲染流程对象。首先,我们在pipelineLayout变量定义之前添加一个VkRenderPass类型的成员变量:
VkRenderPass renderPass;
VkPipelineLayout pipelineLayout;
创建渲染流程对象需要填写VkRenderPassCreateInfo结构体,
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) != VK_SUCCESS) {
throw std::runtime_error("failed to create render pass!");
}
和管线布局对象一样,我们需要在应用程序结束前,清除渲染流程对象:
void cleanup() {
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyRenderPass(device, renderPass, nullptr);
...
}
下一章节,我们开始创建图形管线对象。
本章节代码:
C++:
https://vulkan-tutorial.com/code/11_render_passes.cpp
Vertex Shader:
https://vulkan-tutorial.com/code/09_shader_base.vert
Fragment Shader: