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
|
|
|
|
/**
|
|
|
|
|
* 渲染目标
|
|
|
|
|
*/
|
2020-10-21 12:39:22 +08:00
|
|
|
|
class RenderTarget:public GPUQueue
|
2019-07-16 19:59:53 +08:00
|
|
|
|
{
|
|
|
|
|
protected:
|
2019-06-19 21:12:39 +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
|
|
|
|
|
2020-10-26 21:51:30 +08:00
|
|
|
|
GPUSemaphore *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;
|
|
|
|
|
|
2020-10-27 18:11:39 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
ObjectList<Pipeline> pipeline_list;
|
|
|
|
|
|
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
|
|
|
|
|
2020-10-27 22:43:24 +08:00
|
|
|
|
RenderTarget(GPUDevice *dev,Framebuffer *_fb,const uint32_t fence_count=1);
|
|
|
|
|
RenderTarget(GPUDevice *dev,RenderPass *_rp,Framebuffer *_fb,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-27 22:43:24 +08:00
|
|
|
|
virtual RenderPass * GetRenderPass () {return render_pass;}
|
|
|
|
|
virtual const VkRenderPass GetVkRenderPass ()const {return *render_pass;}
|
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: //pipeline
|
2020-10-27 18:11:39 +08:00
|
|
|
|
|
|
|
|
|
Pipeline *CreatePipeline(Material *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
2021-06-16 11:43:19 +08:00
|
|
|
|
Pipeline *CreatePipeline(MaterialParameters *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
2020-10-27 18:11:39 +08:00
|
|
|
|
Pipeline *CreatePipeline(Material *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
2021-06-16 11:43:19 +08:00
|
|
|
|
Pipeline *CreatePipeline(MaterialParameters *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
2020-10-27 18:11:39 +08:00
|
|
|
|
Pipeline *CreatePipeline(Material *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
2021-06-16 11:43:19 +08:00
|
|
|
|
Pipeline *CreatePipeline(MaterialParameters *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false);
|
2020-10-27 18:11:39 +08:00
|
|
|
|
|
2020-10-27 22:43:24 +08:00
|
|
|
|
public: // command buffer
|
2020-10-26 21:51:30 +08:00
|
|
|
|
|
|
|
|
|
GPUSemaphore * GetRenderCompleteSemaphore (){return render_complete_semaphore;}
|
2020-11-09 15:37:00 +08:00
|
|
|
|
virtual bool Submit (RenderCmdBuffer *,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
|
|
|
|
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:
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
SwapchainRenderTarget(GPUDevice *dev,Swapchain *sc);
|
2019-07-16 19:59:53 +08:00
|
|
|
|
~SwapchainRenderTarget();
|
|
|
|
|
|
2020-10-27 22:43:24 +08:00
|
|
|
|
Framebuffer * GetFramebuffer ()override {return render_frame[current_frame];}
|
|
|
|
|
Framebuffer * GetFramebuffer (const uint32_t index) {return render_frame[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;}
|
|
|
|
|
const uint32_t GetImageCount ()const {return swap_chain_count;}
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
2020-10-26 21:51:30 +08:00
|
|
|
|
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->GetColorTexture(index);}
|
|
|
|
|
virtual Texture2D * GetDepthTexture () override{return swapchain->GetDepthTexture();}
|
|
|
|
|
|
|
|
|
|
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;}
|
|
|
|
|
GPUSemaphore * 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);
|
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
|