Panda3D
|
This is the preferred interface for loading textures from image files. More...
#include "texturePool.h"
Public Types | |
typedef Texture::MakeTextureFunc | MakeTextureFunc |
Public Member Functions | |
MakeTextureFunc * | get_texture_type (const string &extension) const |
Returns the factory function to construct a new texture of the type appropriate for the indicated filename extension, if any, or NULL if the extension is not one of the extensions for a texture file. | |
void | register_filter (TexturePoolFilter *filter) |
Records a TexturePoolFilter object that may operate on texture images as they are loaded from disk. | |
void | register_texture_type (MakeTextureFunc *func, const string &extensions) |
Records a factory function that makes a Texture object of the appropriate type for one or more particular filename extensions. | |
void | write_texture_types (ostream &out, int indent_level) const |
Outputs a list of the available texture types to the indicated output stream. | |
Static Public Member Functions | |
static void | add_texture (Texture *texture) |
Adds the indicated already-loaded texture to the pool. | |
static void | clear_fake_texture_image () |
Restores normal behavior of loading the textures actually requested. | |
static TextureCollection | find_all_textures (const string &name="*") |
Returns the set of all textures found in the pool that match the indicated name (which may contain wildcards). | |
static Texture * | find_texture (const string &name) |
Returns the first texture found in the pool that matches the indicated name (which may contain wildcards). | |
static int | garbage_collect () |
Releases only those textures in the pool that have a reference count of exactly 1; i.e. | |
static Texture * | get_alpha_scale_map () |
Returns a standard Texture object that has been created with Texture::generate_alpha_scale_map(). | |
static const Filename & | get_fake_texture_image () |
Returns the filename that was specified with a previous call to set_fake_texture_image(). | |
static TexturePool * | get_global_ptr () |
Initializes and/or returns the global pointer to the one TexturePool object in the system. | |
static Texture * | get_normalization_cube_map (int size) |
Returns a standard Texture object that has been created with Texture::generate_normalization_cube_map(). | |
static bool | has_fake_texture_image () |
Returns true if fake_texture_image mode has been enabled, false if we are in the normal mode. | |
static bool | has_texture (const Filename &filename) |
Returns true if the texture has ever been loaded, false otherwise. | |
static void | list_contents () |
Lists the contents of the texture pool to cout. | |
static void | list_contents (ostream &out) |
Lists the contents of the texture pool to the indicated output stream. | |
static Texture * | load_2d_texture_array (const Filename &filename_pattern, bool read_mipmaps=false, const LoaderOptions &options=LoaderOptions()) |
Loads a 2-D texture array that is specified with a series of n pages, all numbered in sequence, and beginning with index 0. | |
static Texture * | load_3d_texture (const Filename &filename_pattern, bool read_mipmaps=false, const LoaderOptions &options=LoaderOptions()) |
Loads a 3-D texture that is specified with a series of n pages, all numbered in sequence, and beginning with index 0. | |
static Texture * | load_cube_map (const Filename &filename_pattern, bool read_mipmaps=false, const LoaderOptions &options=LoaderOptions()) |
Loads a cube map texture that is specified with a series of 6 pages, numbered 0 through 5. | |
static Texture * | load_texture (const Filename &filename, const Filename &alpha_filename, int primary_file_num_channels=0, int alpha_file_channel=0, bool read_mipmaps=false, const LoaderOptions &options=LoaderOptions()) |
Loads the given filename up into a texture, if it has not already been loaded, and returns the new texture. | |
static Texture * | load_texture (const Filename &filename, int primary_file_num_channels=0, bool read_mipmaps=false, const LoaderOptions &options=LoaderOptions()) |
Loads the given filename up into a texture, if it has not already been loaded, and returns the new texture. | |
static | PT (Texture) make_texture(const string &extension) |
static void | rehash () |
Should be called when the model-path changes, to blow away the cache of texture pathnames found along the model-path. | |
static void | release_all_textures () |
Releases all textures in the pool and restores the pool to the empty state. | |
static 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. | |
static void | set_fake_texture_image (const Filename &filename) |
Sets a bogus filename that will be loaded in lieu of any textures requested from this point on. | |
static bool | verify_texture (const Filename &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. | |
static void | write (ostream &out) |
Lists the contents of the texture pool to the indicated output stream. |
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 40 of file texturePool.h.
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 194 of file texturePool.I.
References get_global_ptr().
void TexturePool::clear_fake_texture_image | ( | ) | [inline, static] |
Restores normal behavior of loading the textures actually requested.
Definition at line 316 of file texturePool.I.
References set_fake_texture_image().
TextureCollection TexturePool::find_all_textures | ( | const string & | name = "*" | ) | [inline, static] |
Returns the set of all textures found in the pool that match the indicated name (which may contain wildcards).
Definition at line 294 of file texturePool.I.
References get_global_ptr().
Texture * TexturePool::find_texture | ( | const string & | name | ) | [inline, static] |
Returns the first texture found in the pool that matches the indicated name (which may contain wildcards).
Returns the texture if it is found, or NULL if it is not.
Definition at line 282 of file texturePool.I.
References get_global_ptr().
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 248 of file texturePool.I.
References get_global_ptr().
Texture * TexturePool::get_alpha_scale_map | ( | ) | [inline, static] |
Returns a standard Texture object that has been created with Texture::generate_alpha_scale_map().
This Texture object is used internally by Panda to apply an alpha scale to an object (instead of munging its vertices) when gsg->get_alpha_scale_via_texture() returns true.
Definition at line 180 of file texturePool.I.
References get_global_ptr().
Referenced by GraphicsStateGuardian::determine_target_texture().
const Filename & TexturePool::get_fake_texture_image | ( | ) | [inline, static] |
Returns the filename that was specified with a previous call to set_fake_texture_image().
Definition at line 338 of file texturePool.I.
References get_global_ptr().
Referenced by has_fake_texture_image().
TexturePool * TexturePool::get_global_ptr | ( | ) | [static] |
Initializes and/or returns the global pointer to the one TexturePool object in the system.
Definition at line 152 of file texturePool.cxx.
Referenced by add_texture(), find_all_textures(), find_texture(), garbage_collect(), get_alpha_scale_map(), get_fake_texture_image(), get_normalization_cube_map(), get_texture_type(), has_texture(), list_contents(), load_2d_texture_array(), load_3d_texture(), load_cube_map(), load_texture(), rehash(), release_all_textures(), release_texture(), set_fake_texture_image(), write(), and write_texture_types().
Texture * TexturePool::get_normalization_cube_map | ( | int | size | ) | [inline, static] |
Returns a standard Texture object that has been created with Texture::generate_normalization_cube_map().
This Texture may be shared by any application code requiring a normalization cube map. It will be at least as large as the specified size, though it may be larger.
Definition at line 164 of file texturePool.I.
References get_global_ptr().
Referenced by NodePath::set_normal_map().
TexturePool::MakeTextureFunc * TexturePool::get_texture_type | ( | const string & | extension | ) | const |
Returns the factory function to construct a new texture of the type appropriate for the indicated filename extension, if any, or NULL if the extension is not one of the extensions for a texture file.
Definition at line 90 of file texturePool.cxx.
References get_global_ptr(), and PNMFileTypeRegistry::get_type_from_extension().
bool TexturePool::has_fake_texture_image | ( | ) | [inline, static] |
Returns true if fake_texture_image mode has been enabled, false if we are in the normal mode.
Definition at line 327 of file texturePool.I.
References get_fake_texture_image().
bool TexturePool::has_texture | ( | const Filename & | filename | ) | [inline, static] |
Returns true if the texture has ever been loaded, false otherwise.
Definition at line 24 of file texturePool.I.
References get_global_ptr().
void TexturePool::list_contents | ( | ) | [inline, static] |
Lists the contents of the texture pool to cout.
Definition at line 269 of file texturePool.I.
References get_global_ptr().
void TexturePool::list_contents | ( | ostream & | out | ) | [inline, static] |
Lists the contents of the texture pool to the indicated output stream.
Definition at line 259 of file texturePool.I.
References get_global_ptr().
Texture * TexturePool::load_2d_texture_array | ( | const Filename & | filename_pattern, |
bool | read_mipmaps = false , |
||
const LoaderOptions & | options = LoaderOptions() |
||
) | [inline, static] |
Loads a 2-D texture array that is specified with a series of n pages, all numbered in sequence, and beginning with index 0.
The filename should include a sequence of one or more hash characters ("#") which will be filled in with the index number of each level.
If read_mipmaps is true, the filename should contain an additional hash mark. The first hash mark will be filled in with the mipmap level number, and the second with the index number of each 2-d level.
Definition at line 125 of file texturePool.I.
References get_global_ptr().
Referenced by Texture::make_this_from_bam().
Texture * TexturePool::load_3d_texture | ( | const Filename & | filename_pattern, |
bool | read_mipmaps = false , |
||
const LoaderOptions & | options = LoaderOptions() |
||
) | [inline, static] |
Loads a 3-D texture that is specified with a series of n pages, all numbered in sequence, and beginning with index 0.
The filename should include a sequence of one or more hash characters ("#") which will be filled in with the index number of each level.
If read_mipmaps is true, the filename should contain an additional hash mark. The first hash mark will be filled in with the mipmap level number, and the second with the index number of each 3-d level.
Definition at line 104 of file texturePool.I.
References get_global_ptr().
Referenced by Texture::make_this_from_bam().
Texture * TexturePool::load_cube_map | ( | const Filename & | filename_pattern, |
bool | read_mipmaps = false , |
||
const LoaderOptions & | options = LoaderOptions() |
||
) | [inline, static] |
Loads a cube map texture that is specified with a series of 6 pages, numbered 0 through 5.
The filename should include a sequence of one or more hash characters ("#") which will be filled in with the index number of each pagee.
If read_mipmaps is true, the filename should contain an additional hash mark. The first hash mark will be filled in with the mipmap level number, and the second with the face number, 0 through 5.
Definition at line 146 of file texturePool.I.
References get_global_ptr().
Referenced by Texture::make_this_from_bam().
Texture * TexturePool::load_texture | ( | const Filename & | filename, |
const Filename & | alpha_filename, | ||
int | primary_file_num_channels = 0 , |
||
int | alpha_file_channel = 0 , |
||
bool | read_mipmaps = false , |
||
const LoaderOptions & | options = LoaderOptions() |
||
) | [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.
If read_mipmaps is true, both filenames should contain a hash mark ('#'), which will be filled in with the mipmap level number; and the texture will be defined with a series of images, two for each mipmap level.
Definition at line 80 of file texturePool.I.
References get_global_ptr().
Texture * TexturePool::load_texture | ( | const Filename & | filename, |
int | primary_file_num_channels = 0 , |
||
bool | read_mipmaps = false , |
||
const LoaderOptions & | options = LoaderOptions() |
||
) | [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.
If read_mipmaps is true, the filename should contain a hash mark ('#'), which will be filled in with the mipmap level number; and the texture will be defined with a series of images, one for each mipmap level.
Definition at line 58 of file texturePool.I.
References get_global_ptr().
Referenced by Texture::load_related(), RocketRenderInterface::LoadTexture(), Texture::make_this_from_bam(), PfmTrans::process_pfm(), and verify_texture().
void TexturePool::register_filter | ( | TexturePoolFilter * | filter | ) |
Records a TexturePoolFilter object that may operate on texture images as they are loaded from disk.
Definition at line 73 of file texturePool.cxx.
void TexturePool::register_texture_type | ( | MakeTextureFunc * | func, |
const string & | extensions | ||
) |
Records a factory function that makes a Texture object of the appropriate type for one or more particular filename extensions.
The string extensions may be a string that contains space-separated list of extensions, case-insensitive.
Definition at line 54 of file texturePool.cxx.
void TexturePool::rehash | ( | ) | [inline, static] |
Should be called when the model-path changes, to blow away the cache of texture pathnames found along the model-path.
Definition at line 235 of file texturePool.I.
References get_global_ptr().
void TexturePool::release_all_textures | ( | ) | [inline, static] |
Releases all textures in the pool and restores the pool to the empty state.
Definition at line 223 of file texturePool.I.
References get_global_ptr().
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 212 of file texturePool.I.
References get_global_ptr().
void TexturePool::set_fake_texture_image | ( | const Filename & | filename | ) | [inline, static] |
Sets a bogus filename that will be loaded in lieu of any textures requested from this point on.
Definition at line 305 of file texturePool.I.
References get_global_ptr().
Referenced by clear_fake_texture_image().
bool TexturePool::verify_texture | ( | const Filename & | 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 39 of file texturePool.I.
References load_texture().
void TexturePool::write | ( | ostream & | out | ) | [static] |
Lists the contents of the texture pool to the indicated output stream.
For debugging.
Definition at line 40 of file texturePool.cxx.
References get_global_ptr().
void TexturePool::write_texture_types | ( | ostream & | out, |
int | indent_level | ||
) | const |
Outputs a list of the available texture types to the indicated output stream.
This is mostly the list of available image types, with maybe a few additional ones for video textures.
Definition at line 122 of file texturePool.cxx.
References get_global_ptr(), PNMFileTypeRegistry::get_type_from_extension(), and PNMFileTypeRegistry::write().