From 9ba69a3de08b29babd42bed6f592bb8df13a5b61 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 20 Apr 2019 02:28:31 +0800 Subject: [PATCH] =?UTF-8?q?VKFramebuffer=E5=88=9B=E5=BB=BA=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8Bcolor/depth=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/VKFramebuffer.cpp | 30 +++++++++++++++++++++++------- example/Vulkan/VKFramebuffer.h | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/example/Vulkan/VKFramebuffer.cpp b/example/Vulkan/VKFramebuffer.cpp index c710c658..afb56316 100644 --- a/example/Vulkan/VKFramebuffer.cpp +++ b/example/Vulkan/VKFramebuffer.cpp @@ -1,4 +1,4 @@ -#include"VKFramebuffer.h" +#include"VKFramebuffer.h" #include"VKDevice.h" #include"VKRenderPass.h" VK_NAMESPACE_BEGIN @@ -9,23 +9,39 @@ Framebuffer::~Framebuffer() Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,VkImageView color,VkImageView depth) { - if(!dev||!rp||!color||!depth)return(nullptr); + if(!dev||!rp)return(nullptr); + + if(!color&&!depth)return(nullptr); const VkExtent2D extent=dev->GetExtent(); VkImageView attachments[2]; - attachments[0]=color; - attachments[1]=depth; - VkFramebufferCreateInfo fb_info = {}; fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; fb_info.pNext = nullptr; fb_info.renderPass = *rp; - fb_info.attachmentCount = 2; - fb_info.pAttachments = attachments; fb_info.width = extent.width; fb_info.height = extent.height; fb_info.layers = 1; + fb_info.pAttachments = attachments; + + if(color) + { + attachments[0]=color; + + if(depth) + { + attachments[1]=depth; + fb_info.attachmentCount = 2; + } + else + fb_info.attachmentCount = 1; + } + else + { + attachments[0]=depth; + fb_info.attachmentCount = 1; + } VkFramebuffer fb; diff --git a/example/Vulkan/VKFramebuffer.h b/example/Vulkan/VKFramebuffer.h index d6afdc02..40c2c42f 100644 --- a/example/Vulkan/VKFramebuffer.h +++ b/example/Vulkan/VKFramebuffer.h @@ -28,6 +28,6 @@ public: operator VkFramebuffer(){return frame_buffer;} };//class Framebuffer -Framebuffer *CreateFramebuffer(Device *,RenderPass *,VkImageView color,VkImageView depth); +Framebuffer *CreateFramebuffer(Device *,RenderPass *,VkImageView color,VkImageView depth=nullptr); VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE