From b5fbd960cc60bb04e8fb579d802f9b0076c4fb8b Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 19 Jun 2019 17:25:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E6=96=B0=E7=BB=84=E7=BB=87=E7=9A=84Cr?= =?UTF-8?q?eateFramebuffer=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/vulkan/VKFramebuffer.h | 4 +- src/RenderDevice/Vulkan/VKFramebuffer.cpp | 103 +++++++++++++--------- 2 files changed, 60 insertions(+), 47 deletions(-) diff --git a/inc/hgl/graph/vulkan/VKFramebuffer.h b/inc/hgl/graph/vulkan/VKFramebuffer.h index c9f5284b..093fbf68 100644 --- a/inc/hgl/graph/vulkan/VKFramebuffer.h +++ b/inc/hgl/graph/vulkan/VKFramebuffer.h @@ -11,9 +11,7 @@ class Framebuffer private: - friend Framebuffer *CreateFramebuffer(Device *,RenderPass *,List color,ImageView *depth); - friend Framebuffer *CreateFramebuffer(Device *,RenderPass *,ImageView *color,ImageView *depth); - friend Framebuffer *CreateFramebuffer(Device *,RenderPass *,ImageView *depth); + friend Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth); Framebuffer(VkDevice dev,VkFramebuffer fb) { diff --git a/src/RenderDevice/Vulkan/VKFramebuffer.cpp b/src/RenderDevice/Vulkan/VKFramebuffer.cpp index 1e600047..172fe108 100644 --- a/src/RenderDevice/Vulkan/VKFramebuffer.cpp +++ b/src/RenderDevice/Vulkan/VKFramebuffer.cpp @@ -2,6 +2,7 @@ #include #include #include +#include VK_NAMESPACE_BEGIN Framebuffer::~Framebuffer() @@ -9,67 +10,60 @@ Framebuffer::~Framebuffer() vkDestroyFramebuffer(device,frame_buffer,nullptr); } -Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List color,ImageView *depth) +Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth) { if(!dev)return(nullptr); if(!rp)return(nullptr); - if(!color.GetCount()&&!depth)return(nullptr); + + if(!color_count&&!depth)return(nullptr); + uint att_count=color_count; -} + if(depth)++att_count; + + SharedArray attachments=new VkImageView[att_count]; -Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView *color,ImageView *depth) -{ - if(!dev)return(nullptr); - if(!rp)return(nullptr); - if(!color&&!depth)return(nullptr); - - if(color) + if(color_count) { - const auto &cf_list=rp->GetColorFormat(); - - VkFormat cf; + const List &cf_list=rp->GetColorFormat(); - if(!cf_list.Get(0,cf)) + if(color_count!=cf_list.GetCount()) return(nullptr); - if(cf!=color->GetFormat()) - return(nullptr); + const VkFormat *cf=cf_list.GetData(); + ImageView **iv=color_list; + for(uint i=0;iGetFormat()) + return(nullptr); + + attachments[i]=**iv; + + ++cf; + ++iv; + } } if(depth) + { if(rp->GetDepthFormat()!=depth->GetFormat()) return(nullptr); + attachments[color_count]=*depth; + } + const VkExtent2D extent=dev->GetExtent(); - VkImageView attachments[2]; - VkFramebufferCreateInfo fb_info = {}; - fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; - fb_info.pNext = nullptr; - fb_info.renderPass = *rp; - 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; - } + VkFramebufferCreateInfo fb_info; + fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + fb_info.pNext = nullptr; + fb_info.flags = 0; + fb_info.renderPass = *rp; + fb_info.attachmentCount = att_count; + fb_info.pAttachments = attachments; + fb_info.width = extent.width; + fb_info.height = extent.height; + fb_info.layers = 1; VkFramebuffer fb; @@ -79,5 +73,26 @@ Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView *color,Image return(new Framebuffer(dev->GetDevice(),fb)); } -//Framebuffer *CreateFramebuffer(Device *,RenderPass *,ImageView *depth) +Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List color,ImageView *depth) +{ + return CreateFramebuffer(dev,rp,color.GetData(),color.GetCount(),depth); +} + +Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView *color,ImageView *depth) +{ + if(!dev)return(nullptr); + if(!rp)return(nullptr); + if(!color&&!depth)return(nullptr); + + return CreateFramebuffer(dev,rp,&color,1,depth); +} + +Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView *depth) +{ + if(!dev)return(nullptr); + if(!rp)return(nullptr); + if(!depth)return(nullptr); + + return CreateFramebuffer(dev,rp,nullptr,0,depth); +} VK_NAMESPACE_END