AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
texManager.h
1#pragma once
2
3#ifndef _texManager_H_
4#include<map>
5#include<unordered_map>
6#include"../../source/rendering/texture.h"
7
8
9namespace Aire
10{
11 using TexMap = std::map<ResourceHandle, TexturePtr>;
12 using TexNameMap = std::unordered_map<string, TexturePtr>;
13
14 using CubeMapHash = std::map<ResourceHandle, CubeMapPtr>;
15 using CubeMapNameHash = std::unordered_map<string, CubeMapPtr>;
16
17 using ImagePointer = unsigned char*;
18
21
22 private:
23 TexMap texMap;
24 TexNameMap texNameMap;
26 CubeMapHash cubeMapHash;
27 CubeMapNameHash cubeMapNameHash;
28
29 public:
30 //singleton pattern
31 TextureManager(const TextureManager&) = delete;
32 TextureManager& operator=(const TextureManager&) = delete;
33 static TextureManager& get_instance() {
34 static TextureManager instance;
35 return instance;
36 }
38
42 TextureHandle createTextureByImage(const char* filename,bool flipped);
43
45 struct CubemapFaces {
46 const char* filename;
47 bool flipped;
48 };
49
54 CubeMapHandle createCubeMapByImage(const std::vector<CubemapFaces> cubemapFaces, std::string cubeMapName);
55
65 GLuint createTextureInGpu(std::string name,
66 int xOffset,
67 int yOffset,
68 GLenum format = GL_RGBA,
69 GLenum type = GL_UNSIGNED_BYTE,
70 int level = 0);
71
81 GLuint createTextureInGpu(TexturePtr const&,
82 int xOffset = 0,
83 int yOffset = 0,
84 GLenum format = GL_RGBA,
85 GLenum type = GL_UNSIGNED_BYTE,
86 int level = 0);
87
91 void createCubeMapInGpu(CubeMapPtr const&);
92
96 void removeTextureInGpu(std::string name,bool isCubeMap);
97
100 void removeTextureInGpu(TexturePtr const&);
101
102
103 //additional
104
108 void freeTextureInCpu(const TextureHandle& handle);
109
113 void freeTextureInCpu(const std::string & name);
114
118 void freeTextureInCpu(const TexturePtr& tpr);
119
120
124 void freeCubeMapInCpu(const std::string& name);
125
129 void freeCubeMapInCpu(const CubeMapHandle& handle);
130
134 void freeCubeMapInCpu(const CubeMapPtr& cpr);
135
137 void freeAllDataInCpu();
138
142 TexturePtr getTexturePtr(TextureHandle h);
143
147 TexturePtr getTexturePtrByName(std::string name);
148
152 CubeMapPtr getCubeMapPtr(CubeMapHandle h);
153
157 CubeMapPtr getCubeMapPtrByName(std::string name);
158
162 bool isloaded(std::string path);
163
167 TextureHandle getTexturePtrByPath(std::string path);
168
169 };
170
171 inline TextureManager::TextureManager()
172 {
173 }
174}
175
176#endif // !_texManager_H_
Texture manager. Handles texture creation, storage, and deletion.
Definition texManager.h:20
void removeTextureInGpu(std::string name, bool isCubeMap)
Definition texManager.cpp:163
TextureHandle createTextureByImage(const char *filename, bool flipped)
Definition texManager.cpp:30
CubeMapHandle createCubeMapByImage(const std::vector< CubemapFaces > cubemapFaces, std::string cubeMapName)
Definition texManager.cpp:64
void createCubeMapInGpu(CubeMapPtr const &)
Definition texManager.cpp:149
void freeCubeMapInCpu(const std::string &name)
Definition texManager.cpp:227
void freeAllDataInCpu()
Free all texture memory stored on the CPU.
Definition texManager.cpp:317
CubeMapPtr getCubeMapPtrByName(std::string name)
Definition texManager.cpp:371
CubeMapPtr getCubeMapPtr(CubeMapHandle h)
Definition texManager.cpp:366
GLuint createTextureInGpu(std::string name, int xOffset, int yOffset, GLenum format=GL_RGBA, GLenum type=GL_UNSIGNED_BYTE, int level=0)
Definition texManager.cpp:117
TexturePtr getTexturePtrByName(std::string name)
Definition texManager.cpp:361
TextureHandle getTexturePtrByPath(std::string path)
Definition texManager.cpp:385
void freeTextureInCpu(const TextureHandle &handle)
Definition texManager.cpp:271
TexturePtr getTexturePtr(TextureHandle h)
Definition texManager.cpp:356
bool isloaded(std::string path)
Definition texManager.cpp:376
Struct to identify cubemap faces.
Definition texManager.h:45
const char * filename
Path to a texture on disk.
Definition texManager.h:46
bool flipped
True if the texture should be vertically flipped.
Definition texManager.h:47