Browse Source

Added framebuffers

Kajetan Johannes Hammerle 3 tháng trước cách đây
mục cha
commit
9f79669eef
1 tập tin đã thay đổi với 27 bổ sung1 xóa
  1. 27 1
      src/VulkanWrapper.c

+ 27 - 1
src/VulkanWrapper.c

@@ -456,6 +456,31 @@ static bool initRenderPass() {
     return false;
 }
 
+static bool initFramebuffers() {
+    vk.swapchain.framebuffers =
+        coreAllocate(sizeof(VkFramebuffer) * vk.swapchain.amount);
+    for(u32 i = 0; i < vk.swapchain.amount; i++) {
+        VkFramebufferCreateInfo info = {
+            .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
+            .renderPass = vk.renderPass,
+            .attachmentCount = 1,
+            .pAttachments = vk.swapchain.imageViews + i,
+            .width = vk.width,
+            .height = vk.height,
+            .layers = 1};
+        VK_ASSERT(vkCreateFramebuffer(vk.device, &info, nullptr,
+                                      vk.swapchain.framebuffers + i));
+    }
+    return false;
+}
+
+static void destroyFramebuffers() {
+    for(u32 i = 0; i < vk.swapchain.amount; i++) {
+        vkDestroyFramebuffer(vk.device, vk.swapchain.framebuffers[i], nullptr);
+    }
+    coreFree(vk.swapchain.framebuffers);
+}
+
 bool initVulkan() {
     vk.width = 400;
     vk.height = 300;
@@ -463,7 +488,7 @@ bool initVulkan() {
            initPhysicalDevice() || initDevice() || checkPresentationSupport() ||
            initSwapchain() || initSwapchainImages() ||
            initSemaphore(&vk.semaphore) || initSemaphore(&vk.renderSemaphore) ||
-           initCommandBuffers() || initRenderPass();
+           initCommandBuffers() || initRenderPass() || initFramebuffers();
 }
 
 static bool fillCommandBuffer(u32 index) {
@@ -483,6 +508,7 @@ void renderVulkan() {
 
 void destroyVulkan(void) {
     if(vk.device != VK_NULL_HANDLE) {
+        destroyFramebuffers();
         vkDestroyRenderPass(vk.device, vk.renderPass, nullptr);
         destroyCommandBuffers();
         destroySemaphore(vk.semaphore);