TextureManager Class Reference

manages all textures More...

#include <texturemanager.h>

Inherits UniversalManager< Texture, TextureManager >.

Inheritance diagram for TextureManager:

Inheritance graph
[legend]
Collaboration diagram for TextureManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

TRef add (SurfaceFactory *psf, GLint internalFormat=GL_RGBA, GLint level=0)
 Registers the texture using arbitrary SurfaceFactory.
TRef add (std::string fileName, GLint internalFormat=GL_RGBA, GLint level=0)
 Registers the texture using default factory with the file name only.
bool getNPOT (void)
 Non-power-of-two textures extension presence.

Protected Member Functions

 TextureManager ()
 ~TextureManager ()

Private Attributes

bool mNPOT
 true for NPOT textures extension presence, false otherwise

Friends

class Singleton< TextureManager >
 due to singleton DP

Detailed Description

manages all textures

This is a singleton. It provides several add(...) methods to the user. You describe texture source in arguments of add() and you will get the reference TRef, with that you can access the Texture class. If there is not any texture managed matching given description, it will be created and uploaded to OpenGL. Otherwise only the reference to managed item found, is returned.

Example:

        // Loads the file "image.png" with an external alpha channel describet as red channel od "image_alpha.png"
        // (i.e. some grayscale image), builds 2D mipmaps and returns texture reference to it:
        TextureRef tr1 = TextureManager::getInstance()->add(
                                                &SurfExternalAlpha("image.png", "image_alpha.png"), 
                                                GL_RGBA, Texture::BUILD_MIPMAPS);

        // Finds the texture in the registry and returns only a reference to it
        // (GL_RGBA and BUILD_MIPMAPS is ignored when image found in registry):
        TextureRef tr2 = TextureManager::getInstance()->add(
                                                &SurfExternalAlpha("image.png", "image_alpha.png"), 
                                                GL_RGBA, Texture::BUILD_MIPMAPS);

        // Increments the reference count only..
        TextureRef tr3 = tr1;

        // Now, tr1, tr2, tr3 refers to only one texture.

        // ...
        // binds the texture to current texture unit
        t2->bind();

        // Loads image2.png with an explicit color key (0x00, 0x00, 0x00):
        tr1 = TextureManager::getInstance()->add(
                                                &SurfColorKey("image2.png", 0x00, 0x00, 0x00));

        // SDL_Surface * customSurfacePtr = getSomeSurface();
        // Loads the texture from custom surface with explicit color key and prefix its name with "surface1"
        tr2 = TextureManager::getInstance()->add(
                                                &SurfColorKey(customSurfacePtr, 0x00, 0x00, 0x00).pref("surface1"));

        // release last reference to the first texture "image.png"
        tr3 = 0;

        // the first texture is now released...

Note:
You should free all texture references before graphics subsystem exits to avoid warning logs.

OpenGL has to be initialized before registering any texture!

Definition at line 163 of file texturemanager.h.


Constructor & Destructor Documentation

TextureManager::TextureManager  )  [protected]
 

Definition at line 23 of file texturemanager.cpp.

References GFX::checkExtension(), getAppClient(), ApplicationClient::getGFX(), and mNPOT.

Here is the call graph for this function:

TextureManager::~TextureManager  )  [inline, protected]
 

Definition at line 168 of file texturemanager.h.


Member Function Documentation

TextureManager::TUniversalManager::TRef TextureManager::add std::string  fileName,
GLint  internalFormat = GL_RGBA,
GLint  level = 0
 

Registers the texture using default factory with the file name only.

Parameters:
fileName the name of external image-file

Definition at line 44 of file texturemanager.cpp.

References add().

Here is the call graph for this function:

TextureManager::TUniversalManager::TRef TextureManager::add SurfaceFactory psf,
GLint  internalFormat = GL_RGBA,
GLint  level = 0
 

Registers the texture using arbitrary SurfaceFactory.

If this texture (described by psf) doesn't exist, it will be created from source described in psf, uploaded to current texture unit and a reference to it will be returned. If this texture already exists (is registered yet), only a reference will be returned.

Parameters:
psf pointer to surface factory holding texture description
internalFormat see glTexImage2D, the number of color components of the texture (1..4)
level the texture mipmap level. 0 is the base image, n is the n-th mipmap reduction, or Texture::BUILD_MIPMAPS for automatic mipmaps generation.
Returns:
reference to managed data providing access to Texture class

Definition at line 28 of file texturemanager.cpp.

References UniversalManager< Texture, TextureManager >::createAndRegister(), UniversalManager< Texture, TextureManager >::find(), SurfaceFactory::getHashString(), and Texture::upload().

Referenced by add().

Here is the call graph for this function:

bool TextureManager::getNPOT void   )  [inline]
 

Non-power-of-two textures extension presence.

Returns:
true, if the GL_ARB_texture_non_power_of_two extension is present, false if not present.

Definition at line 196 of file texturemanager.h.

References mNPOT.


Friends And Related Function Documentation

friend class Singleton< TextureManager > [friend]
 

due to singleton DP

Definition at line 165 of file texturemanager.h.


Member Data Documentation

bool TextureManager::mNPOT [private]
 

true for NPOT textures extension presence, false otherwise

Definition at line 199 of file texturemanager.h.

Referenced by getNPOT(), and TextureManager().


The documentation for this class was generated from the following files:
Generated on Wed Apr 12 14:33:00 2006 for bjs by  doxygen 1.4.5