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>
|
2019-07-16 19:59:53 +08:00
|
|
|
|
#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
|
2019-07-16 19:59:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 渲染目标
|
|
|
|
|
*/
|
|
|
|
|
class RenderTarget:public SubmitQueue
|
|
|
|
|
{
|
|
|
|
|
protected:
|
2019-06-19 21:12:39 +08:00
|
|
|
|
|
2020-10-18 18:00:37 +08:00
|
|
|
|
RenderPass *rp;
|
2019-07-16 19:59:53 +08:00
|
|
|
|
Framebuffer *fb;
|
2019-07-16 20:22:29 +08:00
|
|
|
|
|
|
|
|
|
VkExtent2D extent;
|
2020-10-17 22:12:16 +08:00
|
|
|
|
|
2020-10-18 13:55:12 +08:00
|
|
|
|
GPUSemaphore * render_complete_semaphore =nullptr;
|
2020-10-17 22:12:16 +08:00
|
|
|
|
CommandBuffer * command_buffer =nullptr;
|
2020-10-15 17:30:03 +08:00
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
2020-10-18 17:50:54 +08:00
|
|
|
|
uint32_t color_count;
|
|
|
|
|
Texture2D **color_textures;
|
2020-10-17 14:20:49 +08:00
|
|
|
|
Texture2D *depth_texture;
|
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
protected:
|
2019-06-19 21:12:39 +08:00
|
|
|
|
|
|
|
|
|
friend class Device;
|
|
|
|
|
|
2020-10-15 17:30:03 +08:00
|
|
|
|
RenderTarget(Device *dev,Framebuffer *_fb,CommandBuffer *_cb,const uint32_t fence_count=1);
|
2020-10-18 18:00:37 +08:00
|
|
|
|
RenderTarget(Device *dev,RenderPass *_rp,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:
|
|
|
|
|
|
2020-10-15 22:13:15 +08:00
|
|
|
|
virtual ~RenderTarget();
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
2020-10-17 22:12:16 +08:00
|
|
|
|
const VkExtent2D & GetExtent ()const {return extent;}
|
2020-10-18 13:55:12 +08:00
|
|
|
|
GPUSemaphore * GetCompleteSemaphore(){return render_complete_semaphore;}
|
2020-10-17 22:12:16 +08:00
|
|
|
|
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();}
|
|
|
|
|
|
2020-10-18 17:50:54 +08:00
|
|
|
|
virtual Texture2D * GetColorTexture (const int index=0){return color_textures[index];}
|
2020-10-17 22:12:16 +08:00
|
|
|
|
virtual Texture2D * GetDepthTexture (){return depth_texture;}
|
|
|
|
|
|
2020-10-18 13:55:12 +08:00
|
|
|
|
virtual bool Submit (GPUSemaphore *present_complete_semaphore=nullptr);
|
2019-07-16 19:59:53 +08:00
|
|
|
|
};//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
|
|
|
|
|
2020-10-18 13:55:12 +08:00
|
|
|
|
GPUSemaphore *present_complete_semaphore=nullptr;
|
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
RenderPass *main_rp=nullptr;
|
2019-06-19 21:12:39 +08:00
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
uint32_t swap_chain_count;
|
|
|
|
|
|
|
|
|
|
uint32_t current_frame;
|
2020-10-18 17:50:54 +08:00
|
|
|
|
Framebuffer **render_frame;
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
|
|
|
|
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();}
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
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;}
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
2020-10-17 14:20:49 +08:00
|
|
|
|
const uint32_t GetCurrentFrameIndices()const{return current_frame;}
|
2020-10-18 13:55:12 +08:00
|
|
|
|
GPUSemaphore * GetPresentCompleteSemaphore(){return present_complete_semaphore;}
|
2020-10-17 14:20:49 +08:00
|
|
|
|
|
|
|
|
|
virtual Texture2D * GetColorTexture(const int index=0) override{return swapchain->GetColorTexture(index);}
|
|
|
|
|
virtual Texture2D * GetDepthTexture() override{return swapchain->GetDepthTexture();}
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 请求下一帧画面的索引
|
|
|
|
|
* @param present_complete_semaphore 推送完成信号
|
|
|
|
|
*/
|
2020-10-18 13:55:12 +08:00
|
|
|
|
int AcquireNextImage();
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 推送后台画面到前台
|
|
|
|
|
* @param render_complete_semaphore 渲染完成信号
|
|
|
|
|
*/
|
2020-10-18 13:55:12 +08:00
|
|
|
|
bool PresentBackbuffer(VkSemaphore *wait_semaphores,const uint32_t wait_semaphore_count);
|
|
|
|
|
|
|
|
|
|
bool PresentBackbuffer();
|
2020-10-17 14:20:49 +08:00
|
|
|
|
|
2020-10-18 13:55:12 +08:00
|
|
|
|
bool Submit(VkCommandBuffer);
|
2020-10-18 18:35:03 +08:00
|
|
|
|
bool Submit(VkCommandBuffer,GPUSemaphore *);
|
2019-07-16 19:59:53 +08:00
|
|
|
|
};//class SwapchainRenderTarget:public RenderTarget
|
2019-06-19 21:12:39 +08:00
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|