Added render pass code

This commit is contained in:
Warwick New 2025-01-15 18:08:20 +00:00
parent 3d48656705
commit dbcf80b0f6

View file

@ -55,6 +55,7 @@ typedef struct Application {
VkExtent2D swapChainExtent;
VkImageView *swapChainImageViews;
uint32_t swapChainImageViewCount;
VkRenderPass renderPass;
VkPipelineLayout pipelineLayout;
} Application;
@ -791,6 +792,40 @@ void createGraphicsPipeline(Application *app) {
vkDestroyShaderModule(app->device, vertShaderModule, NULL);
}
void createRenderPass(Application *app) {
VkAttachmentDescription colorAttachment = {0};
colorAttachment.format = app->swapChainImageFormat;
colorAttachment.samples = 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 = {0};
colorAttachmentRef.attachment = 0;
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass = {0};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef;
VkRenderPassCreateInfo renderPassInfo = {0};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = 1;
renderPassInfo.pAttachments = &colorAttachment;
renderPassInfo.subpassCount = 1;
renderPassInfo.pSubpasses = &subpass;
if (vkCreateRenderPass(app->device, &renderPassInfo, NULL,
&app->renderPass) != VK_SUCCESS) {
fprintf(stderr, "Failed to create render pass!");
exit(EXIT_FAILURE);
}
}
void initVulkan(Application *app) {
createInstance(app);
setupDebugMessenger(app);
@ -799,6 +834,7 @@ void initVulkan(Application *app) {
createLogicalDevice(app);
createSwapChain(app);
createImageViews(app);
createRenderPass(app);
createGraphicsPipeline(app);
}
@ -810,6 +846,7 @@ void mainLoop(Application *app) {
void cleanup(Application *app) {
vkDestroyPipelineLayout(app->device, app->pipelineLayout, NULL);
vkDestroyRenderPass(app->device, app->renderPass, NULL);
for (size_t i = 0; i < app->swapChainImageViewCount; i++) {
vkDestroyImageView(app->device, app->swapChainImageViews[i], NULL);
}