use multi depth in Swapchain FBO
This commit is contained in:
parent
6ca0cd2987
commit
6080422f3a
@ -26,9 +26,9 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
uint32_t color_count;
|
uint32_t color_count; ///<颜色成分数量
|
||||||
Texture2D **color_textures;
|
Texture2D **color_textures; ///<颜色成分纹理列表
|
||||||
Texture2D *depth_texture;
|
Texture2D *depth_texture; ///<深度成分纹理
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -45,9 +45,10 @@ public:
|
|||||||
const VkExtent2D & GetExtent ()const {return extent;}
|
const VkExtent2D & GetExtent ()const {return extent;}
|
||||||
virtual RenderPass * GetRenderPass () {return render_pass;}
|
virtual RenderPass * GetRenderPass () {return render_pass;}
|
||||||
virtual const VkRenderPass GetVkRenderPass ()const {return render_pass->GetVkRenderPass();}
|
virtual const VkRenderPass GetVkRenderPass ()const {return render_pass->GetVkRenderPass();}
|
||||||
virtual const uint32_t GetColorCount ()const {return fbo->GetColorCount();}
|
|
||||||
virtual Framebuffer * GetFramebuffer () {return fbo;}
|
|
||||||
|
|
||||||
|
virtual const uint32_t GetColorCount ()const {return fbo->GetColorCount();}
|
||||||
|
|
||||||
|
virtual Framebuffer * GetFramebuffer () {return fbo;}
|
||||||
virtual Texture2D * GetColorTexture (const int index=0){return color_textures[index];}
|
virtual Texture2D * GetColorTexture (const int index=0){return color_textures[index];}
|
||||||
virtual Texture2D * GetDepthTexture (){return depth_texture;}
|
virtual Texture2D * GetDepthTexture (){return depth_texture;}
|
||||||
|
|
||||||
@ -78,14 +79,15 @@ public:
|
|||||||
RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
|
RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
|
||||||
~RTSwapchain();
|
~RTSwapchain();
|
||||||
|
|
||||||
Framebuffer * GetFramebuffer ()override {return swapchain->sc_fbo[current_frame];}
|
const uint32_t GetColorCount ()const override {return 1;} ///Swapchain的FBO颜色成份只有一个
|
||||||
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->sc_fbo[index];}
|
|
||||||
|
|
||||||
const uint32_t GetColorCount ()const override {return 1;}
|
const uint32_t GetImageCount ()const {return swapchain->image_count;}
|
||||||
const uint32_t GetImageCount ()const {return swapchain->color_count;}
|
|
||||||
|
|
||||||
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->sc_color[index];}
|
Framebuffer * GetFramebuffer ()override {return swapchain->sc_image[current_frame].fbo;}
|
||||||
virtual Texture2D * GetDepthTexture () override{return swapchain->sc_depth;}
|
Framebuffer * GetFramebuffer (const int index) {return swapchain->sc_image[index].fbo;}
|
||||||
|
|
||||||
|
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->sc_image[current_frame].color;}
|
||||||
|
virtual Texture2D * GetDepthTexture () override{return swapchain->sc_image[current_frame].depth;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -1,30 +1,47 @@
|
|||||||
#ifndef HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
#pragma once
|
||||||
#define HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
|
||||||
|
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VK.h>
|
||||||
#include<hgl/graph/VKTexture.h>
|
#include<hgl/graph/VKTexture.h>
|
||||||
#include<hgl/type/List.h>
|
#include<hgl/type/List.h>
|
||||||
|
#include<hgl/graph/VKFramebuffer.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
struct SwapchainImage
|
||||||
|
{
|
||||||
|
Texture2D * color =nullptr;
|
||||||
|
Texture2D * depth =nullptr;
|
||||||
|
|
||||||
|
Framebuffer * fbo =nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
~SwapchainImage()
|
||||||
|
{
|
||||||
|
delete fbo;
|
||||||
|
delete depth;
|
||||||
|
delete color;
|
||||||
|
}
|
||||||
|
};//struct SwapchainImage
|
||||||
|
|
||||||
struct Swapchain
|
struct Swapchain
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VkDevice device =VK_NULL_HANDLE;
|
VkDevice device =VK_NULL_HANDLE;
|
||||||
|
|
||||||
VkExtent2D extent;
|
VkExtent2D extent;
|
||||||
|
VkSurfaceTransformFlagBitsKHR transform;
|
||||||
|
|
||||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||||
|
VkSurfaceFormatKHR surface_format;
|
||||||
|
VkFormat depth_format;
|
||||||
|
|
||||||
uint32_t color_count =0;
|
uint32_t image_count =0;
|
||||||
|
|
||||||
Texture2D ** sc_color =nullptr;
|
SwapchainImage * sc_image =nullptr;
|
||||||
Texture2D * sc_depth =nullptr;
|
|
||||||
|
|
||||||
Framebuffer ** sc_fbo =nullptr;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~Swapchain();
|
virtual ~Swapchain();
|
||||||
};//struct Swapchain
|
};//struct Swapchain
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_SWAP_CHAIN_INCLUDE
|
|
||||||
|
@ -64,7 +64,7 @@ RTSwapchain *GPUDevice::CreateSwapchainRenderTarget()
|
|||||||
if(!sc)
|
if(!sc)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
DeviceQueue *q=CreateQueue(sc->color_count,false);
|
DeviceQueue *q=CreateQueue(sc->image_count,false);
|
||||||
Semaphore *render_complete_semaphore=CreateGPUSemaphore();
|
Semaphore *render_complete_semaphore=CreateGPUSemaphore();
|
||||||
Semaphore *present_complete_semaphore=CreateGPUSemaphore();
|
Semaphore *present_complete_semaphore=CreateGPUSemaphore();
|
||||||
|
|
||||||
|
@ -84,49 +84,41 @@ namespace
|
|||||||
|
|
||||||
bool GPUDevice::CreateSwapchainFBO(Swapchain *swapchain)
|
bool GPUDevice::CreateSwapchainFBO(Swapchain *swapchain)
|
||||||
{
|
{
|
||||||
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),nullptr)!=VK_SUCCESS)
|
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->image_count),nullptr)!=VK_SUCCESS)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
AutoDeleteArray<VkImage> sc_images(swapchain->color_count);
|
AutoDeleteArray<VkImage> sc_images(swapchain->image_count);
|
||||||
|
|
||||||
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS)
|
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->image_count),sc_images)!=VK_SUCCESS)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
swapchain->sc_depth =CreateTexture2D(new SwapchainDepthTextureCreateInfo(attr->physical_device->GetDepthFormat(),swapchain->extent));
|
swapchain->sc_image=hgl_zero_new<SwapchainImage>(swapchain->image_count);
|
||||||
|
|
||||||
if(!swapchain->sc_depth)
|
for(uint32_t i=0;i<swapchain->image_count;i++)
|
||||||
return(false);
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
if(attr->debug_utils)
|
|
||||||
{
|
|
||||||
attr->debug_utils->SetImage(swapchain->sc_depth->GetImage(),"SwapchainDepthImage");
|
|
||||||
attr->debug_utils->SetImageView(swapchain->sc_depth->GetVulkanImageView(),"SwapchainDepthImageView");
|
|
||||||
attr->debug_utils->SetDeviceMemory(swapchain->sc_depth->GetDeviceMemory(),"SwapchainDepthMemory");
|
|
||||||
}
|
|
||||||
#endif//_DEBUG
|
|
||||||
|
|
||||||
swapchain->sc_color =hgl_zero_new<Texture2D *>(swapchain->color_count);
|
|
||||||
swapchain->sc_fbo =hgl_zero_new<Framebuffer *>(swapchain->color_count);
|
|
||||||
|
|
||||||
for(uint32_t i=0;i<swapchain->color_count;i++)
|
|
||||||
{
|
{
|
||||||
swapchain->sc_color[i]=CreateTexture2D(new SwapchainColorTextureCreateInfo(attr->surface_format.format,swapchain->extent,sc_images[i]));
|
swapchain->sc_image[i].color=CreateTexture2D(new SwapchainColorTextureCreateInfo(swapchain->surface_format.format,swapchain->extent,sc_images[i]));
|
||||||
|
|
||||||
if(!swapchain->sc_color[i])
|
if(!swapchain->sc_image[i].color)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
swapchain->sc_fbo[i]=CreateFBO( device_render_pass,
|
swapchain->sc_image[i].depth =CreateTexture2D(new SwapchainDepthTextureCreateInfo(swapchain->depth_format,swapchain->extent));
|
||||||
swapchain->sc_color[i]->GetImageView(),
|
|
||||||
swapchain->sc_depth->GetImageView());
|
if(!swapchain->sc_image[i].depth)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
swapchain->sc_image[i].fbo=CreateFBO( device_render_pass,
|
||||||
|
swapchain->sc_image[i].color->GetImageView(),
|
||||||
|
swapchain->sc_image[i].depth->GetImageView());
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if(attr->debug_utils)
|
if(attr->debug_utils)
|
||||||
{
|
{
|
||||||
attr->debug_utils->SetImage(swapchain->sc_color[i]->GetImage(),"SwapchainColorImage_"+AnsiString::numberOf(i));
|
AnsiString num=AnsiString::numberOf(i);
|
||||||
attr->debug_utils->SetImageView(swapchain->sc_color[i]->GetVulkanImageView(),"SwapchainColorImageView_"+AnsiString::numberOf(i));
|
|
||||||
|
|
||||||
attr->debug_utils->SetFramebuffer(swapchain->sc_fbo[i]->GetFramebuffer(),"SwapchainFBO_"+AnsiString::numberOf(i));
|
attr->debug_utils->SetTexture(swapchain->sc_image[i].color,"SwapchainColor_"+num);
|
||||||
|
attr->debug_utils->SetTexture(swapchain->sc_image[i].depth,"SwapchainDepth_"+num);
|
||||||
|
|
||||||
|
attr->debug_utils->SetFramebuffer(swapchain->sc_image[i].fbo->GetFramebuffer(),"SwapchainFBO_"+num);
|
||||||
}
|
}
|
||||||
#endif//_DEBUG
|
#endif//_DEBUG
|
||||||
}
|
}
|
||||||
@ -138,10 +130,13 @@ Swapchain *GPUDevice::CreateSwapchain(const VkExtent2D &acquire_extent)
|
|||||||
{
|
{
|
||||||
Swapchain *swapchain=new Swapchain;
|
Swapchain *swapchain=new Swapchain;
|
||||||
|
|
||||||
swapchain->device =attr->device;
|
swapchain->device =attr->device;
|
||||||
swapchain->extent =acquire_extent;
|
swapchain->extent =acquire_extent;
|
||||||
|
swapchain->transform =attr->surface_caps.currentTransform;
|
||||||
|
swapchain->surface_format =attr->surface_format;
|
||||||
|
swapchain->depth_format =attr->physical_device->GetDepthFormat();
|
||||||
|
|
||||||
swapchain->swap_chain =CreateSwapChain(attr,acquire_extent);
|
swapchain->swap_chain =CreateSwapChain(attr,acquire_extent);
|
||||||
|
|
||||||
if(swapchain->swap_chain)
|
if(swapchain->swap_chain)
|
||||||
if(CreateSwapchainFBO(swapchain))
|
if(CreateSwapchainFBO(swapchain))
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
Swapchain::~Swapchain()
|
Swapchain::~Swapchain()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_fbo,color_count);
|
SAFE_CLEAR_ARRAY(sc_image);
|
||||||
SAFE_CLEAR(sc_depth);
|
|
||||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_color,color_count)
|
|
||||||
|
|
||||||
if(swap_chain)
|
if(swap_chain)
|
||||||
{
|
{
|
||||||
@ -14,6 +12,6 @@ Swapchain::~Swapchain()
|
|||||||
swap_chain=VK_NULL_HANDLE;
|
swap_chain=VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
color_count=0;
|
image_count=0;
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user