Panda3D
texture.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file texture.I
10  * @author drose
11  * @date 1999-02-05
12  * @author fperazzi, PandaSE
13  * @date 2010-04-29
14  */
15 
16 /**
17  * Returns a new copy of the same Texture. This copy, if applied to geometry,
18  * will be copied into texture as a separate texture from the original, so it
19  * will be duplicated in texture memory (and may be independently modified if
20  * desired).
21  *
22  * If the Texture is a VideoTexture, the resulting duplicate may be animated
23  * independently of the original.
24  */
25 INLINE PT(Texture) Texture::
26 make_copy() const {
27  PT(Texture) tex = make_copy_impl();
28  CDWriter cdata_tex(tex->_cycler, true);
29  cdata_tex->inc_properties_modified();
30  cdata_tex->inc_image_modified();
31  cdata_tex->inc_simple_image_modified();
32  return tex;
33 }
34 
35 /**
36  * Reinitializes the texture to its default, empty state (except for the
37  * name).
38  */
39 INLINE void Texture::
40 clear() {
41  CDWriter cdata(_cycler, true);
42  do_clear(cdata);
43 }
44 
45 /**
46  * Sets the texture to the indicated type and dimensions, presumably in
47  * preparation for calling read() or load(), or set_ram_image() or
48  * modify_ram_image(), or use set_clear_color to let the texture be cleared to
49  * a solid color.
50  */
51 INLINE void Texture::
52 setup_texture(Texture::TextureType texture_type, int x_size, int y_size,
53  int z_size, Texture::ComponentType component_type,
54  Texture::Format format) {
55  CDWriter cdata(_cycler, true);
56  do_setup_texture(cdata, texture_type, x_size, y_size, z_size,
57  component_type, format);
58 }
59 
60 /**
61  * Sets the texture as an empty 1-d texture with no dimensions. Follow up
62  * with read() or load() to fill the texture properties and image data, or use
63  * set_clear_color to let the texture be cleared to a solid color.
64  */
65 INLINE void Texture::
67  setup_1d_texture(0, T_unsigned_byte, F_rgb);
68 }
69 
70 /**
71  * Sets the texture as an empty 1-d texture with the specified dimensions and
72  * properties. Follow up with set_ram_image() or modify_ram_image() to fill
73  * the image data, or use set_clear_color to let the texture be cleared to a
74  * solid color.
75  */
76 INLINE void Texture::
77 setup_1d_texture(int x_size, ComponentType component_type, Format format) {
78  setup_texture(TT_1d_texture, x_size, 1, 1, component_type, format);
79 }
80 
81 /**
82  * Sets the texture as an empty 2-d texture with no dimensions. Follow up
83  * with read() or load() to fill the texture properties and image data, or use
84  * set_clear_color to let the texture be cleared to a solid color.
85  */
86 INLINE void Texture::
88  setup_2d_texture(0, 1, T_unsigned_byte, F_rgb);
89 }
90 
91 /**
92  * Sets the texture as an empty 2-d texture with the specified dimensions and
93  * properties. Follow up with set_ram_image() or modify_ram_image() to fill
94  * the image data, or use set_clear_color to let the texture be cleared to a
95  * solid color.
96  */
97 INLINE void Texture::
98 setup_2d_texture(int x_size, int y_size, ComponentType component_type,
99  Format format) {
100  setup_texture(TT_2d_texture, x_size, y_size, 1, component_type, format);
101 }
102 
103 /**
104  * Sets the texture as an empty 3-d texture with no dimensions (though if you
105  * know the depth ahead of time, it saves a bit of reallocation later). Follow
106  * up with read() or load() to fill the texture properties and image data, or
107  * use set_clear_color to let the texture be cleared to a solid color.
108  */
109 INLINE void Texture::
110 setup_3d_texture(int z_size) {
111  setup_3d_texture(0, 1, z_size, T_unsigned_byte, F_rgb);
112 }
113 
114 /**
115  * Sets the texture as an empty 3-d texture with the specified dimensions and
116  * properties. Follow up with set_ram_image() or modify_ram_image() to fill
117  * the image data.
118  */
119 INLINE void Texture::
120 setup_3d_texture(int x_size, int y_size, int z_size,
121  ComponentType component_type, Format format) {
122  setup_texture(TT_3d_texture, x_size, y_size, z_size, component_type, format);
123 }
124 
125 /**
126  * Sets the texture as an empty 2-d texture array with no dimensions (though
127  * if you know the depth ahead of time, it saves a bit of reallocation later).
128  * Follow up with read() or load() to fill the texture properties and image
129  * data, or use set_clear_color to let the texture be cleared to a solid
130  * color.
131  */
132 INLINE void Texture::
134  setup_2d_texture_array(0, 1, z_size, T_unsigned_byte, F_rgb);
135 }
136 
137 /**
138  * Sets the texture as an empty 2-d texture array with the specified
139  * dimensions and properties. Follow up with set_ram_image() or
140  * modify_ram_image() to fill the image data, or use set_clear_color to let
141  * the texture be cleared to a solid color.
142  */
143 INLINE void Texture::
144 setup_2d_texture_array(int x_size, int y_size, int z_size,
145  ComponentType component_type, Format format) {
146  setup_texture(TT_2d_texture_array, x_size, y_size, z_size, component_type, format);
147 }
148 
149 /**
150  * Sets the texture as an empty cube map texture with no dimensions. Follow
151  * up with read() or load() to fill the texture properties and image data, or
152  * use set_clear_color to let the texture be cleared to a solid color.
153  */
154 INLINE void Texture::
156  setup_cube_map(0, T_unsigned_byte, F_rgb);
157 }
158 
159 /**
160  * Sets the texture as an empty cube map texture with the specified dimensions
161  * and properties. Follow up with set_ram_image() or modify_ram_image() to
162  * fill the image data, or use set_clear_color to let the texture be cleared
163  * to a solid color.
164  *
165  * Note that a cube map should always consist of six square images, so x_size
166  * and y_size will be the same, and z_size is always 6.
167  */
168 INLINE void Texture::
169 setup_cube_map(int size, ComponentType component_type, Format format) {
170  setup_texture(TT_cube_map, size, size, 6, component_type, format);
171 }
172 
173 /**
174  * Sets the texture as cube map array with N cube maps. Note that this number
175  * is not the same as the z_size. Follow up with read() or load() to fill the
176  * texture properties and image data, or use set_clear_color to let the
177  * texture be cleared to a solid color.
178  */
179 INLINE void Texture::
180 setup_cube_map_array(int num_cube_maps) {
181  setup_cube_map_array(0, num_cube_maps, T_unsigned_byte, F_rgb);
182 }
183 
184 /**
185  * Sets the texture as cube map array with N cube maps with the specified
186  * dimensions and format. Follow up with set_ram_image() or
187  * modify_ram_image() to fill the image data, or use set_clear_color to let
188  * the texture be cleared to a solid color.
189  *
190  * The num_cube_maps given here is multiplied by six to become the z_size of
191  * the image.
192  */
193 INLINE void Texture::
194 setup_cube_map_array(int size, int num_cube_maps, ComponentType component_type, Format format) {
195  setup_texture(TT_cube_map_array, size, size, num_cube_maps * 6, component_type, format);
196 }
197 
198 /**
199  * Sets the texture as an empty buffer texture with the specified size and
200  * properties. Follow up with set_ram_image() or modify_ram_image() to fill
201  * the image data, or use set_clear_color to let the texture be cleared to a
202  * solid color.
203  *
204  * Note that a buffer texture's format needs to match the component type.
205  */
206 INLINE void Texture::
207 setup_buffer_texture(int size, ComponentType component_type, Format format,
208  GeomEnums::UsageHint usage) {
209  setup_texture(TT_buffer_texture, size, 1, 1, component_type, format);
210  CDWriter cdata(_cycler);
211  cdata->_usage_hint = usage;
212 }
213 
214 /**
215  * Clears the texture data without changing its format or resolution. The
216  * texture is cleared on both the graphics hardware and from RAM, unlike
217  * clear_ram_image, which only removes the data from RAM.
218  *
219  * If a clear color has been specified using set_clear_color, the texture will
220  * be cleared using a solid color.
221  *
222  * The texture data will be cleared the first time in which the texture is
223  * used after this method is called.
224  */
225 INLINE void Texture::
227  CDWriter cdata(_cycler, true);
228  do_clear_ram_image(cdata);
229  do_clear_simple_ram_image(cdata);
230  cdata->inc_image_modified();
231  cdata->inc_simple_image_modified();
232 }
233 
234 /**
235  * Returns true if a color was previously set using set_clear_color.
236  */
237 INLINE bool Texture::
238 has_clear_color() const {
239  CDReader cdata(_cycler);
240  return cdata->_has_clear_color;
241 }
242 
243 /**
244  * Returns the color that was previously set using set_clear_color.
245  */
246 INLINE LColor Texture::
247 get_clear_color() const {
248  CDReader cdata(_cycler);
249  return cdata->_clear_color;
250 }
251 
252 /**
253  * Sets the color that will be used to fill the texture image in absence of
254  * any image data. It is used when any of the setup_texture functions or
255  * clear_image is called and image data is not provided using read() or
256  * modify_ram_image().
257  *
258  * This does not affect a texture that has already been cleared; call
259  * clear_image to clear it again.
260  */
261 INLINE void Texture::
262 set_clear_color(const LColor &color) {
263  CDWriter cdata(_cycler, true);
264  cdata->_clear_color = color;
265  cdata->_has_clear_color = true;
266 }
267 
268 /**
269  * The opposite of set_clear_color. If the image is cleared after setting
270  * this, its contents may be undefined (or may in fact not be cleared at all).
271  */
272 INLINE void Texture::
273 clear_clear_color() {
274  CDWriter cdata(_cycler, true);
275  cdata->_has_clear_color = true;
276 }
277 
278 /**
279  * Returns the raw image data for a single pixel if it were set to the clear
280  * color.
281  */
282 INLINE vector_uchar Texture::
283 get_clear_data() const {
284  CDReader cdata(_cycler);
285  vector_uchar data(16);
286  data.resize(do_get_clear_data(cdata, &data[0]));
287  return data;
288 }
289 
290 /**
291  * Writes the texture to the named filename.
292  */
293 INLINE bool Texture::
294 write(const Filename &fullpath) {
295  CDWriter cdata(_cycler);
296 
297  // do_write() is non-const, because it might have to reload the ram image.
298  return do_write(cdata, fullpath, 0, 0, false, false);
299 }
300 
301 /**
302  * Writes a single page or mipmap level to a single file, or automatically
303  * writes a series of pages and/or mipmap levels to a numbered series of
304  * files.
305  *
306  * If the filename ends in the extension .txo, this implicitly writes a Panda
307  * texture object (.txo) instead of an image file. In this case, the
308  * remaining parameters are ignored, and only one file is written, which will
309  * contain all of the pages and resident mipmap levels in the texture.
310  *
311  * If write_pages is false, then z indicates the page number to write. 3-D
312  * textures have one page number for each level of depth; cube maps have six
313  * pages number 0 through 5. Other kinds of textures have only one page,
314  * numbered 0. If there are multiple views, the range of z is increased; the
315  * total range is [0, get_num_pages()).
316  *
317  * If write_pages is true, then all pages of the texture will be written. In
318  * this case z is ignored, and the filename should contain a sequence of hash
319  * marks ("#") which will be filled in with the page index number.
320  *
321  * If write_mipmaps is false, then n indicates the mipmap level number to
322  * write. Normally, this is 0, for the base texture image. Normally, the
323  * mipmap levels of a texture are not available in RAM (they are generated
324  * automatically by the graphics card). However, if you have the mipmap levels
325  * available, for instance because you called generate_ram_mipmap_images() to
326  * generate them internally, or you called
327  * GraphicsEngine::extract_texture_data() to retrieve them from the graphics
328  * card, then you may write out each mipmap level with this parameter.
329  *
330  * If write_mipmaps is true, then all mipmap levels of the texture will be
331  * written. In this case n is ignored, and the filename should contain a
332  * sequence of hash marks ("#") which will be filled in with the mipmap level
333  * number.
334  *
335  * If both write_pages and write_mipmaps is true, then all pages and all
336  * mipmap levels will be written. In this case, the filename should contain
337  * two different sequences of hash marks, separated by a character such as a
338  * hyphen, underscore, or dot. The first hash mark sequence will be filled in
339  * with the mipmap level, while the second hash mark sequence will be the page
340  * index.
341  */
342 INLINE bool Texture::
343 write(const Filename &fullpath, int z, int n,
344  bool write_pages, bool write_mipmaps) {
345  CDWriter cdata(_cycler, false);
346  return do_write(cdata, fullpath, z, n, write_pages, write_mipmaps);
347 }
348 
349 /**
350  * Replaces the texture with the indicated image.
351  */
352 INLINE bool Texture::
353 load(const PNMImage &pnmimage, const LoaderOptions &options) {
354  CDWriter cdata(_cycler, true);
355  do_clear(cdata);
356  cdata->inc_properties_modified();
357  cdata->inc_image_modified();
358  if (do_load_one(cdata, pnmimage, get_name(), 0, 0, options)) {
359  bool generate_mipmaps = ((options.get_texture_flags() & LoaderOptions::TF_generate_mipmaps) != 0);
360  consider_auto_process_ram_image(generate_mipmaps || uses_mipmaps(), true);
361  return true;
362  }
363  return false;
364 }
365 
366 /**
367  * Stores the indicated image in the given page and mipmap level. See read().
368  */
369 INLINE bool Texture::
370 load(const PNMImage &pnmimage, int z, int n, const LoaderOptions &options) {
371  CDWriter cdata(_cycler, true);
372  cdata->inc_properties_modified();
373  cdata->inc_image_modified();
374  if (do_load_one(cdata, pnmimage, get_name(), z, n, options)) {
375  return true;
376  }
377  return false;
378 }
379 
380 /**
381  * Replaces the texture with the indicated image.
382  */
383 INLINE bool Texture::
384 load(const PfmFile &pfm, const LoaderOptions &options) {
385  CDWriter cdata(_cycler, true);
386  do_clear(cdata);
387  cdata->inc_properties_modified();
388  cdata->inc_image_modified();
389  if (do_load_one(cdata, pfm, get_name(), 0, 0, options)) {
390  bool generate_mipmaps = ((options.get_texture_flags() & LoaderOptions::TF_generate_mipmaps) != 0);
391  consider_auto_process_ram_image(generate_mipmaps || uses_mipmaps(), true);
392  return true;
393  }
394  return false;
395 }
396 
397 /**
398  * Stores the indicated image in the given page and mipmap level. See read().
399  */
400 INLINE bool Texture::
401 load(const PfmFile &pfm, int z, int n, const LoaderOptions &options) {
402  CDWriter cdata(_cycler, true);
403  cdata->inc_properties_modified();
404  cdata->inc_image_modified();
405  if (do_load_one(cdata, pfm, get_name(), z, n, options)) {
406  return true;
407  }
408  return false;
409 }
410 
411 /**
412  * Stores the indicated image in a region of the texture. The texture
413  * properties remain unchanged. This can be more efficient than updating an
414  * entire texture, but has a few restrictions: for one, you must ensure that
415  * the texture is still in RAM (eg. using set_keep_ram_image) and it may not
416  * be compressed.
417  */
418 INLINE bool Texture::
419 load_sub_image(const PNMImage &image, int x, int y, int z, int n) {
420  CDWriter cdata(_cycler, true);
421  return do_load_sub_image(cdata, image, x, y, z, n);
422 }
423 
424 /**
425  * Saves the texture to the indicated PNMImage, but does not write it to disk.
426  */
427 INLINE bool Texture::
428 store(PNMImage &pnmimage) const {
429  CDWriter cdata(((Texture *)this)->_cycler, false);
430  return ((Texture *)this)->do_store_one(cdata, pnmimage, 0, 0);
431 }
432 
433 /**
434  * Saves the indicated page and mipmap level of the texture to the PNMImage.
435  */
436 INLINE bool Texture::
437 store(PNMImage &pnmimage, int z, int n) const {
438  CDWriter cdata(((Texture *)this)->_cycler, false);
439  return ((Texture *)this)->do_store_one(cdata, pnmimage, z, n);
440 }
441 
442 /**
443  * Saves the texture to the indicated PfmFile, but does not write it to disk.
444  */
445 INLINE bool Texture::
446 store(PfmFile &pfm) const {
447  CDWriter cdata(((Texture *)this)->_cycler, false);
448  return ((Texture *)this)->do_store_one(cdata, pfm, 0, 0);
449 }
450 
451 /**
452  * Saves the indicated page and mipmap level of the texture to the PfmFile.
453  */
454 INLINE bool Texture::
455 store(PfmFile &pfm, int z, int n) const {
456  CDWriter cdata(((Texture *)this)->_cycler, false);
457  return ((Texture *)this)->do_store_one(cdata, pfm, z, n);
458 }
459 
460 /**
461  * Re-reads the Texture from its disk file. Useful when you know the image on
462  * disk has recently changed, and you want to update the Texture image.
463  *
464  * Returns true on success, false on failure (in which case, the Texture may
465  * or may not still be valid).
466  */
467 bool Texture::
469  CDWriter cdata(_cycler, true);
470  return do_reload(cdata);
471 }
472 
473 /**
474  * Returns true if the filename has been set and is available. See
475  * set_filename().
476  */
477 INLINE bool Texture::
478 has_filename() const {
479  CDReader cdata(_cycler);
480  return !cdata->_filename.empty();
481 }
482 
483 /**
484  * Returns the filename that has been set. This is the name of the file as it
485  * was requested. Also see get_fullpath().
486  */
487 INLINE const Filename &Texture::
488 get_filename() const {
489  CDReader cdata(_cycler);
490  return cdata->_filename;
491 }
492 
493 /**
494  * Returns true if the alpha_filename has been set and is available. See
495  * set_alpha_filename().
496  */
497 INLINE bool Texture::
498 has_alpha_filename() const {
499  CDReader cdata(_cycler);
500  return !cdata->_alpha_filename.empty();
501 }
502 
503 /**
504  * Returns the alpha_filename that has been set. If this is set, it
505  * represents the name of the alpha component, which is stored in a separate
506  * file. See also get_filename(), and get_alpha_fullpath().
507  */
508 INLINE const Filename &Texture::
509 get_alpha_filename() const {
510  CDReader cdata(_cycler);
511  return cdata->_alpha_filename;
512 }
513 
514 /**
515  * Returns true if the fullpath has been set and is available. See
516  * set_fullpath().
517  */
518 INLINE bool Texture::
519 has_fullpath() const {
520  CDReader cdata(_cycler);
521  return !cdata->_fullpath.empty();
522 }
523 
524 /**
525  * Returns the fullpath that has been set. This is the full path to the file
526  * as it was found along the texture search path.
527  */
528 INLINE const Filename &Texture::
529 get_fullpath() const {
530  CDReader cdata(_cycler);
531  return cdata->_fullpath;
532 }
533 
534 /**
535  * Returns true if the alpha_fullpath has been set and is available. See
536  * set_alpha_fullpath().
537  */
538 INLINE bool Texture::
539 has_alpha_fullpath() const {
540  CDReader cdata(_cycler);
541  return !cdata->_alpha_fullpath.empty();
542 }
543 
544 /**
545  *
546  * Returns the alpha_fullpath that has been set. This is the full path to the
547  * alpha part of the image file as it was found along the texture search path.
548  */
549 INLINE const Filename &Texture::
550 get_alpha_fullpath() const {
551  CDReader cdata(_cycler);
552  return cdata->_alpha_fullpath;
553 }
554 
555 
556 /**
557  * Returns the width of the texture image in texels.
558  */
559 INLINE int Texture::
560 get_x_size() const {
561  CDReader cdata(_cycler);
562  return cdata->_x_size;
563 }
564 
565 /**
566  * Returns the height of the texture image in texels. For a 1-d texture, this
567  * will be 1.
568  */
569 INLINE int Texture::
570 get_y_size() const {
571  CDReader cdata(_cycler);
572  return cdata->_y_size;
573 }
574 
575 /**
576  * Returns the depth of the texture image in texels. For a 1-d texture or 2-d
577  * texture, this will be 1. For a cube map texture, this will be 6.
578  */
579 INLINE int Texture::
580 get_z_size() const {
581  CDReader cdata(_cycler);
582  return cdata->_z_size;
583 }
584 
585 /**
586  * Returns the number of "views" in the texture. A view is a completely
587  * separate image stored within the Texture object. Most textures have only
588  * one view, but a stereo texture, for instance, may have two views, a left
589  * and a right image. Other uses for multiple views are not yet defined.
590  *
591  * If this value is greater than one, the additional views are accessed as
592  * additional pages beyond get_z_size().
593  */
594 INLINE int Texture::
595 get_num_views() const {
596  CDReader cdata(_cycler);
597  return cdata->_num_views;
598 }
599 
600 /**
601  * Returns the total number of pages in the texture. Each "page" is a 2-d
602  * texture image within the larger image--a face of a cube map, or a level of
603  * a 3-d texture. Normally, get_num_pages() is the same as get_z_size().
604  * However, in a multiview texture, this returns get_z_size() *
605  * get_num_views().
606  */
607 INLINE int Texture::
608 get_num_pages() const {
609  return get_z_size() * get_num_views();
610 }
611 
612 /**
613  * Returns size of the pad region. See set_pad_size.
614  */
615 INLINE int Texture::
616 get_pad_x_size() const {
617  CDReader cdata(_cycler);
618  return cdata->_pad_x_size;
619 }
620 
621 /**
622  * Returns size of the pad region. See set_pad_size.
623  */
624 INLINE int Texture::
625 get_pad_y_size() const {
626  CDReader cdata(_cycler);
627  return cdata->_pad_y_size;
628 }
629 
630 /**
631  * Returns size of the pad region. See set_pad_size.
632  */
633 INLINE int Texture::
634 get_pad_z_size() const {
635  CDReader cdata(_cycler);
636  return cdata->_pad_z_size;
637 }
638 
639 /**
640  * Returns a scale pair that is suitable for applying to geometry via
641  * NodePath::set_tex_scale(), which will convert texture coordinates on the
642  * geometry from the range 0..1 into the appropriate range to render the video
643  * part of the texture.
644  *
645  * This is necessary only if a padding size has been set via set_pad_size()
646  * (or implicitly via something like "textures-power-2 pad" in the config.prc
647  * file). In this case, this is a convenient way to generate UV's that
648  * reflect the built-in padding size.
649  */
650 INLINE LVecBase2 Texture::
651 get_tex_scale() const {
652  CDReader cdata(_cycler);
653  if (cdata->_pad_x_size == 0 || cdata->_pad_y_size == 0 ||
654  cdata->_x_size == 0 || cdata->_y_size == 0) {
655  LVecBase2(1.0f, 1.0f);
656  }
657  return LVecBase2((PN_stdfloat)(cdata->_x_size - cdata->_pad_x_size) / (PN_stdfloat)cdata->_x_size,
658  (PN_stdfloat)(cdata->_y_size - cdata->_pad_y_size) / (PN_stdfloat)cdata->_y_size);
659 }
660 
661 /**
662  * Sets the size of the pad region.
663  *
664  * Sometimes, when a video card demands power-of-two textures, it is necessary
665  * to create a big texture and then only use a portion of it. The pad region
666  * indicates which portion of the texture is not really in use. All
667  * operations use the texture as a whole, including the pad region, unless
668  * they explicitly state that they use only the non-pad region.
669  *
670  * Changing the texture's size clears the pad region.
671  */
672 INLINE void Texture::
673 set_pad_size(int x, int y, int z) {
674  CDWriter cdata(_cycler, true);
675  do_set_pad_size(cdata, x, y, z);
676 }
677 
678 /**
679  * Returns the X size of the original disk image that this Texture was loaded
680  * from (if it came from a disk file), before any automatic rescaling by
681  * Panda.
682  */
683 INLINE int Texture::
684 get_orig_file_x_size() const {
685  CDReader cdata(_cycler);
686  return cdata->_orig_file_x_size;
687 }
688 
689 /**
690  * Returns the Y size of the original disk image that this Texture was loaded
691  * from (if it came from a disk file), before any automatic rescaling by
692  * Panda.
693  */
694 INLINE int Texture::
695 get_orig_file_y_size() const {
696  CDReader cdata(_cycler);
697  return cdata->_orig_file_y_size;
698 }
699 
700 /**
701  * Returns the Z size of the original disk image that this Texture was loaded
702  * from (if it came from a disk file), before any automatic rescaling by
703  * Panda.
704  */
705 INLINE int Texture::
706 get_orig_file_z_size() const {
707  // At the moment, we perform no automatic adjustment of Z size. So we can
708  // just return the current value, since it would be the same thing.
709  CDReader cdata(_cycler);
710  return cdata->_z_size;
711 }
712 
713 /**
714  * Returns the number of color components for each texel of the texture image.
715  * This is 3 for an rgb texture or 4 for an rgba texture; it may also be 1 or
716  * 2 for a grayscale texture.
717  */
718 INLINE int Texture::
719 get_num_components() const {
720  CDReader cdata(_cycler);
721  return cdata->_num_components;
722 }
723 
724 /**
725  * Returns the number of bytes stored for each color component of a texel.
726  * Typically this is 1, but it may be 2 for 16-bit texels.
727  */
728 INLINE int Texture::
729 get_component_width() const {
730  CDReader cdata(_cycler);
731  return cdata->_component_width;
732 }
733 
734 /**
735  * Returns the overall interpretation of the texture.
736  */
737 INLINE Texture::TextureType Texture::
738 get_texture_type() const {
739  CDReader cdata(_cycler);
740  return cdata->_texture_type;
741 }
742 
743 /**
744  * Returns the format of the texture, which represents both the semantic
745  * meaning of the texels and, to some extent, their storage information.
746  */
747 INLINE Texture::Format Texture::
748 get_format() const {
749  CDReader cdata(_cycler);
750  return cdata->_format;
751 }
752 
753 /**
754  * Returns the numeric interpretation of each component of the texture.
755  */
756 INLINE Texture::ComponentType Texture::
757 get_component_type() const {
758  CDReader cdata(_cycler);
759  return cdata->_component_type;
760 }
761 
762 /**
763  * Returns the usage hint specified for buffer textures, or UH_unspecified for
764  * all other texture types.
765  */
766 INLINE GeomEnums::UsageHint Texture::
767 get_usage_hint() const {
768  CDReader cdata(_cycler);
769  return cdata->_usage_hint;
770 }
771 
772 /**
773  * This setting determines what happens when the texture is sampled with a U
774  * value outside the range 0.0-1.0. The default is WM_repeat, which indicates
775  * that the texture should repeat indefinitely.
776  *
777  * This sets the default sampler state for this texture; it may still be
778  * overridden by a sampler state specified at a higher level.
779  */
780 INLINE void Texture::
781 set_wrap_u(SamplerState::WrapMode wrap) {
782  CDWriter cdata(_cycler, true);
783  do_set_wrap_u(cdata, wrap);
784 }
785 
786 /**
787  * This setting determines what happens when the texture is sampled with a V
788  * value outside the range 0.0-1.0. The default is WM_repeat, which indicates
789  * that the texture should repeat indefinitely.
790  *
791  * This sets the default sampler state for this texture; it may still be
792  * overridden by a sampler state specified at a higher level.
793  */
794 INLINE void Texture::
795 set_wrap_v(SamplerState::WrapMode wrap) {
796  CDWriter cdata(_cycler, true);
797  do_set_wrap_v(cdata, wrap);
798 }
799 
800 /**
801  * The W wrap direction is only used for 3-d textures.
802  *
803  * This sets the default sampler state for this texture; it may still be
804  * overridden by a sampler state specified at a higher level.
805  */
806 INLINE void Texture::
807 set_wrap_w(SamplerState::WrapMode wrap) {
808  CDWriter cdata(_cycler, true);
809  do_set_wrap_w(cdata, wrap);
810 }
811 
812 /**
813  * Sets the filtering method that should be used when viewing the texture from
814  * a distance.
815  *
816  * This sets the default sampler state for this texture; it may still be
817  * overridden by a sampler state specified at a higher level.
818  */
819 INLINE void Texture::
820 set_minfilter(SamplerState::FilterType filter) {
821  CDWriter cdata(_cycler, true);
822  do_set_minfilter(cdata, filter);
823 }
824 
825 /**
826  * Sets the filtering method that should be used when viewing the texture up
827  * close.
828  *
829  * This sets the default sampler state for this texture; it may still be
830  * overridden by a sampler state specified at a higher level.
831  */
832 INLINE void Texture::
833 set_magfilter(SamplerState::FilterType filter) {
834  CDWriter cdata(_cycler, true);
835  do_set_magfilter(cdata, filter);
836 }
837 
838 /**
839  * Specifies the level of anisotropic filtering to apply to the texture. Set
840  * this 0 to indicate the default value, which is specified in the texture-
841  * anisotropic-degree config variable.
842  *
843  * To explicitly disable anisotropic filtering, set this value to 1. To
844  * explicitly enable anisotropic filtering, set it to a value higher than 1;
845  * larger numbers indicate greater degrees of filtering.
846  *
847  * This sets the default sampler state for this texture; it may still be
848  * overridden by a sampler state specified at a higher level.
849  */
850 INLINE void Texture::
851 set_anisotropic_degree(int anisotropic_degree) {
852  CDWriter cdata(_cycler, true);
853  do_set_anisotropic_degree(cdata, anisotropic_degree);
854 }
855 
856 /**
857  * Specifies the solid color of the texture's border. Some OpenGL
858  * implementations use a border for tiling textures; in Panda, it is only used
859  * for specifying the clamp color.
860  *
861  * This sets the default sampler state for this texture; it may still be
862  * overridden by a sampler state specified at a higher level.
863  */
864 INLINE void Texture::
865 set_border_color(const LColor &color) {
866  CDWriter cdata(_cycler, true);
867  do_set_border_color(cdata, color);
868 }
869 
870 /**
871  * Requests that this particular Texture be compressed when it is loaded into
872  * texture memory.
873  *
874  * This refers to the internal compression of the texture image within texture
875  * memory; it is not related to jpeg or png compression, which are disk file
876  * compression formats. The actual disk file that generated this texture may
877  * be stored in a compressed or uncompressed format supported by Panda; it
878  * will be decompressed on load, and then recompressed by the graphics API if
879  * this parameter is not CM_off.
880  *
881  * If the GSG does not support this texture compression mode, the texture will
882  * silently be loaded uncompressed.
883  */
884 INLINE void Texture::
885 set_compression(Texture::CompressionMode compression) {
886  CDWriter cdata(_cycler, true);
887  do_set_compression(cdata, compression);
888 }
889 
890 /**
891  * Sets a flag on the texture that indicates whether the texture is intended
892  * to be used as a direct-render target, by binding a framebuffer to a texture
893  * and rendering directly into the texture.
894  *
895  * This controls some low-level choices made about the texture object itself.
896  * For instance, compressed textures are disallowed when this flag is set
897  * true.
898  *
899  * Normally, a user should not need to set this flag directly; it is set
900  * automatically by the low-level display code when a texture is bound to a
901  * framebuffer.
902  */
903 INLINE void Texture::
904 set_render_to_texture(bool render_to_texture) {
905  CDWriter cdata(_cycler, false);
906  cdata->_render_to_texture = render_to_texture;
907 }
908 
909 /**
910  * This returns the default sampler state for this texture, containing the
911  * wrap and filter properties specified on the texture level; it may still be
912  * overridden by a sampler state specified at a higher level.
913  */
914 INLINE const SamplerState &Texture::
915 get_default_sampler() const {
916  CDReader cdata(_cycler);
917  return cdata->_default_sampler;
918 }
919 
920 /**
921  * This sets the default sampler state for this texture, containing the wrap
922  * and filter properties specified on the texture level; it may still be
923  * overridden by a sampler state specified at a higher level. This
924  * encompasses the settings for get_wrap_u, get_minfilter,
925  * get_anisotropic_degree, etc.
926  *
927  * This makes a copy of the SamplerState object, so future modifications of
928  * the same SamplerState will have no effect on this texture unless you call
929  * set_default_sampler again.
930  */
931 INLINE void Texture::
932 set_default_sampler(const SamplerState &sampler) {
933  CDWriter cdata(_cycler, true);
934  cdata->_default_sampler = sampler;
935  cdata->inc_properties_modified();
936 }
937 
938 /**
939  * Returns the wrap mode of the texture in the U direction.
940  *
941  * This returns the default sampler state for this texture; it may still be
942  * overridden by a sampler state specified at a higher level.
943  */
944 INLINE SamplerState::WrapMode Texture::
945 get_wrap_u() const {
946  CDReader cdata(_cycler);
947  return cdata->_default_sampler.get_wrap_u();
948 }
949 
950 /**
951  * Returns the wrap mode of the texture in the V direction.
952  *
953  * This returns the default sampler state for this texture; it may still be
954  * overridden by a sampler state specified at a higher level.
955  */
956 INLINE SamplerState::WrapMode Texture::
957 get_wrap_v() const {
958  CDReader cdata(_cycler);
959  return cdata->_default_sampler.get_wrap_v();
960 }
961 
962 /**
963  * Returns the wrap mode of the texture in the W direction. This is the depth
964  * direction of 3-d textures.
965  *
966  * This returns the default sampler state for this texture; it may still be
967  * overridden by a sampler state specified at a higher level.
968  */
969 INLINE SamplerState::WrapMode Texture::
970 get_wrap_w() const {
971  CDReader cdata(_cycler);
972  return cdata->_default_sampler.get_wrap_w();
973 }
974 
975 /**
976  * Returns the filter mode of the texture for minification. If this is one of
977  * the mipmap constants, then the texture requires mipmaps. This may return
978  * FT_default; see also get_effective_minfilter().
979  *
980  * This returns the default sampler state for this texture; it may still be
981  * overridden by a sampler state specified at a higher level.
982  */
983 INLINE SamplerState::FilterType Texture::
984 get_minfilter() const {
985  CDReader cdata(_cycler);
986  return cdata->_default_sampler.get_minfilter();
987 }
988 
989 /**
990  * Returns the filter mode of the texture for magnification. The mipmap
991  * constants are invalid here. This may return FT_default; see also
992  * get_effective_minfilter().
993  *
994  * This returns the default sampler state for this texture; it may still be
995  * overridden by a sampler state specified at a higher level.
996  */
997 INLINE SamplerState::FilterType Texture::
998 get_magfilter() const {
999  CDReader cdata(_cycler);
1000  return cdata->_default_sampler.get_magfilter();
1001 }
1002 
1003 /**
1004  * Returns the filter mode of the texture for minification, with special
1005  * treatment for FT_default. This will normally not return FT_default, unless
1006  * there is an error in the config file.
1007  *
1008  * This returns the default sampler state for this texture; it may still be
1009  * overridden by a sampler state specified at a higher level.
1010  */
1011 SamplerState::FilterType Texture::
1012 get_effective_minfilter() const {
1013  CDReader cdata(_cycler);
1014  return cdata->_default_sampler.get_effective_minfilter();
1015 }
1016 
1017 /**
1018  * Returns the filter mode of the texture for magnification, with special
1019  * treatment for FT_default. This will normally not return FT_default, unless
1020  * there is an error in the config file.
1021  *
1022  * This returns the default sampler state for this texture; it may still be
1023  * overridden by a sampler state specified at a higher level.
1024  */
1025 SamplerState::FilterType Texture::
1026 get_effective_magfilter() const {
1027  CDReader cdata(_cycler);
1028  return cdata->_default_sampler.get_effective_magfilter();
1029 }
1030 
1031 /**
1032  * Returns the degree of anisotropic filtering that should be applied to the
1033  * texture. This value may return 0, indicating the default value; see also
1034  * get_effective_anisotropic_degree.
1035  *
1036  * This returns the default sampler state for this texture; it may still be
1037  * overridden by a sampler state specified at a higher level.
1038  */
1039 INLINE int Texture::
1040 get_anisotropic_degree() const {
1041  CDReader cdata(_cycler);
1042  return cdata->_default_sampler.get_anisotropic_degree();
1043 }
1044 
1045 /**
1046  * Returns the degree of anisotropic filtering that should be applied to the
1047  * texture. This value will normally not return 0, unless there is an error
1048  * in the config file.
1049  *
1050  * This returns the default sampler state for this texture; it may still be
1051  * overridden by a sampler state specified at a higher level.
1052  */
1053 INLINE int Texture::
1054 get_effective_anisotropic_degree() const {
1055  CDReader cdata(_cycler);
1056  return cdata->_default_sampler.get_effective_anisotropic_degree();
1057 }
1058 
1059 /**
1060  * Returns the solid color of the texture's border. Some OpenGL
1061  * implementations use a border for tiling textures; in Panda, it is only used
1062  * for specifying the clamp color.
1063  *
1064  * This returns the default sampler state for this texture; it may still be
1065  * overridden by a sampler state specified at a higher level.
1066  */
1067 INLINE LColor Texture::
1068 get_border_color() const {
1069  CDReader cdata(_cycler);
1070  return cdata->_default_sampler.get_border_color();
1071 }
1072 
1073 /**
1074  * Returns the compression mode requested for this particular texture, or
1075  * CM_off if the texture is not to be compressed.
1076  *
1077  * If a value other than CM_off is returned, this is not a guarantee that the
1078  * texture is actually successfully compressed on the GSG. It may be that the
1079  * GSG does not support the requested compression mode, in which case the
1080  * texture may actually be stored uncompressed in texture memory.
1081  */
1082 INLINE Texture::CompressionMode Texture::
1083 get_compression() const {
1084  CDReader cdata(_cycler);
1085  return cdata->_compression;
1086 }
1087 
1088 /**
1089  * Returns true if the texture indicates it wants to be compressed, either
1090  * with CM_on or higher, or CM_default and compressed-textures is true.
1091  *
1092  * If true returned, this is not a guarantee that the texture is actually
1093  * successfully compressed on the GSG. It may be that the GSG does not
1094  * support the requested compression mode, in which case the texture may
1095  * actually be stored uncompressed in texture memory.
1096  */
1097 INLINE bool Texture::
1099  CDReader cdata(_cycler);
1100  return do_has_compression(cdata);
1101 }
1102 
1103 /**
1104  * Returns a flag on the texture that indicates whether the texture is
1105  * intended to be used as a direct-render target, by binding a framebuffer to
1106  * a texture and rendering directly into the texture.
1107  *
1108  * Normally, a user should not need to set this flag directly; it is set
1109  * automatically by the low-level display code when a texture is bound to a
1110  * framebuffer.
1111  */
1112 INLINE bool Texture::
1113 get_render_to_texture() const {
1114  CDReader cdata(_cycler);
1115  return cdata->_render_to_texture;
1116 }
1117 
1118 /**
1119  * Returns true if the minfilter settings on this texture indicate the use of
1120  * mipmapping, false otherwise.
1121  */
1122 INLINE bool Texture::
1123 uses_mipmaps() const {
1125 }
1126 
1127 /**
1128  * Sets a hint to the renderer about the desired performance / quality
1129  * tradeoff for this particular texture. This is most useful for the
1130  * tinydisplay software renderer; for normal, hardware-accelerated renderers,
1131  * this may have little or no effect.
1132  */
1133 INLINE void Texture::
1134 set_quality_level(Texture::QualityLevel quality_level) {
1135  CDWriter cdata(_cycler, true);
1136  do_set_quality_level(cdata, quality_level);
1137 }
1138 
1139 /**
1140  * Returns the current quality_level hint. See set_quality_level(). This
1141  * value may return QL_default; see get_effective_quality_level().
1142  */
1143 INLINE Texture::QualityLevel Texture::
1144 get_quality_level() const {
1145  CDReader cdata(_cycler);
1146  return cdata->_quality_level;
1147 }
1148 
1149 /**
1150  * Returns the current quality_level hint, or the global default quality_level
1151  * if this texture doesn't specify a quality level. This value will not
1152  * normally return QL_default (unless there is an error in the config file)
1153  */
1154 INLINE Texture::QualityLevel Texture::
1155 get_effective_quality_level() const {
1156  CDReader cdata(_cycler);
1157  if (cdata->_quality_level == QL_default) {
1158  return texture_quality_level;
1159  }
1160  return cdata->_quality_level;
1161 }
1162 
1163 /**
1164  * Returns the number of mipmap levels that should be defined for this
1165  * texture, given the texture's size.
1166  *
1167  * Note that this returns a number appropriate for mipmapping, even if the
1168  * texture does not currently have mipmapping enabled.
1169  */
1170 INLINE int Texture::
1171 get_expected_num_mipmap_levels() const {
1172  CDReader cdata(_cycler);
1173  return do_get_expected_num_mipmap_levels(cdata);
1174 }
1175 
1176 /**
1177  * Returns the x_size that the nth mipmap level should have, based on the
1178  * texture's size.
1179  */
1180 INLINE int Texture::
1182  CDReader cdata(_cycler);
1183  return do_get_expected_mipmap_x_size(cdata, n);
1184 }
1185 
1186 /**
1187  * Returns the y_size that the nth mipmap level should have, based on the
1188  * texture's size.
1189  */
1190 INLINE int Texture::
1192  CDReader cdata(_cycler);
1193  return do_get_expected_mipmap_y_size(cdata, n);
1194 }
1195 
1196 /**
1197  * Returns the z_size that the nth mipmap level should have, based on the
1198  * texture's size.
1199  */
1200 INLINE int Texture::
1202  CDReader cdata(_cycler);
1203  return do_get_expected_mipmap_z_size(cdata, n);
1204 }
1205 
1206 /**
1207  * Returns the total number of pages that the nth mipmap level should have,
1208  * based on the texture's size. This is usually the same as
1209  * get_expected_mipmap_z_size(), except for a multiview texture, in which case
1210  * it is get_expected_mipmap_z_size() * get_num_views().
1211  */
1212 INLINE int Texture::
1214  CDReader cdata(_cycler);
1215  return do_get_expected_mipmap_num_pages(cdata, n);
1216 }
1217 
1218 /**
1219  * Returns true if the Texture has its image contents available in main RAM,
1220  * false if it exists only in texture memory or in the prepared GSG context.
1221  *
1222  * Note that this has nothing to do with whether get_ram_image() will fail or
1223  * not. Even if has_ram_image() returns false, get_ram_image() may still
1224  * return a valid RAM image, because get_ram_image() will automatically load
1225  * the texture from disk if necessary. The only thing has_ram_image() tells
1226  * you is whether the texture is available right now without hitting the disk
1227  * first.
1228  *
1229  * Note also that if an application uses only one GSG, it may appear that
1230  * has_ram_image() returns true if the texture has not yet been loaded by the
1231  * GSG, but this correlation is not true in general and should not be depended
1232  * on. Specifically, if an application ever uses multiple GSG's in its
1233  * lifetime (for instance, by opening more than one window, or by closing its
1234  * window and opening another one later), then has_ram_image() may well return
1235  * false on textures that have never been loaded on the current GSG.
1236  */
1237 INLINE bool Texture::
1238 has_ram_image() const {
1239  CDReader cdata(_cycler);
1240  return do_has_ram_image(cdata);
1241 }
1242 
1243 /**
1244  * Returns true if the Texture has its image contents available in main RAM
1245  * and is uncompressed, false otherwise. See has_ram_image().
1246  */
1247 INLINE bool Texture::
1249  CDReader cdata(_cycler);
1250  return do_has_uncompressed_ram_image(cdata);
1251 }
1252 
1253 /**
1254  * Returns true if the texture's image contents are currently available in
1255  * main RAM, or there is reason to believe it can be loaded on demand. That
1256  * is, this function returns a "best guess" as to whether get_ram_image() will
1257  * succeed without actually calling it first.
1258  */
1259 INLINE bool Texture::
1261  CDReader cdata(_cycler);
1262  return (do_has_ram_image(cdata) || !cdata->_fullpath.empty());
1263 }
1264 
1265 /**
1266  * Returns the total number of bytes used by the in-memory image, across all
1267  * pages and views, or 0 if there is no in-memory image.
1268  */
1269 INLINE size_t Texture::
1270 get_ram_image_size() const {
1271  CDReader cdata(_cycler);
1272  return do_get_ram_image_size(cdata);
1273 }
1274 
1275 /**
1276  * Returns the number of bytes used by the in-memory image per view, or 0 if
1277  * there is no in-memory image. Since each view is a stack of z_size pages,
1278  * this is get_z_size() * get_ram_page_size().
1279  */
1280 INLINE size_t Texture::
1281 get_ram_view_size() const {
1282  CDReader cdata(_cycler);
1283  if (cdata->_ram_image_compression == CM_off || cdata->_ram_images.empty()) {
1284  return do_get_expected_ram_view_size(cdata);
1285  } else {
1286  return cdata->_z_size * cdata->_ram_images[0]._page_size;
1287  }
1288 }
1289 
1290 /**
1291  * Returns the number of bytes used by the in-memory image per page, or 0 if
1292  * there is no in-memory image.
1293  *
1294  * For a non-compressed texture, this is the same as
1295  * get_expected_ram_page_size(). For a compressed texture, this may be a
1296  * smaller value. (We do assume that all pages will be the same size on a
1297  * compressed texture).
1298  */
1299 INLINE size_t Texture::
1300 get_ram_page_size() const {
1301  CDReader cdata(_cycler);
1302  if (cdata->_ram_image_compression == CM_off || cdata->_ram_images.empty()) {
1303  return do_get_expected_ram_page_size(cdata);
1304  } else {
1305  return cdata->_ram_images[0]._page_size;
1306  }
1307 }
1308 
1309 /**
1310  * Returns the number of bytes that *ought* to be used by the in-memory image,
1311  * based on the texture parameters.
1312  */
1313 INLINE size_t Texture::
1314 get_expected_ram_image_size() const {
1315  CDReader cdata(_cycler);
1316  return do_get_expected_ram_image_size(cdata);
1317 }
1318 
1319 /**
1320  * Returns the number of bytes that should be used per each Z page of the 3-d
1321  * texture. For a 2-d or 1-d texture, this is the same as
1322  * get_expected_ram_image_size().
1323  */
1324 INLINE size_t Texture::
1325 get_expected_ram_page_size() const {
1326  CDReader cdata(_cycler);
1327  return do_get_expected_ram_page_size(cdata);
1328 }
1329 
1330 /**
1331  * Returns the system-RAM image data associated with the texture. If the
1332  * texture does not currently have an associated RAM image, and the texture
1333  * was generated by loading an image from a disk file (the most common case),
1334  * this forces the reload of the same texture. This can happen if
1335  * keep_texture_ram is configured to false, and we have previously prepared
1336  * this texture with a GSG.
1337  *
1338  * Note that it is not correct to call has_ram_image() first to test whether
1339  * this function will fail. A false return value from has_ram_image()
1340  * indicates only that get_ram_image() may need to reload the texture from
1341  * disk, which it will do automatically. However, you can call
1342  * might_have_ram_image(), which will return true if the ram image exists, or
1343  * there is a reasonable reason to believe it can be loaded.
1344  *
1345  * On the other hand, it is possible that the texture cannot be found on disk
1346  * or is otherwise unavailable. If that happens, this function will return
1347  * NULL. There is no way to predict with 100% accuracy whether get_ram_image()
1348  * will return NULL without calling it first; might_have_ram_image() is the
1349  * closest.
1350  */
1351 INLINE CPTA_uchar Texture::
1353  CDWriter cdata(_cycler, unlocked_ensure_ram_image(true));
1354  return do_get_ram_image(cdata);
1355 }
1356 
1357 /**
1358  * Returns the compression mode in which the ram image is already stored pre-
1359  * compressed. If this is other than CM_off, you cannot rely on the contents
1360  * of the ram image to be anything predicatable (it will not be an array of x
1361  * by y pixels, and it probably won't have the same length as
1362  * get_expected_ram_image_size()).
1363  */
1364 INLINE Texture::CompressionMode Texture::
1365 get_ram_image_compression() const {
1366  CDReader cdata(_cycler);
1367  return cdata->_ram_image_compression;
1368 }
1369 
1370 /**
1371  * Returns a modifiable pointer to the system-RAM image. This assumes the RAM
1372  * image should be uncompressed. If the RAM image has been dumped, or is
1373  * stored compressed, creates a new one.
1374  *
1375  * This does *not* affect keep_ram_image.
1376  */
1377 INLINE PTA_uchar Texture::
1379  CDWriter cdata(_cycler, true);
1380  cdata->inc_image_modified();
1381  return do_modify_ram_image(cdata);
1382 }
1383 
1384 /**
1385  * Returns the system-RAM image associated with the texture, in an
1386  * uncompressed form if at all possible.
1387  *
1388  * If get_ram_image_compression() is CM_off, then the system-RAM image is
1389  * already uncompressed, and this returns the same thing as get_ram_image().
1390  *
1391  * If get_ram_image_compression() is anything else, then the system-RAM image
1392  * is compressed. In this case, the image will be reloaded from the
1393  * *original* file (not from the cache), in the hopes that an uncompressed
1394  * image will be found there.
1395  *
1396  * If an uncompressed image cannot be found, returns NULL.
1397  */
1398 INLINE CPTA_uchar Texture::
1400  CDWriter cdata(_cycler, false);
1401  return do_get_uncompressed_ram_image(cdata);
1402 }
1403 
1404 /**
1405  * Discards the current system-RAM image for the texture, if any, and
1406  * allocates a new buffer of the appropriate size. Returns the new buffer.
1407  *
1408  * This does *not* affect keep_ram_image.
1409  */
1410 INLINE PTA_uchar Texture::
1412  CDWriter cdata(_cycler, true);
1413  cdata->inc_image_modified();
1414  return do_make_ram_image(cdata);
1415 }
1416 
1417 /**
1418  * Replaces the current system-RAM image with the new data. If compression is
1419  * not CM_off, it indicates that the new data is already pre-compressed in the
1420  * indicated format.
1421  *
1422  * This does *not* affect keep_ram_image.
1423  */
1424 INLINE void Texture::
1425 set_ram_image(CPTA_uchar image, Texture::CompressionMode compression,
1426  size_t page_size) {
1427  CDWriter cdata(_cycler, true);
1428  do_set_ram_image(cdata, image, compression, page_size);
1429 }
1430 
1431 /**
1432  * Discards the current system-RAM image.
1433  */
1434 INLINE void Texture::
1436  CDWriter cdata(_cycler, false);
1437  do_clear_ram_image(cdata);
1438 }
1439 
1440 /**
1441  * Sets the flag that indicates whether this Texture is eligible to have its
1442  * main RAM copy of the texture memory dumped when the texture is prepared for
1443  * rendering.
1444  *
1445  * This will be false for most textures, which can reload their images if
1446  * needed by rereading the input file. However, textures that were generated
1447  * dynamically and cannot be easily reloaded will want to set this flag to
1448  * true, so that the texture will always keep its image copy around.
1449  */
1450 INLINE void Texture::
1451 set_keep_ram_image(bool keep_ram_image) {
1452  CDWriter cdata(_cycler, true);
1453  cdata->_keep_ram_image = keep_ram_image;
1454 }
1455 
1456 /**
1457  * Attempts to compress the texture's RAM image internally, to a format
1458  * supported by the indicated GSG. In order for this to work, the squish
1459  * library must have been compiled into Panda.
1460  *
1461  * If compression is CM_on, then an appropriate compression method that is
1462  * supported by the indicated GSG is automatically chosen. If the GSG pointer
1463  * is NULL, any of the standard DXT1/3/5 compression methods will be used,
1464  * regardless of whether it is supported.
1465  *
1466  * If compression is any specific compression method, that method is used
1467  * regardless of whether the GSG supports it.
1468  *
1469  * quality_level determines the speed/quality tradeoff of the compression. If
1470  * it is QL_default, the texture's own quality_level parameter is used.
1471  *
1472  * Returns true if successful, false otherwise.
1473  */
1474 INLINE bool Texture::
1475 compress_ram_image(Texture::CompressionMode compression,
1476  Texture::QualityLevel quality_level,
1478  CDWriter cdata(_cycler, false);
1479  if (do_compress_ram_image(cdata, compression, quality_level, gsg)) {
1480  cdata->inc_image_modified();
1481  return true;
1482  }
1483  return false;
1484 }
1485 
1486 /**
1487  * Attempts to uncompress the texture's RAM image internally. In order for
1488  * this to work, the squish library must have been compiled into Panda, and
1489  * the ram image must be compressed in a format supported by squish.
1490  *
1491  * Returns true if successful, false otherwise.
1492  */
1493 INLINE bool Texture::
1495  CDWriter cdata(_cycler, false);
1496  if (do_uncompress_ram_image(cdata)) {
1497  cdata->inc_image_modified();
1498  return true;
1499  }
1500  return false;
1501 }
1502 
1503 /**
1504  * Returns the maximum number of mipmap level images available in system
1505  * memory. The actual number may be less than this (that is, there might be
1506  * gaps in the sequence); use has_ram_mipmap_image() to verify each level.
1507  *
1508  * Also see get_num_loadable_ram_mipmap_images().
1509  */
1510 INLINE int Texture::
1511 get_num_ram_mipmap_images() const {
1512  CDReader cdata(_cycler);
1513  return cdata->_ram_images.size();
1514 }
1515 
1516 /**
1517  * Returns true if the Texture has the nth mipmap level available in system
1518  * memory, false otherwise. If the texture's minfilter mode requires
1519  * mipmapping (see uses_mipmaps()), and all the texture's mipmap levels are
1520  * not available when the texture is rendered, they will be generated
1521  * automatically.
1522  */
1523 INLINE bool Texture::
1524 has_ram_mipmap_image(int n) const {
1525  CDReader cdata(_cycler);
1526  return do_has_ram_mipmap_image(cdata, n);
1527 }
1528 
1529 /**
1530  * Returns true if all expected mipmap levels have been defined and exist in
1531  * the system RAM, or false if even one mipmap level is missing.
1532  */
1533 INLINE bool Texture::
1535  CDReader cdata(_cycler);
1536  return do_has_all_ram_mipmap_images(cdata);
1537 }
1538 
1539 /**
1540  * Returns the number of bytes used by the in-memory image for mipmap level n,
1541  * or 0 if there is no in-memory image for this mipmap level.
1542  */
1543 INLINE size_t Texture::
1545  CDReader cdata(_cycler);
1546  if (n >= 0 && n < (int)cdata->_ram_images.size()) {
1547  if (cdata->_ram_images[n]._pointer_image == nullptr) {
1548  return cdata->_ram_images[n]._image.size();
1549  } else {
1550  // Calculate it based on the given page size.
1551  return do_get_ram_mipmap_page_size(cdata, n) *
1552  do_get_expected_mipmap_z_size(cdata, n) *
1553  cdata->_num_views;
1554  }
1555  }
1556  return 0;
1557 }
1558 
1559 /**
1560  * Returns the number of bytes used by the in-memory image per view for mipmap
1561  * level n, or 0 if there is no in-memory image for this mipmap level.
1562  *
1563  * A "view" is a collection of z_size pages for each mipmap level. Most
1564  * textures have only one view, except for multiview or stereo textures.
1565  *
1566  * For a non-compressed texture, this is the same as
1567  * get_expected_ram_mipmap_view_size(). For a compressed texture, this may be
1568  * a smaller value. (We do assume that all pages will be the same size on a
1569  * compressed texture).
1570  */
1571 INLINE size_t Texture::
1573  CDReader cdata(_cycler);
1574  return do_get_ram_mipmap_page_size(cdata, n) * do_get_expected_mipmap_z_size(cdata, n);
1575 }
1576 
1577 /**
1578  * Returns the number of bytes used by the in-memory image per page for mipmap
1579  * level n, or 0 if there is no in-memory image for this mipmap level.
1580  *
1581  * For a non-compressed texture, this is the same as
1582  * get_expected_ram_mipmap_page_size(). For a compressed texture, this may be
1583  * a smaller value. (We do assume that all pages will be the same size on a
1584  * compressed texture).
1585  */
1586 INLINE size_t Texture::
1588  CDReader cdata(_cycler);
1589  return do_get_ram_mipmap_page_size(cdata, n);
1590 }
1591 
1592 /**
1593  * Returns the number of bytes that *ought* to be used by the in-memory image
1594  * for mipmap level n, based on the texture parameters.
1595  */
1596 INLINE size_t Texture::
1598  CDReader cdata(_cycler);
1599  return do_get_expected_ram_mipmap_image_size(cdata, n);
1600 }
1601 
1602 /**
1603  * Returns the number of bytes that *ought* to be used by each view of the in-
1604  * memory image for mipmap level n, based on the texture parameters. For a
1605  * normal, non-multiview texture, this is the same as
1606  * get_expected_ram_mipmap_image_size(n).
1607  */
1608 INLINE size_t Texture::
1610  CDReader cdata(_cycler);
1611  return do_get_expected_ram_mipmap_view_size(cdata, n);
1612 }
1613 
1614 /**
1615  * Returns the number of bytes that should be used per each Z page of the 3-d
1616  * texture, for mipmap level n. For a 2-d or 1-d texture, this is the same as
1617  * get_expected_ram_mipmap_view_size(n).
1618  */
1619 INLINE size_t Texture::
1621  CDReader cdata(_cycler);
1622  return do_get_expected_ram_mipmap_page_size(cdata, n);
1623 }
1624 
1625 /**
1626  * Returns a modifiable pointer to the system-RAM image for the nth mipmap
1627  * level. This assumes the RAM image is uncompressed; if this is not the
1628  * case, raises an assertion.
1629  *
1630  * This does *not* affect keep_ram_image.
1631  */
1632 INLINE PTA_uchar Texture::
1634  CDWriter cdata(_cycler, false);
1635  cdata->inc_image_modified();
1636  return do_modify_ram_mipmap_image(cdata, n);
1637 }
1638 
1639 /**
1640  * Discards the current system-RAM image for the nth mipmap level, if any, and
1641  * allocates a new buffer of the appropriate size. Returns the new buffer.
1642  *
1643  * This does *not* affect keep_ram_image.
1644  */
1645 INLINE PTA_uchar Texture::
1647  CDWriter cdata(_cycler, false);
1648  cdata->inc_image_modified();
1649  return do_make_ram_mipmap_image(cdata, n);
1650 }
1651 
1652 /**
1653  * Replaces the current system-RAM image for the indicated mipmap level with
1654  * the new data. If compression is not CM_off, it indicates that the new data
1655  * is already pre-compressed in the indicated format.
1656  *
1657  * This does *not* affect keep_ram_image.
1658  */
1659 INLINE void Texture::
1660 set_ram_mipmap_image(int n, CPTA_uchar image, size_t page_size) {
1661  CDWriter cdata(_cycler, false);
1662  do_set_ram_mipmap_image(cdata, n, image, page_size);
1663 }
1664 
1665 /**
1666  * Discards the current system-RAM image for all mipmap levels, except level 0
1667  * (the base image).
1668  */
1669 INLINE void Texture::
1671  CDWriter cdata(_cycler, false);
1672  cdata->inc_image_modified();
1673  do_clear_ram_mipmap_images(cdata);
1674 }
1675 
1676 /**
1677  * Automatically fills in the n mipmap levels of the Texture, based on the
1678  * texture's source image. This requires the texture's uncompressed ram image
1679  * to be available in system memory. If it is not already, it will be fetched
1680  * if possible.
1681  *
1682  * This call is not normally necessary, since the mipmap levels will be
1683  * generated automatically if needed. But there may be certain cases in which
1684  * you would like to call this explicitly.
1685  */
1686 INLINE void Texture::
1688  // Don't use unlocked_ensure_ram_image here, because
1689  // do_generate_ram_mipmap_images will want to decompress and recompress the
1690  // image itself.
1691  CDWriter cdata(_cycler, false);
1692  cdata->inc_image_modified();
1693  do_generate_ram_mipmap_images(cdata, true);
1694 }
1695 
1696 /**
1697  * Returns the width of the "simple" image in texels.
1698  */
1699 INLINE int Texture::
1700 get_simple_x_size() const {
1701  CDReader cdata(_cycler);
1702  return cdata->_simple_x_size;
1703 }
1704 
1705 /**
1706  * Returns the height of the "simple" image in texels.
1707  */
1708 INLINE int Texture::
1709 get_simple_y_size() const {
1710  CDReader cdata(_cycler);
1711  return cdata->_simple_y_size;
1712 }
1713 
1714 /**
1715  * Returns true if the Texture has a "simple" image available in main RAM.
1716  */
1717 INLINE bool Texture::
1718 has_simple_ram_image() const {
1719  CDReader cdata(_cycler);
1720  return !cdata->_simple_ram_image._image.empty();
1721 }
1722 
1723 /**
1724  * Returns the number of bytes used by the "simple" image, or 0 if there is no
1725  * simple image.
1726  */
1727 INLINE size_t Texture::
1729  CDReader cdata(_cycler);
1730  return cdata->_simple_ram_image._image.size();
1731 }
1732 
1733 /**
1734  * Returns the image data associated with the "simple" texture image. This is
1735  * provided for some textures as an option to display while the main texture
1736  * image is being loaded from disk.
1737  *
1738  * Unlike get_ram_image(), this function will always return immediately.
1739  * Either the simple image is available, or it is not.
1740  *
1741  * The "simple" image is always 4 components, 1 byte each, regardless of the
1742  * parameters of the full texture. The simple image is only supported for
1743  * ordinary 2-d textures.
1744  */
1745 INLINE CPTA_uchar Texture::
1746 get_simple_ram_image() const {
1747  CDReader cdata(_cycler);
1748  return cdata->_simple_ram_image._image;
1749 }
1750 
1751 /**
1752  * Replaces the internal "simple" texture image. This can be used as an
1753  * option to display while the main texture image is being loaded from disk.
1754  * It is normally a very small image, 16x16 or smaller (and maybe even 1x1),
1755  * that is designed to give just enough sense of color to serve as a
1756  * placeholder until the full texture is available.
1757  *
1758  * The "simple" image is always 4 components, 1 byte each, regardless of the
1759  * parameters of the full texture. The simple image is only supported for
1760  * ordinary 2-d textures.
1761  *
1762  * Also see generate_simple_ram_image(), modify_simple_ram_image(), and
1763  * new_simple_ram_image().
1764  */
1765 INLINE void Texture::
1766 set_simple_ram_image(CPTA_uchar image, int x_size, int y_size) {
1767  CDWriter cdata(_cycler, true);
1768  do_set_simple_ram_image(cdata, image, x_size, y_size);
1769 }
1770 
1771 /**
1772  * Discards the current "simple" image.
1773  */
1774 INLINE void Texture::
1776  CDWriter cdata(_cycler, true);
1777  do_clear_simple_ram_image(cdata);
1778 }
1779 
1780 /**
1781  * Returns a sequence number which is guaranteed to change at least every time
1782  * the texture properties (unrelated to the image) are modified.
1783  */
1784 INLINE UpdateSeq Texture::
1785 get_properties_modified() const {
1786  CDReader cdata(_cycler);
1787  return cdata->_properties_modified;
1788 }
1789 
1790 /**
1791  * Returns a sequence number which is guaranteed to change at least every time
1792  * the texture image data (including mipmap levels) are modified.
1793  */
1794 INLINE UpdateSeq Texture::
1795 get_image_modified() const {
1796  CDReader cdata(_cycler);
1797  return cdata->_image_modified;
1798 }
1799 
1800 /**
1801  * Returns a sequence number which is guaranteed to change at least every time
1802  * the texture's "simple" image data is modified.
1803  */
1804 INLINE UpdateSeq Texture::
1805 get_simple_image_modified() const {
1806  CDReader cdata(_cycler);
1807  return cdata->_simple_image_modified;
1808 }
1809 
1810 /**
1811  * Specifies the power-of-2 texture-scaling mode that will be applied to this
1812  * particular texture when it is next loaded from disk. See
1813  * set_textures_power_2().
1814  */
1815 INLINE void Texture::
1816 set_auto_texture_scale(AutoTextureScale scale) {
1817  CDWriter cdata(_cycler, true);
1818  cdata->_auto_texture_scale = scale;
1819 }
1820 
1821 /**
1822  * Returns the power-of-2 texture-scaling mode that will be applied to this
1823  * particular texture when it is next loaded from disk. See
1824  * set_textures_power_2().
1825  */
1826 INLINE AutoTextureScale Texture::
1827 get_auto_texture_scale() const {
1828  CDReader cdata(_cycler);
1829  return do_get_auto_texture_scale(cdata);
1830 }
1831 
1832 /**
1833  * Returns true if set_auto_texture_scale() has been set to something other
1834  * than ATS_unspecified for this particular texture.
1835  */
1836 INLINE bool Texture::
1838  CDReader cdata(_cycler);
1839  return (cdata->_auto_texture_scale != ATS_unspecified);
1840 }
1841 
1842 /**
1843  * Set this flag to ATS_none, ATS_up, ATS_down, or ATS_pad to control the
1844  * scaling of textures in general, if a particular texture does not override
1845  * this. See also set_auto_texture_scale() for the per-texture override.
1846  */
1847 INLINE void Texture::
1848 set_textures_power_2(AutoTextureScale scale) {
1849  _textures_power_2 = scale;
1850 }
1851 
1852 /**
1853  * This flag returns ATS_none, ATS_up, or ATS_down and controls the scaling of
1854  * textures in general. It is initialized from the config variable of the
1855  * same name, but it can be subsequently adjusted. See also
1856  * get_auto_texture_scale().
1857  */
1858 INLINE AutoTextureScale Texture::
1860  if (_textures_power_2 == ATS_unspecified) {
1861  return textures_power_2;
1862  } else {
1863  return _textures_power_2;
1864  }
1865 }
1866 
1867 /**
1868  * If true, then get_textures_power_2 has been set using set_textures_power_2.
1869  * If false, then get_textures_power_2 simply returns the config variable of
1870  * the same name.
1871  */
1872 INLINE bool Texture::
1874  return (_textures_power_2 != ATS_unspecified);
1875 }
1876 
1877 /**
1878  * Sets the name of the file that contains the image's contents. Normally,
1879  * this is set automatically when the image is loaded, for instance via
1880  * Texture::read().
1881  *
1882  * The Texture's get_name() function used to return the filename, but now
1883  * returns just the basename (without the extension), which is a more useful
1884  * name for identifying an image in show code.
1885  */
1886 INLINE void Texture::
1887 set_filename(const Filename &filename) {
1888  CDWriter cdata(_cycler, true);
1889  cdata->_filename = filename;
1890 }
1891 
1892 /**
1893  * Removes the alpha filename, if it was previously set. See set_filename().
1894  */
1895 INLINE void Texture::
1896 clear_filename() {
1897  CDWriter cdata(_cycler, true);
1898  cdata->_filename = Filename();
1899 }
1900 
1901 /**
1902  * Sets the name of the file that contains the image's alpha channel contents.
1903  * Normally, this is set automatically when the image is loaded, for instance
1904  * via Texture::read().
1905  *
1906  * The Texture's get_filename() function returns the name of the image file
1907  * that was loaded into the buffer. In the case where a texture specified two
1908  * separate files to load, a 1- or 3-channel color image and a 1-channel alpha
1909  * image, this Filename is update to contain the name of the image file that
1910  * was loaded into the buffer's alpha channel.
1911  */
1912 INLINE void Texture::
1913 set_alpha_filename(const Filename &alpha_filename) {
1914  CDWriter cdata(_cycler, true);
1915  cdata->_alpha_filename = alpha_filename;
1916 }
1917 
1918 /**
1919  * Removes the alpha filename, if it was previously set. See
1920  * set_alpha_filename().
1921  */
1922 INLINE void Texture::
1923 clear_alpha_filename() {
1924  CDWriter cdata(_cycler, true);
1925  cdata->_alpha_filename = Filename();
1926 }
1927 
1928 /**
1929  * Sets the full pathname to the file that contains the image's contents, as
1930  * found along the search path. Normally, this is set automatically when the
1931  * image is loaded, for instance via Texture::read().
1932  */
1933 INLINE void Texture::
1934 set_fullpath(const Filename &fullpath) {
1935  CDWriter cdata(_cycler, true);
1936  cdata->_fullpath = fullpath;
1937 }
1938 
1939 /**
1940  * Removes the alpha fullpath, if it was previously set. See set_fullpath().
1941  */
1942 INLINE void Texture::
1943 clear_fullpath() {
1944  CDWriter cdata(_cycler, true);
1945  cdata->_fullpath = Filename();
1946 }
1947 
1948 /**
1949  * Sets the full pathname to the file that contains the image's alpha channel
1950  * contents, as found along the search path. Normally, this is set
1951  * automatically when the image is loaded, for instance via Texture::read().
1952  */
1953 INLINE void Texture::
1954 set_alpha_fullpath(const Filename &alpha_fullpath) {
1955  CDWriter cdata(_cycler, true);
1956  cdata->_alpha_fullpath = alpha_fullpath;
1957 }
1958 
1959 /**
1960  * Removes the alpha fullpath, if it was previously set. See
1961  * set_alpha_fullpath().
1962  */
1963 INLINE void Texture::
1964 clear_alpha_fullpath() {
1965  CDWriter cdata(_cycler, true);
1966  cdata->_alpha_fullpath = Filename();
1967 }
1968 
1969 /**
1970  * Changes the x size indicated for the texture. This also implicitly unloads
1971  * the texture if it has already been loaded.
1972  */
1973 INLINE void Texture::
1974 set_x_size(int x_size) {
1975  CDWriter cdata(_cycler, true);
1976  do_set_x_size(cdata, x_size);
1977 }
1978 
1979 /**
1980  * Changes the y size indicated for the texture. This also implicitly unloads
1981  * the texture if it has already been loaded.
1982  */
1983 INLINE void Texture::
1984 set_y_size(int y_size) {
1985  CDWriter cdata(_cycler, true);
1986  do_set_y_size(cdata, y_size);
1987 }
1988 
1989 /**
1990  * Changes the z size indicated for the texture. This also implicitly unloads
1991  * the texture if it has already been loaded.
1992  */
1993 INLINE void Texture::
1994 set_z_size(int z_size) {
1995  CDWriter cdata(_cycler, true);
1996  do_set_z_size(cdata, z_size);
1997 }
1998 
1999 /**
2000  * Sets the number of "views" within a texture. A view is a completely
2001  * separate image stored within the Texture object. Most textures have only
2002  * one view, but a stereo texture, for instance, may have two views, a left
2003  * and a right image. Other uses for multiple views are not yet defined.
2004  *
2005  * If this value is greater than one, the additional views are accessed as
2006  * additional pages beyond get_z_size().
2007  *
2008  * This also implicitly unloads the texture if it has already been loaded.
2009  */
2010 INLINE void Texture::
2011 set_num_views(int num_views) {
2012  CDWriter cdata(_cycler, true);
2013  do_set_num_views(cdata, num_views);
2014 }
2015 
2016 /**
2017  * Changes the format value for the texture components. This implicitly sets
2018  * num_components as well.
2019  */
2020 INLINE void Texture::
2021 set_format(Texture::Format format) {
2022  CDWriter cdata(_cycler, true);
2023  do_set_format(cdata, format);
2024 }
2025 
2026 /**
2027  * Changes the data value for the texture components. This implicitly sets
2028  * component_width as well.
2029  */
2030 INLINE void Texture::
2031 set_component_type(Texture::ComponentType component_type) {
2032  CDWriter cdata(_cycler, true);
2033  do_set_component_type(cdata, component_type);
2034 }
2035 
2036 /**
2037  * Sets the flag that indicates the texture has been loaded from a disk file
2038  * or PNMImage. You should also ensure the filename has been set correctly.
2039  * When this flag is true, the texture may be automatically reloaded when its
2040  * ram image needs to be replaced.
2041  */
2042 INLINE void Texture::
2043 set_loaded_from_image(bool flag) {
2044  CDWriter cdata(_cycler, false);
2045  cdata->_loaded_from_image = flag;
2046 }
2047 
2048 /**
2049  * Returns the flag that indicates the texture has been loaded from a disk
2050  * file or PNMImage. See set_loaded_from_image().
2051  */
2052 INLINE bool Texture::
2053 get_loaded_from_image() const {
2054  CDReader cdata(_cycler);
2055  return cdata->_loaded_from_image;
2056 }
2057 
2058 /**
2059  * Sets the flag that indicates the texture has been loaded from a txo file.
2060  * You probably shouldn't be setting this directly; it is set automatically
2061  * when a Texture is loaded.
2062  */
2063 INLINE void Texture::
2064 set_loaded_from_txo(bool flag) {
2065  CDWriter cdata(_cycler, false);
2066  cdata->_loaded_from_txo = flag;
2067 }
2068 
2069 /**
2070  * Returns the flag that indicates the texture has been loaded from a txo
2071  * file.
2072  */
2073 INLINE bool Texture::
2074 get_loaded_from_txo() const {
2075  CDReader cdata(_cycler);
2076  return cdata->_loaded_from_txo;
2077 }
2078 
2079 /**
2080  * Returns true if the special flag was set that indicates to the GSG that the
2081  * Texture's format should be chosen to exactly match the framebuffer's
2082  * format, presumably because the application intends to copy image data from
2083  * the framebuffer into the Texture (or vice-versa).
2084  */
2085 INLINE bool Texture::
2086 get_match_framebuffer_format() const {
2087  CDReader cdata(_cycler);
2088  return cdata->_match_framebuffer_format;
2089 }
2090 
2091 /**
2092  * Sets the special flag that, if true, indicates to the GSG that the
2093  * Texture's format should be chosen to exactly match the framebuffer's
2094  * format, presumably because the application intends to copy image data from
2095  * the framebuffer into the Texture (or vice-versa).
2096  *
2097  * This sets only the graphics card's idea of the texture format; it is not
2098  * related to the system-memory format.
2099  */
2100 INLINE void Texture::
2101 set_match_framebuffer_format(bool flag) {
2102  CDWriter cdata(_cycler, true);
2103  cdata->_match_framebuffer_format = flag;
2104 }
2105 
2106 /**
2107  * Returns the setting of the post_load_store_cache flag. See
2108  * set_post_load_store_cache().
2109  */
2110 INLINE bool Texture::
2111 get_post_load_store_cache() const {
2112  CDReader cdata(_cycler);
2113  return cdata->_post_load_store_cache;
2114 }
2115 
2116 /**
2117  * Sets the post_load_store_cache flag. When this is set, the next time the
2118  * texture is loaded on a GSG, it will automatically extract its RAM image
2119  * from the GSG and save it to the global BamCache.
2120  *
2121  * This is used to store compressed RAM images in the BamCache. This flag
2122  * should not be set explicitly; it is set automatically by the TexturePool
2123  * when model-cache-compressed-textures is set true.
2124  */
2125 INLINE void Texture::
2126 set_post_load_store_cache(bool flag) {
2127  CDWriter cdata(_cycler, true);
2128  cdata->_post_load_store_cache = flag;
2129 }
2130 
2131 /**
2132  * This method is similar to consider_rescale(), but instead of scaling a
2133  * separate PNMImage, it will ask the Texture to rescale its own internal
2134  * image to a power of 2, according to the config file requirements. This may
2135  * be useful after loading a Texture image by hand, instead of reading it from
2136  * a disk file. Returns true if the texture is changed, false if it was not.
2137  */
2138 INLINE bool Texture::
2140  CDWriter cdata(_cycler, true);
2141  return do_rescale_texture(cdata);
2142 }
2143 
2144 /**
2145  * Works like adjust_size, but also considers the texture class. Movie
2146  * textures, for instance, always pad outwards, regardless of textures-
2147  * power-2.
2148  */
2149 INLINE bool Texture::
2150 adjust_this_size(int &x_size, int &y_size, const std::string &name,
2151  bool for_padding) const {
2152  CDReader cdata(_cycler);
2153  return do_adjust_this_size(cdata, x_size, y_size, name, for_padding);
2154 }
2155 
2156 /**
2157  *
2158  */
2159 INLINE size_t Texture::
2160 do_get_ram_image_size(const CData *cdata) const {
2161  if (cdata->_ram_images.empty()) {
2162  return 0;
2163  }
2164  return cdata->_ram_images[0]._image.size();
2165 }
2166 
2167 /**
2168  *
2169  */
2170 INLINE bool Texture::
2171 do_has_ram_mipmap_image(const CData *cdata, int n) const {
2172  return (n >= 0 && n < (int)cdata->_ram_images.size() &&
2173  !cdata->_ram_images[n]._image.empty());
2174 }
2175 
2176 /**
2177  *
2178  */
2179 INLINE size_t Texture::
2180 do_get_expected_ram_image_size(const CData *cdata) const {
2181  return do_get_expected_ram_view_size(cdata) * (size_t)cdata->_num_views;
2182 }
2183 
2184 /**
2185  *
2186  */
2187 INLINE size_t Texture::
2188 do_get_expected_ram_view_size(const CData *cdata) const {
2189  return do_get_expected_ram_page_size(cdata) * (size_t)cdata->_z_size;
2190 }
2191 
2192 /**
2193  *
2194  */
2195 INLINE size_t Texture::
2196 do_get_expected_ram_page_size(const CData *cdata) const {
2197  return (size_t)(cdata->_x_size * cdata->_y_size * cdata->_num_components * cdata->_component_width);
2198 }
2199 
2200 /**
2201  *
2202  */
2203 INLINE size_t Texture::
2204 do_get_expected_ram_mipmap_image_size(const CData *cdata, int n) const {
2205  return do_get_expected_ram_mipmap_view_size(cdata, n) * (size_t)cdata->_num_views;
2206 }
2207 
2208 /**
2209  *
2210  */
2211 INLINE size_t Texture::
2212 do_get_expected_ram_mipmap_view_size(const CData *cdata, int n) const {
2213  return do_get_expected_ram_mipmap_page_size(cdata, n) * (size_t)do_get_expected_mipmap_z_size(cdata, n);
2214 }
2215 
2216 /**
2217  *
2218  */
2219 INLINE size_t Texture::
2220 do_get_expected_ram_mipmap_page_size(const CData *cdata, int n) const {
2221  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);
2222 }
2223 
2224 /**
2225  *
2226  */
2227 INLINE int Texture::
2228 do_get_expected_mipmap_num_pages(const CData *cdata, int n) const {
2229  return do_get_expected_mipmap_z_size(cdata, n) * cdata->_num_views;
2230 }
2231 
2232 /**
2233  *
2234  */
2235 INLINE void Texture::
2236 do_clear_ram_image(CData *cdata) {
2237  cdata->_ram_image_compression = CM_off;
2238  cdata->_ram_images.clear();
2239 }
2240 
2241 /**
2242  *
2243  */
2244 INLINE AutoTextureScale Texture::
2245 do_get_auto_texture_scale(const CData *cdata) const {
2246  if (cdata->_auto_texture_scale == ATS_unspecified) {
2247  return get_textures_power_2();
2248  } else {
2249  return cdata->_auto_texture_scale;
2250  }
2251 }
2252 
2253 /**
2254  * This is used by load() to store the next consecutive component value into
2255  * the indicated element of the array, which is taken to be an array of
2256  * unsigned bytes. The value is assumed to be in the range 0-255.
2257  */
2258 INLINE void Texture::
2259 store_unscaled_byte(unsigned char *&p, int value) {
2260  (*p++) = (uchar)value;
2261 }
2262 
2263 /**
2264  * This is used by load() to store the next consecutive component value into
2265  * the indicated element of the array, which is taken to be an array of
2266  * unsigned shorts. The value is assumed to be in the range 0-65535.
2267  */
2268 INLINE void Texture::
2269 store_unscaled_short(unsigned char *&p, int value) {
2270  union {
2271  ushort us;
2272  uchar uc[2];
2273  } v;
2274  v.us = (ushort)value;
2275  (*p++) = v.uc[0];
2276  (*p++) = v.uc[1];
2277 }
2278 
2279 /**
2280  * This is used by load() to store the next consecutive component value into
2281  * the indicated element of the array, which is taken to be an array of
2282  * unsigned bytes. The value will be scaled by the indicated factor before
2283  * storing it.
2284  */
2285 INLINE void Texture::
2286 store_scaled_byte(unsigned char *&p, int value, double scale) {
2287  store_unscaled_byte(p, (int)(value * scale));
2288 }
2289 
2290 /**
2291  * This is used by load() to store the next consecutive component value into
2292  * the indicated element of the array, which is taken to be an array of
2293  * unsigned shorts. The value will be scaled by the indicated factor before
2294  * storing it.
2295  */
2296 INLINE void Texture::
2297 store_scaled_short(unsigned char *&p, int value, double scale) {
2298  store_unscaled_short(p, (int)(value * scale));
2299 }
2300 
2301 /**
2302  * This is used by store() to retrieve the next consecutive component value
2303  * from the indicated element of the array, which is taken to be an array of
2304  * unsigned bytes.
2305  */
2306 INLINE double Texture::
2307 get_unsigned_byte(const unsigned char *&p) {
2308  return (double)(*p++) / 255.0;
2309 }
2310 
2311 /**
2312  * This is used by store() to retrieve the next consecutive component value
2313  * from the indicated element of the array, which is taken to be an array of
2314  * unsigned shorts.
2315  */
2316 INLINE double Texture::
2317 get_unsigned_short(const unsigned char *&p) {
2318  union {
2319  ushort us;
2320  uchar uc[2];
2321  } v;
2322  v.uc[0] = (*p++);
2323  v.uc[1] = (*p++);
2324  return (double)v.us / 65535.0;
2325 }
2326 
2327 /**
2328  * This is used by store() to retrieve the next consecutive component value
2329  * from the indicated element of the array, which is taken to be an array of
2330  * unsigned ints.
2331  */
2332 INLINE double Texture::
2333 get_unsigned_int(const unsigned char *&p) {
2334  union {
2335  unsigned int ui;
2336  uchar uc[4];
2337  } v;
2338  v.uc[0] = (*p++);
2339  v.uc[1] = (*p++);
2340  v.uc[2] = (*p++);
2341  v.uc[3] = (*p++);
2342  return (double)v.ui / 4294967295.0;
2343 }
2344 
2345 /**
2346  * This is used by store() to retrieve the next consecutive component value
2347  * from the indicated element of the array, which is taken to be an array of
2348  * unsigned ints with the value packed in the 24 least significant bits.
2349  */
2350 INLINE double Texture::
2351 get_unsigned_int_24(const unsigned char *&p) {
2352  union {
2353  uint32_t ui;
2354  uint8_t uc[4];
2355  } v;
2356  v.uc[0] = (*p++);
2357  v.uc[1] = (*p++);
2358  v.uc[2] = (*p++);
2359  v.uc[3] = (*p++);
2360  return (double)(v.ui & 0xffffff) / (double)0xffffff;
2361 }
2362 
2363 /**
2364  * This is used by store() to retrieve the next consecutive component value
2365  * from the indicated element of the array, which is taken to be an array of
2366  * floats.
2367  */
2368 INLINE double Texture::
2369 get_float(const unsigned char *&p) {
2370  double v = *((float *)p);
2371  p += 4;
2372  return v;
2373 }
2374 
2375 /**
2376  * This is used by store() to retrieve the next consecutive component value
2377  * from the indicated element of the array, which is taken to be an array of
2378  * half-floats.
2379  */
2380 INLINE double Texture::
2381 get_half_float(const unsigned char *&p) {
2382  union {
2383  uint32_t ui;
2384  float uf;
2385  } v;
2386  uint16_t in = *(uint16_t *)p;
2387  p += 2;
2388  uint32_t t1 = in & 0x7fff; // Non-sign bits
2389  uint32_t t2 = in & 0x8000; // Sign bit
2390  uint32_t t3 = in & 0x7c00; // Exponent
2391  t1 <<= 13; // Align mantissa on MSB
2392  t2 <<= 16; // Shift sign bit into position
2393  if (t3 != 0x7c00) {
2394  t1 += 0x38000000; // Adjust bias
2395  t1 = (t3 == 0 ? 0 : t1); // Denormals-as-zero
2396  } else {
2397  // Infinity / NaN
2398  t1 |= 0x7f800000;
2399  }
2400  t1 |= t2; // Re-insert sign bit
2401  v.ui = t1;
2402  return v.uf;
2403 }
2404 
2405 /**
2406  * Returns true if the indicated filename ends in .txo or .txo.pz or .txo.gz,
2407  * false otherwise.
2408  */
2409 INLINE bool Texture::
2410 is_txo_filename(const Filename &fullpath) {
2411  std::string extension = fullpath.get_extension();
2412 #ifdef HAVE_ZLIB
2413  if (extension == "pz" || extension == "gz") {
2414  extension = Filename(fullpath.get_basename_wo_extension()).get_extension();
2415  }
2416 #endif // HAVE_ZLIB
2417  return (extension == "txo");
2418 }
2419 
2420 /**
2421  * Returns true if the indicated filename ends in .dds or .dds.pz or .dds.gz,
2422  * false otherwise.
2423  */
2424 INLINE bool Texture::
2425 is_dds_filename(const Filename &fullpath) {
2426  std::string extension = fullpath.get_extension();
2427 #ifdef HAVE_ZLIB
2428  if (extension == "pz" || extension == "gz") {
2429  extension = Filename(fullpath.get_basename_wo_extension()).get_extension();
2430  }
2431 #endif // HAVE_ZLIB
2432  return (downcase(extension) == "dds");
2433 }
2434 
2435 /**
2436  * Returns true if the indicated filename ends in .ktx or .ktx.pz or .ktx.gz,
2437  * false otherwise.
2438  */
2439 INLINE bool Texture::
2440 is_ktx_filename(const Filename &fullpath) {
2441  std::string extension = fullpath.get_extension();
2442 #ifdef HAVE_ZLIB
2443  if (extension == "pz" || extension == "gz") {
2444  extension = Filename(fullpath.get_basename_wo_extension()).get_extension();
2445  }
2446 #endif // HAVE_ZLIB
2447  return (downcase(extension) == "ktx");
2448 }
2449 
2450 /**
2451  *
2452  */
2453 INLINE void Texture::CData::
2454 inc_properties_modified() {
2455  ++_properties_modified;
2456 }
2457 
2458 /**
2459  *
2460  */
2461 INLINE void Texture::CData::
2462 inc_image_modified() {
2463  ++_image_modified;
2464 }
2465 
2466 /**
2467  *
2468  */
2469 INLINE void Texture::CData::
2470 inc_simple_image_modified() {
2471  ++_simple_image_modified;
2472 }
2473 
2474 /**
2475  *
2476  */
2477 INLINE Texture::RamImage::
2478 RamImage() :
2479  _page_size(0),
2480  _pointer_image(nullptr)
2481 {
2482 }
CPTA_uchar get_ram_image()
Returns the system-RAM image data associated with the texture.
Definition: texture.I:1352
set_z_size
Changes the z size indicated for the texture.
Definition: texture.h:342
set_fullpath
Sets the full pathname to the file that contains the image&#39;s contents, as found along the search path...
Definition: texture.h:324
bool has_auto_texture_scale() const
Returns true if set_auto_texture_scale() has been set to something other than ATS_unspecified for thi...
Definition: texture.I:1837
int get_expected_mipmap_x_size(int n) const
Returns the x_size that the nth mipmap level should have, based on the texture&#39;s size.
Definition: texture.I:1181
static void set_textures_power_2(AutoTextureScale scale)
Set this flag to ATS_none, ATS_up, ATS_down, or ATS_pad to control the scaling of textures in general...
Definition: texture.I:1848
set_num_views
Sets the number of "views" within a texture.
Definition: texture.h:346
int get_pad_y_size() const
Returns size of the pad region.
Definition: texture.I:625
get_effective_minfilter
Returns the filter mode of the texture for minification, with special treatment for FT_default...
Definition: texture.h:384
set_filename
Sets the name of the file that contains the image&#39;s contents.
Definition: texture.h:312
size_t get_ram_mipmap_image_size(int n) const
Returns the number of bytes used by the in-memory image for mipmap level n, or 0 if there is no in-me...
Definition: texture.I:1544
void setup_2d_texture()
Sets the texture as an empty 2-d texture with no dimensions.
Definition: texture.I:87
size_t get_expected_ram_mipmap_view_size(int n) const
Returns the number of bytes that *ought* to be used by each view of the in- memory image for mipmap l...
Definition: texture.I:1609
set_loaded_from_txo
Sets the flag that indicates the texture has been loaded from a txo file.
Definition: texture.h:576
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:58
void setup_cube_map_array(int num_cube_maps)
Sets the texture as cube map array with N cube maps.
Definition: texture.I:180
PT(Texture) Texture
Returns a new copy of the same Texture.
Definition: texture.I:25
bool might_have_ram_image() const
Returns true if the texture&#39;s image contents are currently available in main RAM, or there is reason ...
Definition: texture.I:1260
set_auto_texture_scale
Specifies the power-of-2 texture-scaling mode that will be applied to this particular texture when it...
Definition: texture.h:524
void clear_image()
Clears the texture data without changing its format or resolution.
Definition: texture.I:226
set_match_framebuffer_format
Sets the special flag that, if true, indicates to the GSG that the Texture&#39;s format should be chosen ...
Definition: texture.h:581
PTA_uchar make_ram_mipmap_image(int n)
Discards the current system-RAM image for the nth mipmap level, if any, and allocates a new buffer of...
Definition: texture.I:1646
set_magfilter
Sets the filtering method that should be used when viewing the texture up close.
Definition: texture.h:389
set_clear_color
Sets the color that will be used to fill the texture image in absence of any image data...
Definition: texture.h:270
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:23
PTA_uchar make_ram_image()
Discards the current system-RAM image for the texture, if any, and allocates a new buffer of the appr...
Definition: texture.I:1411
bool rescale_texture()
This method is similar to consider_rescale(), but instead of scaling a separate PNMImage, it will ask the Texture to rescale its own internal image to a power of 2, according to the config file requirements.
Definition: texture.I:2139
set_wrap_v
This setting determines what happens when the texture is sampled with a V value outside the range 0...
Definition: texture.h:374
CPTA_uchar get_uncompressed_ram_image()
Returns the system-RAM image associated with the texture, in an uncompressed form if at all possible...
Definition: texture.I:1399
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
Definition: filename.I:386
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
void setup_texture(TextureType texture_type, int x_size, int y_size, int z_size, ComponentType component_type, Format format)
Sets the texture to the indicated type and dimensions, presumably in preparation for calling read() o...
Definition: texture.I:52
bool has_ram_mipmap_image(int n) const
Returns true if the Texture has the nth mipmap level available in system memory, false otherwise...
Definition: texture.I:1524
bool store(PNMImage &pnmimage) const
Saves the texture to the indicated PNMImage, but does not write it to disk.
Definition: texture.I:428
bool load_sub_image(const PNMImage &pnmimage, int x, int y, int z=0, int n=0)
Stores the indicated image in a region of the texture.
Definition: texture.I:419
string downcase(const string &s)
Returns the input string with all uppercase letters converted to lowercase.
static bool is_mipmap(FilterType type)
Returns true if the indicated filter type requires the use of mipmaps, or false if it does not...
Definition: samplerState.I:257
set_alpha_fullpath
Sets the full pathname to the file that contains the image&#39;s alpha channel contents, as found along the search path.
Definition: texture.h:330
set_wrap_w
The W wrap direction is only used for 3-d textures.
Definition: texture.h:378
PTA_uchar modify_ram_mipmap_image(int n)
Returns a modifiable pointer to the system-RAM image for the nth mipmap level.
Definition: texture.I:1633
bool has_ram_image() const
Returns true if the Texture has its image contents available in main RAM, false if it exists only in ...
Definition: texture.I:1238
void setup_cube_map()
Sets the texture as an empty cube map texture with no dimensions.
Definition: texture.I:155
int get_expected_mipmap_y_size(int n) const
Returns the y_size that the nth mipmap level should have, based on the texture&#39;s size.
Definition: texture.I:1191
int get_pad_x_size() const
Returns size of the pad region.
Definition: texture.I:616
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
size_t get_ram_mipmap_view_size(int n) const
Returns the number of bytes used by the in-memory image per view for mipmap level n...
Definition: texture.I:1572
bool adjust_this_size(int &x_size, int &y_size, const std::string &name, bool for_padding) const
Works like adjust_size, but also considers the texture class.
Definition: texture.I:2150
int get_z_size() const
Returns the depth of the texture image that is contributing to the TexturePeeker&#39;s information...
Definition: texturePeeker.I:48
set_border_color
Specifies the solid color of the texture&#39;s border.
Definition: texture.h:400
set_render_to_texture
Sets a flag on the texture that indicates whether the texture is intended to be used as a direct-rend...
Definition: texture.h:409
int get_expected_mipmap_z_size(int n) const
Returns the z_size that the nth mipmap level should have, based on the texture&#39;s size.
Definition: texture.I:1201
static AutoTextureScale get_textures_power_2()
This flag returns ATS_none, ATS_up, or ATS_down and controls the scaling of textures in general...
Definition: texture.I:1859
size_t get_ram_mipmap_page_size(int n) const
Returns the number of bytes used by the in-memory image per page for mipmap level n...
Definition: texture.I:1587
bool uses_mipmaps() const
Returns true if the minfilter settings on this texture indicate the use of mipmapping, false otherwise.
Definition: texture.I:1123
void set_ram_mipmap_image(int n, CPTA_uchar image, size_t page_size=0)
Replaces the current system-RAM image for the indicated mipmap level with the new data...
Definition: texture.I:1660
void setup_3d_texture(int z_size=1)
Sets the texture as an empty 3-d texture with no dimensions (though if you know the depth ahead of ti...
Definition: texture.I:110
void clear_simple_ram_image()
Discards the current "simple" image.
Definition: texture.I:1775
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component, or with a special extension, 2- or 4-component.
Definition: pfmFile.h:31
set_keep_ram_image
Sets the flag that indicates whether this Texture is eligible to have its main RAM copy of the textur...
Definition: texture.h:464
void set_pad_size(int x=0, int y=0, int z=0)
Sets the size of the pad region.
Definition: texture.I:673
void setup_2d_texture_array(int z_size=1)
Sets the texture as an empty 2-d texture array with no dimensions (though if you know the depth ahead...
Definition: texture.I:133
set_format
Changes the format value for the texture components.
Definition: texture.h:362
set_minfilter
Sets the filtering method that should be used when viewing the texture from a distance.
Definition: texture.h:383
void clear_ram_mipmap_images()
Discards the current system-RAM image for all mipmap levels, except level 0 (the base image)...
Definition: texture.I:1670
set_anisotropic_degree
Specifies the level of anisotropic filtering to apply to the texture.
Definition: texture.h:395
void setup_buffer_texture(int size, ComponentType component_type, Format format, GeomEnums::UsageHint usage)
Sets the texture as an empty buffer texture with the specified size and properties.
Definition: texture.I:207
int get_pad_z_size() const
Returns size of the pad region.
Definition: texture.I:634
set_y_size
Changes the y size indicated for the texture.
Definition: texture.h:338
set_post_load_store_cache
Sets the post_load_store_cache flag.
Definition: texture.h:586
void setup_1d_texture()
Sets the texture as an empty 1-d texture with no dimensions.
Definition: texture.I:66
set_x_size
Changes the x size indicated for the texture.
Definition: texture.h:334
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
size_t get_expected_ram_mipmap_image_size(int n) const
Returns the number of bytes that *ought* to be used by the in-memory image for mipmap level n...
Definition: texture.I:1597
set_wrap_u
This setting determines what happens when the texture is sampled with a U value outside the range 0...
Definition: texture.h:370
size_t get_expected_ram_mipmap_page_size(int n) const
Returns the number of bytes that should be used per each Z page of the 3-d texture, for mipmap level n.
Definition: texture.I:1620
std::string get_extension() const
Returns the file extension.
Definition: filename.I:400
void clear_ram_image()
Discards the current system-RAM image.
Definition: texture.I:1435
get_num_views
Returns the number of "views" in the texture.
Definition: texture.h:346
Represents a set of settings that indicate how a texture is sampled.
Definition: samplerState.h:36
bool uncompress_ram_image()
Attempts to uncompress the texture&#39;s RAM image internally.
Definition: texture.I:1494
set_default_sampler
This sets the default sampler state for this texture, containing the wrap and filter properties speci...
Definition: texture.h:413
bool has_all_ram_mipmap_images() const
Returns true if all expected mipmap levels have been defined and exist in the system RAM...
Definition: texture.I:1534
void set_ram_image(CPTA_uchar image, CompressionMode compression=CM_off, size_t page_size=0)
Replaces the current system-RAM image with the new data.
Definition: texture.I:1425
set_component_type
Changes the data value for the texture components.
Definition: texture.h:366
bool load(const PNMImage &pnmimage, const LoaderOptions &options=LoaderOptions())
Replaces the texture with the indicated image.
Definition: texture.I:353
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
set_compression
Requests that this particular Texture be compressed when it is loaded into texture memory...
Definition: texture.h:405
LVecBase2 get_tex_scale() const
Returns a scale pair that is suitable for applying to geometry via NodePath::set_tex_scale(), which will convert texture coordinates on the geometry from the range 0..1 into the appropriate range to render the video part of the texture.
Definition: texture.I:651
void generate_ram_mipmap_images()
Automatically fills in the n mipmap levels of the Texture, based on the texture&#39;s source image...
Definition: texture.I:1687
set_quality_level
Sets a hint to the renderer about the desired performance / quality tradeoff for this particular text...
Definition: texture.h:419
bool compress_ram_image(CompressionMode compression=CM_on, QualityLevel quality_level=QL_default, GraphicsStateGuardianBase *gsg=nullptr)
Attempts to compress the texture&#39;s RAM image internally, to a format supported by the indicated GSG...
Definition: texture.I:1475
set_loaded_from_image
Sets the flag that indicates the texture has been loaded from a disk file or PNMImage.
Definition: texture.h:572
set_alpha_filename
Sets the name of the file that contains the image&#39;s alpha channel contents.
Definition: texture.h:318
int get_expected_mipmap_num_pages(int n) const
Returns the total number of pages that the nth mipmap level should have, based on the texture&#39;s size...
Definition: texture.I:1213
void set_simple_ram_image(CPTA_uchar image, int x_size, int y_size)
Replaces the internal "simple" texture image.
Definition: texture.I:1766
static bool has_textures_power_2()
If true, then get_textures_power_2 has been set using set_textures_power_2.
Definition: texture.I:1873
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
PTA_uchar modify_ram_image()
Returns a modifiable pointer to the system-RAM image.
Definition: texture.I:1378
bool has_compression() const
Returns true if the texture indicates it wants to be compressed, either with CM_on or higher...
Definition: texture.I:1098
vector_uchar get_clear_data() const
Returns the raw image data for a single pixel if it were set to the clear color.
Definition: texture.I:283
size_t get_simple_ram_image_size() const
Returns the number of bytes used by the "simple" image, or 0 if there is no simple image...
Definition: texture.I:1728
bool reload()
Re-reads the Texture from its disk file.
Definition: texture.I:468
bool write(const Filename &fullpath)
Writes the texture to the named filename.
Definition: texture.I:294
Similar to PointerToArray, except that its contents may not be modified.
bool has_uncompressed_ram_image() const
Returns true if the Texture has its image contents available in main RAM and is uncompressed, false otherwise.
Definition: texture.I:1248