restruct codes for TextureManager

This commit is contained in:
2024-11-05 00:04:36 +08:00
parent 1543ed8952
commit f1f562c709
17 changed files with 127 additions and 74 deletions

View File

@@ -9,7 +9,7 @@ const RENDER_BUFFER_NAME RenderBuffer_Swapchain ="Swapchain";
const RENDER_BUFFER_NAME RenderBuffer_Depth ="Depth";
const RENDER_BUFFER_NAME RenderBuffer_Stencil ="Stencil";
const RENDER_BUFFER_NAME VBuffer_MeshID ="VB_MeshID"; ///< 所绘制的Mesh编号, R32UI格式
const RENDER_BUFFER_NAME VBuffer_MeshID ="VB_MeshID"; ///< 所绘制的Mesh编号, RGBA8UI格式
const RENDER_BUFFER_NAME VBuffer_TriangleID ="VB_TriangleID"; ///< 三角形编号, R8UI格式
const RENDER_BUFFER_NAME VBuffer_MaterialID ="VB_MaterialID"; ///< 材质ID与材质实例ID, RG8UI格式

View File

@@ -7,36 +7,41 @@
VK_NAMESPACE_BEGIN
class GraphModule;
class TileData;
class TileFont;
class FontSource;
/**
* 渲染模块工作配置
*/
class GraphModuleWorkConfig
{
/**
* 渲染模块名称
* 在render_module为nullptr时用于创建或加载RenderModule。
* 它和RenderModule返回的名称有可能一样但也有可能不一样
*/
AnsiString render_module_name;
GraphModule *render_module=nullptr;
BlendMode blend_mode;
RenderOrder render_order;
public:
const AnsiString &GetModuleName()const{return render_module_name;} ///<取得渲染模块名称
GraphModule *GetModule(){return render_module;} ///<取得渲染模块
public:
GraphModuleWorkConfig();
virtual ~GraphModuleWorkConfig()=default;
};//class GraphModuleWorkConfig
//
///**
// * 渲染模块工作配置
// */
//class GraphModuleWorkConfig
//{
// /**
// * 渲染模块名称
// * 在render_module为nullptr时用于创建或加载RenderModule
// * 它和RenderModule返回的名称有可能一样但也有可能不一样。
// */
// AnsiString render_module_name;
// GraphModule *render_module=nullptr;
//
// BlendMode blend_mode;
// RenderOrder render_order;
//
//public:
//
// const AnsiString &GetModuleName()const{return render_module_name;} ///<取得渲染模块名称
//
// GraphModule *GetModule(){return render_module;} ///<取得渲染模块
//
//public:
//
// GraphModuleWorkConfig();
// virtual ~GraphModuleWorkConfig()=default;
//};//class GraphModuleWorkConfig
class Window;
class VulkanInstance;
class TextureManager;
@@ -105,6 +110,12 @@ public:
virtual void EndFrame(){}; ///<当前帧结束
virtual void MainLoop(); ///<主循环
public: //TileData
TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class RenderFramework
VK_NAMESPACE_END

View File

@@ -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:
@@ -52,7 +54,7 @@ namespace hgl
public:
TileData(GPUDevice *,Texture2D *,const uint tw,const uint th);
TileData(TextureManager *,Texture2D *,const uint tw,const uint th);
virtual ~TileData();
void BeginCommit();

View File

@@ -198,12 +198,6 @@ 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数据集
TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体
};//class GPUDevice
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE

View File

@@ -34,7 +34,6 @@ using DescriptorSetID =int;
using PrimitiveID =int;
using RenderableID =int;
using SamplerID =int;
using TextureID =int;
using StaticMeshID =int;
class VertexAttribData;
@@ -59,7 +58,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 +103,7 @@ 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);}
// 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);}
@@ -175,7 +173,7 @@ 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);}
// 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 +186,7 @@ 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(Texture * t ){rm_textures.Release(t);}
void Release(Renderable * r ){rm_renderables.Release(r);}
void Release(StaticMesh * sm ){rm_static_mesh.Release(sm);}

View File

@@ -15,11 +15,15 @@ class Texture
{
protected:
TextureManager *manager;
VkDevice device;
TextureData *data;
public:
TextureManager * GetManager () {return manager;}
TextureData * GetData () {return data;}
VkDeviceMemory GetDeviceMemory () {return data?(data->memory?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE):VK_NULL_HANDLE;}
@@ -40,9 +44,9 @@ public:
public:
Texture(VkDevice dev,TextureData *td)
Texture(TextureManager *tm,TextureData *td)
{
device=dev;
manager=tm;
data=td;
}
@@ -95,7 +99,7 @@ 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;}

View File

@@ -24,10 +24,10 @@ namespace hgl
friend class TextLayout;
friend class TextRender;
SortedSets<u32char> chars_sets;
SortedSet<u32char> chars_sets;
const SortedSets<u32char> &GetCharsSets()const{return chars_sets;}
void SetCharsSets(const SortedSets<u32char> &sl){chars_sets=sl;}
const SortedSet<u32char> &GetCharsSets()const{return chars_sets;}
void SetCharsSets(const SortedSet<u32char> &sl){chars_sets=sl;}
void ClearCharsSets(){chars_sets.Clear();}
private:

View File

@@ -1,16 +1,22 @@
#pragma once
#include<hgl/graph/manager/GraphManager.h>
#include<hgl/type/SortedSets.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>
VK_NAMESPACE_BEGIN
using TextureID =int;
class TextureManager:public GraphManager
{
SortedSets<Texture *> texture_list;
SortedSet<VkImage> image_set;
SortedSet<Texture *> texture_set; ///<纹理合集
private:
DeviceQueue *texture_queue;
TextureCmdBuffer *texture_cmd_buf;
@@ -20,11 +26,13 @@ public:
TextureManager();
virtual ~TextureManager();
public: //Buffer
private: //Buffer
DeviceBuffer *CreateTransferSourceBuffer(const VkDeviceSize,const void *data_ptr=nullptr);
public: //Image
friend class TileData;
private: //Image
VkImage CreateImage (VkImageCreateInfo *);
void DestroyImage (VkImage);
@@ -80,6 +88,9 @@ public: //Create/Chagne
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 *);
};//class TextureManager
VK_NAMESPACE_END