few codes about TextureManager
This commit is contained in:
parent
95e9fe79a9
commit
acdbdcd8b5
@ -36,6 +36,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
~DebugUtils()=default;
|
~DebugUtils()=default;
|
||||||
|
|
||||||
void SetName(VkObjectType,uint64_t,const char *);
|
void SetName(VkObjectType,uint64_t,const char *);
|
||||||
|
@ -102,7 +102,6 @@ public: //添加数据到管理器(如果指针为nullptr会返回-1)
|
|||||||
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
|
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
|
||||||
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
|
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
|
||||||
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
|
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);}
|
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
||||||
StaticMeshID Add(StaticMesh * sm ){return rm_static_mesh.Add(sm);}
|
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);}
|
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
|
||||||
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
||||||
Sampler * GetSampler (const SamplerID &id){return rm_samplers.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);}
|
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
||||||
|
|
||||||
StaticMesh * GetStaticMesh (const StaticMeshID &id){return rm_static_mesh.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(Primitive * p ){rm_primitives.Release(p);}
|
||||||
void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);}
|
void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);}
|
||||||
void Release(Sampler * s ){rm_samplers.Release(s);}
|
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(Renderable * r ){rm_renderables.Release(r);}
|
||||||
|
|
||||||
void Release(StaticMesh * sm ){rm_static_mesh.Release(sm);}
|
void Release(StaticMesh * sm ){rm_static_mesh.Release(sm);}
|
||||||
|
@ -11,11 +11,14 @@ VK_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
BitmapData *LoadBitmapFromFile(const OSString &filename);
|
BitmapData *LoadBitmapFromFile(const OSString &filename);
|
||||||
|
|
||||||
|
using TextureID=int;
|
||||||
|
|
||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
TextureManager *manager;
|
TextureManager *manager;
|
||||||
|
TextureID texture_id;
|
||||||
|
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
TextureData *data;
|
TextureData *data;
|
||||||
@ -23,6 +26,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
TextureManager * GetManager () {return manager;}
|
TextureManager * GetManager () {return manager;}
|
||||||
|
const TextureID GetID ()const noexcept {return texture_id;}
|
||||||
|
|
||||||
TextureData * GetData () {return data;}
|
TextureData * GetData () {return data;}
|
||||||
|
|
||||||
@ -44,9 +48,10 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Texture(TextureManager *tm,TextureData *td)
|
Texture(TextureManager *tm,const TextureID &id,TextureData *td)
|
||||||
{
|
{
|
||||||
manager=tm;
|
manager=tm;
|
||||||
|
texture_id=id;
|
||||||
data=td;
|
data=td;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,10 +17,8 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GraphManager(GPUDevice *dev)
|
GraphManager(GPUDevice *dev){device=dev;}
|
||||||
{
|
virtual ~GraphManager()=default;
|
||||||
device=dev;
|
|
||||||
}
|
|
||||||
};//class GraphManager
|
};//class GraphManager
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -6,26 +6,38 @@
|
|||||||
#include<hgl/type/RectScope.h>
|
#include<hgl/type/RectScope.h>
|
||||||
#include<hgl/type/object/ObjectBaseInfo.h>
|
#include<hgl/type/object/ObjectBaseInfo.h>
|
||||||
#include<hgl/graph/ImageRegion.h>
|
#include<hgl/graph/ImageRegion.h>
|
||||||
|
#include<hgl/graph/VKTexture.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
using TextureID =int;
|
|
||||||
|
|
||||||
class TextureManager:public GraphManager
|
class TextureManager:public GraphManager
|
||||||
{
|
{
|
||||||
|
DeviceQueue *texture_queue;
|
||||||
|
TextureCmdBuffer *texture_cmd_buf;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
TextureID texture_serial;
|
||||||
|
|
||||||
|
const TextureID AcquireID(){return texture_serial++;} ///<取得一个新的纹理ID
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
SortedSet<VkImage> image_set;
|
SortedSet<VkImage> image_set;
|
||||||
SortedSet<Texture *> texture_set; ///<纹理合集
|
SortedSet<Texture *> texture_set; ///<纹理合集
|
||||||
|
|
||||||
|
Map<TextureID,Texture *> texture_by_id;
|
||||||
|
|
||||||
Map<OSString,Texture *> texture_by_name;
|
Map<OSString,Texture *> texture_by_name;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
DeviceQueue *texture_queue;
|
const TextureID Add(Texture *);
|
||||||
TextureCmdBuffer *texture_cmd_buf;
|
const TextureID Add(Texture *,const OSString &);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TextureManager();
|
TextureManager(GPUDevice *);
|
||||||
virtual ~TextureManager();
|
virtual ~TextureManager();
|
||||||
|
|
||||||
public: //Buffer
|
public: //Buffer
|
||||||
|
@ -13,7 +13,7 @@ Texture2D *TextureManager::CreateTexture2D(TextureData *tex_data)
|
|||||||
if(!tex_data)
|
if(!tex_data)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
Texture2D *tex=new Texture2D(this,tex_data);
|
Texture2D *tex=new Texture2D(this,AcquireID(),tex_data);
|
||||||
|
|
||||||
texture_set.Add(tex);
|
texture_set.Add(tex);
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ Texture2DArray *TextureManager::CreateTexture2DArray(TextureData *tex_data)
|
|||||||
if(!tex_data)
|
if(!tex_data)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new Texture2DArray(this,tex_data));
|
return(new Texture2DArray(this,AcquireID(),tex_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2DArray *TextureManager::CreateTexture2DArray(TextureCreateInfo *tci)
|
Texture2DArray *TextureManager::CreateTexture2DArray(TextureCreateInfo *tci)
|
||||||
|
@ -12,7 +12,7 @@ TextureCube *TextureManager::CreateTextureCube(TextureData *tex_data)
|
|||||||
if(!tex_data)
|
if(!tex_data)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new TextureCube(this,tex_data));
|
return(new TextureCube(this,AcquireID(),tex_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureCube *TextureManager::CreateTextureCube(TextureCreateInfo *tci)
|
TextureCube *TextureManager::CreateTextureCube(TextureCreateInfo *tci)
|
||||||
|
@ -40,8 +40,6 @@ GPUDevice::~GPUDevice()
|
|||||||
|
|
||||||
bool GPUDevice::Resize(const VkExtent2D &extent)
|
bool GPUDevice::Resize(const VkExtent2D &extent)
|
||||||
{
|
{
|
||||||
graph_module_manager->OnResize(extent);
|
|
||||||
|
|
||||||
SAFE_CLEAR(sc_rt);
|
SAFE_CLEAR(sc_rt);
|
||||||
|
|
||||||
attr->RefreshSurfaceCaps();
|
attr->RefreshSurfaceCaps();
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
#include<hgl/graph/manager/TextureManager.h>
|
#include<hgl/graph/manager/TextureManager.h>
|
||||||
|
#include<hgl/graph/VKDevice.h>
|
||||||
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
TextureManager::TextureManager()
|
TextureManager::TextureManager(GPUDevice *dev):GraphManager(dev)
|
||||||
{
|
{
|
||||||
texture_cmd_buf=CreateTextureCommandBuffer(attr->physical_device->GetDeviceName()+AnsiString(":TexCmdBuffer"));
|
texture_cmd_buf=dev->CreateTextureCommandBuffer(GetPhysicalDevice()->GetDeviceName()+AnsiString(":TexCmdBuffer"));
|
||||||
texture_queue=CreateQueue();
|
texture_queue=dev->CreateQueue();
|
||||||
|
|
||||||
|
texture_serial=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureManager::~TextureManager()
|
TextureManager::~TextureManager()
|
||||||
@ -14,12 +18,47 @@ TextureManager::~TextureManager()
|
|||||||
SAFE_CLEAR(texture_cmd_buf);
|
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)
|
void TextureManager::Release(Texture *tex)
|
||||||
{
|
{
|
||||||
if(!tex)
|
if(!tex)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(!texture_set.Contains(tex))
|
||||||
|
return;
|
||||||
|
|
||||||
texture_set.Delete(tex);
|
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);
|
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)
|
if(tex)
|
||||||
{
|
{
|
||||||
texture_by_name.Add(filename,tex);
|
Add(tex,filename);
|
||||||
Add(tex);
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
//#ifdef _DEBUG
|
||||||
DebugUtils *du=device->GetDebugUtils();
|
// DebugUtils *du=device->GetDebugUtils();
|
||||||
|
|
||||||
if(du)
|
// if(du)
|
||||||
{
|
// {
|
||||||
const UTF8String name=U8_TEXT("Tex2D:")+ToUTF8String(filename);
|
// const UTF8String name=U8_TEXT("Tex2D:")+ToUTF8String(filename);
|
||||||
|
//
|
||||||
du->SetImage(tex->GetImage(),(char *)(name.c_str()));
|
// du->SetImage(tex->GetImage(),(char *)(name.c_str()));
|
||||||
}
|
// }
|
||||||
#endif//_DEBUG
|
//#endif//_DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
return tex;
|
return tex;
|
||||||
@ -62,16 +100,16 @@ Texture2DArray *TextureManager::CreateTexture2DArray(const AnsiString &name,cons
|
|||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
//#ifdef _DEBUG
|
||||||
DebugUtils *du=device->GetDebugUtils();
|
// DebugUtils *du=device->GetDebugUtils();
|
||||||
|
//
|
||||||
if(du)
|
// if(du)
|
||||||
{
|
// {
|
||||||
du->SetImage(ta->GetImage(),"Tex2DArrayImage:"+name);
|
// du->SetImage(ta->GetImage(),"Tex2DArrayImage:"+name);
|
||||||
du->SetImageView(ta->GetVulkanImageView(),"Tex2DArrayImageView:"+name);
|
// du->SetImageView(ta->GetVulkanImageView(),"Tex2DArrayImageView:"+name);
|
||||||
du->SetDeviceMemory(ta->GetDeviceMemory(),"Tex2DArrayMemory:"+name);
|
// du->SetDeviceMemory(ta->GetDeviceMemory(),"Tex2DArrayMemory:"+name);
|
||||||
}
|
// }
|
||||||
#endif//_DEBUG
|
//#endif//_DEBUG
|
||||||
|
|
||||||
return ta;
|
return ta;
|
||||||
}
|
}
|
||||||
@ -101,8 +139,7 @@ TextureCube *TextureManager::LoadTextureCube(const OSString &filename,bool auto_
|
|||||||
|
|
||||||
if(tex)
|
if(tex)
|
||||||
{
|
{
|
||||||
texture_by_name.Add(filename,tex);
|
Add(tex,filename);
|
||||||
Add(tex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tex;
|
return tex;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user