Skip to content

Commit 49cb373

Browse files
committed
create frame buffers
1 parent 611799c commit 49cb373

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

app/src/main/cpp/vulkan_triangle.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,18 @@ void HelloTriangleApplication::initVulkan() {
223223
createImageViews();
224224
createRenderPass();
225225
createGraphicsPipeline();
226+
createFramebuffers();
226227
}
227228

228229
void HelloTriangleApplication::mainLoop() {
229230

230231
}
231232

232233
void HelloTriangleApplication::cleanUp() {
234+
for (size_t i = 0; i < swapchainFramebuffers.size(); i++) {
235+
vkDestroyFramebuffer(device, swapchainFramebuffers[i], nullptr);
236+
}
237+
233238
vkDestroyPipeline(device, graphicsPipeline, nullptr);
234239
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
235240
vkDestroyRenderPass(device, renderPass, nullptr);
@@ -606,6 +611,30 @@ void HelloTriangleApplication::createGraphicsPipeline() {
606611
vkDestroyShaderModule(device, fragmentShaderModule, nullptr);
607612
}
608613

614+
void HelloTriangleApplication::createFramebuffers() {
615+
swapchainFramebuffers.resize(swapchainImageViews.size());
616+
617+
for (size_t i = 0; i < swapchainImageViews.size(); i++) {
618+
VkImageView attachments[] = {
619+
swapchainImageViews[i]
620+
};
621+
622+
VkFramebufferCreateInfo framebufferInfo = {};
623+
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
624+
framebufferInfo.renderPass = renderPass;
625+
framebufferInfo.attachmentCount = 1;
626+
framebufferInfo.pAttachments = attachments;
627+
framebufferInfo.width = swapchainExtent.width;
628+
framebufferInfo.height = swapchainExtent.height;
629+
framebufferInfo.layers = 1;
630+
631+
if (vkCreateFramebuffer(device, &framebufferInfo, nullptr, &swapchainFramebuffers[i])
632+
!= VK_SUCCESS) {
633+
throw std::runtime_error("failed to create framebuffer!");
634+
}
635+
}
636+
}
637+
609638
std::vector<char> HelloTriangleApplication::readAsset(const char *name) {
610639
AAsset *file = AAssetManager_open(assetManager, name, AASSET_MODE_BUFFER);
611640
size_t len = AAsset_getLength(file);

app/src/main/cpp/vulkan_triangle.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class HelloTriangleApplication {
5151

5252
void initVulkan();
5353

54+
void mainLoop();
55+
56+
void cleanUp();
57+
5458
void createInstance();
5559

5660
void setUpDebugCallback();
@@ -69,6 +73,8 @@ class HelloTriangleApplication {
6973

7074
void createGraphicsPipeline();
7175

76+
void createFramebuffers();
77+
7278
std::vector<char> readAsset(const char *name);
7379

7480
VkShaderModule createShaderModule(const std::vector<char> &code);
@@ -81,10 +87,6 @@ class HelloTriangleApplication {
8187

8288
SwapchainSupportDetails querySwapchainSupport(VkPhysicalDevice device);
8389

84-
void mainLoop();
85-
86-
void cleanUp();
87-
8890
AAssetManager *assetManager;
8991
const char *vertexShader;
9092
const char *fragmentShader;
@@ -100,6 +102,7 @@ class HelloTriangleApplication {
100102
VkSwapchainKHR swapchain;
101103
std::vector<VkImage> swapchainImages;
102104
std::vector<VkImageView> swapchainImageViews;
105+
std::vector<VkFramebuffer> swapchainFramebuffers;
103106
VkFormat swapchainImageFormat;
104107
VkExtent2D swapchainExtent;
105108
VkRenderPass renderPass;

0 commit comments

Comments
 (0)