2019-04-30 16:42:59 +08:00
|
|
|
|
#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-22 00:33:48 +08:00
|
|
|
|
|
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 16:57:42 +08:00
|
|
|
|
{
|
|
|
|
|
if(!dev)return(nullptr);
|
|
|
|
|
if(!rp)return(nullptr);
|
2019-06-19 17:25:23 +08:00
|
|
|
|
|
|
|
|
|
if(!color_count&&!depth)return(nullptr);
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
2019-06-19 17:25:23 +08:00
|
|
|
|
uint att_count=color_count;
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
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 16:57:42 +08:00
|
|
|
|
{
|
2019-06-19 17:25:23 +08:00
|
|
|
|
const List<VkFormat> &cf_list=rp->GetColorFormat();
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
2019-06-19 17:25:23 +08:00
|
|
|
|
if(color_count!=cf_list.GetCount())
|
2019-06-19 16:57:42 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2019-06-19 16:57:42 +08:00
|
|
|
|
}
|
2019-04-22 00:33:48 +08:00
|
|
|
|
|
|
|
|
|
if(depth)
|
2019-06-19 17:25:23 +08:00
|
|
|
|
{
|
2019-04-22 00:33:48 +08:00
|
|
|
|
if(rp->GetDepthFormat()!=depth->GetFormat())
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2019-06-19 17:25:23 +08:00
|
|
|
|
attachments[color_count]=*depth;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 21:42:22 +08:00
|
|
|
|
const VkExtent2D extent=dev->GetExtent();
|
2019-04-20 02:28:31 +08:00
|
|
|
|
|
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));
|
|
|
|
|
}
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
2019-06-19 17:25:23 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
2019-04-18 21:42:22 +08:00
|
|
|
|
VK_NAMESPACE_END
|