moved LoadTexture2D/CreateTexture2DArray/LoadTextureCube to TextureManager from VKRenderResource
This commit is contained in:
parent
f6cc1ee619
commit
88f5948a2e
@ -50,7 +50,7 @@ class RenderResource
|
||||
|
||||
ShaderModuleMapByName shader_module_by_name[VK_SHADER_STAGE_TYPE_COUNT];
|
||||
Map<AnsiString,Material *> material_by_name;
|
||||
Map<OSString,Texture *> texture_by_name;
|
||||
//Map<OSString,Texture *> texture_by_name;
|
||||
|
||||
IDObjectManage<MaterialID, Material> rm_material; ///<材质合集
|
||||
IDObjectManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
|
||||
@ -157,14 +157,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);}
|
||||
|
@ -26,12 +26,10 @@ public:
|
||||
TextureManager();
|
||||
virtual ~TextureManager();
|
||||
|
||||
private: //Buffer
|
||||
public: //Buffer
|
||||
|
||||
DeviceBuffer *CreateTransferSourceBuffer(const VkDeviceSize,const void *data_ptr=nullptr);
|
||||
|
||||
friend class TileData;
|
||||
|
||||
private: //Image
|
||||
|
||||
VkImage CreateImage (VkImageCreateInfo *);
|
||||
@ -91,6 +89,15 @@ public: //Create/Chagne
|
||||
public:
|
||||
|
||||
void Release(Texture *);
|
||||
|
||||
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 &);
|
||||
|
||||
};//class TextureManager
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -136,90 +136,4 @@ Sampler *RenderResource::CreateSampler(Texture *tex)
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
Texture2D *RenderResource::LoadTexture2D(const OSString &filename,bool auto_mipmaps)
|
||||
{
|
||||
Texture2D *tex;
|
||||
|
||||
if(texture_by_name.Get(filename,(Texture *&)tex))
|
||||
return tex;
|
||||
|
||||
tex=CreateTexture2DFromFile(device,filename,auto_mipmaps);
|
||||
|
||||
if(tex)
|
||||
{
|
||||
texture_by_name.Add(filename,tex);
|
||||
Add(tex);
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
Texture2DArray *RenderResource::CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps)
|
||||
{
|
||||
Texture2DArray *ta=device->CreateTexture2DArray(width,height,layer,fmt,auto_mipmaps);
|
||||
|
||||
if(ta)
|
||||
Add(ta);
|
||||
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
|
||||
|
||||
return ta;
|
||||
}
|
||||
|
||||
bool LoadTexture2DLayerFromFile(TextureManager *tm,Texture2DArray *t2d,const uint32_t layer,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
bool RenderResource::LoadTexture2DToArray(Texture2DArray *ta,const uint32_t layer,const OSString &filename)
|
||||
{
|
||||
if(!ta)return(false);
|
||||
|
||||
if(!LoadTexture2DLayerFromFile(device,ta,layer,filename,false))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
TextureCube *CreateTextureCubeFromFile(GPUDevice *device,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
TextureCube *RenderResource::LoadTextureCube(const OSString &filename,bool auto_mipmaps)
|
||||
{
|
||||
TextureCube *tex;
|
||||
|
||||
if(texture_by_name.Get(filename,(Texture *&)tex))
|
||||
return tex;
|
||||
|
||||
tex=CreateTextureCubeFromFile(device,filename,auto_mipmaps);
|
||||
|
||||
if(tex)
|
||||
{
|
||||
texture_by_name.Add(filename,tex);
|
||||
Add(tex);
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -10,4 +10,90 @@ void TextureManager::Release(Texture *tex)
|
||||
texture_set.Delete(tex);
|
||||
}
|
||||
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
Texture2D *TextureManager::LoadTexture2D(const OSString &filename,bool auto_mipmaps)
|
||||
{
|
||||
Texture2D *tex;
|
||||
|
||||
if(texture_by_name.Get(filename,(Texture *&)tex))
|
||||
return tex;
|
||||
|
||||
tex=CreateTexture2DFromFile(device,filename,auto_mipmaps);
|
||||
|
||||
if(tex)
|
||||
{
|
||||
texture_by_name.Add(filename,tex);
|
||||
Add(tex);
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
Texture2DArray *TextureManager::CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps)
|
||||
{
|
||||
Texture2DArray *ta=device->CreateTexture2DArray(width,height,layer,fmt,auto_mipmaps);
|
||||
|
||||
if(ta)
|
||||
Add(ta);
|
||||
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
|
||||
|
||||
return ta;
|
||||
}
|
||||
|
||||
bool LoadTexture2DLayerFromFile(TextureManager *tm,Texture2DArray *t2d,const uint32_t layer,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
bool TextureManager::LoadTexture2DToArray(Texture2DArray *ta,const uint32_t layer,const OSString &filename)
|
||||
{
|
||||
if(!ta)return(false);
|
||||
|
||||
if(!LoadTexture2DLayerFromFile(device,ta,layer,filename,false))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
TextureCube *CreateTextureCubeFromFile(GPUDevice *device,const OSString &filename,bool auto_mipmaps);
|
||||
|
||||
TextureCube *TextureManager::LoadTextureCube(const OSString &filename,bool auto_mipmaps)
|
||||
{
|
||||
TextureCube *tex;
|
||||
|
||||
if(texture_by_name.Get(filename,(Texture *&)tex))
|
||||
return tex;
|
||||
|
||||
tex=CreateTextureCubeFromFile(device,filename,auto_mipmaps);
|
||||
|
||||
if(tex)
|
||||
{
|
||||
texture_by_name.Add(filename,tex);
|
||||
Add(tex);
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user