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