restruct codes for TextureManager
This commit is contained in:
parent
1543ed8952
commit
f1f562c709
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 43bc9af0200846ce3f31fe97d963009e6b199f38
|
||||
Subproject commit 6d9bced95c7fb7fe7a3b6c734d0e7330bacfb2d6
|
@ -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格式
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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);}
|
||||
|
@ -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;}
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -139,8 +139,10 @@ SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h
|
||||
Vulkan/VKArrayBuffer.cpp
|
||||
)
|
||||
|
||||
SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
|
||||
Vulkan/Texture/GenMipmaps.cpp
|
||||
SET(VK_IMAGE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
|
||||
Vulkan/VKDeviceImage.cpp)
|
||||
|
||||
SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/GenMipmaps.cpp
|
||||
Vulkan/Texture/VKTexture.cpp
|
||||
Vulkan/Texture/VKTexture2D.cpp
|
||||
Vulkan/Texture/VKTexture2DArray.cpp
|
||||
@ -161,7 +163,6 @@ SET(VK_DEVICE_CREATER_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h
|
||||
|
||||
SET(VK_DEVICE_SOURCE Vulkan/VKDeviceMemory.cpp
|
||||
Vulkan/VKDeviceBuffer.cpp
|
||||
Vulkan/VKDeviceImage.cpp
|
||||
Vulkan/VKDeviceSampler.cpp
|
||||
Vulkan/VKDeviceMaterial.cpp
|
||||
Vulkan/VKDeviceFramebuffer.cpp
|
||||
@ -182,8 +183,9 @@ SOURCE_GROUP("Vulkan\\Device\\Debug" FILES ${VK_DEBUG_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Instance" FILES ${VK_INST_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Physical Device" FILES ${VK_PHYSICAL_DEVICE_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Memory" FILES ${VK_MEMORY_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Texture" FILES ${VK_DEVICE_TEXTURE_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Device\\Texture\\Loader" FILES ${VK_TEXTURE_LOADER_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Texture" FILES ${VK_DEVICE_TEXTURE_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Texture\\Loader" FILES ${VK_TEXTURE_LOADER_SOURCE})
|
||||
SOURCE_GROUP("Vulkan\\Texture\\Image" FILES ${VK_IMAGE_SOURCE})
|
||||
|
||||
SET(VK_DESCRIPTOR_SETS_SOURCE ${SG_INCLUDE_PATH}/VKDescriptorSet.h
|
||||
Vulkan/VKDescriptorSet.cpp
|
||||
@ -356,6 +358,7 @@ SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
|
||||
${VK_PHYSICAL_DEVICE_SOURCE}
|
||||
${VK_DESCRIPTOR_SETS_SOURCE}
|
||||
${VK_SHADER_SOURCE}
|
||||
${VK_IMAGE_SOURCE}
|
||||
${VK_TEXTURE_SOURCE}
|
||||
${VK_MATERIAL_SOURCE}
|
||||
${VK_RENDER_PASS_SOURCE}
|
||||
|
@ -2,14 +2,15 @@
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/manager/TextureManager.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
TileData::TileData(GPUDevice *dev,Texture2D *tt,const uint tw,const uint th)
|
||||
TileData::TileData(TextureManager *tm,Texture2D *tt,const uint tw,const uint th)
|
||||
{
|
||||
device=dev;
|
||||
texture_manager=tm;
|
||||
|
||||
tile_texture=tt;
|
||||
|
||||
@ -52,7 +53,7 @@ namespace hgl
|
||||
|
||||
tile_bytes=GetImageBytes(tile_texture->GetFormat(),tile_width*tile_height);
|
||||
|
||||
tile_buffer=device->CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,tile_bytes*tile_max_count,nullptr);
|
||||
tile_buffer=texture_manager->CreateTransferSourceBuffer(tile_bytes*tile_max_count);
|
||||
|
||||
commit_ptr=nullptr;
|
||||
}
|
||||
@ -79,7 +80,7 @@ namespace hgl
|
||||
tile_buffer->Unmap();
|
||||
commit_ptr=nullptr;
|
||||
|
||||
if(!device->ChangeTexture2D(tile_texture,tile_buffer,commit_list))
|
||||
if(!texture_manager->ChangeTexture2D(tile_texture,tile_buffer,commit_list))
|
||||
return -2;
|
||||
|
||||
const int result=commit_list.GetCount();
|
||||
|
@ -13,7 +13,11 @@ Texture2D *TextureManager::CreateTexture2D(TextureData *tex_data)
|
||||
if(!tex_data)
|
||||
return(nullptr);
|
||||
|
||||
return(new Texture2D(GetVkDevice(),tex_data));
|
||||
Texture2D *tex=new Texture2D(GetVkDevice(),tex_data);
|
||||
|
||||
texture_set.Add(tex);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
Texture2D *TextureManager::CreateTexture2D(TextureCreateInfo *tci)
|
||||
|
@ -13,6 +13,8 @@ VkImage TextureManager::CreateImage(VkImageCreateInfo *ici)
|
||||
if(vkCreateImage(GetVkDevice(),ici, nullptr, &image)!=VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
image_set.Add(image);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -20,6 +22,11 @@ void TextureManager::DestroyImage(VkImage img)
|
||||
{
|
||||
if(img==VK_NULL_HANDLE)return;
|
||||
|
||||
if(!image_set.Contains(img))
|
||||
return;
|
||||
|
||||
image_set.Delete(img);
|
||||
|
||||
vkDestroyImage(GetVkDevice(),img,nullptr);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -1,11 +1,14 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKImageView.h>
|
||||
#include<hgl/graph/VKMemory.h>
|
||||
#include<hgl/graph/manager/TextureManager.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture::~Texture()
|
||||
{
|
||||
if(!data)return;
|
||||
|
||||
manager->Release(this);
|
||||
|
||||
if(data->image_view)
|
||||
delete data->image_view;
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/TileData.h>
|
||||
#include<hgl/graph/manager/TextureManager.h>
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -61,7 +63,7 @@ namespace
|
||||
}//namespace
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count)
|
||||
TileData *RenderFramework::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count)
|
||||
{
|
||||
if(!CheckVulkanFormat(format))
|
||||
return(nullptr);
|
||||
@ -69,7 +71,7 @@ TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const
|
||||
if(width<=0||height<=0||count<=0)
|
||||
return(nullptr);
|
||||
|
||||
const uint32_t max_2d_texture=attr->physical_device->GetMaxImage2D();
|
||||
const uint32_t max_2d_texture=device->GetPhysicalDevice()->GetMaxImage2D();
|
||||
|
||||
uint tex_width,tex_height;
|
||||
|
||||
@ -84,16 +86,16 @@ TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const
|
||||
|
||||
if(RangeCheck(vf->color))
|
||||
{
|
||||
tex=CreateTexture2D(new ColorTextureCreateInfo(format,extent));
|
||||
tex=texture_manager->CreateTexture2D(new ColorTextureCreateInfo(format,extent));
|
||||
}
|
||||
else
|
||||
if(RangeCheck(vf->depth))
|
||||
{
|
||||
tex=CreateTexture2D(new DepthTextureCreateInfo(format,extent));
|
||||
tex=texture_manager->CreateTexture2D(new DepthTextureCreateInfo(format,extent));
|
||||
}
|
||||
else
|
||||
return(nullptr);
|
||||
|
||||
return(new TileData(this,tex,width,height));
|
||||
return(new TileData(texture_manager,tex,width,height));
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -7,7 +7,7 @@ VK_NAMESPACE_BEGIN
|
||||
* @param f 字体需求信息
|
||||
* @param limit_count 缓冲字符数量上限
|
||||
*/
|
||||
TileFont *GPUDevice::CreateTileFont(FontSource *fs,int limit_count)
|
||||
TileFont *RenderFramework::CreateTileFont(FontSource *fs,int limit_count)
|
||||
{
|
||||
if(!fs)return(nullptr);
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
#include<hgl/graph/manager/TextureManager.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
void TextureManager::Release(Texture *tex)
|
||||
{
|
||||
if(!tex)
|
||||
return;
|
||||
|
||||
texture_set.Delete(tex);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user