ULRE/src/RenderDevice/Vulkan/VKFramebuffer.cpp

110 lines
3.0 KiB
C++
Raw Normal View History

#include<hgl/graph/vulkan/VKFramebuffer.h>
#include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKImageView.h>
#include<hgl/graph/vulkan/VKRenderPass.h>
2019-06-19 17:25:23 +08:00
#include<hgl/type/Smart.h>
2019-04-18 21:42:22 +08:00
VK_NAMESPACE_BEGIN
Framebuffer::~Framebuffer()
{
vkDestroyFramebuffer(device,frame_buffer,nullptr);
}
2019-06-19 17:25:23 +08:00
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
{
2019-06-19 17:25:23 +08:00
uint att_count=color_count;
2019-06-19 17:25:23 +08:00
if(depth)++att_count;
SharedArray<VkImageView> attachments=new VkImageView[att_count];
2019-04-18 21:42:22 +08:00
2019-06-19 17:25:23 +08:00
if(color_count)
{
2019-06-19 17:25:23 +08:00
const List<VkFormat> &cf_list=rp->GetColorFormat();
2019-06-19 17:25:23 +08:00
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)
2019-06-19 17:25:23 +08:00
{
if(rp->GetDepthFormat()!=depth->GetFormat())
return(nullptr);
2019-06-19 17:25:23 +08:00
attachments[color_count]=*depth;
}
const VkExtent3D extent=depth->GetExtent();
2019-06-19 17:25:23 +08:00
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;
2019-04-18 21:42:22 +08:00
VkFramebuffer fb;
if(vkCreateFramebuffer(dev->GetDevice(), &fb_info, nullptr, &fb)!=VK_SUCCESS)
return(nullptr);
return(new Framebuffer(dev->GetDevice(),fb));
}
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> &color,ImageView *depth)
2019-06-19 17:25:23 +08:00
{
if(!dev)return(nullptr);
if(!rp)return(nullptr);
if(rp->GetColorFormat().GetCount()!=color.GetCount())return(nullptr);
if(color.GetCount()==0&&!depth)return(nullptr);
2019-06-19 17:25:23 +08:00
return CreateFramebuffer(dev,rp,color.GetData(),color.GetCount(),depth);
}
2019-07-05 19:56:15 +08:00
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,List<ImageView *> &image_view_list)
{
const int count=image_view_list.GetCount();
ImageView *last_iv=*(image_view_list.GetData()+count-1);
if(last_iv->GetAspectFlags()&VK_IMAGE_ASPECT_DEPTH_BIT)
return CreateFramebuffer(dev,rp,image_view_list.GetData(),count-1,last_iv);
else
return CreateFramebuffer(dev,rp,image_view_list.GetData(),count,nullptr);
}
2019-06-19 17:25:23 +08:00
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);
}
2019-04-18 21:42:22 +08:00
VK_NAMESPACE_END