ULRE/inc/hgl/graph/vulkan/VKRenderTarget.h

107 lines
3.7 KiB
C
Raw Normal View History

2019-06-19 21:12:39 +08:00
#ifndef HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
#define HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
#include<hgl/graph/vulkan/VK.h>
#include<hgl/graph/vulkan/VKRenderPass.h>
#include<hgl/graph/vulkan/VKFramebuffer.h>
#include<hgl/graph/vulkan/VKSwapchain.h>
2020-10-17 14:20:49 +08:00
#include<hgl/graph/vulkan/VKSubmitQueue.h>
2019-06-19 21:12:39 +08:00
VK_NAMESPACE_BEGIN
/**
*
*/
class RenderTarget:public SubmitQueue
{
protected:
2019-06-19 21:12:39 +08:00
Framebuffer *fb;
VkExtent2D extent;
Semaphore * render_complete_semaphore =nullptr;
CommandBuffer * command_buffer =nullptr;
2020-10-17 14:20:49 +08:00
protected:
ObjectList<Texture2D> color_texture;
Texture2D *depth_texture;
protected:
2019-06-19 21:12:39 +08:00
friend class Device;
RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,const uint32_t fence_count=1);
2020-10-17 14:20:49 +08:00
RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture,const uint32_t fence_count=1);
2019-06-19 21:12:39 +08:00
public:
virtual ~RenderTarget();
const VkExtent2D & GetExtent ()const {return extent;}
Semaphore * GetCompleteSemaphore(){return render_complete_semaphore;}
CommandBuffer * GetCommandBuffer () {return command_buffer;}
virtual const VkRenderPass GetRenderPass ()const {return fb->GetRenderPass();}
virtual const uint32_t GetColorCount ()const {return fb->GetColorCount();}
virtual const VkFramebuffer GetFramebuffer ()const {return fb->GetFramebuffer();}
virtual Texture2D * GetColorTexture (const int index=0){return color_texture[index];}
virtual Texture2D * GetDepthTexture (){return depth_texture;}
virtual bool Submit (Semaphore *present_complete_semaphore=nullptr);
};//class RenderTarget
/**
*
*/
class SwapchainRenderTarget:public RenderTarget
{
Swapchain *swapchain;
VkSwapchainKHR vk_swapchain;
2020-09-27 20:58:25 +08:00
PresentInfo present_info;
2019-06-19 21:12:39 +08:00
RenderPass *main_rp=nullptr;
2019-06-19 21:12:39 +08:00
uint32_t swap_chain_count;
uint32_t current_frame;
ObjectList<Framebuffer> render_frame;
public:
SwapchainRenderTarget(Device *dev,Swapchain *sc);
~SwapchainRenderTarget();
2020-10-17 14:20:49 +08:00
const VkRenderPass GetRenderPass ()const override {return *main_rp;}
const VkFramebuffer GetFramebuffer ()const override {return render_frame[current_frame]->GetFramebuffer();}
VkFramebuffer GetFramebuffer (const uint32_t index) {return render_frame[index]->GetFramebuffer();}
2020-10-17 14:20:49 +08:00
const uint32_t GetColorCount ()const override {return 1;}
const uint32_t GetImageCount ()const {return swap_chain_count;}
2020-10-17 14:20:49 +08:00
const uint32_t GetCurrentFrameIndices()const{return current_frame;}
virtual Texture2D * GetColorTexture(const int index=0) override{return swapchain->GetColorTexture(index);}
virtual Texture2D * GetDepthTexture() override{return swapchain->GetDepthTexture();}
public:
/**
*
* @param present_complete_semaphore
*/
2020-10-17 14:20:49 +08:00
int AcquireNextImage(VkSemaphore present_complete_semaphore);
/**
*
* @param render_complete_semaphore
*/
2020-10-17 14:20:49 +08:00
bool PresentBackbuffer(VkSemaphore *render_complete_semaphore,const uint32_t count);
bool PresentBackbuffer(VkSemaphore render_complete_semaphore)
{
return PresentBackbuffer(&render_complete_semaphore,1);
}
};//class SwapchainRenderTarget:public RenderTarget
2019-06-19 21:12:39 +08:00
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE