diff --git a/inc/hgl/graph/VKDebugUtils.h b/inc/hgl/graph/VKDebugUtils.h index a3e73a55..a159b5d4 100644 --- a/inc/hgl/graph/VKDebugUtils.h +++ b/inc/hgl/graph/VKDebugUtils.h @@ -36,6 +36,7 @@ private: } public: + ~DebugUtils()=default; void SetName(VkObjectType,uint64_t,const char *); diff --git a/inc/hgl/graph/VKRenderResource.h b/inc/hgl/graph/VKRenderResource.h index 4f7f765e..537bb797 100644 --- a/inc/hgl/graph/VKRenderResource.h +++ b/inc/hgl/graph/VKRenderResource.h @@ -102,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);} @@ -164,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);} @@ -177,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);} diff --git a/inc/hgl/graph/VKTexture.h b/inc/hgl/graph/VKTexture.h index 67884fbb..e97103e9 100644 --- a/inc/hgl/graph/VKTexture.h +++ b/inc/hgl/graph/VKTexture.h @@ -11,11 +11,14 @@ VK_NAMESPACE_BEGIN BitmapData *LoadBitmapFromFile(const OSString &filename); +using TextureID=int; + class Texture { protected: TextureManager *manager; + TextureID texture_id; VkDevice device; TextureData *data; @@ -23,6 +26,7 @@ protected: public: TextureManager * GetManager () {return manager;} + const TextureID GetID ()const noexcept {return texture_id;} TextureData * GetData () {return data;} @@ -44,9 +48,10 @@ public: public: - Texture(TextureManager *tm,TextureData *td) + Texture(TextureManager *tm,const TextureID &id,TextureData *td) { manager=tm; + texture_id=id; data=td; } diff --git a/inc/hgl/graph/manager/GraphManager.h b/inc/hgl/graph/manager/GraphManager.h index 3252755c..3efb599e 100644 --- a/inc/hgl/graph/manager/GraphManager.h +++ b/inc/hgl/graph/manager/GraphManager.h @@ -17,10 +17,8 @@ public: public: - GraphManager(GPUDevice *dev) - { - device=dev; - } + GraphManager(GPUDevice *dev){device=dev;} + virtual ~GraphManager()=default; };//class GraphManager VK_NAMESPACE_END diff --git a/inc/hgl/graph/manager/TextureManager.h b/inc/hgl/graph/manager/TextureManager.h index 6623cc05..32678a24 100644 --- a/inc/hgl/graph/manager/TextureManager.h +++ b/inc/hgl/graph/manager/TextureManager.h @@ -6,26 +6,38 @@ #include #include #include +#include VK_NAMESPACE_BEGIN -using TextureID =int; - class TextureManager:public GraphManager { + DeviceQueue *texture_queue; + TextureCmdBuffer *texture_cmd_buf; + +private: + + TextureID texture_serial; + + const TextureID AcquireID(){return texture_serial++;} ///<取得一个新的纹理ID + +private: + SortedSet image_set; SortedSet texture_set; ///<纹理合集 + Map texture_by_id; + Map texture_by_name; private: - DeviceQueue *texture_queue; - TextureCmdBuffer *texture_cmd_buf; + const TextureID Add(Texture *); + const TextureID Add(Texture *,const OSString &); public: - TextureManager(); + TextureManager(GPUDevice *); virtual ~TextureManager(); public: //Buffer diff --git a/src/SceneGraph/Vulkan/Texture/VKTexture2D.cpp b/src/SceneGraph/Vulkan/Texture/VKTexture2D.cpp index 14df3d2d..026e7fb8 100644 --- a/src/SceneGraph/Vulkan/Texture/VKTexture2D.cpp +++ b/src/SceneGraph/Vulkan/Texture/VKTexture2D.cpp @@ -13,7 +13,7 @@ Texture2D *TextureManager::CreateTexture2D(TextureData *tex_data) if(!tex_data) return(nullptr); - Texture2D *tex=new Texture2D(this,tex_data); + Texture2D *tex=new Texture2D(this,AcquireID(),tex_data); texture_set.Add(tex); diff --git a/src/SceneGraph/Vulkan/Texture/VKTexture2DArray.cpp b/src/SceneGraph/Vulkan/Texture/VKTexture2DArray.cpp index 6ef06ef3..aeacec87 100644 --- a/src/SceneGraph/Vulkan/Texture/VKTexture2DArray.cpp +++ b/src/SceneGraph/Vulkan/Texture/VKTexture2DArray.cpp @@ -13,7 +13,7 @@ Texture2DArray *TextureManager::CreateTexture2DArray(TextureData *tex_data) if(!tex_data) return(nullptr); - return(new Texture2DArray(this,tex_data)); + return(new Texture2DArray(this,AcquireID(),tex_data)); } Texture2DArray *TextureManager::CreateTexture2DArray(TextureCreateInfo *tci) diff --git a/src/SceneGraph/Vulkan/Texture/VKTextureCube.cpp b/src/SceneGraph/Vulkan/Texture/VKTextureCube.cpp index 504d0a0a..df2f63dd 100644 --- a/src/SceneGraph/Vulkan/Texture/VKTextureCube.cpp +++ b/src/SceneGraph/Vulkan/Texture/VKTextureCube.cpp @@ -12,7 +12,7 @@ TextureCube *TextureManager::CreateTextureCube(TextureData *tex_data) if(!tex_data) return(nullptr); - return(new TextureCube(this,tex_data)); + return(new TextureCube(this,AcquireID(),tex_data)); } TextureCube *TextureManager::CreateTextureCube(TextureCreateInfo *tci) diff --git a/src/SceneGraph/Vulkan/VKDevice.cpp b/src/SceneGraph/Vulkan/VKDevice.cpp index 5901b5b8..04ac7652 100644 --- a/src/SceneGraph/Vulkan/VKDevice.cpp +++ b/src/SceneGraph/Vulkan/VKDevice.cpp @@ -40,8 +40,6 @@ GPUDevice::~GPUDevice() bool GPUDevice::Resize(const VkExtent2D &extent) { - graph_module_manager->OnResize(extent); - SAFE_CLEAR(sc_rt); attr->RefreshSurfaceCaps(); diff --git a/src/SceneGraph/manager/TextureManager.cpp b/src/SceneGraph/manager/TextureManager.cpp index 40b129d1..4baf1c0c 100644 --- a/src/SceneGraph/manager/TextureManager.cpp +++ b/src/SceneGraph/manager/TextureManager.cpp @@ -1,11 +1,15 @@ #include +#include +#include VK_NAMESPACE_BEGIN -TextureManager::TextureManager() +TextureManager::TextureManager(GPUDevice *dev):GraphManager(dev) { - texture_cmd_buf=CreateTextureCommandBuffer(attr->physical_device->GetDeviceName()+AnsiString(":TexCmdBuffer")); - texture_queue=CreateQueue(); + texture_cmd_buf=dev->CreateTextureCommandBuffer(GetPhysicalDevice()->GetDeviceName()+AnsiString(":TexCmdBuffer")); + texture_queue=dev->CreateQueue(); + + texture_serial=0; } TextureManager::~TextureManager() @@ -14,12 +18,47 @@ TextureManager::~TextureManager() SAFE_CLEAR(texture_cmd_buf); } +const TextureID TextureManager::Add(Texture *tex) +{ + if(!tex) + return(-1); + + if(tex->GetManager()!=this) + return(-2); + + if(texture_set.Contains(tex)) + return tex->GetID(); + + texture_set.Add(tex); + texture_by_id.Add(tex->GetID(),tex); + + return tex->GetID(); +} + +const TextureID TextureManager::Add(Texture *tex,const OSString &tn) +{ + TextureID id=Add(tex); + + if(id<0) + return id; + + if(!tn.IsEmpty()) + texture_by_name.Add(tn,tex); + + return id; +} + void TextureManager::Release(Texture *tex) { if(!tex) return; + if(!texture_set.Contains(tex)) + return; + texture_set.Delete(tex); + texture_by_id.DeleteByKey(tex->GetID()); + texture_by_name.DeleteByValue(tex); } Texture2D *CreateTexture2DFromFile(TextureManager *tm,const OSString &filename,bool auto_mipmaps); @@ -35,19 +74,18 @@ Texture2D *TextureManager::LoadTexture2D(const OSString &filename,bool auto_mipm if(tex) { - texture_by_name.Add(filename,tex); - Add(tex); + Add(tex,filename); - #ifdef _DEBUG - DebugUtils *du=device->GetDebugUtils(); + //#ifdef _DEBUG + // DebugUtils *du=device->GetDebugUtils(); - if(du) - { - const UTF8String name=U8_TEXT("Tex2D:")+ToUTF8String(filename); - - du->SetImage(tex->GetImage(),(char *)(name.c_str())); - } - #endif//_DEBUG + // if(du) + // { + // const UTF8String name=U8_TEXT("Tex2D:")+ToUTF8String(filename); + // + // du->SetImage(tex->GetImage(),(char *)(name.c_str())); + // } + //#endif//_DEBUG } return tex; @@ -62,16 +100,16 @@ Texture2DArray *TextureManager::CreateTexture2DArray(const AnsiString &name,cons else return nullptr; - #ifdef _DEBUG - DebugUtils *du=device->GetDebugUtils(); - - if(du) - { - du->SetImage(ta->GetImage(),"Tex2DArrayImage:"+name); - du->SetImageView(ta->GetVulkanImageView(),"Tex2DArrayImageView:"+name); - du->SetDeviceMemory(ta->GetDeviceMemory(),"Tex2DArrayMemory:"+name); - } - #endif//_DEBUG + //#ifdef _DEBUG + // DebugUtils *du=device->GetDebugUtils(); + // + // if(du) + // { + // du->SetImage(ta->GetImage(),"Tex2DArrayImage:"+name); + // du->SetImageView(ta->GetVulkanImageView(),"Tex2DArrayImageView:"+name); + // du->SetDeviceMemory(ta->GetDeviceMemory(),"Tex2DArrayMemory:"+name); + // } + //#endif//_DEBUG return ta; } @@ -101,8 +139,7 @@ TextureCube *TextureManager::LoadTextureCube(const OSString &filename,bool auto_ if(tex) { - texture_by_name.Add(filename,tex); - Add(tex); + Add(tex,filename); } return tex;