Panda3D

texture.I

00001 // Filename: texture.I
00002 // Created by:  drose (05Feb99)
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: Texture::make_copy
00018 //       Access: Published
00019 //  Description: Returns a new copy of the same Texture.  This copy,
00020 //               if applied to geometry, will be copied into texture
00021 //               as a separate texture from the original, so it will
00022 //               be duplicated in texture memory (and may be
00023 //               independently modified if desired).
00024 //
00025 //               If the Texture is a VideoTexture, the resulting
00026 //               duplicate may be animated independently of the
00027 //               original.
00028 ////////////////////////////////////////////////////////////////////
00029 INLINE PT(Texture) Texture::
00030 make_copy() {
00031   MutexHolder holder(_lock);
00032   PT(Texture) tex = do_make_copy();
00033   ++(tex->_properties_modified);
00034   ++(tex->_image_modified);
00035   ++(tex->_simple_image_modified);
00036   return tex;
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: Texture::clear
00041 //       Access: Published, Virtual
00042 //  Description: Reinitializes the texture to its default, empty
00043 //               state (except for the name).
00044 ////////////////////////////////////////////////////////////////////
00045 INLINE void Texture::
00046 clear() {
00047   MutexHolder holder(_lock);
00048   do_clear();
00049 }
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //     Function: Texture::setup_texture
00053 //       Access: Published
00054 //  Description: Sets the texture to the indicated type and
00055 //               dimensions, presumably in preparation for calling
00056 //               read() or load(), or set_ram_image() or
00057 //               modify_ram_image().
00058 ////////////////////////////////////////////////////////////////////
00059 INLINE void Texture::
00060 setup_texture(Texture::TextureType texture_type, int x_size, int y_size,
00061               int z_size, Texture::ComponentType component_type,
00062               Texture::Format format) {
00063   MutexHolder holder(_lock);
00064   do_setup_texture(texture_type, x_size, y_size, z_size,
00065                    component_type, format);
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: Texture::setup_1d_texture
00070 //       Access: Published
00071 //  Description: Sets the texture as an empty 1-d texture with no
00072 //               dimensions.  Follow up with read() or load() to fill
00073 //               the texture properties and image data.
00074 ////////////////////////////////////////////////////////////////////
00075 INLINE void Texture::
00076 setup_1d_texture() {
00077   setup_1d_texture(0, T_unsigned_byte, F_rgb);
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: Texture::setup_1d_texture
00082 //       Access: Published
00083 //  Description: Sets the texture as an empty 1-d texture with the
00084 //               specified dimensions and properties.  Follow up with
00085 //               set_ram_image() or modify_ram_image() to fill the
00086 //               image data.
00087 ////////////////////////////////////////////////////////////////////
00088 INLINE void Texture::
00089 setup_1d_texture(int x_size, ComponentType component_type, Format format) {
00090   setup_texture(TT_1d_texture, x_size, 1, 1, component_type, format);
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: Texture::setup_2d_texture
00095 //       Access: Published
00096 //  Description: Sets the texture as an empty 2-d texture with no
00097 //               dimensions.  Follow up with read() or load() to fill
00098 //               the texture properties and image data.
00099 ////////////////////////////////////////////////////////////////////
00100 INLINE void Texture::
00101 setup_2d_texture() {
00102   setup_2d_texture(0, 1, T_unsigned_byte, F_rgb);
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: Texture::setup_2d_texture
00107 //       Access: Published
00108 //  Description: Sets the texture as an empty 2-d texture with the
00109 //               specified dimensions and properties.  Follow up with
00110 //               set_ram_image() or modify_ram_image() to fill the
00111 //               image data.
00112 ////////////////////////////////////////////////////////////////////
00113 INLINE void Texture::
00114 setup_2d_texture(int x_size, int y_size, ComponentType component_type, 
00115                  Format format) {
00116   setup_texture(TT_2d_texture, x_size, y_size, 1, component_type, format);
00117 }
00118 
00119 ////////////////////////////////////////////////////////////////////
00120 //     Function: Texture::setup_3d_texture
00121 //       Access: Published
00122 //  Description: Sets the texture as an empty 3-d texture with no
00123 //               dimensions (though if you know the depth ahead
00124 //               of time, it saves a bit of reallocation later).
00125 //               Follow up with read() or load() to fill the texture
00126 //               properties and image data.
00127 ////////////////////////////////////////////////////////////////////
00128 INLINE void Texture::
00129 setup_3d_texture(int z_size) {
00130   setup_3d_texture(0, 1, z_size, T_unsigned_byte, F_rgb);
00131 }
00132 
00133 ////////////////////////////////////////////////////////////////////
00134 //     Function: Texture::setup_3d_texture
00135 //       Access: Published
00136 //  Description: Sets the texture as an empty 3-d texture with the
00137 //               specified dimensions and properties.  Follow up with
00138 //               set_ram_image() or modify_ram_image() to fill the
00139 //               image data.
00140 ////////////////////////////////////////////////////////////////////
00141 INLINE void Texture::
00142 setup_3d_texture(int x_size, int y_size, int z_size,
00143                  ComponentType component_type, Format format) {
00144   setup_texture(TT_3d_texture, x_size, y_size, z_size, component_type, format);
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: Texture::setup_cube_map
00149 //       Access: Published
00150 //  Description: Sets the texture as an empty cube map texture with no
00151 //               dimensions.  Follow up with read() or load() to fill
00152 //               the texture properties and image data.
00153 ////////////////////////////////////////////////////////////////////
00154 INLINE void Texture::
00155 setup_cube_map() {
00156   setup_cube_map(0, T_unsigned_byte, F_rgb);
00157 }
00158 
00159 ////////////////////////////////////////////////////////////////////
00160 //     Function: Texture::setup_cube_map
00161 //       Access: Published
00162 //  Description: Sets the texture as an empty cube map texture with
00163 //               the specified dimensions and properties.  Follow up
00164 //               with set_ram_image() or modify_ram_image() to fill
00165 //               the image data.  
00166 //
00167 //               Note that a cube map should always consist of six
00168 //               square images, so x_size and y_size will be the same,
00169 //               and z_size is always 6.
00170 ////////////////////////////////////////////////////////////////////
00171 INLINE void Texture::
00172 setup_cube_map(int size, ComponentType component_type, 
00173                Format format) {
00174   setup_texture(TT_cube_map, size, size, 6, component_type, format);
00175 }
00176 
00177 ////////////////////////////////////////////////////////////////////
00178 //     Function: Texture::write
00179 //       Access: Published
00180 //  Description: Writes the texture to the named filename.
00181 ////////////////////////////////////////////////////////////////////
00182 INLINE bool Texture::
00183 write(const Filename &fullpath) {
00184   MutexHolder holder(_lock);
00185   return do_write(fullpath, 0, 0, false, false);
00186 }
00187 
00188 ////////////////////////////////////////////////////////////////////
00189 //     Function: Texture::write
00190 //       Access: Published
00191 //  Description: Writes a single page or mipmap level to a single
00192 //               file, or automatically writes a series of pages
00193 //               and/or mipmap levels to a numbered series of files.
00194 //
00195 //               If the filename ends in the extension .txo, this
00196 //               implicitly writes a Panda texture object (.txo)
00197 //               instead of an image file.  In this case, the
00198 //               remaining parameters are ignored, and only one file
00199 //               is written, which will contain all of the pages and
00200 //               resident mipmap levels in the texture.
00201 //
00202 //               If write_pages is false, then z indicates the page
00203 //               number to write.  3-D textures have one page number
00204 //               for each level of depth; cube maps have six pages
00205 //               number 0 through 5.  Other kinds of textures have
00206 //               only one page, numbered 0.
00207 //
00208 //               If write_pages is true, then all pages of the texture
00209 //               will be written.  In this case z is ignored, and the
00210 //               filename should contain a sequence of hash marks
00211 //               ("#") which will be filled in with the page index
00212 //               number.
00213 //
00214 //               If write_mipmaps is false, then n indicates the
00215 //               mipmap level number to write.  Normally, this is 0,
00216 //               for the base texture image.  Normally, the mipmap
00217 //               levels of a texture are not available in RAM (they
00218 //               are generated automatically by the graphics card).
00219 //               However, if you have the mipmap levels available, for
00220 //               instance because you called
00221 //               generate_ram_mipmap_images() to generate them
00222 //               internally, or you called
00223 //               GraphicsEngine::extract_texture_data() to retrieve
00224 //               them from the graphics card, then you may write out
00225 //               each mipmap level with this parameter.
00226 //
00227 //               If write_mipmaps is true, then all mipmap levels of
00228 //               the texture will be written.  In this case n is
00229 //               ignored, and the filename should contain a sequence
00230 //               of hash marks ("#") which will be filled in with the
00231 //               mipmap level number.
00232 //
00233 //               If both write_pages and write_mipmaps is true, then
00234 //               all pages and all mipmap levels will be written.  In
00235 //               this case, the filename should contain two different
00236 //               sequences of hash marks, separated by a character
00237 //               such as a hyphen, underscore, or dot.  The first hash
00238 //               mark sequence will be filled in with the mipmap
00239 //               level, while the second hash mark sequence will be
00240 //               the page index.
00241 ////////////////////////////////////////////////////////////////////
00242 INLINE bool Texture::
00243 write(const Filename &fullpath, int z, int n, 
00244       bool write_pages, bool write_mipmaps) {
00245   MutexHolder holder(_lock);
00246   return do_write(fullpath, z, n, write_pages, write_mipmaps);
00247 }
00248 
00249 ////////////////////////////////////////////////////////////////////
00250 //     Function: Texture::load
00251 //       Access: Published
00252 //  Description: Replaces the texture with the indicated image.
00253 ////////////////////////////////////////////////////////////////////
00254 INLINE bool Texture::
00255 load(const PNMImage &pnmimage, const LoaderOptions &options) {
00256   MutexHolder holder(_lock);
00257   do_clear();
00258   ++_properties_modified;
00259   ++_image_modified;
00260   if (do_load_one(pnmimage, get_name(), 0, 0, options)) {
00261     bool generate_mipmaps = ((options.get_texture_flags() & LoaderOptions::TF_generate_mipmaps) != 0);
00262     consider_auto_process_ram_image(generate_mipmaps || uses_mipmaps(), true);
00263     return true;
00264   }
00265   return false;
00266 }
00267 
00268 ////////////////////////////////////////////////////////////////////
00269 //     Function: Texture::load
00270 //       Access: Published
00271 //  Description: Stores the indicated image in the given page and
00272 //               mipmap level.  See read().
00273 ////////////////////////////////////////////////////////////////////
00274 INLINE bool Texture::
00275 load(const PNMImage &pnmimage, int z, int n, const LoaderOptions &options) {
00276   MutexHolder holder(_lock);
00277   ++_properties_modified;
00278   ++_image_modified;
00279   if (do_load_one(pnmimage, get_name(), z, n, options)) {
00280     return true;
00281   }
00282   return false;
00283 }
00284 
00285 ////////////////////////////////////////////////////////////////////
00286 //     Function: Texture::store
00287 //       Access: Published
00288 //  Description: Saves the texture to the indicated PNMImage, but does
00289 //               not write it to disk.
00290 ////////////////////////////////////////////////////////////////////
00291 INLINE bool Texture::
00292 store(PNMImage &pnmimage) const {
00293   MutexHolder holder(_lock);
00294   return do_store_one(pnmimage, 0, 0);
00295 }
00296 
00297 ////////////////////////////////////////////////////////////////////
00298 //     Function: Texture::store
00299 //       Access: Published
00300 //  Description: Saves the indicated page and mipmap level of the
00301 //               texture to the PNMImage.
00302 ////////////////////////////////////////////////////////////////////
00303 INLINE bool Texture::
00304 store(PNMImage &pnmimage, int z, int n) const {
00305   MutexHolder holder(_lock);
00306   return do_store_one(pnmimage, z, n);
00307 }
00308 
00309 ////////////////////////////////////////////////////////////////////
00310 //     Function: Texture::reload
00311 //       Access: Published
00312 //  Description: Re-reads the Texture from its disk file.  Useful when
00313 //               you know the image on disk has recently changed, and
00314 //               you want to update the Texture image.
00315 //
00316 //               Returns true on success, false on failure (in which
00317 //               case, the Texture may or may not still be valid).
00318 ////////////////////////////////////////////////////////////////////
00319 bool Texture::
00320 reload() {
00321   MutexHolder holder(_lock);
00322   return do_reload();
00323 }
00324 
00325 ////////////////////////////////////////////////////////////////////
00326 //     Function: Texture::has_filename
00327 //       Access: Published
00328 //  Description: Returns true if the filename has been set and
00329 //               is available.  See set_filename().
00330 ////////////////////////////////////////////////////////////////////
00331 INLINE bool Texture::
00332 has_filename() const {
00333   MutexHolder holder(_lock);
00334   return !_filename.empty();
00335 }
00336 
00337 ////////////////////////////////////////////////////////////////////
00338 //     Function: Texture::get_filename
00339 //       Access: Published
00340 //  Description: Returns the filename that has been set.  This is the
00341 //               name of the file as it was requested.  Also see
00342 //               get_fullpath().
00343 ////////////////////////////////////////////////////////////////////
00344 INLINE const Filename &Texture::
00345 get_filename() const {
00346   MutexHolder holder(_lock);
00347   return _filename;
00348 }
00349 
00350 ////////////////////////////////////////////////////////////////////
00351 //     Function: Texture::has_alpha_filename
00352 //       Access: Published
00353 //  Description: Returns true if the alpha_filename has been set and
00354 //               is available.  See set_alpha_filename().
00355 ////////////////////////////////////////////////////////////////////
00356 INLINE bool Texture::
00357 has_alpha_filename() const {
00358   MutexHolder holder(_lock);
00359   return !_alpha_filename.empty();
00360 }
00361 
00362 ////////////////////////////////////////////////////////////////////
00363 //     Function: Texture::get_alpha_filename
00364 //       Access: Published
00365 //  Description: Returns the alpha_filename that has been set.  If
00366 //               this is set, it represents the name of the alpha
00367 //               component, which is stored in a separate file.  See
00368 //               also get_filename(), and get_alpha_fullpath().
00369 ////////////////////////////////////////////////////////////////////
00370 INLINE const Filename &Texture::
00371 get_alpha_filename() const {
00372   MutexHolder holder(_lock);
00373   return _alpha_filename;
00374 }
00375 
00376 ////////////////////////////////////////////////////////////////////
00377 //     Function: Texture::has_fullpath
00378 //       Access: Published
00379 //  Description: Returns true if the fullpath has been set and
00380 //               is available.  See set_fullpath().
00381 ////////////////////////////////////////////////////////////////////
00382 INLINE bool Texture::
00383 has_fullpath() const {
00384   MutexHolder holder(_lock);
00385   return !_fullpath.empty();
00386 }
00387 
00388 ////////////////////////////////////////////////////////////////////
00389 //     Function: Texture::get_fullpath
00390 //       Access: Published
00391 //  Description: Returns the fullpath that has been set.  This is the
00392 //               full path to the file as it was found along the
00393 //               texture search path.
00394 ////////////////////////////////////////////////////////////////////
00395 INLINE const Filename &Texture::
00396 get_fullpath() const {
00397   MutexHolder holder(_lock);
00398   return _fullpath;
00399 }
00400 
00401 ////////////////////////////////////////////////////////////////////
00402 //     Function: Texture::has_alpha_fullpath
00403 //       Access: Published
00404 //  Description: Returns true if the alpha_fullpath has been set and
00405 //               is available.  See set_alpha_fullpath().
00406 ////////////////////////////////////////////////////////////////////
00407 INLINE bool Texture::
00408 has_alpha_fullpath() const {
00409   MutexHolder holder(_lock);
00410   return !_alpha_fullpath.empty();
00411 }
00412 
00413 ////////////////////////////////////////////////////////////////////
00414 //     Function: Texture::get_alpha_fullpath
00415 //       Access: Published
00416 //  Description: 
00417 //               Returns the alpha_fullpath that has been set.  This
00418 //               is the full path to the alpha part of the image file
00419 //               as it was found along the texture search path.
00420 ////////////////////////////////////////////////////////////////////
00421 INLINE const Filename &Texture::
00422 get_alpha_fullpath() const {
00423   MutexHolder holder(_lock);
00424   return _alpha_fullpath;
00425 }
00426 
00427 
00428 ////////////////////////////////////////////////////////////////////
00429 //     Function: Texture::get_x_size
00430 //       Access: Published
00431 //  Description: Returns the width of the texture image in texels.
00432 ////////////////////////////////////////////////////////////////////
00433 INLINE int Texture::
00434 get_x_size() const {
00435   return _x_size;
00436 }
00437 
00438 ////////////////////////////////////////////////////////////////////
00439 //     Function: Texture::get_y_size
00440 //       Access: Published
00441 //  Description: Returns the height of the texture image in texels.
00442 //               For a 1-d texture, this will be 1.
00443 ////////////////////////////////////////////////////////////////////
00444 INLINE int Texture::
00445 get_y_size() const {
00446   return _y_size;
00447 }
00448 
00449 ////////////////////////////////////////////////////////////////////
00450 //     Function: Texture::get_z_size
00451 //       Access: Published
00452 //  Description: Returns the depth of the texture image in texels.
00453 //               For a 1-d texture or 2-d texture, this will be 1.
00454 //               For a cube map texture, this will be 6.
00455 ////////////////////////////////////////////////////////////////////
00456 INLINE int Texture::
00457 get_z_size() const {
00458   return _z_size;
00459 }
00460 
00461 ////////////////////////////////////////////////////////////////////
00462 //     Function: Texture::get_pad_x_size
00463 //       Access: Published
00464 //  Description: Returns size of the pad region.  See set_pad_size.
00465 ////////////////////////////////////////////////////////////////////
00466 INLINE int Texture::
00467 get_pad_x_size() const {
00468   return _pad_x_size;
00469 }
00470 
00471 ////////////////////////////////////////////////////////////////////
00472 //     Function: Texture::get_pad_y_size
00473 //       Access: Published
00474 //  Description: Returns size of the pad region.  See set_pad_size.
00475 ////////////////////////////////////////////////////////////////////
00476 INLINE int Texture::
00477 get_pad_y_size() const {
00478   return _pad_y_size;
00479 }
00480 
00481 ////////////////////////////////////////////////////////////////////
00482 //     Function: Texture::get_pad_z_size
00483 //       Access: Published
00484 //  Description: Returns size of the pad region.  See set_pad_size.
00485 ////////////////////////////////////////////////////////////////////
00486 INLINE int Texture::
00487 get_pad_z_size() const {
00488   return _pad_z_size;
00489 }
00490 
00491 ////////////////////////////////////////////////////////////////////
00492 //     Function: Texture::set_pad_size
00493 //       Access: Published
00494 //  Description: Sets the size of the pad region.
00495 //
00496 //               Sometimes, when a video card demands power-of-two
00497 //               textures, it is necessary to create a big texture
00498 //               and then only use a portion of it.  The pad region
00499 //               indicates which portion of the texture is not
00500 //               really in use.  All operations use the texture
00501 //               as a whole, including the pad region, unless they
00502 //               explicitly state that they use only the non-pad
00503 //               region.
00504 //
00505 //               Changing the texture's size clears the pad region.
00506 ////////////////////////////////////////////////////////////////////
00507 INLINE void Texture::
00508 set_pad_size(int x, int y, int z) {
00509   MutexHolder holder(_lock);
00510   do_set_pad_size(x, y, z);
00511 }
00512 
00513 ////////////////////////////////////////////////////////////////////
00514 //     Function: Texture::get_orig_file_x_size
00515 //       Access: Published
00516 //  Description: Returns the X size of the original disk image that
00517 //               this Texture was loaded from (if it came from a disk
00518 //               file), before any automatic rescaling by Panda.
00519 ////////////////////////////////////////////////////////////////////
00520 INLINE int Texture::
00521 get_orig_file_x_size() const {
00522   return _orig_file_x_size;
00523 }
00524 
00525 ////////////////////////////////////////////////////////////////////
00526 //     Function: Texture::get_orig_file_y_size
00527 //       Access: Published
00528 //  Description: Returns the Y size of the original disk image that
00529 //               this Texture was loaded from (if it came from a disk
00530 //               file), before any automatic rescaling by Panda.
00531 ////////////////////////////////////////////////////////////////////
00532 INLINE int Texture::
00533 get_orig_file_y_size() const {
00534   return _orig_file_y_size;
00535 }
00536 
00537 ////////////////////////////////////////////////////////////////////
00538 //     Function: Texture::get_orig_file_z_size
00539 //       Access: Published
00540 //  Description: Returns the Z size of the original disk image that
00541 //               this Texture was loaded from (if it came from a disk
00542 //               file), before any automatic rescaling by Panda.
00543 ////////////////////////////////////////////////////////////////////
00544 INLINE int Texture::
00545 get_orig_file_z_size() const {
00546   // At the moment, we perform no automatic adjustment of Z size.  So
00547   // we can just return the current value, since it would be the same
00548   // thing.
00549   return _z_size;
00550 }
00551 
00552 ////////////////////////////////////////////////////////////////////
00553 //     Function: Texture::get_num_components
00554 //       Access: Published
00555 //  Description: Returns the number of color components for each texel
00556 //               of the texture image.  This is 3 for an rgb texture
00557 //               or 4 for an rgba texture; it may also be 1 or 2 for a
00558 //               grayscale texture.
00559 ////////////////////////////////////////////////////////////////////
00560 INLINE int Texture::
00561 get_num_components() const {
00562   return _num_components;
00563 }
00564 
00565 ////////////////////////////////////////////////////////////////////
00566 //     Function: Texture::get_component_width
00567 //       Access: Published
00568 //  Description: Returns the number of bytes stored for each color
00569 //               component of a texel.  Typically this is 1, but it
00570 //               may be 2 for 16-bit texels.
00571 ////////////////////////////////////////////////////////////////////
00572 INLINE int Texture::
00573 get_component_width() const {
00574   return _component_width;
00575 }
00576 
00577 ////////////////////////////////////////////////////////////////////
00578 //     Function: Texture::get_texture_type
00579 //       Access: Published
00580 //  Description: Returns the overall interpretation of the texture.
00581 ////////////////////////////////////////////////////////////////////
00582 INLINE Texture::TextureType Texture::
00583 get_texture_type() const {
00584   return _texture_type;
00585 }
00586 
00587 ////////////////////////////////////////////////////////////////////
00588 //     Function: Texture::get_format
00589 //       Access: Published
00590 //  Description: Returns the format of the texture, which represents
00591 //               both the semantic meaning of the texels and, to some
00592 //               extent, their storage information.
00593 ////////////////////////////////////////////////////////////////////
00594 INLINE Texture::Format Texture::
00595 get_format() const {
00596   return _format;
00597 }
00598 
00599 ////////////////////////////////////////////////////////////////////
00600 //     Function: Texture::get_component_type
00601 //       Access: Published
00602 //  Description: Returns the numeric interpretation of each component
00603 //               of the texture.
00604 ////////////////////////////////////////////////////////////////////
00605 INLINE Texture::ComponentType Texture::
00606 get_component_type() const {
00607   return _component_type;
00608 }
00609 
00610 ////////////////////////////////////////////////////////////////////
00611 //     Function: Texture::set_wrap_u
00612 //       Access: Published
00613 //  Description:
00614 ////////////////////////////////////////////////////////////////////
00615 INLINE void Texture::
00616 set_wrap_u(Texture::WrapMode wrap) {
00617   MutexHolder holder(_lock);
00618   do_set_wrap_u(wrap);
00619 }
00620 
00621 ////////////////////////////////////////////////////////////////////
00622 //     Function: Texture::set_wrap_v
00623 //       Access: Published
00624 //  Description:
00625 ////////////////////////////////////////////////////////////////////
00626 INLINE void Texture::
00627 set_wrap_v(Texture::WrapMode wrap) {
00628   MutexHolder holder(_lock);
00629   do_set_wrap_v(wrap);
00630 }
00631 
00632 ////////////////////////////////////////////////////////////////////
00633 //     Function: Texture::set_wrap_w
00634 //       Access: Published
00635 //  Description: The W wrap direction is only used for 3-d textures.
00636 ////////////////////////////////////////////////////////////////////
00637 INLINE void Texture::
00638 set_wrap_w(Texture::WrapMode wrap) {
00639   MutexHolder holder(_lock);
00640   do_set_wrap_w(wrap);
00641 }
00642 
00643 ////////////////////////////////////////////////////////////////////
00644 //     Function: Texture::set_minfilter
00645 //       Access: Published
00646 //  Description:
00647 ////////////////////////////////////////////////////////////////////
00648 INLINE void Texture::
00649 set_minfilter(Texture::FilterType filter) {
00650   MutexHolder holder(_lock);
00651   do_set_minfilter(filter);
00652 }
00653 
00654 ////////////////////////////////////////////////////////////////////
00655 //     Function: Texture::set_magfilter
00656 //       Access: Published
00657 //  Description:
00658 ////////////////////////////////////////////////////////////////////
00659 INLINE void Texture::
00660 set_magfilter(Texture::FilterType filter) {
00661   MutexHolder holder(_lock);
00662   do_set_magfilter(filter);
00663 }
00664 
00665 ////////////////////////////////////////////////////////////////////
00666 //     Function: Texture::set_anisotropic_degree
00667 //       Access: Published
00668 //  Description: Specifies the level of anisotropic filtering to apply
00669 //               to the texture.  Set this 0 to indicate the default
00670 //               value, which is specified in the
00671 //               texture-anisotropic-degree config variable.
00672 //
00673 //               To explicitly disable anisotropic filtering, set this
00674 //               value to 1.  To explicitly enable anisotropic
00675 //               filtering, set it to a value higher than 1; larger
00676 //               numbers indicate greater degrees of filtering.
00677 ////////////////////////////////////////////////////////////////////
00678 INLINE void Texture::
00679 set_anisotropic_degree(int anisotropic_degree) {
00680   MutexHolder holder(_lock);
00681   do_set_anisotropic_degree(anisotropic_degree);
00682 }
00683 
00684 ////////////////////////////////////////////////////////////////////
00685 //     Function: Texture::set_border_color
00686 //       Access: Published
00687 //  Description: Specifies the solid color of the texture's border.
00688 //               Some OpenGL implementations use a border for tiling
00689 //               textures; in Panda, it is only used for specifying
00690 //               the clamp color.
00691 ////////////////////////////////////////////////////////////////////
00692 INLINE void Texture::
00693 set_border_color(const Colorf &color) {
00694   MutexHolder holder(_lock);
00695   do_set_border_color(color);
00696 }
00697 
00698 ////////////////////////////////////////////////////////////////////
00699 //     Function: Texture::set_compression
00700 //       Access: Published
00701 //  Description: Requests that this particular Texture be compressed
00702 //               when it is loaded into texture memory.  
00703 //
00704 //               This refers to the internal compression of the
00705 //               texture image within texture memory; it is not
00706 //               related to jpeg or png compression, which are disk
00707 //               file compression formats.  The actual disk file that
00708 //               generated this texture may be stored in a compressed
00709 //               or uncompressed format supported by Panda; it will be
00710 //               decompressed on load, and then recompressed by the
00711 //               graphics API if this parameter is not CM_off.
00712 //
00713 //               If the GSG does not support this texture compression
00714 //               mode, the texture will silently be loaded
00715 //               uncompressed.
00716 ////////////////////////////////////////////////////////////////////
00717 INLINE void Texture::
00718 set_compression(Texture::CompressionMode compression) {
00719   MutexHolder holder(_lock);
00720   do_set_compression(compression);
00721 }
00722 
00723 ////////////////////////////////////////////////////////////////////
00724 //     Function: Texture::set_render_to_texture
00725 //       Access: Published
00726 //  Description: Sets a flag on the texture that indicates whether the
00727 //               texture is intended to be used as a direct-render
00728 //               target, by binding a framebuffer to a texture and
00729 //               rendering directly into the texture.
00730 //
00731 //               This controls some low-level choices made about the
00732 //               texture object itself.  For instance, compressed
00733 //               textures are disallowed when this flag is set true.
00734 //
00735 //               Normally, a user should not need to set this flag
00736 //               directly; it is set automatically by the low-level
00737 //               display code when a texture is bound to a
00738 //               framebuffer.
00739 ////////////////////////////////////////////////////////////////////
00740 INLINE void Texture::
00741 set_render_to_texture(bool render_to_texture) {
00742   _render_to_texture = render_to_texture;
00743 }
00744 
00745 ////////////////////////////////////////////////////////////////////
00746 //     Function: Texture::get_wrap_u
00747 //       Access: Published
00748 //  Description: Returns the wrap mode of the texture in the U
00749 //               direction.
00750 ////////////////////////////////////////////////////////////////////
00751 INLINE Texture::WrapMode Texture::
00752 get_wrap_u() const {
00753   return _wrap_u;
00754 }
00755 
00756 ////////////////////////////////////////////////////////////////////
00757 //     Function: Texture::get_wrap_v
00758 //       Access: Published
00759 //  Description: Returns the wrap mode of the texture in the V
00760 //               direction.
00761 ////////////////////////////////////////////////////////////////////
00762 INLINE Texture::WrapMode Texture::
00763 get_wrap_v() const {
00764   return _wrap_v;
00765 }
00766 
00767 ////////////////////////////////////////////////////////////////////
00768 //     Function: Texture::get_wrap_w
00769 //       Access: Published
00770 //  Description: Returns the wrap mode of the texture in the W
00771 //               direction.  This is the depth direction of 3-d
00772 //               textures.
00773 ////////////////////////////////////////////////////////////////////
00774 INLINE Texture::WrapMode Texture::
00775 get_wrap_w() const {
00776   return _wrap_w;
00777 }
00778 
00779 ////////////////////////////////////////////////////////////////////
00780 //     Function: Texture::get_minfilter
00781 //       Access: Published
00782 //  Description: Returns the filter mode of the texture for
00783 //               minification.  If this is one of the mipmap
00784 //               constants, then the texture requires mipmaps.  This
00785 //               may return FT_default; see also
00786 //               get_effective_minfilter().
00787 ////////////////////////////////////////////////////////////////////
00788 INLINE Texture::FilterType Texture::
00789 get_minfilter() const {
00790   return _minfilter;
00791 }
00792 
00793 ////////////////////////////////////////////////////////////////////
00794 //     Function: Texture::get_magfilter
00795 //       Access: Published
00796 //  Description: Returns the filter mode of the texture for
00797 //               magnification.  The mipmap constants are invalid
00798 //               here.  This may return FT_default; see also
00799 //               get_effective_minfilter().
00800 ////////////////////////////////////////////////////////////////////
00801 INLINE Texture::FilterType Texture::
00802 get_magfilter() const {
00803   return _magfilter;
00804 }
00805 
00806 ////////////////////////////////////////////////////////////////////
00807 //     Function: Texture::get_anisotropic_degree
00808 //       Access: Published
00809 //  Description: Returns the degree of anisotropic filtering that
00810 //               should be applied to the texture.  This value may
00811 //               return 0, indicating the default value; see also
00812 //               get_effective_anisotropic_degree.
00813 ////////////////////////////////////////////////////////////////////
00814 INLINE int Texture::
00815 get_anisotropic_degree() const {
00816   return _anisotropic_degree;
00817 }
00818 
00819 ////////////////////////////////////////////////////////////////////
00820 //     Function: Texture::get_effective_anisotropic_degree
00821 //       Access: Published
00822 //  Description: Returns the degree of anisotropic filtering that
00823 //               should be applied to the texture.  This value will
00824 //               normally not return 0, unless there is an error in
00825 //               the config file.
00826 ////////////////////////////////////////////////////////////////////
00827 INLINE int Texture::
00828 get_effective_anisotropic_degree() const {
00829   if (_anisotropic_degree != 0) {
00830     return _anisotropic_degree;
00831   }
00832   return texture_anisotropic_degree;
00833 }
00834 
00835 ////////////////////////////////////////////////////////////////////
00836 //     Function: Texture::get_border_color
00837 //       Access: Published
00838 //  Description: Returns the solid color of the texture's border.
00839 //               Some OpenGL implementations use a border for tiling
00840 //               textures; in Panda, it is only used for specifying
00841 //               the clamp color.
00842 ////////////////////////////////////////////////////////////////////
00843 INLINE Colorf Texture::
00844 get_border_color() const {
00845   return _border_color;
00846 }
00847 
00848 ////////////////////////////////////////////////////////////////////
00849 //     Function: Texture::get_compression
00850 //       Access: Published
00851 //  Description: Returns the compression mode requested for this
00852 //               particular texture, or CM_off if the texture is not
00853 //               to be compressed.
00854 //
00855 //               If a value other than CM_off is returned, this is
00856 //               not a guarantee that the texture is actually
00857 //               successfully compressed on the GSG.  It may be that
00858 //               the GSG does not support the requested compression
00859 //               mode, in which case the texture may actually be
00860 //               stored uncompressed in texture memory.
00861 ////////////////////////////////////////////////////////////////////
00862 INLINE Texture::CompressionMode Texture::
00863 get_compression() const {
00864   return _compression;
00865 }
00866 
00867 ////////////////////////////////////////////////////////////////////
00868 //     Function: Texture::has_compression
00869 //       Access: Published
00870 //  Description: Returns true if the texture indicates it wants to be
00871 //               compressed, either with CM_on or higher, or
00872 //               CM_default and compressed-textures is true.
00873 //
00874 //               If true returned, this is not a guarantee that the
00875 //               texture is actually successfully compressed on the
00876 //               GSG.  It may be that the GSG does not support the
00877 //               requested compression mode, in which case the texture
00878 //               may actually be stored uncompressed in texture
00879 //               memory.
00880 ////////////////////////////////////////////////////////////////////
00881 INLINE bool Texture::
00882 has_compression() const {
00883   MutexHolder holder(_lock);
00884   return do_has_compression();
00885 }
00886 
00887 ////////////////////////////////////////////////////////////////////
00888 //     Function: Texture::get_render_to_texture
00889 //       Access: Published
00890 //  Description: Returns a flag on the texture that indicates whether the
00891 //               texture is intended to be used as a direct-render
00892 //               target, by binding a framebuffer to a texture and
00893 //               rendering directly into the texture.
00894 //
00895 //               Normally, a user should not need to set this flag
00896 //               directly; it is set automatically by the low-level
00897 //               display code when a texture is bound to a
00898 //               framebuffer.
00899 ////////////////////////////////////////////////////////////////////
00900 INLINE bool Texture::
00901 get_render_to_texture() const {
00902   return _render_to_texture;
00903 }
00904 
00905 ////////////////////////////////////////////////////////////////////
00906 //     Function: Texture::uses_mipmaps
00907 //       Access: Public
00908 //  Description: Returns true if the minfilter settings on this
00909 //               texture indicate the use of mipmapping, false
00910 //               otherwise.
00911 ////////////////////////////////////////////////////////////////////
00912 INLINE bool Texture::
00913 uses_mipmaps() const {
00914   return is_mipmap(get_effective_minfilter());
00915 }
00916 
00917 ////////////////////////////////////////////////////////////////////
00918 //     Function: Texture::set_quality_level
00919 //       Access: Public
00920 //  Description: Sets a hint to the renderer about the desired
00921 //               performance / quality tradeoff for this particular
00922 //               texture.  This is most useful for the tinydisplay
00923 //               software renderer; for normal, hardware-accelerated
00924 //               renderers, this may have little or no effect.
00925 ////////////////////////////////////////////////////////////////////
00926 INLINE void Texture::
00927 set_quality_level(Texture::QualityLevel quality_level) {
00928   MutexHolder holder(_lock);
00929   do_set_quality_level(quality_level);
00930 }
00931 
00932 ////////////////////////////////////////////////////////////////////
00933 //     Function: Texture::get_quality_level
00934 //       Access: Public
00935 //  Description: Returns the current quality_level hint.  See
00936 //               set_quality_level().  This value may return
00937 //               QL_default; see get_effective_quality_level().
00938 ////////////////////////////////////////////////////////////////////
00939 INLINE Texture::QualityLevel Texture::
00940 get_quality_level() const {
00941   return _quality_level;
00942 }
00943 
00944 ////////////////////////////////////////////////////////////////////
00945 //     Function: Texture::get_effective_quality_level
00946 //       Access: Public
00947 //  Description: Returns the current quality_level hint, or the global
00948 //               default quality_level if this texture doesn't specify
00949 //               a quality level.  This value will not normally return
00950 //               QL_default (unless there is an error in the config
00951 //               file)
00952 ////////////////////////////////////////////////////////////////////
00953 INLINE Texture::QualityLevel Texture::
00954 get_effective_quality_level() const {
00955   if (_quality_level == QL_default) {
00956     return texture_quality_level;
00957   }
00958   return _quality_level;
00959 }
00960 
00961 ////////////////////////////////////////////////////////////////////
00962 //     Function: Texture::get_expected_num_mipmap_levels
00963 //       Access: Published
00964 //  Description: Returns the number of mipmap levels that should be
00965 //               defined for this texture, given the texture's size.
00966 //
00967 //               Note that this returns a number appropriate for
00968 //               mipmapping, even if the texture does not currently
00969 //               have mipmapping enabled.
00970 ////////////////////////////////////////////////////////////////////
00971 INLINE int Texture::
00972 get_expected_num_mipmap_levels() const {
00973   MutexHolder holder(_lock);
00974   return do_get_expected_num_mipmap_levels();
00975 }
00976 
00977 ////////////////////////////////////////////////////////////////////
00978 //     Function: Texture::get_expected_mipmap_x_size
00979 //       Access: Published
00980 //  Description: Returns the x_size that the nth mipmap level should
00981 //               have, based on the texture's size.
00982 ////////////////////////////////////////////////////////////////////
00983 INLINE int Texture::
00984 get_expected_mipmap_x_size(int n) const {
00985   MutexHolder holder(_lock);
00986   return do_get_expected_mipmap_x_size(n);
00987 }
00988 
00989 ////////////////////////////////////////////////////////////////////
00990 //     Function: Texture::get_expected_mipmap_y_size
00991 //       Access: Published
00992 //  Description: Returns the y_size that the nth mipmap level should
00993 //               have, based on the texture's size.
00994 ////////////////////////////////////////////////////////////////////
00995 INLINE int Texture::
00996 get_expected_mipmap_y_size(int n) const {
00997   MutexHolder holder(_lock);
00998   return do_get_expected_mipmap_y_size(n);
00999 }
01000 
01001 ////////////////////////////////////////////////////////////////////
01002 //     Function: Texture::get_expected_mipmap_z_size
01003 //       Access: Published
01004 //  Description: Returns the z_size that the nth mipmap level should
01005 //               have, based on the texture's size.
01006 ////////////////////////////////////////////////////////////////////
01007 INLINE int Texture::
01008 get_expected_mipmap_z_size(int n) const {
01009   MutexHolder holder(_lock);
01010   return do_get_expected_mipmap_z_size(n);
01011 }
01012 
01013 ////////////////////////////////////////////////////////////////////
01014 //     Function: Texture::has_ram_image
01015 //       Access: Published
01016 //  Description: Returns true if the Texture has its image contents
01017 //               available in main RAM, false if it exists only in
01018 //               texture memory or in the prepared GSG context.
01019 //
01020 //               Note that this has nothing to do with whether
01021 //               get_ram_image() will fail or not.  Even if
01022 //               has_ram_image() returns false, get_ram_image() may
01023 //               still return a valid RAM image, because
01024 //               get_ram_image() will automatically load the texture
01025 //               from disk if necessary.  The only thing
01026 //               has_ram_image() tells you is whether the texture is
01027 //               available right now without hitting the disk first.
01028 //
01029 //               Note also that if an application uses only one GSG,
01030 //               it may appear that has_ram_image() returns true if
01031 //               the texture has not yet been loaded by the GSG, but
01032 //               this correlation is not true in general and should
01033 //               not be depended on.  Specifically, if an application
01034 //               ever uses multiple GSG's in its lifetime (for
01035 //               instance, by opening more than one window, or by
01036 //               closing its window and opening another one later),
01037 //               then has_ram_image() may well return false on
01038 //               textures that have never been loaded on the current
01039 //               GSG.
01040 ////////////////////////////////////////////////////////////////////
01041 INLINE bool Texture::
01042 has_ram_image() const {
01043   MutexHolder holder(_lock);
01044   return do_has_ram_image();
01045 }
01046 
01047 ////////////////////////////////////////////////////////////////////
01048 //     Function: Texture::has_uncompressed_ram_image
01049 //       Access: Published
01050 //  Description: Returns true if the Texture has its image contents
01051 //               available in main RAM and is uncompressed, false
01052 //               otherwise.  See has_ram_image().
01053 ////////////////////////////////////////////////////////////////////
01054 INLINE bool Texture::
01055 has_uncompressed_ram_image() const {
01056   MutexHolder holder(_lock);
01057   return do_has_uncompressed_ram_image();
01058 }
01059 
01060 ////////////////////////////////////////////////////////////////////
01061 //     Function: Texture::might_have_ram_image
01062 //       Access: Published
01063 //  Description: Returns true if the texture's image contents are
01064 //               currently available in main RAM, or there is reason
01065 //               to believe it can be loaded on demand.  That is, this
01066 //               function returns a "best guess" as to whether
01067 //               get_ram_image() will succeed without actually calling
01068 //               it first.
01069 ////////////////////////////////////////////////////////////////////
01070 INLINE bool Texture::
01071 might_have_ram_image() const {
01072   MutexHolder holder(_lock);
01073   return (do_has_ram_image() || !_fullpath.empty());
01074 }
01075 
01076 ////////////////////////////////////////////////////////////////////
01077 //     Function: Texture::get_ram_image_size
01078 //       Access: Published
01079 //  Description: Returns the number of bytes used by the in-memory
01080 //               image, or 0 if there is no in-memory image.
01081 ////////////////////////////////////////////////////////////////////
01082 INLINE size_t Texture::
01083 get_ram_image_size() const {
01084   MutexHolder holder(_lock);
01085   return do_get_ram_image_size();
01086 }
01087 
01088 ////////////////////////////////////////////////////////////////////
01089 //     Function: Texture::get_ram_page_size
01090 //       Access: Published
01091 //  Description: Returns the number of bytes used by the in-memory
01092 //               image per page, or 0 if there is no in-memory image.
01093 //
01094 //               For a non-compressed texture, this is the same as
01095 //               get_expected_ram_page_size().  For a compressed
01096 //               texture, this may be a smaller value.  (We do assume
01097 //               that all pages will be the same size on a compressed
01098 //               texture).
01099 ////////////////////////////////////////////////////////////////////
01100 INLINE size_t Texture::
01101 get_ram_page_size() const {
01102   MutexHolder holder(_lock);
01103   if (_ram_image_compression == CM_off || _ram_images.empty()) {
01104     return do_get_expected_ram_page_size();
01105   } else {
01106     return _ram_images[0]._page_size;
01107   }
01108 }
01109 
01110 ////////////////////////////////////////////////////////////////////
01111 //     Function: Texture::get_expected_ram_image_size
01112 //       Access: Published
01113 //  Description: Returns the number of bytes that *ought* to be used
01114 //               by the in-memory image, based on the texture
01115 //               parameters.
01116 ////////////////////////////////////////////////////////////////////
01117 INLINE size_t Texture::
01118 get_expected_ram_image_size() const {
01119   MutexHolder holder(_lock);
01120   return do_get_expected_ram_image_size();
01121 }
01122 
01123 ////////////////////////////////////////////////////////////////////
01124 //     Function: Texture::get_expected_ram_page_size
01125 //       Access: Published
01126 //  Description: Returns the number of bytes that should be used per
01127 //               each Z page of the 3-d texture.  For a 2-d or 1-d
01128 //               texture, this is the same as
01129 //               get_expected_ram_image_size().
01130 ////////////////////////////////////////////////////////////////////
01131 INLINE size_t Texture::
01132 get_expected_ram_page_size() const {
01133   MutexHolder holder(_lock);
01134   return do_get_expected_ram_page_size();
01135 }
01136 
01137 ////////////////////////////////////////////////////////////////////
01138 //     Function: Texture::get_ram_image
01139 //       Access: Published
01140 //  Description: Returns the system-RAM image data associated with the
01141 //               texture.  If the texture does not currently have an
01142 //               associated RAM image, and the texture was generated
01143 //               by loading an image from a disk file (the most common
01144 //               case), this forces the reload of the same texture.
01145 //               This can happen if keep_texture_ram is configured to
01146 //               false, and we have previously prepared this texture
01147 //               with a GSG.
01148 //
01149 //               Note that it is not correct to call has_ram_image()
01150 //               first to test whether this function will fail.  A
01151 //               false return value from has_ram_image() indicates
01152 //               only that get_ram_image() may need to reload the
01153 //               texture from disk, which it will do automatically.
01154 //               However, you can call might_have_ram_image(), which
01155 //               will return true if the ram image exists, or there is
01156 //               a reasonable reason to believe it can be loaded.
01157 //
01158 //               On the other hand, it is possible that the texture
01159 //               cannot be found on disk or is otherwise unavailable.
01160 //               If that happens, this function will return NULL.
01161 //               There is no way to predict with 100% accuracy whether
01162 //               get_ram_image() will return NULL without calling it
01163 //               first; might_have_ram_image() is the closest.
01164 ////////////////////////////////////////////////////////////////////
01165 INLINE CPTA_uchar Texture::
01166 get_ram_image() {
01167   MutexHolder holder(_lock);
01168   return do_get_ram_image();
01169 }
01170 
01171 ////////////////////////////////////////////////////////////////////
01172 //     Function: Texture::get_ram_image_compression
01173 //       Access: Published
01174 //  Description: Returns the compression mode in which the ram image
01175 //               is already stored pre-compressed.  If this is other
01176 //               than CM_off, you cannot rely on the contents of the
01177 //               ram image to be anything predicatable (it will not be
01178 //               an array of x by y pixels, and it probably won't have
01179 //               the same length as get_expected_ram_image_size()).
01180 ////////////////////////////////////////////////////////////////////
01181 INLINE Texture::CompressionMode Texture::
01182 get_ram_image_compression() const {
01183   return _ram_image_compression;
01184 }
01185 
01186 ////////////////////////////////////////////////////////////////////
01187 //     Function: Texture::modify_ram_image
01188 //       Access: Published
01189 //  Description: Returns a modifiable pointer to the system-RAM image.
01190 //               This assumes the RAM image should be uncompressed.
01191 //               If the RAM image has been dumped, or is stored
01192 //               compressed, creates a new one.
01193 //
01194 //               This does *not* affect keep_ram_image.
01195 ////////////////////////////////////////////////////////////////////
01196 INLINE PTA_uchar Texture::
01197 modify_ram_image() {
01198   MutexHolder holder(_lock);
01199   ++_image_modified;
01200   return do_modify_ram_image();
01201 }
01202 
01203 ////////////////////////////////////////////////////////////////////
01204 //     Function: Texture::get_uncompressed_ram_image
01205 //       Access: Published
01206 //  Description: Returns the system-RAM image associated with the
01207 //               texture, in an uncompressed form if at all possible.
01208 //
01209 //               If get_ram_image_compression() is CM_off, then the
01210 //               system-RAM image is already uncompressed, and this
01211 //               returns the same thing as get_ram_image().
01212 //
01213 //               If get_ram_image_compression() is anything else, then
01214 //               the system-RAM image is compressed.  In this case,
01215 //               the image will be reloaded from the *original* file
01216 //               (not from the cache), in the hopes that an
01217 //               uncompressed image will be found there.
01218 //
01219 //               If an uncompressed image cannot be found, returns
01220 //               NULL.
01221 ////////////////////////////////////////////////////////////////////
01222 INLINE CPTA_uchar Texture::
01223 get_uncompressed_ram_image() {
01224   MutexHolder holder(_lock);
01225   return do_get_uncompressed_ram_image();
01226 }
01227 
01228 ////////////////////////////////////////////////////////////////////
01229 //     Function: Texture::make_ram_image
01230 //       Access: Published
01231 //  Description: Discards the current system-RAM image for the
01232 //               texture, if any, and allocates a new buffer of the
01233 //               appropriate size.  Returns the new buffer.
01234 //
01235 //               This does *not* affect keep_ram_image.
01236 ////////////////////////////////////////////////////////////////////
01237 INLINE PTA_uchar Texture::
01238 make_ram_image() {
01239   MutexHolder holder(_lock);
01240   ++_image_modified;
01241   return do_make_ram_image();
01242 }
01243 
01244 ////////////////////////////////////////////////////////////////////
01245 //     Function: Texture::clear_ram_image
01246 //       Access: Published
01247 //  Description: Discards the current system-RAM image.
01248 ////////////////////////////////////////////////////////////////////
01249 INLINE void Texture::
01250 clear_ram_image() {
01251   MutexHolder holder(_lock);
01252   do_clear_ram_image();
01253 }
01254 
01255 ////////////////////////////////////////////////////////////////////
01256 //     Function: Texture::set_keep_ram_image
01257 //       Access: Published
01258 //  Description: Sets the flag that indicates whether this Texture is
01259 //               eligible to have its main RAM copy of the texture
01260 //               memory dumped when the texture is prepared for
01261 //               rendering.
01262 //
01263 //               This will be false for most textures, which can
01264 //               reload their images if needed by rereading the input
01265 //               file.  However, textures that were generated
01266 //               dynamically and cannot be easily reloaded will want
01267 //               to set this flag to true, so that the texture will
01268 //               always keep its image copy around.
01269 ////////////////////////////////////////////////////////////////////
01270 INLINE void Texture::
01271 set_keep_ram_image(bool keep_ram_image) {
01272   _keep_ram_image = keep_ram_image;
01273 }
01274 
01275 ////////////////////////////////////////////////////////////////////
01276 //     Function: Texture::compress_ram_image
01277 //       Access: Published
01278 //  Description: Attempts to compress the texture's RAM image
01279 //               internally, to a format supported by the indicated
01280 //               GSG.  In order for this to work, the squish library
01281 //               must have been compiled into Panda.
01282 //
01283 //               If compression is CM_on, then an appropriate
01284 //               compression method that is supported by the indicated
01285 //               GSG is automatically chosen.  If the GSG pointer is
01286 //               NULL, any of the standard DXT1/3/5 compression
01287 //               methods will be used, regardless of whether it is
01288 //               supported.
01289 //
01290 //               If compression is any specific compression method,
01291 //               that method is used regardless of whether the GSG
01292 //               supports it.
01293 //
01294 //               quality_level determines the speed/quality tradeoff
01295 //               of the compression.  If it is QL_default, the
01296 //               texture's own quality_level parameter is used.
01297 //
01298 //               Returns true if successful, false otherwise.
01299 ////////////////////////////////////////////////////////////////////
01300 INLINE bool Texture::
01301 compress_ram_image(Texture::CompressionMode compression,
01302                    Texture::QualityLevel quality_level,
01303                    GraphicsStateGuardianBase *gsg) {
01304   MutexHolder holder(_lock);
01305   if (do_compress_ram_image(compression, quality_level, gsg)) {
01306     ++_image_modified;
01307     return true;
01308   }
01309   return false;
01310 }
01311 
01312 ////////////////////////////////////////////////////////////////////
01313 //     Function: Texture::uncompress_ram_image
01314 //       Access: Published
01315 //  Description: Attempts to uncompress the texture's RAM image
01316 //               internally.  In order for this to work, the squish
01317 //               library must have been compiled into Panda, and the
01318 //               ram image must be compressed in a format supported by
01319 //               squish.
01320 //
01321 //               Returns true if successful, false otherwise.
01322 ////////////////////////////////////////////////////////////////////
01323 INLINE bool Texture::
01324 uncompress_ram_image() {
01325   MutexHolder holder(_lock);
01326   if (do_uncompress_ram_image()) {
01327     ++_image_modified;
01328     return true;
01329   }
01330   return false;
01331 }
01332 
01333 ////////////////////////////////////////////////////////////////////
01334 //     Function: Texture::get_num_ram_mipmap_images
01335 //       Access: Published
01336 //  Description: Returns the maximum number of mipmap level images
01337 //               available in system memory.  The actual number may be
01338 //               less than this (that is, there might be gaps in the
01339 //               sequence); use has_ram_mipmap_image() to verify each
01340 //               level.
01341 //
01342 //               Also see get_num_loadable_ram_mipmap_images().
01343 ////////////////////////////////////////////////////////////////////
01344 INLINE int Texture::
01345 get_num_ram_mipmap_images() const {
01346   MutexHolder holder(_lock);
01347   return _ram_images.size();
01348 }
01349 
01350 ////////////////////////////////////////////////////////////////////
01351 //     Function: Texture::has_ram_mipmap_image
01352 //       Access: Published
01353 //  Description: Returns true if the Texture has the nth mipmap level
01354 //               available in system memory, false otherwise.  If the
01355 //               texture's minfilter mode requires mipmapping (see
01356 //               uses_mipmaps()), and all the texture's mipmap levels
01357 //               are not available when the texture is rendered, they
01358 //               will be generated automatically.
01359 ////////////////////////////////////////////////////////////////////
01360 INLINE bool Texture::
01361 has_ram_mipmap_image(int n) const {
01362   MutexHolder holder(_lock);
01363   return do_has_ram_mipmap_image(n);
01364 }
01365 
01366 ////////////////////////////////////////////////////////////////////
01367 //     Function: Texture::has_all_ram_mipmap_images
01368 //       Access: Published
01369 //  Description: Returns true if all expected mipmap levels have been
01370 //               defined and exist in the system RAM, or false if even
01371 //               one mipmap level is missing.
01372 ////////////////////////////////////////////////////////////////////
01373 INLINE bool Texture::
01374 has_all_ram_mipmap_images() const {
01375   MutexHolder holder(_lock);
01376   return do_has_all_ram_mipmap_images();
01377 }
01378 
01379 ////////////////////////////////////////////////////////////////////
01380 //     Function: Texture::get_ram_mipmap_image_size
01381 //       Access: Published
01382 //  Description: Returns the number of bytes used by the in-memory
01383 //               image for mipmap level n, or 0 if there is no
01384 //               in-memory image for this mipmap level.
01385 ////////////////////////////////////////////////////////////////////
01386 INLINE size_t Texture::
01387 get_ram_mipmap_image_size(int n) const {
01388   MutexHolder holder(_lock);
01389   if (n >= 0 && n < (int)_ram_images.size()) {
01390     return _ram_images[n]._image.size();
01391   }
01392   return 0;
01393 }
01394 
01395 ////////////////////////////////////////////////////////////////////
01396 //     Function: Texture::get_ram_mipmap_page_size
01397 //       Access: Published
01398 //  Description: Returns the number of bytes used by the in-memory
01399 //               image per page for mipmap level n, or 0 if there is
01400 //               no in-memory image for this mipmap level.
01401 //
01402 //               For a non-compressed texture, this is the same as
01403 //               get_expected_ram_mipmap_page_size().  For a compressed
01404 //               texture, this may be a smaller value.  (We do assume
01405 //               that all pages will be the same size on a compressed
01406 //               texture).
01407 ////////////////////////////////////////////////////////////////////
01408 INLINE size_t Texture::
01409 get_ram_mipmap_page_size(int n) const {
01410   MutexHolder holder(_lock);
01411   return do_get_ram_mipmap_page_size(n);
01412 }
01413 
01414 ////////////////////////////////////////////////////////////////////
01415 //     Function: Texture::get_expected_ram_mipmap_image_size
01416 //       Access: Published
01417 //  Description: Returns the number of bytes that *ought* to be used
01418 //               by the in-memory image for mipmap level n, based on
01419 //               the texture parameters.
01420 ////////////////////////////////////////////////////////////////////
01421 INLINE size_t Texture::
01422 get_expected_ram_mipmap_image_size(int n) const {
01423   MutexHolder holder(_lock);
01424   return do_get_expected_ram_mipmap_image_size(n);
01425 }
01426 
01427 ////////////////////////////////////////////////////////////////////
01428 //     Function: Texture::get_expected_ram_mipmap_page_size
01429 //       Access: Published
01430 //  Description: Returns the number of bytes that should be used per
01431 //               each Z page of the 3-d texture, for mipmap level n.
01432 //               For a 2-d or 1-d texture, this is the same as
01433 //               get_expected_ram_mipmap_image_size(n).
01434 ////////////////////////////////////////////////////////////////////
01435 INLINE size_t Texture::
01436 get_expected_ram_mipmap_page_size(int n) const {
01437   MutexHolder holder(_lock);
01438   return do_get_expected_ram_mipmap_page_size(n);
01439 }
01440 
01441 ////////////////////////////////////////////////////////////////////
01442 //     Function: Texture::modify_ram_mipmap_image
01443 //       Access: Published
01444 //  Description: Returns a modifiable pointer to the system-RAM image
01445 //               for the nth mipmap level.  This assumes the RAM image
01446 //               is uncompressed; if this is not the case, raises an
01447 //               assertion.
01448 //
01449 //               This does *not* affect keep_ram_image.
01450 ////////////////////////////////////////////////////////////////////
01451 INLINE PTA_uchar Texture::
01452 modify_ram_mipmap_image(int n) {
01453   MutexHolder holder(_lock);
01454   ++_image_modified;
01455   return do_modify_ram_mipmap_image(n);
01456 }
01457 
01458 ////////////////////////////////////////////////////////////////////
01459 //     Function: Texture::make_ram_mipmap_image
01460 //       Access: Published
01461 //  Description: Discards the current system-RAM image for the
01462 //               nth mipmap level, if any, and allocates a new buffer
01463 //               of the appropriate size.  Returns the new buffer.
01464 //
01465 //               This does *not* affect keep_ram_image.
01466 ////////////////////////////////////////////////////////////////////
01467 INLINE PTA_uchar Texture::
01468 make_ram_mipmap_image(int n) {
01469   MutexHolder holder(_lock);
01470   ++_image_modified;
01471   return do_make_ram_mipmap_image(n);
01472 }
01473 
01474 ////////////////////////////////////////////////////////////////////
01475 //     Function: Texture::set_ram_mipmap_image
01476 //       Access: Published
01477 //  Description: Replaces the current system-RAM image for the
01478 //               indicated mipmap level with the new data.  If
01479 //               compression is not CM_off, it indicates that the new
01480 //               data is already pre-compressed in the indicated
01481 //               format.
01482 //
01483 //               This does *not* affect keep_ram_image.
01484 ////////////////////////////////////////////////////////////////////
01485 INLINE void Texture::
01486 set_ram_mipmap_image(int n, CPTA_uchar image, size_t page_size) {
01487   MutexHolder holder(_lock);
01488   do_set_ram_mipmap_image(n, image, page_size);
01489 }
01490 
01491 ////////////////////////////////////////////////////////////////////
01492 //     Function: Texture::clear_ram_mipmap_images
01493 //       Access: Published
01494 //  Description: Discards the current system-RAM image for all
01495 //               mipmap levels, except level 0 (the base image).
01496 ////////////////////////////////////////////////////////////////////
01497 INLINE void Texture::
01498 clear_ram_mipmap_images() {
01499   MutexHolder holder(_lock);
01500   ++_image_modified;
01501   do_clear_ram_mipmap_images();
01502 }
01503 
01504 ////////////////////////////////////////////////////////////////////
01505 //     Function: Texture::generate_ram_mipmap_images
01506 //       Access: Published
01507 //  Description: Automatically fills in the n mipmap levels of the
01508 //               Texture, based on the texture's source image.  This
01509 //               requires the texture's uncompressed ram image to be
01510 //               available in system memory.  If it is not already, it
01511 //               will be fetched if possible.
01512 //
01513 //               This call is not normally necessary, since the mipmap
01514 //               levels will be generated automatically if needed.
01515 //               But there may be certain cases in which you would
01516 //               like to call this explicitly.
01517 ////////////////////////////////////////////////////////////////////
01518 INLINE void Texture::
01519 generate_ram_mipmap_images() {
01520   MutexHolder holder(_lock);
01521   ++_image_modified;
01522   do_generate_ram_mipmap_images();
01523 }
01524 
01525 ////////////////////////////////////////////////////////////////////
01526 //     Function: Texture::get_simple_x_size
01527 //       Access: Published
01528 //  Description: Returns the width of the "simple" image in texels.
01529 ////////////////////////////////////////////////////////////////////
01530 INLINE int Texture::
01531 get_simple_x_size() const {
01532   return _simple_x_size;
01533 }
01534 
01535 ////////////////////////////////////////////////////////////////////
01536 //     Function: Texture::get_simple_y_size
01537 //       Access: Published
01538 //  Description: Returns the height of the "simple" image in texels.
01539 ////////////////////////////////////////////////////////////////////
01540 INLINE int Texture::
01541 get_simple_y_size() const {
01542   return _simple_y_size;
01543 }
01544 
01545 ////////////////////////////////////////////////////////////////////
01546 //     Function: Texture::has_simple_ram_image
01547 //       Access: Published, Virtual
01548 //  Description: Returns true if the Texture has a "simple" image
01549 //               available in main RAM.
01550 ////////////////////////////////////////////////////////////////////
01551 INLINE bool Texture::
01552 has_simple_ram_image() const {
01553   MutexHolder holder(_lock);
01554   return !_simple_ram_image._image.empty();
01555 }
01556 
01557 ////////////////////////////////////////////////////////////////////
01558 //     Function: Texture::get_simple_ram_image_size
01559 //       Access: Published
01560 //  Description: Returns the number of bytes used by the "simple"
01561 //               image, or 0 if there is no simple image.
01562 ////////////////////////////////////////////////////////////////////
01563 INLINE size_t Texture::
01564 get_simple_ram_image_size() const {
01565   MutexHolder holder(_lock);
01566   return _simple_ram_image._image.size();
01567 }
01568 
01569 ////////////////////////////////////////////////////////////////////
01570 //     Function: Texture::get_simple_ram_image
01571 //       Access: Published
01572 //  Description: Returns the image data associated with the "simple"
01573 //               texture image.  This is provided for some textures as
01574 //               an option to display while the main texture image is
01575 //               being loaded from disk.
01576 //
01577 //               Unlike get_ram_image(), this function will always
01578 //               return immediately.  Either the simple image is
01579 //               available, or it is not.
01580 //
01581 //               The "simple" image is always 4 components, 1 byte
01582 //               each, regardless of the parameters of the full
01583 //               texture.  The simple image is only supported for
01584 //               ordinary 2-d textures.
01585 ////////////////////////////////////////////////////////////////////
01586 INLINE CPTA_uchar Texture::
01587 get_simple_ram_image() const {
01588   MutexHolder holder(_lock);
01589   return _simple_ram_image._image;
01590 }
01591 
01592 ////////////////////////////////////////////////////////////////////
01593 //     Function: Texture::set_simple_ram_image
01594 //       Access: Published
01595 //  Description: Replaces the internal "simple" texture image.  This
01596 //               can be used as an option to display while the main
01597 //               texture image is being loaded from disk.  It is
01598 //               normally a very small image, 16x16 or smaller (and
01599 //               maybe even 1x1), that is designed to give just enough
01600 //               sense of color to serve as a placeholder until the
01601 //               full texture is available.
01602 //
01603 //               The "simple" image is always 4 components, 1 byte
01604 //               each, regardless of the parameters of the full
01605 //               texture.  The simple image is only supported for
01606 //               ordinary 2-d textures.
01607 //
01608 //               Also see generate_simple_ram_image(),
01609 //               modify_simple_ram_image(), and
01610 //               new_simple_ram_image().
01611 ////////////////////////////////////////////////////////////////////
01612 INLINE void Texture::
01613 set_simple_ram_image(CPTA_uchar image, int x_size, int y_size) {
01614   MutexHolder holder(_lock);
01615   do_set_simple_ram_image(image, x_size, y_size);
01616 }
01617 
01618 ////////////////////////////////////////////////////////////////////
01619 //     Function: Texture::clear_simple_ram_image
01620 //       Access: Published
01621 //  Description: Discards the current "simple" image.
01622 ////////////////////////////////////////////////////////////////////
01623 INLINE void Texture::
01624 clear_simple_ram_image() {
01625   MutexHolder holder(_lock);
01626   do_clear_simple_ram_image();
01627 }
01628 
01629 ////////////////////////////////////////////////////////////////////
01630 //     Function: Texture::get_properties_modified
01631 //       Access: Published
01632 //  Description: Returns a sequence number which is guaranteed to
01633 //               change at least every time the texture properties
01634 //               (unrelated to the image) are modified.
01635 ////////////////////////////////////////////////////////////////////
01636 INLINE UpdateSeq Texture::
01637 get_properties_modified() const {
01638   return _properties_modified;
01639 }
01640 
01641 ////////////////////////////////////////////////////////////////////
01642 //     Function: Texture::get_image_modified
01643 //       Access: Published
01644 //  Description: Returns a sequence number which is guaranteed to
01645 //               change at least every time the texture image data
01646 //               (including mipmap levels) are modified.
01647 ////////////////////////////////////////////////////////////////////
01648 INLINE UpdateSeq Texture::
01649 get_image_modified() const {
01650   return _image_modified;
01651 }
01652 
01653 ////////////////////////////////////////////////////////////////////
01654 //     Function: Texture::get_simple_image_modified
01655 //       Access: Published
01656 //  Description: Returns a sequence number which is guaranteed to
01657 //               change at least every time the texture's "simple"
01658 //               image data is modified.
01659 ////////////////////////////////////////////////////////////////////
01660 INLINE UpdateSeq Texture::
01661 get_simple_image_modified() const {
01662   return _simple_image_modified;
01663 }
01664 
01665 ////////////////////////////////////////////////////////////////////
01666 //     Function: Texture::set_filename
01667 //       Access: Published
01668 //  Description: Sets the name of the file that contains the image's
01669 //               contents.  Normally, this is set automatically when
01670 //               the image is loaded, for instance via
01671 //               Texture::read().
01672 //
01673 //               The Texture's get_name() function used to return
01674 //               the filename, but now returns just the basename
01675 //               (without the extension), which is a more useful name
01676 //               for identifying an image in show code.
01677 ////////////////////////////////////////////////////////////////////
01678 INLINE void Texture::
01679 set_filename(const Filename &filename) {
01680   MutexHolder holder(_lock);
01681   _filename = filename;
01682 }
01683 
01684 ////////////////////////////////////////////////////////////////////
01685 //     Function: Texture::clear_filename
01686 //       Access: Published
01687 //  Description: Removes the alpha filename, if it was previously set.
01688 //               See set_filename().
01689 ////////////////////////////////////////////////////////////////////
01690 INLINE void Texture::
01691 clear_filename() {
01692   MutexHolder holder(_lock);
01693   _filename = Filename();
01694 }
01695 
01696 ////////////////////////////////////////////////////////////////////
01697 //     Function: Texture::set_alpha_filename
01698 //       Access: Published
01699 //  Description: Sets the name of the file that contains the image's
01700 //               alpha channel contents.  Normally, this is set
01701 //               automatically when the image is loaded, for instance
01702 //               via Texture::read().
01703 //
01704 //               The Texture's get_filename() function returns the
01705 //               name of the image file that was loaded into the
01706 //               buffer.  In the case where a texture specified two
01707 //               separate files to load, a 1- or 3-channel color image
01708 //               and a 1-channel alpha image, this Filename is update
01709 //               to contain the name of the image file that was loaded
01710 //               into the buffer's alpha channel.
01711 ////////////////////////////////////////////////////////////////////
01712 INLINE void Texture::
01713 set_alpha_filename(const Filename &alpha_filename) {
01714   MutexHolder holder(_lock);
01715   _alpha_filename = alpha_filename;
01716 }
01717 
01718 ////////////////////////////////////////////////////////////////////
01719 //     Function: Texture::clear_alpha_filename
01720 //       Access: Published
01721 //  Description: Removes the alpha filename, if it was previously set.
01722 //               See set_alpha_filename().
01723 ////////////////////////////////////////////////////////////////////
01724 INLINE void Texture::
01725 clear_alpha_filename() {
01726   MutexHolder holder(_lock);
01727   _alpha_filename = Filename();
01728 }
01729 
01730 ////////////////////////////////////////////////////////////////////
01731 //     Function: Texture::set_fullpath
01732 //       Access: Published
01733 //  Description: Sets the full pathname to the file that contains the
01734 //               image's contents, as found along the search path.
01735 //               Normally, this is set automatically when the image is
01736 //               loaded, for instance via Texture::read().
01737 ////////////////////////////////////////////////////////////////////
01738 INLINE void Texture::
01739 set_fullpath(const Filename &fullpath) {
01740   MutexHolder holder(_lock);
01741   _fullpath = fullpath;
01742 }
01743 
01744 ////////////////////////////////////////////////////////////////////
01745 //     Function: Texture::clear_fullpath
01746 //       Access: Published
01747 //  Description: Removes the alpha fullpath, if it was previously set.
01748 //               See set_fullpath().
01749 ////////////////////////////////////////////////////////////////////
01750 INLINE void Texture::
01751 clear_fullpath() {
01752   MutexHolder holder(_lock);
01753   _fullpath = Filename();
01754 }
01755 
01756 ////////////////////////////////////////////////////////////////////
01757 //     Function: Texture::set_alpha_fullpath
01758 //       Access: Published
01759 //  Description: Sets the full pathname to the file that contains the
01760 //               image's alpha channel contents, as found along the
01761 //               search path.  Normally, this is set automatically
01762 //               when the image is loaded, for instance via
01763 //               Texture::read().
01764 ////////////////////////////////////////////////////////////////////
01765 INLINE void Texture::
01766 set_alpha_fullpath(const Filename &alpha_fullpath) {
01767   MutexHolder holder(_lock);
01768   _alpha_fullpath = alpha_fullpath;
01769 }
01770 
01771 ////////////////////////////////////////////////////////////////////
01772 //     Function: Texture::clear_alpha_fullpath
01773 //       Access: Published
01774 //  Description: Removes the alpha fullpath, if it was previously set.
01775 //               See set_alpha_fullpath().
01776 ////////////////////////////////////////////////////////////////////
01777 INLINE void Texture::
01778 clear_alpha_fullpath() {
01779   MutexHolder holder(_lock);
01780   _alpha_fullpath = Filename();
01781 }
01782 
01783 ////////////////////////////////////////////////////////////////////
01784 //     Function: Texture::set_x_size
01785 //       Access: Published
01786 //  Description: Changes the x size indicated for the texture.  This
01787 //               also implicitly unloads the texture if it has already
01788 //               been loaded.
01789 ////////////////////////////////////////////////////////////////////
01790 INLINE void Texture::
01791 set_x_size(int x_size) {
01792   MutexHolder holder(_lock);
01793   do_set_x_size(x_size);
01794 }
01795 
01796 ////////////////////////////////////////////////////////////////////
01797 //     Function: Texture::set_y_size
01798 //       Access: Published
01799 //  Description: Changes the y size indicated for the texture.  This
01800 //               also implicitly unloads the texture if it has already
01801 //               been loaded.
01802 ////////////////////////////////////////////////////////////////////
01803 INLINE void Texture::
01804 set_y_size(int y_size) {
01805   MutexHolder holder(_lock);
01806   do_set_y_size(y_size);
01807 }
01808 
01809 ////////////////////////////////////////////////////////////////////
01810 //     Function: Texture::set_z_size
01811 //       Access: Published
01812 //  Description: Changes the z size indicated for the texture.  This
01813 //               also implicitly unloads the texture if it has already
01814 //               been loaded.
01815 ////////////////////////////////////////////////////////////////////
01816 INLINE void Texture::
01817 set_z_size(int z_size) {
01818   MutexHolder holder(_lock);
01819   do_set_z_size(z_size);
01820 }
01821 
01822 ////////////////////////////////////////////////////////////////////
01823 //     Function: Texture::set_format
01824 //       Access: Published
01825 //  Description: Changes the format value for the texture components.
01826 //               This implicitly sets num_components as well.
01827 ////////////////////////////////////////////////////////////////////
01828 INLINE void Texture::
01829 set_format(Texture::Format format) {
01830   MutexHolder holder(_lock);
01831   do_set_format(format);
01832 }
01833 
01834 ////////////////////////////////////////////////////////////////////
01835 //     Function: Texture::set_component_type
01836 //       Access: Published
01837 //  Description: Changes the data value for the texture components.
01838 //               This implicitly sets component_width as well.
01839 ////////////////////////////////////////////////////////////////////
01840 INLINE void Texture::
01841 set_component_type(Texture::ComponentType component_type) {
01842   MutexHolder holder(_lock);
01843   do_set_component_type(component_type);
01844 }
01845 
01846 ////////////////////////////////////////////////////////////////////
01847 //     Function: Texture::set_loaded_from_image
01848 //       Access: Published
01849 //  Description: Sets the flag that indicates the texture has been
01850 //               loaded from a disk file or PNMImage.  You should also
01851 //               ensure the filename has been set correctly.  When
01852 //               this flag is true, the texture may be automatically
01853 //               reloaded when its ram image needs to be replaced.
01854 ////////////////////////////////////////////////////////////////////
01855 INLINE void Texture::
01856 set_loaded_from_image() {
01857   _loaded_from_image = true;
01858 }
01859 
01860 ////////////////////////////////////////////////////////////////////
01861 //     Function: Texture::get_loaded_from_image
01862 //       Access: Published
01863 //  Description: Returns the flag that indicates the texture has been
01864 //               loaded from a disk file or PNMImage.  See
01865 //               set_loaded_from_image().
01866 ////////////////////////////////////////////////////////////////////
01867 INLINE bool Texture::
01868 get_loaded_from_image() const {
01869   return _loaded_from_image;
01870 }
01871 
01872 ////////////////////////////////////////////////////////////////////
01873 //     Function: Texture::set_loaded_from_txo
01874 //       Access: Published
01875 //  Description: Sets the flag that indicates the texture has been
01876 //               loaded from a txo file.  You probably shouldn't be
01877 //               setting this directly; it is set automatically when a
01878 //               Texture is loaded.
01879 ////////////////////////////////////////////////////////////////////
01880 INLINE void Texture::
01881 set_loaded_from_txo() {
01882   _loaded_from_txo = true;
01883 }
01884 
01885 ////////////////////////////////////////////////////////////////////
01886 //     Function: Texture::get_loaded_from_txo
01887 //       Access: Published
01888 //  Description: Returns the flag that indicates the texture has been
01889 //               loaded from a txo file.
01890 ////////////////////////////////////////////////////////////////////
01891 INLINE bool Texture::
01892 get_loaded_from_txo() const {
01893   return _loaded_from_txo;
01894 }
01895 
01896 ////////////////////////////////////////////////////////////////////
01897 //     Function: Texture::get_match_framebuffer_format
01898 //       Access: Public
01899 //  Description: Returns true if the special flag was set that
01900 //               indicates to the GSG that the Texture's format should
01901 //               be chosen to exactly match the framebuffer's format,
01902 //               presumably because the application intends to copy
01903 //               image data from the framebuffer into the Texture (or
01904 //               vice-versa).
01905 ////////////////////////////////////////////////////////////////////
01906 INLINE bool Texture::
01907 get_match_framebuffer_format() const {
01908   return _match_framebuffer_format;
01909 }
01910 
01911 ////////////////////////////////////////////////////////////////////
01912 //     Function: Texture::set_match_framebuffer_format
01913 //       Access: Public
01914 //  Description: Sets the special flag that, if true, indicates to the
01915 //               GSG that the Texture's format should be chosen to
01916 //               exactly match the framebuffer's format, presumably
01917 //               because the application intends to copy image data
01918 //               from the framebuffer into the Texture (or
01919 //               vice-versa).
01920 //
01921 //               This sets only the graphics card's idea of the
01922 //               texture format; it is not related to the
01923 //               system-memory format.
01924 ////////////////////////////////////////////////////////////////////
01925 INLINE void Texture::
01926 set_match_framebuffer_format(bool flag) {
01927   _match_framebuffer_format = flag;
01928 }
01929 
01930 ////////////////////////////////////////////////////////////////////
01931 //     Function: Texture::get_post_load_store_cache
01932 //       Access: Public
01933 //  Description: Returns the setting of the post_load_store_cache
01934 //               flag.  See set_post_load_store_cache().
01935 ////////////////////////////////////////////////////////////////////
01936 INLINE bool Texture::
01937 get_post_load_store_cache() const {
01938   return _post_load_store_cache;
01939 }
01940 
01941 ////////////////////////////////////////////////////////////////////
01942 //     Function: Texture::set_post_load_store_cache
01943 //       Access: Public
01944 //  Description: Sets the post_load_store_cache flag.  When this is
01945 //               set, the next time the texture is loaded on a GSG, it
01946 //               will automatically extract its RAM image from the GSG
01947 //               and save it to the global BamCache.
01948 //
01949 //               This is used to store compressed RAM images in the
01950 //               BamCache.  This flag should not be set explicitly; it
01951 //               is set automatically by the TexturePool when
01952 //               model-cache-compressed-textures is set true.
01953 ////////////////////////////////////////////////////////////////////
01954 INLINE void Texture::
01955 set_post_load_store_cache(bool flag) {
01956   _post_load_store_cache = flag;
01957 }
01958 
01959 ////////////////////////////////////////////////////////////////////
01960 //     Function: Texture::do_get_ram_image_size
01961 //       Access: Protected
01962 //  Description: 
01963 ////////////////////////////////////////////////////////////////////
01964 INLINE size_t Texture::
01965 do_get_ram_image_size() const {
01966   if (_ram_images.empty()) {
01967     return 0;
01968   }
01969   return _ram_images[0]._image.size();
01970 }
01971 
01972 ////////////////////////////////////////////////////////////////////
01973 //     Function: Texture::do_has_ram_mipmap_image
01974 //       Access: Protected
01975 //  Description: 
01976 ////////////////////////////////////////////////////////////////////
01977 INLINE bool Texture::
01978 do_has_ram_mipmap_image(int n) const {
01979   return (n >= 0 && n < (int)_ram_images.size() && !_ram_images[n]._image.empty());
01980 }
01981 
01982 ////////////////////////////////////////////////////////////////////
01983 //     Function: Texture::do_get_expected_ram_image_size
01984 //       Access: Protected
01985 //  Description: 
01986 ////////////////////////////////////////////////////////////////////
01987 INLINE size_t Texture::
01988 do_get_expected_ram_image_size() const {
01989   return do_get_expected_ram_page_size() * (size_t)_z_size;
01990 }
01991 
01992 ////////////////////////////////////////////////////////////////////
01993 //     Function: Texture::do_get_expected_ram_page_size
01994 //       Access: Protected
01995 //  Description: 
01996 ////////////////////////////////////////////////////////////////////
01997 INLINE size_t Texture::
01998 do_get_expected_ram_page_size() const {
01999   return (size_t)(_x_size * _y_size * _num_components * _component_width);
02000 }
02001 
02002 ////////////////////////////////////////////////////////////////////
02003 //     Function: Texture::do_get_expected_ram_mipmap_image_size
02004 //       Access: Protected
02005 //  Description: 
02006 ////////////////////////////////////////////////////////////////////
02007 INLINE size_t Texture::
02008 do_get_expected_ram_mipmap_image_size(int n) const {
02009   return do_get_expected_ram_mipmap_page_size(n) * (size_t)do_get_expected_mipmap_z_size(n);
02010 }
02011 
02012 ////////////////////////////////////////////////////////////////////
02013 //     Function: Texture::do_get_expected_ram_mipmap_page_size
02014 //       Access: Protected
02015 //  Description: 
02016 ////////////////////////////////////////////////////////////////////
02017 INLINE size_t Texture::
02018 do_get_expected_ram_mipmap_page_size(int n) const {
02019   return (size_t)(do_get_expected_mipmap_x_size(n) * do_get_expected_mipmap_y_size(n) * _num_components * _component_width);
02020 }
02021 
02022 ////////////////////////////////////////////////////////////////////
02023 //     Function: Texture::do_clear_ram_image
02024 //       Access: Protected
02025 //  Description: 
02026 ////////////////////////////////////////////////////////////////////
02027 INLINE void Texture::
02028 do_clear_ram_image() {
02029   _ram_image_compression = CM_off;
02030   _ram_images.clear();
02031 }
02032 
02033 ////////////////////////////////////////////////////////////////////
02034 //     Function: Texture::store_unscaled_byte
02035 //       Access: Private, Static
02036 //  Description: This is used by load() to store the next consecutive
02037 //               component value into the indicated element of the
02038 //               array, which is taken to be an array of unsigned
02039 //               bytes.  The value is assumed to be in the range
02040 //               0-255.
02041 ////////////////////////////////////////////////////////////////////
02042 INLINE void Texture::
02043 store_unscaled_byte(unsigned char *&p, int value) {
02044   (*p++) = (uchar)value;
02045 }
02046 
02047 ////////////////////////////////////////////////////////////////////
02048 //     Function: Texture::store_unscaled_short
02049 //       Access: Private, Static
02050 //  Description: This is used by load() to store the next consecutive
02051 //               component value into the indicated element of the
02052 //               array, which is taken to be an array of unsigned
02053 //               shorts.  The value is assumed to be in the range
02054 //               0-65535.
02055 ////////////////////////////////////////////////////////////////////
02056 INLINE void Texture::
02057 store_unscaled_short(unsigned char *&p, int value) {
02058   union {
02059     ushort us;
02060     uchar uc[2];
02061   } v;
02062   v.us = (ushort)value;
02063   (*p++) = v.uc[0];
02064   (*p++) = v.uc[1];
02065 }
02066 
02067 ////////////////////////////////////////////////////////////////////
02068 //     Function: Texture::store_scaled_byte
02069 //       Access: Private, Static
02070 //  Description: This is used by load() to store the next consecutive
02071 //               component value into the indicated element of the
02072 //               array, which is taken to be an array of unsigned
02073 //               bytes.  The value will be scaled by the indicated
02074 //               factor before storing it.
02075 ////////////////////////////////////////////////////////////////////
02076 INLINE void Texture::
02077 store_scaled_byte(unsigned char *&p, int value, double scale) {
02078   store_unscaled_byte(p, (int)(value * scale));
02079 }
02080 
02081 ////////////////////////////////////////////////////////////////////
02082 //     Function: Texture::store_scaled_short
02083 //       Access: Private, Static
02084 //  Description: This is used by load() to store the next consecutive
02085 //               component value into the indicated element of the
02086 //               array, which is taken to be an array of unsigned
02087 //               shorts.  The value will be scaled by the indicated
02088 //               factor before storing it.
02089 ////////////////////////////////////////////////////////////////////
02090 INLINE void Texture::
02091 store_scaled_short(unsigned char *&p, int value, double scale) {
02092   store_unscaled_short(p, (int)(value * scale));
02093 }
02094 
02095 ////////////////////////////////////////////////////////////////////
02096 //     Function: Texture::get_unsigned_byte
02097 //       Access: Private, Static
02098 //  Description: This is used by store() to retrieve the next
02099 //               consecutive component value from the indicated
02100 //               element of the array, which is taken to be an array
02101 //               of unsigned bytes.
02102 ////////////////////////////////////////////////////////////////////
02103 INLINE double Texture::
02104 get_unsigned_byte(const unsigned char *&p) {
02105   return (double)(*p++) / 255.0;
02106 }
02107 
02108 ////////////////////////////////////////////////////////////////////
02109 //     Function: Texture::get_unsigned_short
02110 //       Access: Private, Static
02111 //  Description: This is used by store() to retrieve the next
02112 //               consecutive component value from the indicated
02113 //               element of the array, which is taken to be an array
02114 //               of unsigned shorts.
02115 ////////////////////////////////////////////////////////////////////
02116 INLINE double Texture::
02117 get_unsigned_short(const unsigned char *&p) {
02118   union {
02119     ushort us;
02120     uchar uc[2];
02121   } v;
02122   v.uc[0] = (*p++);
02123   v.uc[1] = (*p++);
02124   return (double)v.us / 65535.0;
02125 }
02126 
02127 ////////////////////////////////////////////////////////////////////
02128 //     Function: Texture::is_txo_filename
02129 //       Access: Private, Static
02130 //  Description: Returns true if the indicated filename ends in .txo
02131 //               or .txo.pz, false otherwise.
02132 ////////////////////////////////////////////////////////////////////
02133 INLINE bool Texture::
02134 is_txo_filename(const Filename &fullpath) {
02135   string extension = fullpath.get_extension();
02136 #ifdef HAVE_ZLIB
02137   if (extension == "pz") {
02138     extension = Filename(fullpath.get_basename_wo_extension()).get_extension();
02139   }
02140 #endif  // HAVE_ZLIB
02141   return (extension == "txo");
02142 }
02143 
02144 ////////////////////////////////////////////////////////////////////
02145 //     Function: Texture::is_dds_filename
02146 //       Access: Private, Static
02147 //  Description: Returns true if the indicated filename ends in .dds
02148 //               or .dds.pz, false otherwise.
02149 ////////////////////////////////////////////////////////////////////
02150 INLINE bool Texture::
02151 is_dds_filename(const Filename &fullpath) {
02152   string extension = fullpath.get_extension();
02153 #ifdef HAVE_ZLIB
02154   if (extension == "pz") {
02155     extension = Filename(fullpath.get_basename_wo_extension()).get_extension();
02156   }
02157 #endif  // HAVE_ZLIB
02158   return (downcase(extension) == "dds");
02159 }
02160 
02161 ////////////////////////////////////////////////////////////////////
02162 //     Function: Texture::set_textures_power_2
02163 //       Access: Published, Static
02164 //  Description: Set this flag to ATS_none, ATS_up, or ATS_down
02165 //               to control the scaling of textures.
02166 ////////////////////////////////////////////////////////////////////
02167 INLINE void Texture::
02168 set_textures_power_2(AutoTextureScale scale) {
02169   _textures_power_2 = scale;
02170 }
02171 
02172 ////////////////////////////////////////////////////////////////////
02173 //     Function: Texture::get_textures_power_2
02174 //       Access: Published, Static
02175 //  Description: This flag returns ATS_none, ATS_up, or ATS_down
02176 //               and controls the scaling of textures.  It is
02177 //               initialized from the config variable of the same
02178 //               name, but it can be subsequently adjusted.
02179 ////////////////////////////////////////////////////////////////////
02180 INLINE AutoTextureScale Texture::
02181 get_textures_power_2() {
02182   if (_textures_power_2 == ATS_UNSPECIFIED) {
02183     return textures_power_2;
02184   } else {
02185     return _textures_power_2;
02186   }
02187 }
02188 
02189 ////////////////////////////////////////////////////////////////////
02190 //     Function: Texture::have_textures_power_2
02191 //       Access: Published, Static
02192 //  Description: If true, then get_textures_power_2 has been
02193 //               set using set_textures_power_2.
02194 //               If false, then get_textures_power_2 simply
02195 //               returns the config variable of the same name.
02196 ////////////////////////////////////////////////////////////////////
02197 INLINE bool Texture::
02198 have_textures_power_2() {
02199   return (_textures_power_2 != ATS_UNSPECIFIED);
02200 }
02201 
02202 ////////////////////////////////////////////////////////////////////
02203 //     Function: Texture::RamImage::Constructor
02204 //       Access: Public
02205 //  Description: 
02206 ////////////////////////////////////////////////////////////////////
02207 INLINE Texture::RamImage::
02208 RamImage() :
02209   _page_size(0),
02210   _pointer_image(NULL)
02211 {
02212 }
 All Classes Functions Variables Enumerations