2019-06-19 21:12:39 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|
|
|
|
|
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VK.h>
|
|
|
|
|
#include<hgl/graph/VKRenderPass.h>
|
|
|
|
|
#include<hgl/graph/VKFramebuffer.h>
|
|
|
|
|
#include<hgl/graph/VKSwapchain.h>
|
2020-10-21 12:39:22 +08:00
|
|
|
|
#include<hgl/graph/VKQueue.h>
|
2020-10-27 18:11:39 +08:00
|
|
|
|
#include<hgl/graph/VKPipeline.h>
|
2019-06-19 21:12:39 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-07-16 19:59:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* 渲染目标
|
|
|
|
|
*/
|
2021-12-15 19:57:35 +08:00
|
|
|
|
class RenderTarget
|
2019-07-16 19:59:53 +08:00
|
|
|
|
{
|
|
|
|
|
protected:
|
2019-06-19 21:12:39 +08:00
|
|
|
|
|
2023-03-02 20:19:25 +08:00
|
|
|
|
DeviceQueue *queue;
|
2021-12-15 19:57:35 +08:00
|
|
|
|
|
2020-10-26 21:51:30 +08:00
|
|
|
|
RenderPass *render_pass;
|
|
|
|
|
Framebuffer *fbo;
|
2019-07-16 20:22:29 +08:00
|
|
|
|
|
|
|
|
|
VkExtent2D extent;
|
2020-10-17 22:12:16 +08:00
|
|
|
|
|
2022-10-14 19:40:16 +08:00
|
|
|
|
Semaphore *render_complete_semaphore =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
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
friend class GPUDevice;
|
2019-06-19 21:12:39 +08:00
|
|
|
|
|
2023-03-02 20:19:25 +08:00
|
|
|
|
RenderTarget(DeviceQueue *,Semaphore *);
|
|
|
|
|
RenderTarget(DeviceQueue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
|
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
|
|
|
|
|
2023-03-02 20:19:25 +08:00
|
|
|
|
DeviceQueue * GetQueue () {return queue;}
|
2020-10-17 22:12:16 +08:00
|
|
|
|
const VkExtent2D & GetExtent ()const {return extent;}
|
2020-10-27 22:43:24 +08:00
|
|
|
|
virtual RenderPass * GetRenderPass () {return render_pass;}
|
2021-09-22 17:15:17 +08:00
|
|
|
|
virtual const VkRenderPass GetVkRenderPass ()const {return render_pass->GetVkRenderPass();}
|
2020-10-26 21:51:30 +08:00
|
|
|
|
virtual const uint32_t GetColorCount ()const {return fbo->GetColorCount();}
|
2020-10-27 22:43:24 +08:00
|
|
|
|
virtual Framebuffer * GetFramebuffer () {return fbo;}
|
2020-10-17 22:12:16 +08:00
|
|
|
|
|
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-27 22:43:24 +08:00
|
|
|
|
public: // command buffer
|
2020-10-26 21:51:30 +08:00
|
|
|
|
|
2023-03-02 20:19:25 +08:00
|
|
|
|
Semaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
2022-10-14 19:40:16 +08:00
|
|
|
|
virtual bool Submit (RenderCmdBuffer *,Semaphore *present_complete_semaphore=nullptr);
|
2021-12-15 19:57:35 +08:00
|
|
|
|
|
|
|
|
|
bool WaitQueue(){return queue->WaitQueue();}
|
|
|
|
|
bool WaitFence(){return queue->WaitFence();}
|
2019-07-16 19:59:53 +08:00
|
|
|
|
};//class RenderTarget
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 交换链专用渲染目标
|
|
|
|
|
*/
|
2023-08-17 11:08:21 +08:00
|
|
|
|
class RTSwapchain:public RenderTarget
|
2019-07-16 19:59:53 +08:00
|
|
|
|
{
|
2021-12-15 19:57:35 +08:00
|
|
|
|
VkDevice device;
|
2019-07-16 19:59:53 +08:00
|
|
|
|
Swapchain *swapchain;
|
2020-09-27 20:58:25 +08:00
|
|
|
|
PresentInfo present_info;
|
2019-06-19 21:12:39 +08:00
|
|
|
|
|
2022-10-14 19:40:16 +08:00
|
|
|
|
Semaphore *present_complete_semaphore=nullptr;
|
2020-10-18 13:55:12 +08:00
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
uint32_t current_frame;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2023-08-17 11:08:21 +08:00
|
|
|
|
RTSwapchain(VkDevice dev,Swapchain *sc,DeviceQueue *q,Semaphore *rcs,Semaphore *pcs,RenderPass *rp);
|
|
|
|
|
~RTSwapchain();
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
2023-05-11 00:55:44 +08:00
|
|
|
|
Framebuffer * GetFramebuffer ()override {return swapchain->sc_fbo[current_frame];}
|
|
|
|
|
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->sc_fbo[index];}
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
2020-10-26 21:51:30 +08:00
|
|
|
|
const uint32_t GetColorCount ()const override {return 1;}
|
2021-12-15 20:46:33 +08:00
|
|
|
|
const uint32_t GetImageCount ()const {return swapchain->color_count;}
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
2021-12-15 20:46:33 +08:00
|
|
|
|
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->sc_color[index];}
|
|
|
|
|
virtual Texture2D * GetDepthTexture () override{return swapchain->sc_depth;}
|
2020-10-26 21:51:30 +08:00
|
|
|
|
|
|
|
|
|
public:
|
2020-10-17 14:20:49 +08:00
|
|
|
|
|
2020-10-26 21:51:30 +08:00
|
|
|
|
const uint32_t GetCurrentFrameIndices ()const {return current_frame;}
|
2023-03-02 20:19:25 +08:00
|
|
|
|
Semaphore * GetPresentCompleteSemaphore () {return present_complete_semaphore;}
|
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);
|
2022-10-14 19:40:16 +08:00
|
|
|
|
bool Submit(VkCommandBuffer,Semaphore *);
|
2023-08-17 11:08:21 +08:00
|
|
|
|
};//class RTSwapchain:public RenderTarget
|
2019-06-19 21:12:39 +08:00
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_RENDER_TARGET_INCLUDE
|