improved codes of CreateSwapchain

This commit is contained in:
hyzboy 2021-12-15 20:52:52 +08:00
parent ee9be8a4a2
commit 4a24a05360
2 changed files with 10 additions and 27 deletions

View File

@ -50,9 +50,7 @@ private:
VkCommandBuffer CreateCommandBuffer(); VkCommandBuffer CreateCommandBuffer();
bool CreateSwapchainColorTexture(Swapchain *); bool CreateSwapchainFBO(Swapchain *);
bool CreateSwapchainDepthTexture(Swapchain *);
void CreateSwapchainFBO(Swapchain *);
Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent); Swapchain *CreateSwapchain(const VkExtent2D &acquire_extent);

View File

@ -68,7 +68,7 @@ namespace
} }
}//namespace }//namespace
bool GPUDevice::CreateSwapchainColorTexture(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->color_count),nullptr)!=VK_SUCCESS)
return(false); return(false);
@ -78,31 +78,20 @@ bool GPUDevice::CreateSwapchainColorTexture(Swapchain *swapchain)
if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS) if(vkGetSwapchainImagesKHR(attr->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS)
return(false); return(false);
swapchain->sc_color=new Texture2D *[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]));
return(true);
}
bool GPUDevice::CreateSwapchainDepthTexture(Swapchain *swapchain)
{
swapchain->sc_depth =CreateTexture2D(new SwapchainDepthTextureCreateInfo(attr->physical_device->GetDepthFormat(),swapchain->extent)); swapchain->sc_depth =CreateTexture2D(new SwapchainDepthTextureCreateInfo(attr->physical_device->GetDepthFormat(),swapchain->extent));
swapchain->sc_color =new Texture2D *[swapchain->color_count];
return swapchain->sc_depth;
}
void GPUDevice::CreateSwapchainFBO(Swapchain *swapchain)
{
swapchain->render_frame =new Framebuffer *[swapchain->color_count]; swapchain->render_frame =new Framebuffer *[swapchain->color_count];
for(uint32_t i=0;i<swapchain->color_count;i++) 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->render_frame[i]=CreateFramebuffer( device_render_pass, swapchain->render_frame[i]=CreateFramebuffer( device_render_pass,
swapchain->sc_color[i]->GetImageView(), swapchain->sc_color[i]->GetImageView(),
swapchain->sc_depth->GetImageView()); swapchain->sc_depth->GetImageView());
} }
return(true);
} }
Swapchain *GPUDevice::CreateSwapchain(const VkExtent2D &acquire_extent) Swapchain *GPUDevice::CreateSwapchain(const VkExtent2D &acquire_extent)
@ -115,12 +104,8 @@ Swapchain *GPUDevice::CreateSwapchain(const VkExtent2D &acquire_extent)
swapchain->swap_chain =CreateSwapChain(attr,acquire_extent); swapchain->swap_chain =CreateSwapChain(attr,acquire_extent);
if(swapchain->swap_chain) if(swapchain->swap_chain)
if(CreateSwapchainColorTexture(swapchain)) if(CreateSwapchainFBO(swapchain))
if(CreateSwapchainDepthTexture(swapchain))
{
CreateSwapchainFBO(swapchain);
return(swapchain); return(swapchain);
}
delete swapchain; delete swapchain;
swapchain=nullptr; swapchain=nullptr;