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

TexturePool Class Reference

This is the preferred interface for loading textures from image files. More...

#include <texturePool.h>

List of all members.

Static Public Member Functions

bool has_texture (const string &filename)
 Returns true if the texture has ever been loaded, false otherwise.

bool verify_texture (const string &filename)
 Loads the given filename up into a texture, if it has not already been loaded, and returns true to indicate success, or false to indicate failure.

Textureload_texture (const string &filename, int primary_file_num_channels=0)
 Loads the given filename up into a texture, if it has not already been loaded, and returns the new texture.

Textureload_texture (const string &filename, const string &alpha_filename, int primary_file_num_channels=0, int alpha_file_channel=0)
 Loads the given filename up into a texture, if it has not already been loaded, and returns the new texture.

void add_texture (Texture *texture)
 Adds the indicated already-loaded texture to the pool.

void release_texture (Texture *texture)
 Removes the indicated texture from the pool, indicating it will never be loaded again; the texture may then be freed.

void release_all_textures ()
 Releases all textures in the pool and restores the pool to the empty state.

int garbage_collect ()
 Releases only those textures in the pool that have a reference count of exactly 1; i.e.

void list_contents (ostream &out)
 Lists the contents of the texture pool to the indicated output stream.


Private Types

typedef pmap< string, PointerTo<
Texture > > 
Textures

Private Member Functions

 TexturePool ()
 The constructor is not intended to be called directly; there's only supposed to be one TexturePool in the universe and it constructs itself.

bool ns_has_texture (const Filename &orig_filename)
 The nonstatic implementation of has_texture().

Texturens_load_texture (const Filename &orig_filename, int primary_file_num_channels)
 The nonstatic implementation of load_texture().

Texturens_load_texture (const Filename &orig_filename, const Filename &orig_alpha_filename, int primary_file_num_channels, int alpha_file_channel)
 The nonstatic implementation of load_texture().

void ns_add_texture (Texture *texture)
 The nonstatic implementation of add_texture().

void ns_release_texture (Texture *texture)
 The nonstatic implementation of release_texture().

void ns_release_all_textures ()
 The nonstatic implementation of release_all_textures().

int ns_garbage_collect ()
 The nonstatic implementation of garbage_collect().

void ns_list_contents (ostream &out)
 The nonstatic implementation of list_contents().


Static Private Member Functions

TexturePool * get_ptr ()
 Initializes and/or returns the global pointer to the one TexturePool object in the system.


Private Attributes

Textures _textures

Static Private Attributes

TexturePool * _global_ptr = (TexturePool *)NULL


Detailed Description

This is the preferred interface for loading textures from image files.

It unifies all references to the same filename, so that multiple models that reference the same textures don't waste texture memory unnecessarily.

Definition at line 46 of file texturePool.h.


Member Typedef Documentation

typedef pmap<string, PointerTo< Texture > > TexturePool::Textures [private]
 

Definition at line 85 of file texturePool.h.


Constructor & Destructor Documentation

TexturePool::TexturePool  )  [inline, private]
 

The constructor is not intended to be called directly; there's only supposed to be one TexturePool in the universe and it constructs itself.

Definition at line 217 of file texturePool.I.


Member Function Documentation

void TexturePool::add_texture Texture texture  )  [inline, static]
 

Adds the indicated already-loaded texture to the pool.

The texture must have a filename set for its name. The texture will always replace any previously-loaded texture in the pool that had the same filename.

Definition at line 122 of file texturePool.I.

References get_ptr(), INLINE, and ns_garbage_collect().

int TexturePool::garbage_collect  )  [inline, static]
 

Releases only those textures in the pool that have a reference count of exactly 1; i.e.

only those textures that are not being used outside of the pool. Returns the number of textures released.

Definition at line 185 of file texturePool.I.

TexturePool * TexturePool::get_ptr  )  [static, private]
 

Initializes and/or returns the global pointer to the one TexturePool object in the system.

Definition at line 292 of file texturePool.cxx.

Referenced by add_texture(), and load_texture().

bool TexturePool::has_texture const string &  filename  )  [inline, static]
 

Returns true if the texture has ever been loaded, false otherwise.

Definition at line 33 of file texturePool.I.

References INLINE, load_texture(), and NULL.

void TexturePool::list_contents ostream &  out  )  [inline, static]
 

Lists the contents of the texture pool to the indicated output stream.

Definition at line 200 of file texturePool.I.

Texture * TexturePool::load_texture const string &  filename,
const string &  alpha_filename,
int  primary_file_num_channels = 0,
int  alpha_file_channel = 0
[inline, static]
 

Loads the given filename up into a texture, if it has not already been loaded, and returns the new texture.

If a texture with the same filename was previously loaded, returns that one instead. If the texture file cannot be found, returns NULL.

Definition at line 98 of file texturePool.I.

References get_ptr(), INLINE, and ns_release_texture().

Texture * TexturePool::load_texture const string &  filename,
int  primary_file_num_channels = 0
[inline, static]
 

Loads the given filename up into a texture, if it has not already been loaded, and returns the new texture.

If a texture with the same filename was previously loaded, returns that one instead. If the texture file cannot be found, returns NULL.

Definition at line 77 of file texturePool.I.

References get_ptr(), INLINE, and ns_add_texture().

Referenced by demo_keys(), event_L(), and has_texture().

void TexturePool::ns_add_texture Texture texture  )  [private]
 

The nonstatic implementation of add_texture().

Definition at line 189 of file texturePool.cxx.

References _textures, PointerToArray< PointerTo< Texture > >::end(), PointerToArray< PointerTo< Texture > >::erase(), ImageBuffer::get_filename(), and tex.

Referenced by load_texture().

int TexturePool::ns_garbage_collect  )  [private]
 

The nonstatic implementation of garbage_collect().

Definition at line 239 of file texturePool.cxx.

References Texture::_pbuffer, _textures, PointerToArray< PointerTo< Texture > >::begin(), PointerToArray< PointerTo< Texture > >::end(), ReferenceCount::get_ref_count(), and PointerToArray< PointerTo< Texture > >::size().

Referenced by add_texture().

bool TexturePool::ns_has_texture const Filename orig_filename  )  [private]
 

The nonstatic implementation of has_texture().

Definition at line 41 of file texturePool.cxx.

References VirtualFileSystem::get_global_ptr(), get_model_path(), get_texture_path(), and VirtualFileSystem::resolve_filename().

void TexturePool::ns_list_contents ostream &  out  )  [private]
 

The nonstatic implementation of list_contents().

Definition at line 270 of file texturePool.cxx.

Texture * TexturePool::ns_load_texture const Filename orig_filename,
const Filename orig_alpha_filename,
int  primary_file_num_channels,
int  alpha_file_channel
[private]
 

The nonstatic implementation of load_texture().

Definition at line 127 of file texturePool.cxx.

Texture * TexturePool::ns_load_texture const Filename orig_filename,
int  primary_file_num_channels
[private]
 

The nonstatic implementation of load_texture().

Definition at line 77 of file texturePool.cxx.

void TexturePool::ns_release_all_textures  )  [private]
 

The nonstatic implementation of release_all_textures().

Definition at line 226 of file texturePool.cxx.

void TexturePool::ns_release_texture Texture texture  )  [private]
 

The nonstatic implementation of release_texture().

Definition at line 208 of file texturePool.cxx.

References _textures, PointerToArray< PointerTo< Texture > >::begin(), PointerToArray< PointerTo< Texture > >::end(), ReferenceCount::get_ref_count(), and tex.

Referenced by load_texture().

void TexturePool::release_all_textures  )  [inline, static]
 

Releases all textures in the pool and restores the pool to the empty state.

Definition at line 166 of file texturePool.I.

void TexturePool::release_texture Texture texture  )  [inline, static]
 

Removes the indicated texture from the pool, indicating it will never be loaded again; the texture may then be freed.

If this function is never called, a reference count will be maintained on every texture every loaded, and textures will never be freed.

The texture's name should not have been changed during its lifetime, or this function may fail to locate it in the pool.

Definition at line 151 of file texturePool.I.

bool TexturePool::verify_texture const string &  filename  )  [inline, static]
 

Loads the given filename up into a texture, if it has not already been loaded, and returns true to indicate success, or false to indicate failure.

If this returns true, it is guaranteed that a subsequent call to load_texture() with the same texture name will return a valid Texture pointer.

Definition at line 56 of file texturePool.I.


Member Data Documentation

TexturePool * TexturePool::_global_ptr = (TexturePool *)NULL [static, private]
 

Definition at line 29 of file texturePool.cxx.

Textures TexturePool::_textures [private]
 

Definition at line 86 of file texturePool.h.

Referenced by ns_add_texture(), ns_garbage_collect(), and ns_release_texture().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:55:36 2003 for Panda by doxygen1.3