Panda3D

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
TexturePool Class Reference

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 std::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 std::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 (std::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 std::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 std::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 Texture * | get_texture (const Filename &filename, const Filename &alpha_filename, int primary_file_num_channels=0, int alpha_file_channel=0, bool read_mipmaps=false)
| Returns the texture that has already been previously loaded, or NULL otherwise.
static Texture * | get_texture (const Filename &filename, int primary_file_num_channels=0, bool read_mipmaps=false)
| Returns the texture that has already been previously loaded, or NULL otherwise.
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 (std::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 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 static PT(Texture) make_texture(const std void | write (std::ostream &out)
| Lists the contents of the texture pool to the indicated output stream.

## 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 37 of file texturePool.h.

## Member Typedef Documentation

## ◆ MakeTextureFunc

typedef Texture::MakeTextureFunc TexturePool::MakeTextureFunc

Definition at line 94 of file texturePool.h.

## Member Function Documentation

## ◆ add_texture()

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 176 of file texturePool.I.

References get_global_ptr().

## ◆ clear_fake_texture_image()

void TexturePool::clear_fake_texture_image | ( |  | ) |
| inline static

Restores normal behavior of loading the textures actually requested.

Definition at line 269 of file texturePool.I.

References set_fake_texture_image().

## ◆ find_all_textures()

TextureCollection TexturePool::find_all_textures | ( | const std::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 252 of file texturePool.I.

References get_global_ptr().

## ◆ find_texture()

Texture * TexturePool::find_texture | ( | const std::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 243 of file texturePool.I.

References get_global_ptr().

## ◆ 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 217 of file texturePool.I.

References get_global_ptr().

## ◆ get_alpha_scale_map()

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 166 of file texturePool.I.

References get_global_ptr().

## ◆ get_fake_texture_image()

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 287 of file texturePool.I.

References get_global_ptr().

Referenced by has_fake_texture_image().

## ◆ get_global_ptr()

TexturePool * TexturePool::get_global_ptr | ( |  | ) |
| static

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

Definition at line 145 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(), get_texture(), has_texture(), init_libgrutil(), init_libvision(), list_contents(), list_contents(), load_2d_texture_array(), load_3d_texture(), load_cube_map(), WindowFramework::load_model(), load_texture(), load_texture(), PT(), rehash(), release_all_textures(), release_texture(), set_fake_texture_image(), and write().

## ◆ get_normalization_cube_map()

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 153 of file texturePool.I.

References get_global_ptr().

## ◆ get_texture() [1/2]

Texture * TexturePool::get_texture | ( | const Filename & | filename,
|  | const Filename & | alpha_filename,
|  | int | primary_file_num_channels = 0,
|  | int | alpha_file_channel = 0,
|  | bool | read_mipmaps = false )
| inline static

Returns the texture that has already been previously loaded, or NULL otherwise.

Definition at line 51 of file texturePool.I.

References get_global_ptr().

## ◆ get_texture() [2/2]

Texture * TexturePool::get_texture | ( | const Filename & | filename,
|  | int | primary_file_num_channels = 0,
|  | bool | read_mipmaps = false )
| inline static

Returns the texture that has already been previously loaded, or NULL otherwise.

Definition at line 40 of file texturePool.I.

References get_global_ptr().

## ◆ get_texture_type()

TexturePool::MakeTextureFunc * TexturePool::get_texture_type | ( | const std::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 83 of file texturePool.cxx.

References downcase(), PNMFileTypeRegistry::get_global_ptr(), and PNMFileTypeRegistry::get_type_from_extension().

Referenced by WindowFramework::load_model(), and PT().

## ◆ has_fake_texture_image()

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 278 of file texturePool.I.

References get_fake_texture_image().

## ◆ has_texture()

bool TexturePool::has_texture | ( | const Filename & | filename | ) |
| inline static

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

Definition at line 19 of file texturePool.I.

References get_global_ptr().

## ◆ list_contents() [1/2]

void TexturePool::list_contents | ( |  | ) |
| inline static

Lists the contents of the texture pool to cout.

Definition at line 233 of file texturePool.I.

References get_global_ptr().

## ◆ list_contents() [2/2]

void TexturePool::list_contents | ( | std::ostream & | out | ) |
| inline static

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

Definition at line 225 of file texturePool.I.

References get_global_ptr().

## ◆ load_2d_texture_array()

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 123 of file texturePool.I.

References get_global_ptr().

## ◆ load_3d_texture()

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 106 of file texturePool.I.

References get_global_ptr().

## ◆ load_cube_map()

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 140 of file texturePool.I.

References get_global_ptr().

## ◆ load_texture() [1/2]

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 86 of file texturePool.I.

References get_global_ptr().

## ◆ load_texture() [2/2]

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 69 of file texturePool.I.

References get_global_ptr().

Referenced by Texture::load_related(), PfmTrans::process_pfm(), and verify_texture().

## ◆ register_filter()

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 69 of file texturePool.cxx.

## ◆ register_texture_type()

void TexturePool::register_texture_type | ( | MakeTextureFunc * | func,
|  | const std::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 52 of file texturePool.cxx.

References downcase(), and extract_words().

Referenced by init_libgrutil(), and init_libvision().

## ◆ rehash()

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 207 of file texturePool.I.

References get_global_ptr().

## ◆ release_all_textures()

void TexturePool::release_all_textures | ( |  | ) |
| inline static

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

Definition at line 198 of file texturePool.I.

References get_global_ptr().

## ◆ release_texture()

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 190 of file texturePool.I.

References get_global_ptr().

## ◆ set_fake_texture_image()

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 261 of file texturePool.I.

References get_global_ptr().

Referenced by clear_fake_texture_image().

## ◆ verify_texture()

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 31 of file texturePool.I.

References load_texture().

## ◆ write()

void TexturePool::write | ( | std::ostream & | out | ) |
| inline static

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

For debugging.

Definition at line 41 of file texturePool.cxx.

References get_global_ptr().

## ◆ write_texture_types()

void TexturePool::write_texture_types | ( | std::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 112 of file texturePool.cxx.

References PNMFileTypeRegistry::get_global_ptr(), PNMFileTypeRegistry::get_type_from_extension(), indent(), and PNMFileTypeRegistry::write().

Referenced by WindowFramework::load_model().

The documentation for this class was generated from the following files:

- panda/src/gobj/texturePool.h
- panda/src/gobj/texturePool.cxx
- panda/src/gobj/texturePool.I