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 Texturefind_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 Textureget_alpha_scale_map ()
 Returns a standard Texture object that has been created with Texture::generate_alpha_scale_map(). More...
 
static const Filenameget_fake_texture_image ()
 Returns the filename that was specified with a previous call to set_fake_texture_image(). More...
 
static TexturePoolget_global_ptr ()
 Initializes and/or returns the global pointer to the one TexturePool object in the system. More...
 
static Textureget_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 (std::ostream &out)
 Lists the contents of the texture pool to the indicated output stream. More...
 
static void list_contents ()
 Lists the contents of the texture pool to cout. More...
 
static Textureload_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 Textureload_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 Textureload_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 Textureload_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 Textureload_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 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)
inlinestatic

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

References get_global_ptr().

◆ clear_fake_texture_image()

void TexturePool::clear_fake_texture_image ( )
inlinestatic

Restores normal behavior of loading the textures actually requested.

Definition at line 247 of file texturePool.I.

References set_fake_texture_image().

◆ find_all_textures()

TextureCollection TexturePool::find_all_textures ( const std::string &  name = "*")
inlinestatic

Returns the set of all textures found in the pool that match the indicated name (which may contain wildcards).

Definition at line 230 of file texturePool.I.

References get_global_ptr().

◆ find_texture()

Texture * TexturePool::find_texture ( const std::string &  name)
inlinestatic

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

References get_global_ptr().

◆ garbage_collect()

int TexturePool::garbage_collect ( )
inlinestatic

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

References get_global_ptr().

◆ get_alpha_scale_map()

Texture * TexturePool::get_alpha_scale_map ( )
inlinestatic

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

References get_global_ptr().

◆ get_fake_texture_image()

const Filename & TexturePool::get_fake_texture_image ( )
inlinestatic

Returns the filename that was specified with a previous call to set_fake_texture_image().

Definition at line 265 of file texturePool.I.

References get_global_ptr().

Referenced by has_fake_texture_image().

◆ get_global_ptr()

TexturePool * TexturePool::get_global_ptr ( )
static

◆ get_normalization_cube_map()

Texture * TexturePool::get_normalization_cube_map ( int  size)
inlinestatic

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 131 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 84 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 ( )
inlinestatic

Returns true if fake_texture_image mode has been enabled, false if we are in the normal mode.

Definition at line 256 of file texturePool.I.

References get_fake_texture_image().

◆ has_texture()

bool TexturePool::has_texture ( const Filename filename)
inlinestatic

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

Definition at line 20 of file texturePool.I.

References get_global_ptr().

◆ list_contents() [1/2]

void TexturePool::list_contents ( std::ostream &  out)
inlinestatic

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

Definition at line 203 of file texturePool.I.

References get_global_ptr().

◆ list_contents() [2/2]

void TexturePool::list_contents ( )
inlinestatic

Lists the contents of the texture pool to cout.

Definition at line 211 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() 
)
inlinestatic

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 101 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() 
)
inlinestatic

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 84 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() 
)
inlinestatic

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

References get_global_ptr().

◆ load_texture() [1/2]

Texture * TexturePool::load_texture ( const Filename filename,
int  primary_file_num_channels = 0,
bool  read_mipmaps = false,
const LoaderOptions options = LoaderOptions() 
)
inlinestatic

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

References get_global_ptr().

Referenced by PT(), and verify_texture().

◆ load_texture() [2/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() 
)
inlinestatic

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

References get_global_ptr().

◆ 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 70 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 53 of file texturePool.cxx.

References downcase(), and extract_words().

Referenced by init_libgrutil(), and init_libvision().

◆ rehash()

void TexturePool::rehash ( )
inlinestatic

Should be called when the model-path changes, to blow away the cache of texture pathnames found along the model-path.

Definition at line 185 of file texturePool.I.

References get_global_ptr().

◆ release_all_textures()

void TexturePool::release_all_textures ( )
inlinestatic

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

Definition at line 176 of file texturePool.I.

References get_global_ptr().

◆ release_texture()

void TexturePool::release_texture ( Texture texture)
inlinestatic

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

References get_global_ptr().

◆ set_fake_texture_image()

void TexturePool::set_fake_texture_image ( const Filename filename)
inlinestatic

Sets a bogus filename that will be loaded in lieu of any textures requested from this point on.

Definition at line 239 of file texturePool.I.

References get_global_ptr().

Referenced by clear_fake_texture_image().

◆ verify_texture()

bool TexturePool::verify_texture ( const Filename filename)
inlinestatic

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

References load_texture().

◆ 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 113 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: