Panda3D

texturePool.I

00001 // Filename: texturePool.I
00002 // Created by:  drose (26Apr00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: TexturePool::has_texture
00018 //       Access: Published, Static
00019 //  Description: Returns true if the texture has ever been loaded,
00020 //               false otherwise.
00021 ////////////////////////////////////////////////////////////////////
00022 INLINE bool TexturePool::
00023 has_texture(const Filename &filename) {
00024   return get_global_ptr()->ns_has_texture(filename);
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: TexturePool::verify_texture
00029 //       Access: Published, Static
00030 //  Description: Loads the given filename up into a texture, if it has
00031 //               not already been loaded, and returns true to indicate
00032 //               success, or false to indicate failure.  If this
00033 //               returns true, it is guaranteed that a subsequent call
00034 //               to load_texture() with the same texture name will
00035 //               return a valid Texture pointer.
00036 ////////////////////////////////////////////////////////////////////
00037 INLINE bool TexturePool::
00038 verify_texture(const Filename &filename) {
00039   return load_texture(filename) != (Texture *)NULL;
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: TexturePool::load_texture
00044 //       Access: Published, Static
00045 //  Description: Loads the given filename up into a texture, if it has
00046 //               not already been loaded, and returns the new texture.
00047 //               If a texture with the same filename was previously
00048 //               loaded, returns that one instead.  If the texture
00049 //               file cannot be found, returns NULL.
00050 //
00051 //               If read_mipmaps is true, the filename should contain
00052 //               a hash mark ('#'), which will be filled in with the
00053 //               mipmap level number; and the texture will be defined
00054 //               with a series of images, one for each mipmap level.
00055 ////////////////////////////////////////////////////////////////////
00056 INLINE Texture *TexturePool::
00057 load_texture(const Filename &filename, int primary_file_num_channels,
00058              bool read_mipmaps, const LoaderOptions &options) {
00059   return get_global_ptr()->ns_load_texture(filename, primary_file_num_channels,
00060                                            read_mipmaps, options);
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: TexturePool::load_texture
00065 //       Access: Published, Static
00066 //  Description: Loads the given filename up into a texture, if it has
00067 //               not already been loaded, and returns the new texture.
00068 //               If a texture with the same filename was previously
00069 //               loaded, returns that one instead.  If the texture
00070 //               file cannot be found, returns NULL.
00071 //
00072 //               If read_mipmaps is true, both filenames should
00073 //               contain a hash mark ('#'), which will be filled in
00074 //               with the mipmap level number; and the texture will be
00075 //               defined with a series of images, two for each mipmap
00076 //               level.
00077 ////////////////////////////////////////////////////////////////////
00078 INLINE Texture *TexturePool::
00079 load_texture(const Filename &filename, const Filename &alpha_filename,
00080              int primary_file_num_channels, int alpha_file_channel,
00081              bool read_mipmaps, const LoaderOptions &options) {
00082   return get_global_ptr()->ns_load_texture(filename, alpha_filename, 
00083                                            primary_file_num_channels,
00084                                            alpha_file_channel,
00085                                            read_mipmaps, options);
00086 }
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: TexturePool::load_3d_texture
00090 //       Access: Published, Static
00091 //  Description: Loads a 3-D texture that is specified with a series
00092 //               of n pages, all numbered in sequence, and beginning
00093 //               with index 0.  The filename should include a sequence
00094 //               of one or more hash characters ("#") which will be
00095 //               filled in with the index number of each level.
00096 //
00097 //               If read_mipmaps is true, the filename should contain
00098 //               an additional hash mark.  The first hash mark will be
00099 //               filled in with the mipmap level number, and the
00100 //               second with the index number of each 3-d level.
00101 ////////////////////////////////////////////////////////////////////
00102 INLINE Texture *TexturePool::
00103 load_3d_texture(const Filename &filename_pattern, bool read_mipmaps, 
00104                 const LoaderOptions &options) {
00105   return get_global_ptr()->ns_load_3d_texture(filename_pattern, read_mipmaps, 
00106                                               options);
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////
00110 //     Function: TexturePool::load_cube_map
00111 //       Access: Published, Static
00112 //  Description: Loads a cube map texture that is specified with a
00113 //               series of 6 pages, numbered 0 through 5.  The
00114 //               filename should include a sequence of one or more
00115 //               hash characters ("#") which will be filled in with
00116 //               the index number of each pagee.
00117 //
00118 //               If read_mipmaps is true, the filename should contain
00119 //               an additional hash mark.  The first hash mark will be
00120 //               filled in with the mipmap level number, and the
00121 //               second with the face number, 0 through 5.
00122 ////////////////////////////////////////////////////////////////////
00123 INLINE Texture *TexturePool::
00124 load_cube_map(const Filename &filename_pattern, bool read_mipmaps, 
00125               const LoaderOptions &options) {
00126   return get_global_ptr()->ns_load_cube_map(filename_pattern, read_mipmaps, 
00127                                             options);
00128 }
00129 
00130 ////////////////////////////////////////////////////////////////////
00131 //     Function: TexturePool::get_normalization_cube_map
00132 //       Access: Published, Static
00133 //  Description: Returns a standard Texture object that has been
00134 //               created with
00135 //               Texture::generate_normalization_cube_map().  This
00136 //               Texture may be shared by any application code
00137 //               requiring a normalization cube map.  It will be at
00138 //               least as large as the specified size, though it may
00139 //               be larger.
00140 ////////////////////////////////////////////////////////////////////
00141 INLINE Texture *TexturePool::
00142 get_normalization_cube_map(int size) {
00143   return get_global_ptr()->ns_get_normalization_cube_map(size);
00144 }
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //     Function: TexturePool::get_alpha_scale_map
00148 //       Access: Published, Static
00149 //  Description: Returns a standard Texture object that has been
00150 //               created with Texture::generate_alpha_scale_map().
00151 //
00152 //               This Texture object is used internally by Panda to
00153 //               apply an alpha scale to an object (instead of munging
00154 //               its vertices) when gsg->get_alpha_scale_via_texture()
00155 //               returns true.
00156 ////////////////////////////////////////////////////////////////////
00157 INLINE Texture *TexturePool::
00158 get_alpha_scale_map() {
00159   return get_global_ptr()->ns_get_alpha_scale_map();
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: TexturePool::add_texture
00164 //       Access: Published, Static
00165 //  Description: Adds the indicated already-loaded texture to the
00166 //               pool.  The texture must have a filename set for its
00167 //               name.  The texture will always replace any
00168 //               previously-loaded texture in the pool that had the
00169 //               same filename.
00170 ////////////////////////////////////////////////////////////////////
00171 INLINE void TexturePool::
00172 add_texture(Texture *texture) {
00173   get_global_ptr()->ns_add_texture(texture);
00174 }
00175 
00176 ////////////////////////////////////////////////////////////////////
00177 //     Function: TexturePool::release_texture
00178 //       Access: Published, Static
00179 //  Description: Removes the indicated texture from the pool,
00180 //               indicating it will never be loaded again; the texture
00181 //               may then be freed.  If this function is never called,
00182 //               a reference count will be maintained on every texture
00183 //               every loaded, and textures will never be freed.
00184 //
00185 //               The texture's name should not have been changed
00186 //               during its lifetime, or this function may fail to
00187 //               locate it in the pool.
00188 ////////////////////////////////////////////////////////////////////
00189 INLINE void TexturePool::
00190 release_texture(Texture *texture) {
00191   get_global_ptr()->ns_release_texture(texture);
00192 }
00193 
00194 ////////////////////////////////////////////////////////////////////
00195 //     Function: TexturePool::release_all_textures
00196 //       Access: Published, Static
00197 //  Description: Releases all textures in the pool and restores the
00198 //               pool to the empty state.
00199 ////////////////////////////////////////////////////////////////////
00200 INLINE void TexturePool::
00201 release_all_textures() {
00202   get_global_ptr()->ns_release_all_textures();
00203 }
00204 
00205 ////////////////////////////////////////////////////////////////////
00206 //     Function: TexturePool::rehash
00207 //       Access: Published, Static
00208 //  Description: Should be called when the model-path changes, to blow
00209 //               away the cache of texture pathnames found along the
00210 //               model-path.
00211 ////////////////////////////////////////////////////////////////////
00212 INLINE void TexturePool::
00213 rehash() {
00214   get_global_ptr()->_relpath_lookup.clear();
00215 }
00216 
00217 ////////////////////////////////////////////////////////////////////
00218 //     Function: TexturePool::garbage_collect
00219 //       Access: Published, Static
00220 //  Description: Releases only those textures in the pool that have a
00221 //               reference count of exactly 1; i.e. only those
00222 //               textures that are not being used outside of the pool.
00223 //               Returns the number of textures released.
00224 ////////////////////////////////////////////////////////////////////
00225 INLINE int TexturePool::
00226 garbage_collect() {
00227   return get_global_ptr()->ns_garbage_collect();
00228 }
00229 
00230 ////////////////////////////////////////////////////////////////////
00231 //     Function: TexturePool::list_contents
00232 //       Access: Published, Static
00233 //  Description: Lists the contents of the texture pool to the
00234 //               indicated output stream.
00235 ////////////////////////////////////////////////////////////////////
00236 INLINE void TexturePool::
00237 list_contents(ostream &out) {
00238   get_global_ptr()->ns_list_contents(out);
00239 }
00240 
00241 ////////////////////////////////////////////////////////////////////
00242 //     Function: TexturePool::list_contents
00243 //       Access: Published, Static
00244 //  Description: Lists the contents of the texture pool to cout
00245 ////////////////////////////////////////////////////////////////////
00246 INLINE void TexturePool::
00247 list_contents() {
00248   get_global_ptr()->ns_list_contents(cout);
00249 }
00250 
00251 ////////////////////////////////////////////////////////////////////
00252 //     Function: TexturePool::find_texture
00253 //       Access: Published, Static
00254 //  Description: Returns the first texture found in the pool that
00255 //               matches the indicated name (which may contain
00256 //               wildcards).  Returns the texture if it is found, or
00257 //               NULL if it is not.
00258 ////////////////////////////////////////////////////////////////////
00259 INLINE Texture *TexturePool::
00260 find_texture(const string &name) {
00261   return get_global_ptr()->ns_find_texture(name);
00262 }
00263 
00264 ////////////////////////////////////////////////////////////////////
00265 //     Function: TexturePool::find_all_textures
00266 //       Access: Published, Static
00267 //  Description: Returns the set of all textures found in the pool
00268 //               that match the indicated name (which may contain
00269 //               wildcards).
00270 ////////////////////////////////////////////////////////////////////
00271 INLINE TextureCollection TexturePool::
00272 find_all_textures(const string &name) {
00273   return get_global_ptr()->ns_find_all_textures(name);
00274 }
00275 
00276 ////////////////////////////////////////////////////////////////////
00277 //     Function: TexturePool::set_fake_texture_image
00278 //       Access: Published, Static
00279 //  Description: Sets a bogus filename that will be loaded in lieu of
00280 //               any textures requested from this point on.
00281 ////////////////////////////////////////////////////////////////////
00282 INLINE void TexturePool::
00283 set_fake_texture_image(const Filename &filename) {
00284   get_global_ptr()->_fake_texture_image = filename;
00285 }
00286 
00287 ////////////////////////////////////////////////////////////////////
00288 //     Function: TexturePool::clear_fake_texture_image
00289 //       Access: Published, Static
00290 //  Description: Restores normal behavior of loading the textures
00291 //               actually requested.
00292 ////////////////////////////////////////////////////////////////////
00293 INLINE void TexturePool::
00294 clear_fake_texture_image() {
00295   set_fake_texture_image(string());
00296 }
00297 
00298 ////////////////////////////////////////////////////////////////////
00299 //     Function: TexturePool::has_fake_texture_image
00300 //       Access: Published, Static
00301 //  Description: Returns true if fake_texture_image mode has been
00302 //               enabled, false if we are in the normal mode.
00303 ////////////////////////////////////////////////////////////////////
00304 INLINE bool TexturePool::
00305 has_fake_texture_image() {
00306   return !get_fake_texture_image().empty();
00307 }
00308 
00309 ////////////////////////////////////////////////////////////////////
00310 //     Function: TexturePool::get_fake_texture_image
00311 //       Access: Published, Static
00312 //  Description: Returns the filename that was specified with a
00313 //               previous call to set_fake_texture_image().
00314 ////////////////////////////////////////////////////////////////////
00315 INLINE const Filename &TexturePool::
00316 get_fake_texture_image() {
00317   return get_global_ptr()->_fake_texture_image;
00318 }
 All Classes Functions Variables Enumerations