增加VKFramebuffer

This commit is contained in:
HuYingzhuo 2019-04-18 21:42:22 +08:00
parent da0fae8703
commit 08e353b07a
3 changed files with 67 additions and 0 deletions

View File

@ -23,6 +23,7 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
VKVertexInput.cpp
VKPipeline.cpp
VKSemaphore.cpp
VKFramebuffer.cpp
)
SET(VULKAN_TEST_HEADER_FILES VK.h
@ -41,6 +42,7 @@ SET(VULKAN_TEST_HEADER_FILES VK.h
VKVertexInput.h
VKSemaphore.h
VKPipeline.h
VKFramebuffer.h
Window.h)
SET(SHADER_FILES shader_compile.bat

View File

@ -0,0 +1,35 @@
#include"VKFramebuffer.h"
VK_NAMESPACE_BEGIN
Framebuffer::~Framebuffer()
{
vkDestroyFramebuffer(device,frame_buffer,nullptr);
}
Framebuffer *CreateFramebuffer(Device *dev,RenderPass *rp,VkImageView color,VkImageView depth)
{
if(!dev||!rp||!color||!depth)return(nullptr);
const VkExtent2D extent=dev->GetExtent();
VkImageView attachments[2];
attachments[0]=color;
attachments[1]=depth;
VkFramebufferCreateInfo fb_info = {};
fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
fb_info.pNext = nullptr;
fb_info.renderPass = *rp;
fb_info.attachmentCount = 2;
fb_info.pAttachments = attachments;
fb_info.width = extent.width;
fb_info.height = extent.height;
fb_info.layers = 1;
VkFramebuffer fb;
if(vkCreateFramebuffer(dev->GetDevice(), &fb_info, nullptr, &fb)!=VK_SUCCESS)
return(nullptr);
return(new Framebuffer(dev->GetDevice(),fb));
}
VK_NAMESPACE_END

View File

@ -0,0 +1,30 @@
#ifndef HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
#define HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
#include"VK.h"
#include"VKDevice.h"
#include"VKRenderPass.h"
VK_NAMESPACE_BEGIN
class Framebuffer
{
VkDevice device;
VkFramebuffer frame_buffer;
private:
friend Framebuffer *CreateFramebuffer(Device *,RenderPass *,VkImageView color,VkImageView depth);;
Framebuffer(VkDevice dev,VkFramebuffer fb)
{
device=dev;
frame_buffer=fb;
}
public:
~Framebuffer();
};//class Framebuffer
Framebuffer *CreateFramebuffer(Device *,RenderPass *,VkImageView color,VkImageView depth);
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE