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