ULRE/src/RenderDevice/Vulkan/VKFramebuffer.cpp

64 lines
1.5 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-04-18 21:42:22 +08:00
VK_NAMESPACE_BEGIN
Framebuffer::~Framebuffer()
{
vkDestroyFramebuffer(device,frame_buffer,nullptr);
}
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,ImageView *color,ImageView *depth)
2019-04-18 21:42:22 +08:00
{
if(!dev)return(nullptr);
if(!rp)return(nullptr);
if(!color&&!depth)return(nullptr);
2019-04-18 21:42:22 +08:00
if(color)
if(rp->GetColorFormat()!=color->GetFormat())
return(nullptr);
if(depth)
if(rp->GetDepthFormat()!=depth->GetFormat())
return(nullptr);
2019-04-18 21:42:22 +08:00
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;
}
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));
}
VK_NAMESPACE_END