[WIP,can't RUN] recreated TextureManager/RenderTargetManager/SwapchainModule
This commit is contained in:
@@ -25,7 +25,7 @@ public:
|
||||
virtual const AnsiString &GetName()const=0;
|
||||
};//class GraphModule
|
||||
|
||||
template<typename T> class GraphModuleInherit:public GraphModule
|
||||
template<typename T,typename BASE> class GraphModuleInherit:public BASE
|
||||
{
|
||||
AnsiString manager_name;
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
GraphModuleInherit(GPUDevice *dev,const AnsiString &name):GraphModule(dev)
|
||||
GraphModuleInherit(GPUDevice *dev,const AnsiString &name):BASE(dev)
|
||||
{
|
||||
manager_name=name;
|
||||
}
|
||||
@@ -51,8 +51,8 @@ public:
|
||||
virtual ~GraphModuleInherit()=default;
|
||||
};//class GraphModuleInherit
|
||||
|
||||
#define GRAPH_MODULE_CLASS(class_name) class class_name:public GraphModuleInherit<class_name>
|
||||
#define GRAPH_MODULE_CLASS(class_name) class class_name:public GraphModuleInherit<class_name,GraphModule>
|
||||
|
||||
#define GRAPH_MODULE_CONSTRUCT(class_name) class_name::class_name(GPUDevice *dev):GraphModuleInherit<class_name>(dev,#class_name)
|
||||
#define GRAPH_MODULE_CONSTRUCT(class_name) class_name::class_name(GPUDevice *dev):GraphModuleInherit<class_name,GraphModule>(dev,#class_name)
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -10,8 +10,6 @@ VK_NAMESPACE_BEGIN
|
||||
*/
|
||||
class RenderModule:public GraphModule
|
||||
{
|
||||
VkExtent2D current_extent;
|
||||
|
||||
public:
|
||||
|
||||
NO_COPY_NO_MOVE(RenderModule)
|
||||
@@ -19,9 +17,13 @@ public:
|
||||
using GraphModule::GraphModule;
|
||||
virtual ~RenderModule()=default;
|
||||
|
||||
virtual void OnResize(const VkExtent2D &ext){current_extent=ext;} ///<窗口大小改变
|
||||
virtual void OnResize(const VkExtent2D &)=0; ///<窗口大小改变
|
||||
|
||||
virtual void OnFrameRender(const double,RenderCmdBuffer *)=0; ///<帧绘制回调
|
||||
//virtual void OnFrameRender(const double,RenderCmdBuffer *)=0; ///<帧绘制回调
|
||||
};//class RenderModule
|
||||
|
||||
#define RENDER_MODULE_CLASS(class_name) class class_name:public GraphModuleInherit<class_name,RenderModule>
|
||||
|
||||
#define RENDER_MODULE_CONSTRUCT(class_name) class_name::class_name(GPUDevice *dev):GraphModuleInherit<class_name,RenderModule>(dev,#class_name)
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -7,12 +7,13 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
using RenderPassHASHCode=util::HashCode<128/8>;
|
||||
|
||||
inline util::Hash *CreateRenderPassHash()
|
||||
{
|
||||
return util::CreateHash(util::HASH::xxH3_128);
|
||||
}
|
||||
|
||||
class RenderPassManager:public GraphModuleInherit<RenderPassManager>
|
||||
GRAPH_MODULE_CLASS(RenderPassManager)
|
||||
{
|
||||
VkPipelineCache pipeline_cache;
|
||||
|
||||
|
33
inc/hgl/graph/module/RenderTargetManager.h
Normal file
33
inc/hgl/graph/module/RenderTargetManager.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class TextureManager;
|
||||
class RenderPassManager;
|
||||
|
||||
GRAPH_MODULE_CLASS(RenderTargetManager)
|
||||
{
|
||||
TextureManager *tex_manager;
|
||||
RenderPassManager *rp_manager;
|
||||
|
||||
public:
|
||||
|
||||
RenderTargetManager(GPUDevice *,TextureManager *tm,RenderPassManager *rpm);
|
||||
virtual ~RenderTargetManager();
|
||||
|
||||
public: //FrameBuffer相关
|
||||
|
||||
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint image_count,ImageView *depth);
|
||||
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *,ImageView *);
|
||||
|
||||
public:
|
||||
|
||||
RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1);
|
||||
RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1);
|
||||
};//class RenderTargetManager
|
||||
|
||||
VK_NAMESPACE_END
|
56
inc/hgl/graph/module/SwapchainModule.h
Normal file
56
inc/hgl/graph/module/SwapchainModule.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/RenderModule.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class RenderTargetManager;
|
||||
|
||||
RENDER_MODULE_CLASS(SwapchainModule)
|
||||
{
|
||||
Swapchain *swapchain=nullptr;
|
||||
|
||||
TextureManager *tex_manager=nullptr;
|
||||
RenderTargetManager *rt_manager=nullptr;
|
||||
RenderPassManager *rp_manager=nullptr;
|
||||
|
||||
RTSwapchain *swapchain_rt=nullptr;
|
||||
|
||||
RenderPass *swapchain_rp=nullptr;
|
||||
|
||||
RenderCmdBuffer **cmd_buf=nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
bool CreateSwapchainFBO();
|
||||
bool CreateSwapchain();
|
||||
bool CreateSwapchainRenderTarget();
|
||||
|
||||
void InitRenderCmdBuffer();
|
||||
void ClearRenderCmdBuffer();
|
||||
|
||||
public:
|
||||
|
||||
virtual void OnResize(const VkExtent2D &)override; ///<窗口大小改变
|
||||
|
||||
public:
|
||||
|
||||
SwapchainModule(GPUDevice *,TextureManager *tm,RenderTargetManager *rtm,RenderPassManager *rpm);
|
||||
virtual ~SwapchainModule();
|
||||
|
||||
bool BeginFrame();
|
||||
void EndFrame();
|
||||
|
||||
public:
|
||||
|
||||
RenderPass * GetRenderPass () {return swapchain_rp;}
|
||||
|
||||
RTSwapchain * GetRenderTarget () {return swapchain_rt;}
|
||||
|
||||
const VkExtent2D & GetSwapchainSize()const {return swapchain_rt->GetExtent();}
|
||||
|
||||
RenderCmdBuffer *GetRenderCmdBuffer();
|
||||
|
||||
};//class SwapchainModule:public RenderModule
|
||||
|
||||
VK_NAMESPACE_END
|
126
inc/hgl/graph/module/TextureManager.h
Normal file
126
inc/hgl/graph/module/TextureManager.h
Normal file
@@ -0,0 +1,126 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
#include<hgl/type/IDName.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/type/object/ObjectBaseInfo.h>
|
||||
#include<hgl/graph/ImageRegion.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
GRAPH_MODULE_CLASS(TextureManager)
|
||||
{
|
||||
DeviceQueue *texture_queue=nullptr;
|
||||
TextureCmdBuffer *texture_cmd_buf=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
TextureID texture_serial=0;
|
||||
|
||||
const TextureID AcquireID(){return texture_serial++;} ///<取得一个新的纹理ID
|
||||
|
||||
private:
|
||||
|
||||
SortedSet<VkImage> image_set;
|
||||
SortedSet<Texture *> texture_set; ///<纹理合集
|
||||
|
||||
Map<TextureID,Texture *> texture_by_id;
|
||||
Map<OSString,Texture *> texture_by_filename;
|
||||
|
||||
const TextureID Add(Texture *);
|
||||
const TextureID Add(Texture *,const OSString &);
|
||||
|
||||
public:
|
||||
|
||||
TextureManager(GPUDevice *);
|
||||
virtual ~TextureManager();
|
||||
|
||||
const VkFormatProperties GetFormatProperties(const VkFormat)const;
|
||||
|
||||
public: //Buffer
|
||||
|
||||
DeviceBuffer *CreateTransferSourceBuffer(const VkDeviceSize,const void *data_ptr=nullptr);
|
||||
|
||||
private: //Image
|
||||
|
||||
VkImage CreateImage (VkImageCreateInfo *);
|
||||
void DestroyImage (VkImage);
|
||||
|
||||
private: //texture
|
||||
|
||||
bool CopyBufferToImage (const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage);
|
||||
|
||||
bool CopyBufferToImage (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
|
||||
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
|
||||
|
||||
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
|
||||
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
|
||||
|
||||
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
|
||||
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
|
||||
|
||||
bool CommitTextureCube (TextureCube *,DeviceBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
|
||||
bool CommitTextureCubeMipmaps (TextureCube *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
|
||||
|
||||
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
|
||||
|
||||
public: //Format
|
||||
|
||||
bool CheckFormatSupport(const VkFormat,const uint32_t bits,ImageTiling tiling=ImageTiling::Optimal)const;
|
||||
|
||||
bool CheckTextureFormatSupport(const VkFormat fmt,ImageTiling tiling=ImageTiling::Optimal)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT,tiling);}
|
||||
|
||||
bool CheckColorAttachmentFormatSupport(const VkFormat fmt)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT,ImageTiling::Optimal);}
|
||||
bool CheckDepthStencilAttachFormatSupport(const VkFormat fmt)const{return CheckFormatSupport(fmt,VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT,ImageTiling::Optimal);}
|
||||
|
||||
public: //Create/Chagne
|
||||
|
||||
Texture2D *CreateTexture2D(TextureData *);
|
||||
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
|
||||
|
||||
Texture2DArray *CreateTexture2DArray(TextureData *);
|
||||
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
|
||||
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
|
||||
|
||||
TextureCube *CreateTextureCube(TextureData *);
|
||||
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
|
||||
|
||||
void Clear(TextureCreateInfo *);
|
||||
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,const void *data,const VkDeviceSize size, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
// bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const List<Image2DRegion> &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2DArray(Texture2DArray *,const void *data,const VkDeviceSize size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
public:
|
||||
|
||||
void Release(Texture *);
|
||||
void Destory(Texture *tex)
|
||||
{
|
||||
if(!tex)return;
|
||||
|
||||
Release(tex);
|
||||
delete tex;
|
||||
}
|
||||
|
||||
public: // Load
|
||||
|
||||
Texture2D * LoadTexture2D(const OSString &,bool auto_mipmaps=false);
|
||||
TextureCube * LoadTextureCube(const OSString &,bool auto_mipmaps=false);
|
||||
|
||||
Texture2DArray * CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps=false);
|
||||
bool LoadTexture2DToArray(Texture2DArray *,const uint32_t layer,const OSString &);
|
||||
|
||||
public: //TileData
|
||||
|
||||
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
||||
|
||||
};//class TextureManager
|
||||
VK_NAMESPACE_END
|
0
inc/hgl/graph/module/VkModuleDebugUtil.h
Normal file
0
inc/hgl/graph/module/VkModuleDebugUtil.h
Normal file
Reference in New Issue
Block a user