Panda3D

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