完成render pass 创建
parent
a5df364c00
commit
7b1d83753f
|
@ -112,6 +112,7 @@ void HelloTriangleApplication::initVulkan() {
|
||||||
|
|
||||||
creatImageView();
|
creatImageView();
|
||||||
|
|
||||||
|
createRenderPass();
|
||||||
createGraphicPipeline();
|
createGraphicPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +131,10 @@ void HelloTriangleApplication::mainLoop(GLFWwindow* window){
|
||||||
|
|
||||||
void HelloTriangleApplication::cleanup(GLFWwindow* window) {
|
void HelloTriangleApplication::cleanup(GLFWwindow* window) {
|
||||||
|
|
||||||
std::cout << "start to destroy resource" << std::endl;
|
std::cout << "\nstart to destroy resource\n" << std::endl;
|
||||||
|
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||||
|
vkDestroyRenderPass(device, renderPass, nullptr);
|
||||||
|
|
||||||
for (auto imageView : swapChainImageViews)
|
for (auto imageView : swapChainImageViews)
|
||||||
{
|
{
|
||||||
|
@ -603,6 +605,44 @@ VkShaderModule HelloTriangleApplication::createShaderModule(const std::vector<ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HelloTriangleApplication::createRenderPass()
|
||||||
|
{
|
||||||
|
VkAttachmentDescription colorAttachment{};
|
||||||
|
colorAttachment.format = swapChainImageFormat;
|
||||||
|
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
//颜色和深度数据
|
||||||
|
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; // 开始时清除附件数据
|
||||||
|
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;// 存储渲染内容到内存
|
||||||
|
//stencil数据
|
||||||
|
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;// just dont care
|
||||||
|
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
|
||||||
|
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;// render pass 开始前图形具有的布局
|
||||||
|
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;// render pass 完成时自动转换到的布局,此处为准备用交换链进行呈现
|
||||||
|
|
||||||
|
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(device,&renderPassInfo,nullptr,&renderPass) != VK_SUCCESS)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("failed to create render pass in createRenderPass");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void HelloTriangleApplication::createGraphicPipeline()
|
void HelloTriangleApplication::createGraphicPipeline()
|
||||||
{
|
{
|
||||||
auto vertShaderCode = readFile("../../../shaders/triangleVert.spv");
|
auto vertShaderCode = readFile("../../../shaders/triangleVert.spv");
|
||||||
|
|
|
@ -63,6 +63,7 @@ private:
|
||||||
|
|
||||||
std::vector<VkImageView> swapChainImageViews;
|
std::vector<VkImageView> swapChainImageViews;
|
||||||
|
|
||||||
|
VkRenderPass renderPass;
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
|
|
||||||
struct QueueFamilyIndices
|
struct QueueFamilyIndices
|
||||||
|
@ -128,6 +129,7 @@ private:
|
||||||
|
|
||||||
void creatImageView();
|
void creatImageView();
|
||||||
|
|
||||||
|
void createRenderPass();
|
||||||
void createGraphicPipeline();
|
void createGraphicPipeline();
|
||||||
|
|
||||||
static std::vector<char> readFile(const std::string& filename);
|
static std::vector<char> readFile(const std::string& filename);
|
||||||
|
|
Loading…
Reference in New Issue