move CreateFramebuffer functions to VKDeviceFramebuffer.cpp

This commit is contained in:
hyzboy 2020-10-16 19:24:33 +08:00
parent cc18764cf6
commit 093eb13f16
4 changed files with 108 additions and 100 deletions

View File

@ -250,6 +250,11 @@ public: //Command Buffer 相关
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
RenderPass * CreateRenderPass( const List<VkFormat> &color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
RenderPass * CreateRenderPass( const VkFormat color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
@ -258,6 +263,13 @@ public: //Command Buffer 相关
Fence * CreateFence(bool);
vulkan::Semaphore * CreateSem();
public: //FrameBuffer相关
Framebuffer *CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFramebuffer(RenderPass *,ImageView *);
public:
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
@ -284,7 +296,7 @@ public:
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class Device
void CreateSubpassDependency(VkSubpassDependency *);
//void CreateSubpassDependency(VkSubpassDependency *);
void CreateSubpassDependency(List<VkSubpassDependency> &dependency,const uint32_t count);
void CreateAttachmentReference(VkAttachmentReference *ref_list,uint start,uint count,VkImageLayout layout);
@ -297,7 +309,7 @@ inline void CreateInputAttachmentReference(VkAttachmentReference *ref_list, uint
bool CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
bool CreateAttachment( List<VkAttachmentDescription> &color_output_desc_list,
bool CreateAttachmentDescription( List<VkAttachmentDescription> &color_output_desc_list,
const List<VkFormat> &color_format,
const VkFormat depth_format,
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,

View File

@ -18,7 +18,7 @@ class Framebuffer
private:
friend Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
friend class Device;
Framebuffer(VkDevice dev,VkFramebuffer fb,VkFramebufferCreateInfo *fb_create_info,bool depth);
@ -38,9 +38,5 @@ public:
Texture2D * GetColorTexture (const int index=0){return color_texture[index];}
Texture2D * GetDepthTexture (){return depth_texture;}
};//class Framebuffer
Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,List<ImageView *> &color,ImageView *depth);
Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,ImageView *color,ImageView *depth);
Framebuffer *CreateFramebuffer(VkDevice,RenderPass *,ImageView *);
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE

View File

@ -0,0 +1,92 @@
#include<hgl/graph/vulkan/VKDevice.h>
VK_NAMESPACE_BEGIN
Framebuffer *Device::CreateFramebuffer(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
{
uint att_count=color_count;
if(depth)++att_count;
VkImageView *attachments=new VkImageView[att_count];
if(color_count)
{
const List<VkFormat> &cf_list=rp->GetColorFormat();
const VkFormat *cf=cf_list.GetData();
ImageView **iv=color_list;
for(uint i=0;i<color_count;i++)
{
if(*cf!=(*iv)->GetFormat())
return(nullptr);
attachments[i]=**iv;
++cf;
++iv;
}
}
if(depth)
{
if(rp->GetDepthFormat()!=depth->GetFormat())
{
delete[] attachments;
return(nullptr);
}
attachments[color_count]=*depth;
}
const VkExtent3D extent=depth->GetExtent();
FramebufferCreateInfo *fb_info=new FramebufferCreateInfo;
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;
if(vkCreateFramebuffer(GetDevice(),fb_info,nullptr,&fb)!=VK_SUCCESS)
return(nullptr);
return(new Framebuffer(GetDevice(),fb,fb_info,depth));
}
Framebuffer *Device::CreateFramebuffer(RenderPass *rp,List<ImageView *> &color,ImageView *depth)
{
if(!rp)return(nullptr);
if(rp->GetColorFormat().GetCount()!=color.GetCount())return(nullptr);
if(color.GetCount()==0&&!depth)return(nullptr);
return CreateFramebuffer(rp,color.GetData(),color.GetCount(),depth);
}
Framebuffer *Device::CreateFramebuffer(RenderPass *rp,ImageView *color,ImageView *depth)
{
if(!rp)return(nullptr);
if(!color&&!depth)return(nullptr);
return CreateFramebuffer(rp,&color,1,depth);
}
Framebuffer *Device::CreateFramebuffer(RenderPass *rp,ImageView *iv)
{
if(!rp)return(nullptr);
if(!iv)return(nullptr);
if(iv->hasColor())
return CreateFramebuffer(rp,&iv,1,nullptr);
else
if(iv->hasDepth())
return CreateFramebuffer(rp,nullptr,0,iv);
else
return nullptr;
}
VK_NAMESPACE_END

View File

@ -32,96 +32,4 @@ Framebuffer::~Framebuffer()
vkDestroyFramebuffer(device,frame_buffer,nullptr);
}
Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
{
uint att_count=color_count;
if(depth)++att_count;
VkImageView *attachments=new VkImageView[att_count];
if(color_count)
{
const List<VkFormat> &cf_list=rp->GetColorFormat();
const VkFormat *cf=cf_list.GetData();
ImageView **iv=color_list;
for(uint i=0;i<color_count;i++)
{
if(*cf!=(*iv)->GetFormat())
return(nullptr);
attachments[i]=**iv;
++cf;
++iv;
}
}
if(depth)
{
if(rp->GetDepthFormat()!=depth->GetFormat())
{
delete[] attachments;
return(nullptr);
}
attachments[color_count]=*depth;
}
const VkExtent3D extent=depth->GetExtent();
FramebufferCreateInfo *fb_info=new FramebufferCreateInfo;
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;
if(vkCreateFramebuffer(dev,fb_info,nullptr,&fb)!=VK_SUCCESS)
return(nullptr);
return(new Framebuffer(dev,fb,fb_info,depth));
}
Framebuffer *CreateFramebuffer(VkDevice dev,RenderPass *rp,List<ImageView *> &color,ImageView *depth)
{
if(!dev)return(nullptr);
if(!rp)return(nullptr);
if(rp->GetColorFormat().GetCount()!=color.GetCount())return(nullptr);
if(color.GetCount()==0&&!depth)return(nullptr);
return CreateFramebuffer(dev,rp,color.GetData(),color.GetCount(),depth);
}
Framebuffer *CreateFramebuffer(VkDevice 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(VkDevice dev,RenderPass *rp,ImageView *iv)
{
if(!dev)return(nullptr);
if(!rp)return(nullptr);
if(!iv)return(nullptr);
if(iv->hasColor())
return CreateFramebuffer(dev,rp,&iv,1,nullptr);
else
if(iv->hasDepth())
return CreateFramebuffer(dev,rp,nullptr,0,iv);
else
return nullptr;
}
VK_NAMESPACE_END