全新组织的CreateFramebuffer函数

This commit is contained in:
hyzboy 2019-06-19 17:25:23 +08:00
parent d7dbbea3e6
commit b5fbd960cc
2 changed files with 60 additions and 47 deletions

View File

@ -11,9 +11,7 @@ class Framebuffer
private: private:
friend Framebuffer *CreateFramebuffer(Device *,RenderPass *,List<ImageView *> color,ImageView *depth); friend Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
friend Framebuffer *CreateFramebuffer(Device *,RenderPass *,ImageView *color,ImageView *depth);
friend Framebuffer *CreateFramebuffer(Device *,RenderPass *,ImageView *depth);
Framebuffer(VkDevice dev,VkFramebuffer fb) Framebuffer(VkDevice dev,VkFramebuffer fb)
{ {

View File

@ -2,6 +2,7 @@
#include<hgl/graph/vulkan/VKDevice.h> #include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKImageView.h> #include<hgl/graph/vulkan/VKImageView.h>
#include<hgl/graph/vulkan/VKRenderPass.h> #include<hgl/graph/vulkan/VKRenderPass.h>
#include<hgl/type/Smart.h>
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
Framebuffer::~Framebuffer() Framebuffer::~Framebuffer()
@ -9,67 +10,60 @@ Framebuffer::~Framebuffer()
vkDestroyFramebuffer(device,frame_buffer,nullptr); vkDestroyFramebuffer(device,frame_buffer,nullptr);
} }
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> color,ImageView *depth) Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
{ {
if(!dev)return(nullptr); if(!dev)return(nullptr);
if(!rp)return(nullptr); if(!rp)return(nullptr);
if(!color.GetCount()&&!depth)return(nullptr);
if(!color_count&&!depth)return(nullptr);
} uint att_count=color_count;
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView *color,ImageView *depth) if(depth)++att_count;
{
if(!dev)return(nullptr);
if(!rp)return(nullptr);
if(!color&&!depth)return(nullptr);
if(color) SharedArray<VkImageView> attachments=new VkImageView[att_count];
if(color_count)
{ {
const auto &cf_list=rp->GetColorFormat(); const List<VkFormat> &cf_list=rp->GetColorFormat();
VkFormat cf; if(color_count!=cf_list.GetCount())
if(!cf_list.Get(0,cf))
return(nullptr); return(nullptr);
if(cf!=color->GetFormat()) const VkFormat *cf=cf_list.GetData();
ImageView **iv=color_list;
for(uint i=0;i<color_count;i++)
{
if(*cf!=(*iv)->GetFormat())
return(nullptr); return(nullptr);
attachments[i]=**iv;
++cf;
++iv;
}
} }
if(depth) if(depth)
{
if(rp->GetDepthFormat()!=depth->GetFormat()) if(rp->GetDepthFormat()!=depth->GetFormat())
return(nullptr); return(nullptr);
const VkExtent2D extent=dev->GetExtent(); attachments[color_count]=*depth;
VkImageView attachments[2]; }
VkFramebufferCreateInfo fb_info = {}; const VkExtent2D extent=dev->GetExtent();
VkFramebufferCreateInfo fb_info;
fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
fb_info.pNext = nullptr; fb_info.pNext = nullptr;
fb_info.flags = 0;
fb_info.renderPass = *rp; fb_info.renderPass = *rp;
fb_info.attachmentCount = att_count;
fb_info.pAttachments = attachments;
fb_info.width = extent.width; fb_info.width = extent.width;
fb_info.height = extent.height; fb_info.height = extent.height;
fb_info.layers = 1; 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; VkFramebuffer fb;
@ -79,5 +73,26 @@ Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView *color,Image
return(new Framebuffer(dev->GetDevice(),fb)); return(new Framebuffer(dev->GetDevice(),fb));
} }
//Framebuffer *CreateFramebuffer(Device *,RenderPass *,ImageView *depth) Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> 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 VK_NAMESPACE_END