[WIP,can't RUN] recreated TextureManager/RenderTargetManager/SwapchainModule
This commit is contained in:
@@ -6,7 +6,12 @@
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class FontSource;
|
||||
class TileFont;
|
||||
class RenderPassManager;
|
||||
class TextureManager;
|
||||
class RenderTargetManager;
|
||||
class SwapchainModule;
|
||||
|
||||
class RenderFramework:public io::WindowEvent
|
||||
{
|
||||
@@ -19,10 +24,15 @@ class RenderFramework:public io::WindowEvent
|
||||
|
||||
protected:
|
||||
|
||||
GraphModuleManager *module_manager =nullptr;
|
||||
GraphModuleManager * module_manager =nullptr;
|
||||
|
||||
RenderPassManager * render_pass_manager =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
RenderPassManager * render_pass_manager =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
|
||||
TextureManager * texture_manager =nullptr;
|
||||
RenderTargetManager * rt_manager =nullptr;
|
||||
|
||||
SwapchainModule * swapchain_module =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
@@ -33,9 +43,13 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
GraphModuleManager *GetModuleManager(){return module_manager;}
|
||||
RenderPassManager * GetRenderPassManager(){return render_pass_manager;}
|
||||
GraphModuleManager * GetModuleManager(){return module_manager;}
|
||||
|
||||
RenderPassManager * GetRenderPassManager (){return render_pass_manager;}
|
||||
TextureManager * GetTextureManager (){return texture_manager;}
|
||||
RenderTargetManager * GetRenderTargetManager (){return rt_manager;}
|
||||
|
||||
SwapchainModule * GetSwapchainModule (){return swapchain_module;}
|
||||
|
||||
public:
|
||||
|
||||
@@ -44,6 +58,10 @@ public:
|
||||
|
||||
virtual bool Init(uint w,uint h);
|
||||
|
||||
public:
|
||||
|
||||
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建只使用一种字符的Tile字符管理对象
|
||||
|
||||
public: // event
|
||||
|
||||
void OnResize(uint w,uint h);
|
||||
|
@@ -12,13 +12,15 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class TextureManager;
|
||||
|
||||
/**
|
||||
* TileData是一种处理大量等同尺寸及格式贴图的管理机制,程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注:Tile的大小不必符合2次幂)
|
||||
* Tile的增加或删除,程序会自动排序,尽可能小的减少I/O消耗。
|
||||
*/
|
||||
class TileData ///Tile纹理管理
|
||||
{
|
||||
GPUDevice *device;
|
||||
TextureManager *texture_manager;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -51,8 +53,8 @@ namespace hgl
|
||||
Texture2D * GetTexture ()const{return tile_texture;} ///<取得贴图
|
||||
|
||||
public:
|
||||
|
||||
TileData(GPUDevice *,Texture2D *,const uint tw,const uint th);
|
||||
|
||||
TileData(TextureManager *,Texture2D *,const uint tw,const uint th);
|
||||
virtual ~TileData();
|
||||
|
||||
void BeginCommit();
|
||||
|
@@ -152,57 +152,6 @@ public: //间接绘制
|
||||
IndirectDrawIndexedBuffer * CreateIndirectDrawIndexedBuffer(const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
|
||||
IndirectDispatchBuffer * CreateIndirectDispatchBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
|
||||
|
||||
public: //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: //Texture
|
||||
|
||||
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);}
|
||||
|
||||
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 *,void *data,const uint32_t 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 *,void *data,const uint32_t size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
public: //
|
||||
|
||||
Sampler *CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
@@ -228,18 +177,6 @@ public:
|
||||
|
||||
DeviceQueue *CreateQueue(const uint32_t fence_count=1,const bool create_signaled=false);
|
||||
|
||||
public: //FrameBuffer相关
|
||||
|
||||
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_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);
|
||||
|
||||
public:
|
||||
|
||||
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
|
||||
|
@@ -16,7 +16,7 @@ class Framebuffer
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
friend class RenderTargetManager;
|
||||
|
||||
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t color_count,bool depth);
|
||||
|
||||
|
@@ -34,7 +34,6 @@ using DescriptorSetID =int;
|
||||
using PrimitiveID =int;
|
||||
using RenderableID =int;
|
||||
using SamplerID =int;
|
||||
using TextureID =int;
|
||||
using StaticMeshID =int;
|
||||
|
||||
class VertexAttribData;
|
||||
@@ -51,7 +50,6 @@ class RenderResource
|
||||
|
||||
ShaderModuleMapByName shader_module_by_name[VK_SHADER_STAGE_TYPE_COUNT];
|
||||
Map<AnsiString,Material *> material_by_name;
|
||||
Map<OSString,Texture *> texture_by_name;
|
||||
|
||||
IDObjectManage<MaterialID, Material> rm_material; ///<材质合集
|
||||
IDObjectManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
|
||||
@@ -59,7 +57,6 @@ class RenderResource
|
||||
IDObjectManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
|
||||
IDObjectManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
|
||||
IDObjectManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
|
||||
IDObjectManage<TextureID, Texture> rm_textures; ///<纹理合集
|
||||
IDObjectManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
|
||||
|
||||
IDObjectManage<StaticMeshID, StaticMesh> rm_static_mesh; ///<静态网格合集
|
||||
@@ -105,7 +102,6 @@ public: //添加数据到管理器(如果指针为nullptr会返回-1)
|
||||
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
|
||||
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
|
||||
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
|
||||
TextureID Add(Texture * t ){return rm_textures.Add(t);}
|
||||
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
||||
StaticMeshID Add(StaticMesh * sm ){return rm_static_mesh.Add(sm);}
|
||||
|
||||
@@ -159,14 +155,6 @@ public: //Material
|
||||
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
Sampler * CreateSampler(Texture *);
|
||||
|
||||
public: //texture
|
||||
|
||||
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: //Get
|
||||
|
||||
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
||||
@@ -175,7 +163,6 @@ public: //Get
|
||||
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
|
||||
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
||||
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
|
||||
Texture * GetTexture (const TextureID &id){return rm_textures.Get(id);}
|
||||
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
||||
|
||||
StaticMesh * GetStaticMesh (const StaticMeshID &id){return rm_static_mesh.Get(id);}
|
||||
@@ -188,7 +175,6 @@ public: //Release
|
||||
void Release(Primitive * p ){rm_primitives.Release(p);}
|
||||
void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);}
|
||||
void Release(Sampler * s ){rm_samplers.Release(s);}
|
||||
void Release(Texture * t ){rm_textures.Release(t);}
|
||||
void Release(Renderable * r ){rm_renderables.Release(r);}
|
||||
|
||||
void Release(StaticMesh * sm ){rm_static_mesh.Release(sm);}
|
||||
|
@@ -32,7 +32,7 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
friend class GPUDevice;
|
||||
friend class RenderTargetManager;
|
||||
|
||||
RenderTarget(DeviceQueue *,Semaphore *);
|
||||
RenderTarget(DeviceQueue *,Semaphore *,RenderPass *_rp,Framebuffer *_fb,Texture2D **color_texture_list,const uint32_t color_count,Texture2D *depth_texture);
|
||||
|
@@ -9,18 +9,21 @@ struct Swapchain
|
||||
{
|
||||
public:
|
||||
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
|
||||
VkExtent2D extent;
|
||||
VkExtent2D extent;
|
||||
VkSurfaceTransformFlagBitsKHR transform;
|
||||
|
||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swap_chain =VK_NULL_HANDLE;
|
||||
VkSurfaceFormatKHR surface_format;
|
||||
VkFormat depth_format;
|
||||
|
||||
uint32_t color_count =0;
|
||||
uint32_t color_count =0;
|
||||
|
||||
Texture2D ** sc_color =nullptr;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
Texture2D ** sc_color =nullptr;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
|
||||
Framebuffer ** sc_fbo =nullptr;
|
||||
Framebuffer ** sc_fbo =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -11,15 +11,23 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
BitmapData *LoadBitmapFromFile(const OSString &filename);
|
||||
|
||||
using TextureID=int;
|
||||
class TextureManager;
|
||||
|
||||
class Texture
|
||||
{
|
||||
protected:
|
||||
|
||||
TextureManager *manager;
|
||||
TextureID texture_id;
|
||||
|
||||
VkDevice device;
|
||||
TextureData *data;
|
||||
|
||||
public:
|
||||
|
||||
TextureManager * GetManager () {return manager;}
|
||||
const TextureID GetID ()const noexcept {return texture_id;}
|
||||
|
||||
TextureData * GetData () {return data;}
|
||||
|
||||
VkDeviceMemory GetDeviceMemory () {return data?(data->memory?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE):VK_NULL_HANDLE;}
|
||||
@@ -40,9 +48,10 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
Texture(VkDevice dev,TextureData *td)
|
||||
Texture(TextureManager *tm,const TextureID &id,TextureData *td)
|
||||
{
|
||||
device=dev;
|
||||
manager=tm;
|
||||
texture_id=id;
|
||||
data=td;
|
||||
}
|
||||
|
||||
@@ -94,8 +103,8 @@ public:
|
||||
class TextureCube:public Texture
|
||||
{
|
||||
public:
|
||||
|
||||
TextureCube(VkDevice dev,TextureData *td):Texture(dev,td){}
|
||||
|
||||
using Texture::Texture;
|
||||
~TextureCube()=default;
|
||||
|
||||
static VkImageViewType GetImageViewType(){return VK_IMAGE_VIEW_TYPE_CUBE;}
|
||||
|
@@ -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