Added render pass code
This commit is contained in:
parent
3d48656705
commit
dbcf80b0f6
1 changed files with 37 additions and 0 deletions
37
src/main.c
37
src/main.c
|
|
@ -55,6 +55,7 @@ typedef struct Application {
|
||||||
VkExtent2D swapChainExtent;
|
VkExtent2D swapChainExtent;
|
||||||
VkImageView *swapChainImageViews;
|
VkImageView *swapChainImageViews;
|
||||||
uint32_t swapChainImageViewCount;
|
uint32_t swapChainImageViewCount;
|
||||||
|
VkRenderPass renderPass;
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
} Application;
|
} Application;
|
||||||
|
|
||||||
|
|
@ -791,6 +792,40 @@ void createGraphicsPipeline(Application *app) {
|
||||||
vkDestroyShaderModule(app->device, vertShaderModule, NULL);
|
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) {
|
void initVulkan(Application *app) {
|
||||||
createInstance(app);
|
createInstance(app);
|
||||||
setupDebugMessenger(app);
|
setupDebugMessenger(app);
|
||||||
|
|
@ -799,6 +834,7 @@ void initVulkan(Application *app) {
|
||||||
createLogicalDevice(app);
|
createLogicalDevice(app);
|
||||||
createSwapChain(app);
|
createSwapChain(app);
|
||||||
createImageViews(app);
|
createImageViews(app);
|
||||||
|
createRenderPass(app);
|
||||||
createGraphicsPipeline(app);
|
createGraphicsPipeline(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -810,6 +846,7 @@ void mainLoop(Application *app) {
|
||||||
|
|
||||||
void cleanup(Application *app) {
|
void cleanup(Application *app) {
|
||||||
vkDestroyPipelineLayout(app->device, app->pipelineLayout, NULL);
|
vkDestroyPipelineLayout(app->device, app->pipelineLayout, NULL);
|
||||||
|
vkDestroyRenderPass(app->device, app->renderPass, NULL);
|
||||||
for (size_t i = 0; i < app->swapChainImageViewCount; i++) {
|
for (size_t i = 0; i < app->swapChainImageViewCount; i++) {
|
||||||
vkDestroyImageView(app->device, app->swapChainImageViews[i], NULL);
|
vkDestroyImageView(app->device, app->swapChainImageViews[i], NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue