Skylicht Engine
Loading...
Searching...
No Matches
CTextureManager.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "pch.h"
28
29#include "Utils/CSingleton.h"
30#include "Utils/CStringImp.h"
31
32namespace Skylicht
33{
43 class SKYLICHT_API CTextureManager
44 {
45 public:
47
48
52 static const char* getGlobalName();
53
54 protected:
55
60 struct STexturePackage
61 {
63 std::string Package;
65 std::string Path;
68
69 STexturePackage()
70 {
71 Texture = NULL;
72 }
73 };
74
76 std::string m_currentPackage;
77
79 std::vector<STexturePackage*> m_textureList;
80
82 std::vector<std::string> m_listCommonTexture;
83
86
89
90 public:
95
100
105 static std::vector<std::string> getTextureExts();
106
112 static bool isTextureExt(const char* ext);
113
118 inline void setCurrentPackage(const char* name)
119 {
120 m_currentPackage = name;
121 }
122
127 inline const char* getCurrentPackage()
128 {
129 return m_currentPackage.c_str();
130 }
131
136
141 void removeTexture(const char* namePackage);
142
148
154 const char* getTexturePath(ITexture* tex);
155
161 bool existTexture(const char* path);
162
169 bool resolveTexturePath(const char* path, std::string& result);
170
176 bool isTextureLoaded(const char* path);
177
183 ITexture* getTexture(const char* path);
184
191 ITexture* getTexture(const char* filename, const std::vector<std::string>& folders);
192
199
211 const char* pathX1,
212 const char* pathX2,
213 const char* pathY1,
214 const char* pathY2,
215 const char* pathZ1,
216 const char* pathZ2);
217
223 ITexture* getTextureArray(std::vector<std::string>& listTexture);
224
230 {
231 return m_nullNormalMap;
232 }
233
239 {
240 return m_nullTexture;
241 }
242
251 ITexture* createTransformTexture2D(const char* name, core::matrix4* transforms, int w, int h);
252
261 ITexture* createVectorTexture2D(const char* name, core::vector3df* vectors, int w, int h);
262
263 protected:
264
270 void registerTexture(ITexture* tex, const char* path);
271 };
272
273}
ITexture * getCubeTexture(const char *pathX1, const char *pathX2, const char *pathY1, const char *pathY2, const char *pathZ1, const char *pathZ2)
Load a cube map texture from 6 image paths.
CTextureManager()
Constructor.
void setCurrentPackage(const char *name)
Set the current texture package name.
Definition CTextureManager.h:118
ITexture * getNullNormalMap()
Get the default null normal map texture.
Definition CTextureManager.h:229
const char * getCurrentPackage()
Get the current texture package name.
Definition CTextureManager.h:127
ITexture * createVectorTexture2D(const char *name, core::vector3df *vectors, int w, int h)
Create a 2D texture from a list of vector3df values.
ITexture * createTransformTexture2D(const char *name, core::matrix4 *transforms, int w, int h)
Create a 2D texture from a list of transformation matrices.
ITexture * getTextureArray(std::vector< std::string > &listTexture)
Load a texture array from a list of texture paths.
bool isTextureLoaded(const char *path)
Check if a texture is already loaded.
ITexture * getTexture(const char *filename, const std::vector< std::string > &folders)
Load and get a texture from a set of folders.
ITexture * getNullTexture()
Get the default null texture.
Definition CTextureManager.h:238
ITexture * getTexture(const char *path)
Load and get a texture by path.
static const char * getGlobalName()
Get the global package name.
std::vector< std::string > m_listCommonTexture
List of common textures.
Definition CTextureManager.h:82
bool existTexture(const char *path)
Check if a texture exists by path.
ITexture * getTextureFromRealPath(const char *path)
Get texture using the real file path.
std::vector< STexturePackage * > m_textureList
List of loaded texture packages.
Definition CTextureManager.h:79
const char * getTexturePath(ITexture *tex)
Get the file path of a texture.
static std::vector< std::string > getTextureExts()
Get supported texture file extensions.
bool resolveTexturePath(const char *path, std::string &result)
Finds the actual, existing file path for a texture, resolving the correct file extension.
void removeAllTexture()
Remove all loaded textures.
static bool isTextureExt(const char *ext)
Check if a file extension is a supported texture format.
void removeTexture(const char *namePackage)
Remove all textures in a specific package.
ITexture * m_nullTexture
Default null texture.
Definition CTextureManager.h:88
void registerTexture(ITexture *tex, const char *path)
Register a texture with the manager.
ITexture * m_nullNormalMap
Default null normal map texture.
Definition CTextureManager.h:85
virtual ~CTextureManager()
Destructor. Releases all resources.
void removeTexture(ITexture *tex)
Remove a specific texture resource.
std::string m_currentPackage
Current package used for loading textures.
Definition CTextureManager.h:76
Interface of a Video Driver dependent Texture.
Definition ITexture.h:119
#define DECLARE_SINGLETON(className)
Declare the standard singleton accessors for a class.
Definition CSingleton.h:36
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2241
std::string Path
Actual path of the texture file.
Definition CTextureManager.h:65
std::string Package
Name of the package containing the texture.
Definition CTextureManager.h:63
ITexture * Texture
Pointer to the texture resource.
Definition CTextureManager.h:67