Panda3D

Classes | 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. More...
void | register_filter (TexturePoolFilter *filter)
| Records a TexturePoolFilter object that may operate on texture images as they are loaded from disk. More...
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. More...
void | write_texture_types (std::ostream &out, int indent_level) const
| Outputs a list of the available texture types to the indicated output stream. More...

## Static Public Member Functions
static void | add_texture (Texture *texture)
| Adds the indicated already-loaded texture to the pool. More...
static void | clear_fake_texture_image ()
| Restores normal behavior of loading the textures actually requested. More...
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). More...
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). More...
static int | garbage_collect ()
| Releases only those textures in the pool that have a reference count of exactly 1; i.e. More...
static Texture * | get_alpha_scale_map ()
| Returns a standard Texture object that has been created with Texture::generate_alpha_scale_map(). More...
static const Filename & | get_fake_texture_image ()
| Returns the filename that was specified with a previous call to set_fake_texture_image(). More...
static TexturePool * | get_global_ptr ()
| Initializes and/or returns the global pointer to the one TexturePool object in the system. More...
static Texture * | get_normalization_cube_map (int size)
| Returns a standard Texture object that has been created with Texture::generate_normalization_cube_map(). More...
static bool | has_fake_texture_image ()
| Returns true if fake_texture_image mode has been enabled, false if we are in the normal mode. More...
static bool | has_texture (const Filename &filename)
| Returns true if the texture has ever been loaded, false otherwise. More...
static void | list_contents ()
| Lists the contents of the texture pool to cout. More...
static void | list_contents (std::ostream &out)
| Lists the contents of the texture pool to the indicated output stream. More...
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. More...
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. More...
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. More...
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. More...
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. More...
static void | rehash ()
| Should be called when the model-path changes, to blow away the cache of texture pathnames found along the model-path. More...
static void | release_all_textures ()
| Releases all textures in the pool and restores the pool to the empty state. More...
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. More...
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. More...
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. More...

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

## ◆ clear_fake_texture_image()

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

Restores normal behavior of loading the textures actually requested.

Definition at line 246 of file texturePool.I.

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

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

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

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

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

## ◆ 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 init_libgrutil(), init_libvision(), and PT().

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

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

## ◆ 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.

## ◆ list_contents() [1/2]

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

Lists the contents of the texture pool to cout.

Definition at line 210 of file texturePool.I.

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

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

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

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

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

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

Referenced by PT().

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

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

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

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

## ◆ 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.

## ◆ 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().

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