Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

P3DTexMgr Class Reference

Texture manager. More...

#include <P3DTexMgr.hpp>

List of all members.

Public Methods

 P3DTexMgr (const PLMResFinder &source, u32 initialsize=4)
 ~P3DTexMgr ()
P3DTextureLoadFromFile (const char *name, GLint filter=GL_LINEAR, bool repeat=true, GLenum format=0)
P3DTextureLoadFromImage (const char *name, const PLMImage *img, GLint filter=GL_LINEAR, bool repeat=true, GLenum format=0)
P3DTextureAddTexture (const char *name, GLuint index)
P3DTextureGetTexture (const char *name)
P3DTextureGetTexture (GLuint index)
const char * GetTextureName (GLuint index)
bool FreeTexture (const char *name)
bool FreeTexture (P3DTexture *tex)
bool FreeTexture (GLuint index)
void ReloadTextures ()


Detailed Description

Texture manager.

This manager allows to easily load images from files and convert them into textures suitable for the current OpenGL context. The textures can be added from many sources :

  • from a file in the current directory
  • from a file inside an archive
  • from an existing PLMImage (can not be restored when if the context is recreated) Even an existing OpenGL texture can be added to the manager. The manager can also reload all the textures on demand (when the context is recreated for example), but only those added from a suitable source (i.e. from files and archives).
You should always use P3DTexture pointers (then ->index) in your code instead of directly storing the texture index, because this index can be modified if the textures are reloaded, whereas the pointers will not. The pointers returned by GetTexture() may become invalid if the texture is released or lost by a call to ReloadTextures().


Constructor & Destructor Documentation

P3DTexMgr::P3DTexMgr const PLMResFinder   source,
u32    initialsize = 4
 

Create a new empty texture manager.

Parameters:
source  a resource loader object, to load textures from. The finder should be initialised with the directories/archives you want to use, but they sources may be added at any moment (in the finder).
initialsize  initial allocated size (empty slots) in the texture list.

P3DTexMgr::~P3DTexMgr  
 

Note that this destructor MUST be called BEFORE the P3DScreen destructor to nicely release any OpenGL resources before the context is deleted.


Member Function Documentation

P3DTexture* P3DTexMgr::LoadFromFile const char *    name,
GLint    filter = GL_LINEAR,
bool    repeat = true,
GLenum    format = 0
 

Load a texture from a file.

If the name is already in the list, the existing texture is returned and its reference counter is incremented. All the sources currently defined in the finder are checked, and the first matching name is used. Supported formats = PCX, GIF, BMP, TGA. The size must be a power of 2.

Parameters:
name  the file name to load an image from (can contain a path). This texture is then associated to this name, and it can be used in GetTexture() to retieve it.
filter  the type of filter to apply (GL_LINEAR, GL_NEAREST).
repeat  true = GL_REPEAT, false = GL_CLAMP.
format  the pixel format (0 = autodetect, GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, ...)
Returns:
a pointer on a P3DTexture structure containing informations about the texture (and its index), or NULL on error (file not found, or invalid arguments).

P3DTexture* P3DTexMgr::LoadFromImage const char *    name,
const PLMImage   img,
GLint    filter = GL_LINEAR,
bool    repeat = true,
GLenum    format = 0
 

Load a texture from an existing image (already in memory).

You must provide a name to retrieve the texture later with GetTexture() and prevent from creating it multiple times. If the name is already used, the existing texture is returned and the image is ignored, the reference counter is then incremented.

Parameters:
name  the name to associate with this texture (no restriction)
img  a valid image, whose size is a power of 2
filter  the type of filter to apply (GL_LINEAR, GL_NEAREST).
repeat  true = GL_REPEAT, false = GL_CLAMP.
format  the pixel format (0 = autodetect, GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, ...) Notes :
  • The image data may be modified (converted to the right format).
  • This texture will be lost when ReloadTextures() is called.
  • The image can be deleted after the call.
Returns:
a pointer on a P3DTexture structure containing informations about the texture (and its index), or NULL on error (invalid arguments).

P3DTexture* P3DTexMgr::AddTexture const char *    name,
GLuint    index
 

Add an existing OpenGL texture to the manager, and associate it to a name.

If the name is already used, the existing texture is returned and the index is ignored, the reference counter is then incremented.

Parameters:
name  the name to associate with this texture (no restriction)
index  a valid OpenGL texture index (existing) Note that this texture will be lost when ReloadTextures() is called.
Returns:
a pointer on a P3DTexture structure containing informations about the texture (and its index), or NULL on error (invalid index).

P3DTexture* P3DTexMgr::GetTexture const char *    name
 

Get an already loaded texture.

Does not modify its reference counter.

Returns:
a P3DTexture pointer if the name is found, or NULL on error.

P3DTexture* P3DTexMgr::GetTexture GLuint    index
 

Get an already loaded texture, identified by its OpenGL index.

Does not modify its reference counter.

Returns:
a P3DTexture pointer if the index is found, or NULL on error.

const char* P3DTexMgr::GetTextureName GLuint    index
 

Get the name associated with a texture identified by its OpenGL index.

Returns:
the name of the texture if the index is found, or NULL on error. Note that the name must not be modified or deleted.

bool P3DTexMgr::FreeTexture const char *    name
 

Unload a texture identified by its name.

Decrease its reference counter and delete it if it reaches 0. Returns false if not found.

bool P3DTexMgr::FreeTexture P3DTexture   tex
 

Unload a texture.

Decrease its reference counter and delete it if it reaches 0. Returns false if not found.

bool P3DTexMgr::FreeTexture GLuint    index
 

Unload a texture identified by its OpenGL index.

Decrease its reference counter and delete it if it reaches 0. Returns false if not found.

void P3DTexMgr::ReloadTextures  
 

Try to reload all textures (that can be reloaded).

Note that only textures loaded from files and archives can be reloaded. Textures added with LoadFromImage() or AddTexture() can not. All the textures that can not be reloaded are removed from the list. Call this when the OpenGL context is recreated (P3DScreen::Init()).


The documentation for this class was generated from the following file:
  • P3DTexMgr.hpp

Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:45 2004.