1 #ifndef __TEXTUREMANAGER__ 2 #define __TEXTUREMANAGER__ 5 #define texManager TextureManager::Instance() 47 void bindTexture (GLenum texType, GLuint texID,
int texture_unit)
49 glActiveTexture(GL_TEXTURE0 + texture_unit);
50 glBindTexture(texType, texID);
52 if (used_units[texture_unit] != -1)
54 cerr <<
"WARNING: Texture unit already used. Replacing bound texture..." << endl;
57 used_units[texture_unit] = texID;
66 int free_unit = getAvailableUnit();
70 glActiveTexture(GL_TEXTURE0 + free_unit);
71 glBindTexture(texType, texID);
72 used_units[free_unit] = texID;
76 cerr <<
"WARNING: no free texture unit found!\n";
87 for (
int i = 0; i < max_texture_units; ++i)
89 if (used_units[i] == -1)
100 void setUnavailableUnit(
int unit);
105 glActiveTexture(GL_TEXTURE0 + texture_unit);
106 glBindTexture(texType, 0);
107 used_units[texture_unit] = -1;
118 for (
int i = 0; i < max_texture_units; ++i) {
119 if (used_units[i] == (GLint)texID) {
120 glActiveTexture(GL_TEXTURE0 + i);
121 glBindTexture(texType, 0);
137 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units);
139 for (
int i = 0; i < max_texture_units; ++i) {
140 used_units.push_back(-1);
~TextureManager()
Definition: texturemanager.hpp:128
Singleton class that manages texture unit allocation.
Definition: texturemanager.hpp:24
void unbindTextureID(GLenum texType, GLuint texID)
Unbinds a texture with given ID Searches texture unit vector for the texture and frees unit...
Definition: texturemanager.hpp:116
Definition: bufferobject.hpp:34
void unbindTexture(GLenum texType, int texture_unit)
Unbinds the texture from the specific texture unit.
Definition: texturemanager.hpp:103
TextureManager(TextureManager const &)
Copy Constructor.
Definition: texturemanager.hpp:145
static TextureManager & Instance(void)
Returns the unique instance. If no instace exists, it will create one (only once).
Definition: texturemanager.hpp:38
int max_texture_units
Maximum number of texture units.
Definition: texturemanager.hpp:154
TextureManager()
Default Constructor.
Definition: texturemanager.hpp:135
int bindTexture(GLenum texType, GLuint texID)
Binds a texture to the first free texture unit and returns the allocated unit.
Definition: texturemanager.hpp:64
int getAvailableUnit(void)
Returns the first available texture unit.
Definition: texturemanager.hpp:85
static TextureManager * pInstance
Pointer to the instance of the Texture Manager object.
Definition: texturemanager.hpp:151
std::vector< int > used_units
Texture units in use. each slot holds the texture id or -1 if free.
Definition: texturemanager.hpp:157
void bindTexture(GLenum texType, GLuint texID, int texture_unit)
Binds a texture to a unit given by the user.
Definition: texturemanager.hpp:47