Browse Source

Create framebuffers.

master
Amber 2 years ago
parent
commit
362cabb972
  1. 35
      src/main.c

35
src/main.c

@ -60,6 +60,8 @@ typedef struct ApplicationState { @@ -60,6 +60,8 @@ typedef struct ApplicationState {
VkPipelineLayout pipeline_layout;
VkPipeline graphics_pipeline;
VkFramebuffer* framebuffers;
} ApplicationState;
typedef struct QueueFamilyIndices {
@ -783,6 +785,34 @@ void create_graphics_pipeline(ApplicationState* state) { @@ -783,6 +785,34 @@ void create_graphics_pipeline(ApplicationState* state) {
printf("created graphics pipeline\n");
}
void create_framebuffers(ApplicationState* state) {
printf("creating framebuffers\n");
state->framebuffers = malloc(sizeof(VkFramebuffer) * state->swapchain_image_count);
for (int i = 0; i < state->swapchain_image_count; i++) {
printf("creating framebuffer %x\n", i);
VkImageView attachments[] = {
state->swapchain_image_views[i]
};
VkFramebufferCreateInfo framebuffer_info = {0};
framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
framebuffer_info.renderPass = state->render_pass;
framebuffer_info.attachmentCount = 1;
framebuffer_info.pAttachments = attachments;
framebuffer_info.width = state->swapchain_extent.width;
framebuffer_info.height = state->swapchain_extent.height;
framebuffer_info.layers = 1;
if (vkCreateFramebuffer(state->device, &framebuffer_info, NULL, &state->framebuffers[i]) != VK_SUCCESS) {
printf("failed to create framebuffer");
exit(1);
}
printf("created framebuffer %x\n", i);
}
printf("created framebuffers\n");
}
void init_vulkan(ApplicationState* state) {
create_instance(state);
create_surface(state);
@ -792,6 +822,7 @@ void init_vulkan(ApplicationState* state) { @@ -792,6 +822,7 @@ void init_vulkan(ApplicationState* state) {
create_image_views(state);
create_render_pass(state);
create_graphics_pipeline(state);
create_framebuffers(state);
}
void main_loop(ApplicationState* state) {
@ -801,6 +832,10 @@ void main_loop(ApplicationState* state) { @@ -801,6 +832,10 @@ void main_loop(ApplicationState* state) {
}
void terminate(ApplicationState* state) {
for (int i = 0; i < state->swapchain_image_count; i++) {
vkDestroyFramebuffer(state->device, state->framebuffers[i], NULL);
}
vkDestroyPipeline(state->device, state->graphics_pipeline, NULL);
vkDestroyRenderPass(state->device, state->render_pass, NULL);
vkDestroyPipelineLayout(state->device, state->pipeline_layout, NULL);
for (int i = 0; i < state->swapchain_image_count; i++) {

Loading…
Cancel
Save