The material managing static class. More...
#include <VR3TextureManager.h>
Classes | |
struct | MapElement |
An element in the texture map. More... | |
Static Public Member Functions | |
static void | LoadTexture (const char *file_name, VR3Texture *texture, GLenum tex_type=VR3TEX_2D) |
Loads a new texture from an image file. | |
Private Member Functions | |
VR3TextureManager () | |
Private constructor to avoid explicit instantiation. | |
Static Private Member Functions | |
static void | Load2D (const char *file_name, GLuint &tex) |
Loads a 2D texture (type = VR3TEX_2D) | |
static void | LoadCubeMap (const char *file_name, GLuint &tex) |
Loads a cube map texture (type = VR3TEX_CUBE_MAP) | |
Static Private Attributes | |
static std::map< std::string, std::map< GLenum, MapElement > , VR3Map::Less > | ms_textures |
Mapping of texture file names and types to texture object references. | |
Texture Management Functions | |
static void | CreateTexture (VR3Texture *texture) |
Notifies the creation of a new texture. | |
static VR3Texture * | FindTexture (const char *file_name, GLenum tex_type) |
Searches the current texture pool for the provided texture file name. | |
static void | DeleteReference (VR3Texture *texture) |
Notifies the deletion of a reference to a texture. | |
static void | AddReference (VR3Texture *texture) |
Notifies that a reference has been instantiated. |
The material managing static class.
This class can be viewed as a namespace with private data members, it cannot be instantiated explicitly and should only be used through the static texture loading methods.
The VR3MaterialManager class works as the texture manager class, notice that 3 entities may have references to texture objects:
This class also provides the texture loading functions, so it is the texture loader and manager class. For easy handling of texture images, the DevIL library is used.
Definition at line 49 of file VR3TextureManager.h.
VR3TextureManager::VR3TextureManager | ( | ) | [private] |
Private constructor to avoid explicit instantiation.
static void VR3TextureManager::AddReference | ( | VR3Texture * | texture ) | [static] |
Notifies that a reference has been instantiated.
This function is useful when a reference to a texture is returned to a user asking it to a VR3Material object or when the user commands a material to use a specific texture. The AddReference function simply increments the reference counter associated to a particular VR3Texture object.
[in] | texture | The texture referenced |
static void VR3TextureManager::CreateTexture | ( | VR3Texture * | texture ) | [static, private] |
Notifies the creation of a new texture.
When a new texture is created, this function is called inside the texture loading function to notify the VR3TextureManager that a new texture is being created. An error arises if a texture with the same file name already exists. This function is called from the VR3MaterialManager::LoadTexture() function.
[in] | texture | A reference to the new texture object |
static void VR3TextureManager::DeleteReference | ( | VR3Texture * | texture ) | [static] |
Notifies the deletion of a reference to a texture.
A material may only be deleted by this texture loading and managing module, when a material linked to some texture terminates its life time, it simply calls the pseudo-destructor VR3Texture::Destroy(). The VR3Texture::Destroy() method will simply notify the texture manager that a reference to the specified texture has been deleted.
[in] | texture | The texture referenced |
static VR3Texture* VR3TextureManager::FindTexture | ( | const char * | file_name, |
GLenum | tex_type | ||
) | [static] |
Searches the current texture pool for the provided texture file name.
This function is used to avoid multiple instantiations of the same texture. A mesh pool is mantained and continuously updated stating which VR3Texture object is associated to which texture file. This function is used to avoid texture instantiation if possible.
[in] | file_name | The requested file name |
[in] | tex_type | Type of the texture to find |
static void VR3TextureManager::Load2D | ( | const char * | file_name, |
GLuint & | tex | ||
) | [static, private] |
Loads a 2D texture (type = VR3TEX_2D)
This function is used when a standard 2D texture must be loaded, it is called by the main LoadTexture() function.
[in] | file_name | Name of the texture file |
[in] | tex | The texture GL name to fill |
static void VR3TextureManager::LoadCubeMap | ( | const char * | file_name, |
GLuint & | tex | ||
) | [static, private] |
Loads a cube map texture (type = VR3TEX_CUBE_MAP)
This function is used when a cube map texture must be loaded, it is called by the main LoadTexture() function. For a cube map to be correctly loaded from an image, the image must have the standard cross layout (horizontal or vertical).
Vertical Cross (ATI CubeMapGen): ________________________________ | | | TOP(+Y) | | | | LEFT(-X) FRONT(+Z) RIGHT(+X) | | | | BOTTOM(-Y) | | | | BACK(-Z) | |________________________________| Horizontal Cross: __________________________________________ | | | TOP(+Y) | | | | LEFT(-X) FRONT(+Z) RIGHT(+X) BACK(-Z) | | | | BOTTOM(-Y) | |__________________________________________|
If your cube map texture (or skybox) is provided as 6 distinct pictures, you may use utility programs like ATI CubeMapGen to obtain a single cross-shaped cube map image.
[in] | file_name | Name of the texture file |
[in] | tex | The texture GL name to fill |
static void VR3TextureManager::LoadTexture | ( | const char * | file_name, |
VR3Texture * | texture, | ||
GLenum | tex_type = VR3TEX_2D |
||
) | [static] |
Loads a new texture from an image file.
This function loads a new texture file and writes the parameters in a given VR3Texture object. A single VR3Texture object may be used for different materials of different objects and meshes. A texture object is uniquely identified by its absolute texture file path. Loaded texture data is automatically passed to the GL and stored on the server side.
[in] | file_name | Name of the texture file |
[out] | texture | The texture object to fill |
[in] | tex_type | Type of the texture to load |
std::map<std::string, std::map<GLenum,MapElement> , VR3Map::Less> VR3TextureManager::ms_textures [static, private] |
Mapping of texture file names and types to texture object references.
Definition at line 60 of file VR3TextureManager.h.