Panda3D
Loading...
Searching...
No Matches
texture.h
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.h
10 * @author mike
11 * @date 1997-01-09
12 * @author fperazzi, PandaSE
13 * @date 2010-04-29
14 */
15
16#ifndef TEXTURE_H
17#define TEXTURE_H
18
19#include "pandabase.h"
20
21#include "filename.h"
23#include "namable.h"
24#include "internalName.h"
26#include "updateSeq.h"
27#include "pmap.h"
28#include "config_gobj.h"
29#include "pStatCollector.h"
30#include "pmutex.h"
31#include "mutexHolder.h"
32#include "conditionVarFull.h"
33#include "loaderOptions.h"
34#include "string_utils.h"
35#include "cycleData.h"
37#include "cycleDataReader.h"
38#include "cycleDataWriter.h"
41#include "pipelineCycler.h"
42#include "samplerState.h"
43#include "colorSpace.h"
44#include "geomEnums.h"
45#include "bamCacheRecord.h"
46#include "pnmImage.h"
47#include "pfmFile.h"
48#include "asyncFuture.h"
49#include "extension.h"
50
51class TextureContext;
52class FactoryParams;
54class CullTraverser;
56class TexturePeeker;
57struct DDSHeader;
58
59/**
60 * Represents a texture object, which is typically a single 2-d image but may
61 * also represent a 1-d or 3-d texture image, or the six 2-d faces of a cube
62 * map texture.
63 *
64 * A texture's image data might be stored in system RAM (see get_ram_image())
65 * or its image may be represented in texture memory on one or more
66 * GraphicsStateGuardians (see prepare()), or both. The typical usage pattern
67 * is that a texture is loaded from an image file on disk, which copies its
68 * image data into system RAM; then the first time the texture is rendered its
69 * image data is copied to texture memory (actually, to the graphics API), and
70 * the system RAM image is automatically freed.
71 */
72class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Namable {
73PUBLISHED:
74 typedef PT(Texture) MakeTextureFunc();
75
76 enum TextureType {
77 TT_1d_texture,
78 TT_2d_texture,
79 TT_3d_texture,
80 TT_2d_texture_array,
81 TT_cube_map,
82 TT_buffer_texture,
83 TT_cube_map_array,
84 TT_1d_texture_array,
85 };
86
87 enum ComponentType {
88 T_unsigned_byte,
89 T_unsigned_short,
90 T_float,
91 T_unsigned_int_24_8, // Packed
92 T_int,
93 T_byte,
94 T_short,
95 T_half_float,
96 T_unsigned_int,
97 };
98
99 enum Format {
100 F_depth_stencil = 1,
101 F_color_index,
102 F_red,
103 F_green,
104 F_blue,
105 F_alpha,
106 F_rgb, // any suitable RGB mode, whatever the hardware prefers
107
108 // The following request a particular number of bits for the GSG's
109 // internal_format (as stored in the framebuffer), but this request is not
110 // related to the pixel storage within the Texture object itself, which is
111 // always get_num_components() * get_component_width().
112 F_rgb5, // 5 bits per R,G,B channel
113 F_rgb8, // 8 bits per R,G,B channel
114 F_rgb12, // 12 bits per R,G,B channel
115 F_rgb332, // 3 bits per R & G, 2 bits for B
116
117 F_rgba, // any suitable RGBA mode, whatever the hardware prefers
118
119 // Again, the following bitdepth requests are only for the GSG; within the
120 // Texture object itself, these are all equivalent.
121 F_rgbm, // as above, but only requires 1 bit for alpha (i.e. mask)
122 F_rgba4, // 4 bits per R,G,B,A channel
123 F_rgba5, // 5 bits per R,G,B channel, 1 bit alpha
124 F_rgba8, // 8 bits per R,G,B,A channel
125 F_rgba12, // 12 bits per R,G,B,A channel
126
127 F_luminance,
128 F_luminance_alpha, // 8 bits luminance, 8 bits alpha
129 F_luminance_alphamask, // 8 bits luminance, only needs 1 bit of alpha
130
131 F_rgba16, // 16 bits per R,G,B,A channel
132 F_rgba32, // 32 bits per R,G,B,A channel
133
134 F_depth_component,
135 F_depth_component16,
136 F_depth_component24,
137 F_depth_component32,
138
139 F_r16,
140 F_rg16,
141 F_rgb16,
142
143 // These formats are in the sRGB color space. RGB is 2.2 gamma corrected,
144 // alpha is always linear.
145 F_srgb,
146 F_srgb_alpha,
147 F_sluminance,
148 F_sluminance_alpha,
149
150 F_r32i, // 32-bit integer, used for atomic access
151 F_r32,
152 F_rg32,
153 F_rgb32,
154
155 F_r8i, // 8 integer bits per R channel
156 F_rg8i, // 8 integer bits per R,G channel
157 F_rgb8i, // 8 integer bits per R,G,B channel
158 F_rgba8i, // 8 integer bits per R,G,B,A channel
159
160 F_r11_g11_b10, // unsigned floating-point, 11 Red, 11 Green, 10 Blue Bits
161 F_rgb9_e5,
162 F_rgb10_a2,
163
164 F_rg,
165
166 F_r16i,
167 F_rg16i,
168 F_rgb16i, // not recommended
169 F_rgba16i,
170
171 F_rg32i,
172 F_rgb32i,
173 F_rgba32i,
174 };
175
176 // Deprecated. See SamplerState.FilterType.
177 enum DeprecatedFilterType {
178 FT_nearest = SamplerState::FT_nearest,
179 FT_linear = SamplerState::FT_linear,
180 FT_nearest_mipmap_nearest = SamplerState::FT_nearest_mipmap_nearest,
181 FT_linear_mipmap_nearest = SamplerState::FT_linear_mipmap_nearest,
182 FT_nearest_mipmap_linear = SamplerState::FT_nearest_mipmap_linear,
183 FT_linear_mipmap_linear = SamplerState::FT_linear_mipmap_linear,
184 FT_shadow = SamplerState::FT_shadow,
185 FT_default = SamplerState::FT_default,
186 FT_invalid = SamplerState::FT_invalid
187 };
188 typedef SamplerState::FilterType FilterType;
189
190 // Deprecated. See SamplerState.WrapMode.
191 enum DeprecatedWrapMode {
192 WM_clamp = SamplerState::WM_clamp,
193 WM_repeat = SamplerState::WM_repeat,
194 WM_mirror = SamplerState::WM_mirror,
195 WM_mirror_once = SamplerState::WM_mirror_once,
196 WM_border_color = SamplerState::WM_border_color,
197 WM_invalid = SamplerState::WM_invalid
198 };
199 typedef SamplerState::WrapMode WrapMode;
200
201 enum CompressionMode {
202 // Generic compression modes. Usually, you should choose one of these.
203 CM_default, // on or off, according to compressed-textures
204 CM_off, // uncompressed image
205 CM_on, // whatever compression the driver supports
206
207 // Specific compression modes. Use only when you really want to use a
208 // particular compression algorithm. Use with caution; not all drivers
209 // support all compression modes. You can use
210 // GSG::get_supports_compressed_texture_format() to query the available
211 // compression modes for a particular GSG.
212 CM_fxt1,
213 CM_dxt1, // BC1: RGB with optional binary alpha.
214 CM_dxt2, // Like DXT3, but assumes premultiplied alpha
215 CM_dxt3, // BC2: RGB with uncompressed 4-bit alpha.
216 CM_dxt4, // Like DXT5, but assumes premultiplied alpha
217 CM_dxt5, // BC3: RGB with separately compressed 8-bit alpha.
218 CM_pvr1_2bpp,
219 CM_pvr1_4bpp,
220 CM_rgtc, // BC4/BC5: 1 or 2 channels, individually compressed.
221 CM_etc1,
222 CM_etc2,
223 CM_eac, // EAC: 1 or 2 channels.
224 };
225
226 enum QualityLevel {
227 QL_default, // according to texture-quality-level
228 QL_fastest,
229 QL_normal,
230 QL_best,
231 };
232
233PUBLISHED:
234 explicit Texture(const std::string &name = std::string());
235
236protected:
237 Texture(const Texture &copy);
238 void operator = (const Texture &copy);
239
240PUBLISHED:
241 virtual ~Texture();
242
243 INLINE PT(Texture) make_copy() const;
244 INLINE void clear();
245
246 INLINE void setup_texture(TextureType texture_type,
247 int x_size, int y_size, int z_size,
248 ComponentType component_type, Format format);
249 INLINE void setup_1d_texture();
250 INLINE void setup_1d_texture(int x_size,
251 ComponentType component_type, Format format);
252 INLINE void setup_2d_texture();
253 INLINE void setup_2d_texture(int x_size, int y_size,
254 ComponentType component_type, Format format);
255 INLINE void setup_3d_texture(int z_size = 1);
256 INLINE void setup_3d_texture(int x_size, int y_size, int z_size,
257 ComponentType component_type, Format format);
258 INLINE void setup_cube_map();
259 INLINE void setup_cube_map(int size,
260 ComponentType component_type, Format format);
261 INLINE void setup_2d_texture_array(int z_size = 1);
262 INLINE void setup_2d_texture_array(int x_size, int y_size, int z_size,
263 ComponentType component_type, Format format);
264 INLINE void setup_cube_map_array(int num_cube_maps);
265 INLINE void setup_cube_map_array(int size, int num_cube_maps,
266 ComponentType component_type, Format format);
267 INLINE void setup_buffer_texture(int size, ComponentType component_type,
268 Format format, GeomEnums::UsageHint usage);
269 void generate_normalization_cube_map(int size);
271
272 INLINE void clear_image();
273 INLINE bool has_clear_color() const;
274 INLINE LColor get_clear_color() const;
275 INLINE void set_clear_color(const LColor &color);
276 INLINE void clear_clear_color();
277 INLINE vector_uchar get_clear_data() const;
278 MAKE_PROPERTY2(clear_color, has_clear_color, get_clear_color,
280
281 BLOCKING bool read(const Filename &fullpath, const LoaderOptions &options = LoaderOptions());
282 BLOCKING bool read(const Filename &fullpath, const Filename &alpha_fullpath,
283 int primary_file_num_channels, int alpha_file_channel,
284 const LoaderOptions &options = LoaderOptions());
285 BLOCKING bool read(const Filename &fullpath, int z, int n,
286 bool read_pages, bool read_mipmaps,
287 const LoaderOptions &options = LoaderOptions());
288 BLOCKING bool read(const Filename &fullpath, const Filename &alpha_fullpath,
289 int primary_file_num_channels, int alpha_file_channel,
290 int z, int n, bool read_pages, bool read_mipmaps,
291 BamCacheRecord *record = nullptr,
292 const LoaderOptions &options = LoaderOptions());
293
294 BLOCKING INLINE bool write(const Filename &fullpath);
295 BLOCKING INLINE bool write(const Filename &fullpath, int z, int n,
296 bool write_pages, bool write_mipmaps);
297
298 BLOCKING bool read_txo(std::istream &in, const std::string &filename = "");
299 BLOCKING static PT(Texture) make_from_txo(std::istream &in, const std::string &filename = "");
300 BLOCKING bool write_txo(std::ostream &out, const std::string &filename = "") const;
301 BLOCKING bool read_dds(std::istream &in, const std::string &filename = "", bool header_only = false);
302 BLOCKING bool read_ktx(std::istream &in, const std::string &filename = "", bool header_only = false);
303
304 BLOCKING INLINE bool load(const PNMImage &pnmimage, const LoaderOptions &options = LoaderOptions());
305 BLOCKING INLINE bool load(const PNMImage &pnmimage, int z, int n, const LoaderOptions &options = LoaderOptions());
306 BLOCKING INLINE bool load(const PfmFile &pfm, const LoaderOptions &options = LoaderOptions());
307 BLOCKING INLINE bool load(const PfmFile &pfm, int z, int n, const LoaderOptions &options = LoaderOptions());
308 BLOCKING INLINE bool load_sub_image(const PNMImage &pnmimage, int x, int y, int z=0, int n=0);
309 BLOCKING INLINE bool store(PNMImage &pnmimage) const;
310 BLOCKING INLINE bool store(PNMImage &pnmimage, int z, int n) const;
311 BLOCKING INLINE bool store(PfmFile &pfm) const;
312 BLOCKING INLINE bool store(PfmFile &pfm, int z, int n) const;
313
314 BLOCKING INLINE bool reload();
315 BLOCKING Texture *load_related(const InternalName *suffix) const;
316
317 INLINE bool has_filename() const;
318 INLINE const Filename &get_filename() const;
319 INLINE void set_filename(const Filename &filename);
320 INLINE void clear_filename();
322
323 INLINE bool has_alpha_filename() const;
324 INLINE const Filename &get_alpha_filename() const;
325 INLINE void set_alpha_filename(const Filename &alpha_filename);
326 INLINE void clear_alpha_filename();
328
329 INLINE bool has_fullpath() const;
330 INLINE const Filename &get_fullpath() const;
331 INLINE void set_fullpath(const Filename &fullpath);
332 INLINE void clear_fullpath();
334
335 INLINE bool has_alpha_fullpath() const;
336 INLINE const Filename &get_alpha_fullpath() const;
337 INLINE void set_alpha_fullpath(const Filename &alpha_fullpath);
338 INLINE void clear_alpha_fullpath();
340
341 INLINE int get_x_size() const;
342 INLINE void set_x_size(int x_size);
343 MAKE_PROPERTY(x_size, get_x_size, set_x_size);
344
345 INLINE int get_y_size() const;
346 INLINE void set_y_size(int y_size);
347 MAKE_PROPERTY(y_size, get_y_size, set_y_size);
348
349 INLINE int get_z_size() const;
350 INLINE void set_z_size(int z_size);
351 MAKE_PROPERTY(z_size, get_z_size, set_z_size);
352
353 INLINE int get_num_views() const;
354 INLINE void set_num_views(int num_views);
355 MAKE_PROPERTY(num_views, get_num_views, set_num_views);
356
357 INLINE int get_num_pages() const;
358 INLINE int get_num_components() const;
359 INLINE int get_component_width() const;
360 INLINE TextureType get_texture_type() const;
361 INLINE GeomEnums::UsageHint get_usage_hint() const;
362
363 MAKE_PROPERTY(num_pages, get_num_pages);
364 MAKE_PROPERTY(num_components, get_num_components);
365 MAKE_PROPERTY(component_width, get_component_width);
366 MAKE_PROPERTY(texture_type, get_texture_type);
367 MAKE_PROPERTY(usage_hint, get_usage_hint);
368
369 INLINE Format get_format() const;
370 INLINE void set_format(Format format);
371 MAKE_PROPERTY(format, get_format, set_format);
372
373 INLINE ComponentType get_component_type() const;
374 INLINE void set_component_type(ComponentType component_type);
375 MAKE_PROPERTY(component_type, get_component_type, set_component_type);
376
377 INLINE SamplerState::WrapMode get_wrap_u() const;
378 INLINE void set_wrap_u(WrapMode wrap);
379 MAKE_PROPERTY(wrap_u, get_wrap_u, set_wrap_u);
380
381 INLINE SamplerState::WrapMode get_wrap_v() const;
382 INLINE void set_wrap_v(WrapMode wrap);
383 MAKE_PROPERTY(wrap_v, get_wrap_v, set_wrap_v);
384
385 INLINE SamplerState::WrapMode get_wrap_w() const;
386 INLINE void set_wrap_w(WrapMode wrap);
387 MAKE_PROPERTY(wrap_w, get_wrap_w, set_wrap_w);
388
389 INLINE SamplerState::FilterType get_minfilter() const;
390 INLINE SamplerState::FilterType get_effective_minfilter() const;
391 INLINE void set_minfilter(FilterType filter);
392 MAKE_PROPERTY(minfilter, get_minfilter, set_minfilter);
393 MAKE_PROPERTY(effective_minfilter, get_effective_minfilter);
394
395 INLINE SamplerState::FilterType get_magfilter() const;
396 INLINE SamplerState::FilterType get_effective_magfilter() const;
397 INLINE void set_magfilter(FilterType filter);
398 MAKE_PROPERTY(magfilter, get_magfilter, set_magfilter);
399 MAKE_PROPERTY(effective_magfilter, get_effective_magfilter);
400
401 INLINE int get_anisotropic_degree() const;
402 INLINE int get_effective_anisotropic_degree() const;
403 INLINE void set_anisotropic_degree(int anisotropic_degree);
404 MAKE_PROPERTY(anisotropic_degree, get_anisotropic_degree, set_anisotropic_degree);
405 MAKE_PROPERTY(effective_anisotropic_degree, get_effective_anisotropic_degree);
406
407 INLINE LColor get_border_color() const;
408 INLINE void set_border_color(const LColor &color);
409 MAKE_PROPERTY(border_color, get_border_color, set_border_color);
410
411 INLINE bool has_compression() const;
412 INLINE CompressionMode get_compression() const;
413 INLINE void set_compression(CompressionMode compression);
414 MAKE_PROPERTY(compression, get_compression, set_compression); // Could maybe use has_compression here, too
415
416 INLINE bool get_render_to_texture() const;
417 INLINE void set_render_to_texture(bool render_to_texture);
418 MAKE_PROPERTY(render_to_texture, get_render_to_texture, set_render_to_texture);
419
420 INLINE const SamplerState &get_default_sampler() const;
421 INLINE void set_default_sampler(const SamplerState &sampler);
422 MAKE_PROPERTY(default_sampler, get_default_sampler, set_default_sampler);
423 INLINE bool uses_mipmaps() const;
424
425 INLINE QualityLevel get_quality_level() const;
426 INLINE QualityLevel get_effective_quality_level() const;
427 INLINE void set_quality_level(QualityLevel quality_level);
428 MAKE_PROPERTY(quality_level, get_quality_level, set_quality_level);
429 MAKE_PROPERTY(effective_quality_level, get_effective_quality_level);
430
431 INLINE int get_expected_num_mipmap_levels() const;
432 INLINE int get_expected_mipmap_x_size(int n) const;
433 INLINE int get_expected_mipmap_y_size(int n) const;
434 INLINE int get_expected_mipmap_z_size(int n) const;
435 INLINE int get_expected_mipmap_num_pages(int n) const;
436 MAKE_PROPERTY(expected_num_mipmap_levels, get_expected_num_mipmap_levels);
437
438 INLINE bool has_ram_image() const;
439 INLINE bool has_uncompressed_ram_image() const;
440 INLINE bool might_have_ram_image() const;
441 INLINE size_t get_ram_image_size() const;
442 INLINE size_t get_ram_view_size() const;
443 INLINE size_t get_ram_page_size() const;
444 INLINE size_t get_expected_ram_image_size() const;
445 INLINE size_t get_expected_ram_page_size() const;
446 MAKE_PROPERTY(ram_image_size, get_ram_image_size);
447 MAKE_PROPERTY(ram_view_size, get_ram_view_size);
448 MAKE_PROPERTY(ram_page_size, get_ram_page_size);
449 MAKE_PROPERTY(expected_ram_image_size, get_expected_ram_image_size);
450 MAKE_PROPERTY(expected_ram_page_size, get_expected_ram_page_size);
451
452 INLINE CPTA_uchar get_ram_image();
453 INLINE CompressionMode get_ram_image_compression() const;
454 INLINE CPTA_uchar get_uncompressed_ram_image();
455 CPTA_uchar get_ram_image_as(const std::string &requested_format);
456 INLINE PTA_uchar modify_ram_image();
457 INLINE PTA_uchar make_ram_image();
458#ifndef CPPPARSER
459 INLINE void set_ram_image(CPTA_uchar image, CompressionMode compression = CM_off,
460 size_t page_size = 0);
461 void set_ram_image_as(CPTA_uchar image, const std::string &provided_format);
462#else
463 EXTEND void set_ram_image(PyObject *image, CompressionMode compression = CM_off,
464 size_t page_size = 0);
465 EXTEND void set_ram_image_as(PyObject *image, const std::string &provided_format);
466#endif
467 INLINE void clear_ram_image();
468 INLINE void set_keep_ram_image(bool keep_ram_image);
469 virtual bool get_keep_ram_image() const;
470 virtual bool is_cacheable() const;
471
472 MAKE_PROPERTY(ram_image_compression, get_ram_image_compression);
473 MAKE_PROPERTY(keep_ram_image, get_keep_ram_image, set_keep_ram_image);
474 MAKE_PROPERTY(cacheable, is_cacheable);
475
476 EXTENSION(PT(Texture) __deepcopy__(PyObject *memo) const);
477
478 BLOCKING INLINE bool compress_ram_image(CompressionMode compression = CM_on,
479 QualityLevel quality_level = QL_default,
480 GraphicsStateGuardianBase *gsg = nullptr);
481 BLOCKING INLINE bool uncompress_ram_image();
482
483 INLINE int get_num_ram_mipmap_images() const;
484 INLINE bool has_ram_mipmap_image(int n) const;
486 INLINE bool has_all_ram_mipmap_images() const;
487 INLINE size_t get_ram_mipmap_image_size(int n) const;
488 INLINE size_t get_ram_mipmap_view_size(int n) const;
489 INLINE size_t get_ram_mipmap_page_size(int n) const;
490 INLINE size_t get_expected_ram_mipmap_image_size(int n) const;
491 INLINE size_t get_expected_ram_mipmap_view_size(int n) const;
492 INLINE size_t get_expected_ram_mipmap_page_size(int n) const;
493 CPTA_uchar get_ram_mipmap_image(int n) const;
494 void *get_ram_mipmap_pointer(int n) const;
495 INLINE PTA_uchar modify_ram_mipmap_image(int n);
496 INLINE PTA_uchar make_ram_mipmap_image(int n);
497 void set_ram_mipmap_pointer(int n, void *image, size_t page_size = 0);
498 void set_ram_mipmap_pointer_from_int(long long pointer, int n, int page_size);
499 INLINE void set_ram_mipmap_image(int n, CPTA_uchar image, size_t page_size = 0);
500 void clear_ram_mipmap_image(int n);
501 INLINE void clear_ram_mipmap_images();
502 INLINE void generate_ram_mipmap_images();
503
504 MAKE_PROPERTY(num_ram_mipmap_images, get_num_ram_mipmap_images);
505 MAKE_PROPERTY(num_loadable_ram_mipmap_images, get_num_loadable_ram_mipmap_images);
506
507 INLINE int get_simple_x_size() const;
508 INLINE int get_simple_y_size() const;
509 INLINE bool has_simple_ram_image() const;
510 INLINE size_t get_simple_ram_image_size() const;
511 INLINE CPTA_uchar get_simple_ram_image() const;
512 INLINE void set_simple_ram_image(CPTA_uchar image, int x_size, int y_size);
513 PTA_uchar modify_simple_ram_image();
514 PTA_uchar new_simple_ram_image(int x_size, int y_size);
516 INLINE void clear_simple_ram_image();
517
518 MAKE_PROPERTY(simple_x_size, get_simple_x_size);
519 MAKE_PROPERTY(simple_y_size, get_simple_y_size);
520 MAKE_PROPERTY2(simple_ram_image, has_simple_ram_image, get_simple_ram_image);
521
522 PT(TexturePeeker) peek();
523
524 INLINE UpdateSeq get_properties_modified() const;
525 INLINE UpdateSeq get_image_modified() const;
527 MAKE_PROPERTY(properties_modified, get_properties_modified);
528 MAKE_PROPERTY(image_modified, get_image_modified);
529 MAKE_PROPERTY(simple_image_modified, get_simple_image_modified);
530
531 INLINE bool has_auto_texture_scale() const;
532 INLINE AutoTextureScale get_auto_texture_scale() const;
533 INLINE void set_auto_texture_scale(AutoTextureScale scale);
534 MAKE_PROPERTY(auto_texture_scale, get_auto_texture_scale,
536
537 PT(AsyncFuture) prepare(PreparedGraphicsObjects *prepared_objects);
538 bool is_prepared(PreparedGraphicsObjects *prepared_objects) const;
539 bool was_image_modified(PreparedGraphicsObjects *prepared_objects) const;
540 size_t get_data_size_bytes(PreparedGraphicsObjects *prepared_objects) const;
541 bool get_active(PreparedGraphicsObjects *prepared_objects) const;
542 bool get_resident(PreparedGraphicsObjects *prepared_objects) const;
543
544 bool release(PreparedGraphicsObjects *prepared_objects);
545 int release_all();
546
547 void write(std::ostream &out, int indent_level) const;
548
549 size_t estimate_texture_memory() const;
550
551 void set_aux_data(const std::string &key, TypedReferenceCount *aux_data);
552 void clear_aux_data(const std::string &key);
553 TypedReferenceCount *get_aux_data(const std::string &key) const;
554 MAKE_MAP_PROPERTY(aux_data, get_aux_data, get_aux_data,
556
557 INLINE static void set_textures_power_2(AutoTextureScale scale);
558 INLINE static AutoTextureScale get_textures_power_2();
559 INLINE static bool has_textures_power_2();
560
561PUBLISHED:
562
563 INLINE int get_pad_x_size() const;
564 INLINE int get_pad_y_size() const;
565 INLINE int get_pad_z_size() const;
566 INLINE LVecBase2 get_tex_scale() const;
567
568 INLINE void set_pad_size(int x=0, int y=0, int z=0);
569 void set_size_padded(int x=1, int y=1, int z=1);
570
571 INLINE int get_orig_file_x_size() const;
572 INLINE int get_orig_file_y_size() const;
573 INLINE int get_orig_file_z_size() const;
574
575 MAKE_PROPERTY(orig_file_x_size, get_orig_file_x_size);
576 MAKE_PROPERTY(orig_file_y_size, get_orig_file_y_size);
577 MAKE_PROPERTY(orig_file_z_size, get_orig_file_z_size);
578
579 void set_orig_file_size(int x, int y, int z = 1);
580
581 INLINE void set_loaded_from_image(bool flag = true);
582 INLINE bool get_loaded_from_image() const;
583 MAKE_PROPERTY(loaded_from_image, get_loaded_from_image, set_loaded_from_image);
584
585 INLINE void set_loaded_from_txo(bool flag = true);
586 INLINE bool get_loaded_from_txo() const;
587 MAKE_PROPERTY(loaded_from_txo, get_loaded_from_txo, set_loaded_from_txo);
588
589 INLINE bool get_match_framebuffer_format() const;
590 INLINE void set_match_framebuffer_format(bool flag);
591 MAKE_PROPERTY(match_framebuffer_format, get_match_framebuffer_format,
593
594 INLINE bool get_post_load_store_cache() const;
595 INLINE void set_post_load_store_cache(bool flag);
596 MAKE_PROPERTY(post_load_store_cache, get_post_load_store_cache,
598
599 TextureContext *prepare_now(int view,
600 PreparedGraphicsObjects *prepared_objects,
602
603 static int up_to_power_2(int value);
604 static int down_to_power_2(int value);
605
606 void consider_rescale(PNMImage &pnmimage);
607 static void consider_rescale(PNMImage &pnmimage, const std::string &name, AutoTextureScale auto_texture_scale = ATS_unspecified);
608 INLINE bool rescale_texture();
609
610 static std::string format_texture_type(TextureType tt);
611 static TextureType string_texture_type(const std::string &str);
612
613 static std::string format_component_type(ComponentType ct);
614 static ComponentType string_component_type(const std::string &str);
615
616 static std::string format_format(Format f);
617 static Format string_format(const std::string &str);
618
619 static std::string format_compression_mode(CompressionMode cm);
620 static CompressionMode string_compression_mode(const std::string &str);
621
622 static std::string format_quality_level(QualityLevel tql);
623 static QualityLevel string_quality_level(const std::string &str);
624
625public:
626 void texture_uploaded();
627
628 virtual bool has_cull_callback() const;
629 virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const;
630
631 static PT(Texture) make_texture();
632
633public:
634 static bool is_unsigned(ComponentType ctype);
635 static bool is_specific(CompressionMode compression);
636 static bool has_alpha(Format format);
637 static bool has_binary_alpha(Format format);
638 static bool is_srgb(Format format);
639 static bool is_integer(Format format);
640
641 static bool adjust_size(int &x_size, int &y_size, const std::string &name,
642 bool for_padding, AutoTextureScale auto_texture_scale = ATS_unspecified);
643 INLINE bool adjust_this_size(int &x_size, int &y_size, const std::string &name,
644 bool for_padding) const;
645
646 virtual void ensure_loader_type(const Filename &filename);
647
648protected:
649 class CData;
650 class RamImage;
651
652 virtual void reconsider_dirty();
653
654 // All of the functions in this class that begin "do_" are protected
655 // methods. Many of them are implementations of public-facing versions of
656 // the same methods.
657
658 // All of these assume the CData lock is already held (and receive a CData
659 // pointer representing that lock); generally, they also avoid adjusting the
660 // _properties_modified and _image_modified semaphores.
661 virtual bool do_adjust_this_size(const CData *cdata,
662 int &x_size, int &y_size, const std::string &name,
663 bool for_padding) const;
664
665 virtual bool do_read(CData *cdata,
666 const Filename &fullpath, const Filename &alpha_fullpath,
667 int primary_file_num_channels, int alpha_file_channel,
668 int z, int n, bool read_pages, bool read_mipmaps,
669 const LoaderOptions &options, BamCacheRecord *record);
670 virtual bool do_read_one(CData *cdata,
671 const Filename &fullpath, const Filename &alpha_fullpath,
672 int z, int n, int primary_file_num_channels, int alpha_file_channel,
673 const LoaderOptions &options,
674 bool header_only, BamCacheRecord *record);
675 virtual bool do_load_one(CData *cdata,
676 const PNMImage &pnmimage, const std::string &name,
677 int z, int n, const LoaderOptions &options);
678 virtual bool do_load_one(CData *cdata,
679 const PfmFile &pfm, const std::string &name,
680 int z, int n, const LoaderOptions &options);
681 virtual bool do_load_sub_image(CData *cdata, const PNMImage &image,
682 int x, int y, int z, int n);
683 bool do_read_txo_file(CData *cdata, const Filename &fullpath);
684 bool do_read_txo(CData *cdata, std::istream &in, const std::string &filename);
685 bool do_read_dds_file(CData *cdata, const Filename &fullpath, bool header_only);
686 bool do_read_dds(CData *cdata, std::istream &in, const std::string &filename, bool header_only);
687 bool do_read_ktx_file(CData *cdata, const Filename &fullpath, bool header_only);
688 bool do_read_ktx(CData *cdata, std::istream &in, const std::string &filename, bool header_only);
689
690 bool do_write(CData *cdata, const Filename &fullpath, int z, int n,
691 bool write_pages, bool write_mipmaps);
692 bool do_write_one(CData *cdata, const Filename &fullpath, int z, int n);
693 bool do_store_one(CData *cdata, PNMImage &pnmimage, int z, int n);
694 bool do_store_one(CData *cdata, PfmFile &pfm, int z, int n);
695 bool do_write_txo_file(const CData *cdata, const Filename &fullpath) const;
696 bool do_write_txo(const CData *cdata, std::ostream &out, const std::string &filename) const;
697
698 virtual CData *unlocked_ensure_ram_image(bool allow_compression);
699 virtual void do_reload_ram_image(CData *cdata, bool allow_compression);
700
701 PTA_uchar do_modify_ram_image(CData *cdata);
702 PTA_uchar do_make_ram_image(CData *cdata);
703 void do_set_ram_image(CData *cdata, CPTA_uchar image,
704 CompressionMode compression = CM_off, size_t page_size = 0);
705 PTA_uchar do_modify_ram_mipmap_image(CData *cdata, int n);
706 PTA_uchar do_make_ram_mipmap_image(CData *cdata, int n);
707 void do_set_ram_mipmap_image(CData *cdata, int n, CPTA_uchar image, size_t page_size);
708 size_t do_get_clear_data(const CData *cdata, unsigned char *into) const;
709
710 bool consider_auto_process_ram_image(bool generate_mipmaps, bool allow_compression);
711 bool do_consider_auto_process_ram_image(CData *cdata, bool generate_mipmaps,
712 bool allow_compression);
713 bool do_compress_ram_image(CData *cdata, CompressionMode compression,
714 QualityLevel quality_level,
716 bool do_uncompress_ram_image(CData *cdata);
717
718 static void do_compress_ram_image_bc4(const RamImage &src, RamImage &dest,
719 int x_size, int y_size, int z_size);
720 static void do_compress_ram_image_bc5(const RamImage &src, RamImage &dest,
721 int x_size, int y_size, int z_size);
722 static void do_uncompress_ram_image_bc4(const RamImage &src, RamImage &dest,
723 int x_size, int y_size, int z_size);
724 static void do_uncompress_ram_image_bc5(const RamImage &src, RamImage &dest,
725 int x_size, int y_size, int z_size);
726 bool do_has_all_ram_mipmap_images(const CData *cdata) const;
727
728 bool do_reconsider_z_size(CData *cdata, int z, const LoaderOptions &options);
729 virtual void do_allocate_pages(CData *cdata);
730 bool do_reconsider_image_properties(CData *cdata,
731 int x_size, int y_size, int num_components,
732 ComponentType component_type, int z,
733 const LoaderOptions &options);
734 bool do_rescale_texture(CData *cdata);
735
736 virtual PT(Texture) make_copy_impl() const;
737 PT(Texture) do_make_copy(const CData *cdata) const;
738 void do_assign(CData *cdata, const Texture *copy, const CData *cdata_copy);
739 virtual void do_clear(CData *cdata);
740 void do_setup_texture(CData *cdata,
741 TextureType texture_type, int x_size, int y_size,
742 int z_size, ComponentType component_type,
743 Format format);
744 void do_set_num_views(CData *cdata, int num_views);
745 void do_set_format(CData *cdata, Format format);
746 void do_set_component_type(CData *cdata, ComponentType component_type);
747 void do_set_x_size(CData *cdata, int x_size);
748 void do_set_y_size(CData *cdata, int y_size);
749 void do_set_z_size(CData *cdata, int z_size);
750
751 void do_set_wrap_u(CData *cdata, WrapMode wrap);
752 void do_set_wrap_v(CData *cdata, WrapMode wrap);
753 void do_set_wrap_w(CData *cdata, WrapMode wrap);
754 void do_set_minfilter(CData *cdata, FilterType filter);
755 void do_set_magfilter(CData *cdata, FilterType filter);
756 void do_set_anisotropic_degree(CData *cdata, int anisotropic_degree);
757 void do_set_border_color(CData *cdata, const LColor &color);
758 void do_set_compression(CData *cdata, CompressionMode compression);
759 void do_set_quality_level(CData *cdata, QualityLevel quality_level);
760
761 bool do_has_compression(const CData *cdata) const;
762 virtual bool do_has_ram_image(const CData *cdata) const;
763 virtual bool do_has_uncompressed_ram_image(const CData *cdata) const;
764 CPTA_uchar do_get_ram_image(CData *cdata);
765 CPTA_uchar do_get_uncompressed_ram_image(CData *cdata);
766 void do_set_simple_ram_image(CData *cdata, CPTA_uchar image, int x_size, int y_size);
767 INLINE size_t do_get_ram_image_size(const CData *cdata) const;
768 INLINE bool do_has_ram_mipmap_image(const CData *cdata, int n) const;
769 int do_get_expected_num_mipmap_levels(const CData *cdata) const;
770 INLINE size_t do_get_expected_ram_image_size(const CData *cdata) const;
771 INLINE size_t do_get_expected_ram_view_size(const CData *cdata) const;
772 INLINE size_t do_get_expected_ram_page_size(const CData *cdata) const;
773 size_t do_get_ram_mipmap_page_size(const CData *cdata, int n) const;
774 INLINE size_t do_get_expected_ram_mipmap_image_size(const CData *cdata, int n) const;
775 INLINE size_t do_get_expected_ram_mipmap_view_size(const CData *cdata, int n) const;
776 INLINE size_t do_get_expected_ram_mipmap_page_size(const CData *cdata, int n) const;
777 int do_get_expected_mipmap_x_size(const CData *cdata, int n) const;
778 int do_get_expected_mipmap_y_size(const CData *cdata, int n) const;
779 int do_get_expected_mipmap_z_size(const CData *cdata, int n) const;
780 INLINE int do_get_expected_mipmap_num_pages(const CData *cdata, int n) const;
781 INLINE void do_clear_ram_image(CData *cdata);
782 void do_clear_simple_ram_image(CData *cdata);
783 void do_clear_ram_mipmap_images(CData *cdata);
784 void do_generate_ram_mipmap_images(CData *cdata, bool allow_recompress);
785 void do_set_pad_size(CData *cdata, int x, int y, int z);
786 virtual bool do_can_reload(const CData *cdata) const;
787 bool do_reload(CData *cdata);
788
789 INLINE AutoTextureScale do_get_auto_texture_scale(const CData *cdata) const;
790
791 virtual bool do_has_bam_rawdata(const CData *cdata) const;
792 virtual void do_get_bam_rawdata(CData *cdata);
793
794 // This nested class declaration is used below.
795 class RamImage {
796 public:
797 INLINE RamImage();
798
799 PTA_uchar _image;
800 size_t _page_size;
801
802 // If _pointer_image is non-NULL, it represents an external block of
803 // memory that is used instead of the above PTA_uchar.
804 void *_pointer_image;
805 };
806
807private:
808 static void convert_from_pnmimage(PTA_uchar &image, size_t page_size,
809 int row_stride, int x, int y, int z,
810 const PNMImage &pnmimage,
811 int num_components, int component_width);
812 static void convert_from_pfm(PTA_uchar &image, size_t page_size,
813 int z, const PfmFile &pfm,
814 int num_components, int component_width);
815 static bool convert_to_pnmimage(PNMImage &pnmimage, int x_size, int y_size,
816 int num_components,
817 ComponentType component_type, bool is_srgb,
818 CPTA_uchar image, size_t page_size,
819 int z);
820 static bool convert_to_pfm(PfmFile &pfm, int x_size, int y_size,
821 int num_components, int component_width,
822 CPTA_uchar image, size_t page_size,
823 int z);
824 static PTA_uchar read_dds_level_bgr8(Texture *tex, CData *cdata, const DDSHeader &header,
825 int n, std::istream &in);
826 static PTA_uchar read_dds_level_rgb8(Texture *tex, CData *cdata, const DDSHeader &header,
827 int n, std::istream &in);
828 static PTA_uchar read_dds_level_abgr8(Texture *tex, CData *cdata, const DDSHeader &header,
829 int n, std::istream &in);
830 static PTA_uchar read_dds_level_rgba8(Texture *tex, CData *cdata, const DDSHeader &header,
831 int n, std::istream &in);
832 static PTA_uchar read_dds_level_abgr16(Texture *tex, CData *cdata, const DDSHeader &header,
833 int n, std::istream &in);
834 static PTA_uchar read_dds_level_abgr32(Texture *tex, CData *cdata, const DDSHeader &header,
835 int n, std::istream &in);
836 static PTA_uchar read_dds_level_raw(Texture *tex, CData *cdata, const DDSHeader &header,
837 int n, std::istream &in);
838 static PTA_uchar read_dds_level_generic_uncompressed(Texture *tex, CData *cdata,
839 const DDSHeader &header,
840 int n, std::istream &in);
841 static PTA_uchar read_dds_level_luminance_uncompressed(Texture *tex, CData *cdata,
842 const DDSHeader &header,
843 int n, std::istream &in);
844 static PTA_uchar read_dds_level_bc1(Texture *tex, CData *cdata,
845 const DDSHeader &header,
846 int n, std::istream &in);
847 static PTA_uchar read_dds_level_bc2(Texture *tex, CData *cdata,
848 const DDSHeader &header,
849 int n, std::istream &in);
850 static PTA_uchar read_dds_level_bc3(Texture *tex, CData *cdata,
851 const DDSHeader &header,
852 int n, std::istream &in);
853 static PTA_uchar read_dds_level_bc4(Texture *tex, CData *cdata,
854 const DDSHeader &header,
855 int n, std::istream &in);
856 static PTA_uchar read_dds_level_bc5(Texture *tex, CData *cdata,
857 const DDSHeader &header,
858 int n, std::istream &in);
859
860 void clear_prepared(int view, PreparedGraphicsObjects *prepared_objects);
861
862 static void consider_downgrade(PNMImage &pnmimage, int num_channels, const std::string &name);
863
864 static bool compare_images(const PNMImage &a, const PNMImage &b);
865
866 INLINE static void store_unscaled_byte(unsigned char *&p, int value);
867 INLINE static void store_unscaled_short(unsigned char *&p, int value);
868 INLINE static void store_scaled_byte(unsigned char *&p, int value, double scale);
869 INLINE static void store_scaled_short(unsigned char *&p, int value, double scale);
870 INLINE static double get_unsigned_byte(const unsigned char *&p);
871 INLINE static double get_unsigned_short(const unsigned char *&p);
872 INLINE static double get_unsigned_int(const unsigned char *&p);
873 INLINE static double get_unsigned_int_24(const unsigned char *&p);
874 INLINE static double get_float(const unsigned char *&p);
875 INLINE static double get_half_float(const unsigned char *&p);
876
877 INLINE static bool is_txo_filename(const Filename &fullpath);
878 INLINE static bool is_dds_filename(const Filename &fullpath);
879 INLINE static bool is_ktx_filename(const Filename &fullpath);
880
881 void do_filter_2d_mipmap_pages(const CData *cdata,
882 RamImage &to, const RamImage &from,
883 int x_size, int y_size) const;
884
885 void do_filter_3d_mipmap_level(const CData *cdata,
886 RamImage &to, const RamImage &from,
887 int x_size, int y_size, int z_size) const;
888
889 typedef void Filter2DComponent(unsigned char *&p,
890 const unsigned char *&q,
891 size_t pixel_size, size_t row_size);
892
893 typedef void Filter3DComponent(unsigned char *&p,
894 const unsigned char *&q,
895 size_t pixel_size, size_t row_size,
896 size_t page_size);
897
898 static void filter_2d_unsigned_byte(unsigned char *&p,
899 const unsigned char *&q,
900 size_t pixel_size, size_t row_size);
901 static void filter_2d_unsigned_byte_srgb(unsigned char *&p,
902 const unsigned char *&q,
903 size_t pixel_size, size_t row_size);
904 static void filter_2d_unsigned_byte_srgb_sse2(unsigned char *&p,
905 const unsigned char *&q,
906 size_t pixel_size, size_t row_size);
907 static void filter_2d_unsigned_short(unsigned char *&p,
908 const unsigned char *&q,
909 size_t pixel_size, size_t row_size);
910 static void filter_2d_float(unsigned char *&p, const unsigned char *&q,
911 size_t pixel_size, size_t row_size);
912
913 static void filter_3d_unsigned_byte(unsigned char *&p,
914 const unsigned char *&q,
915 size_t pixel_size, size_t row_size,
916 size_t page_size);
917 static void filter_3d_unsigned_byte_srgb(unsigned char *&p,
918 const unsigned char *&q,
919 size_t pixel_size, size_t row_size,
920 size_t page_size);
921 static void filter_3d_unsigned_byte_srgb_sse2(unsigned char *&p,
922 const unsigned char *&q,
923 size_t pixel_size, size_t row_size,
924 size_t page_size);
925 static void filter_3d_unsigned_short(unsigned char *&p,
926 const unsigned char *&q,
927 size_t pixel_size, size_t row_size,
928 size_t page_size);
929 static void filter_3d_float(unsigned char *&p, const unsigned char *&q,
930 size_t pixel_size, size_t row_size, size_t page_size);
931
932 bool do_squish(CData *cdata, CompressionMode compression, int squish_flags);
933 bool do_unsquish(CData *cdata, int squish_flags);
934
935protected:
936 typedef pvector<RamImage> RamImages;
937
938 // This is the data that must be cycled between pipeline stages.
939 class EXPCL_PANDA_GOBJ CData : public CycleData {
940 public:
941 CData();
942 CData(const CData &copy);
943 ALLOC_DELETED_CHAIN(CData);
944 virtual CycleData *make_copy() const;
945 virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
946 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
947 virtual void fillin(DatagramIterator &scan, BamReader *manager);
948 virtual TypeHandle get_parent_type() const {
949 return Texture::get_class_type();
950 }
951
952 void do_assign(const CData *copy);
953 INLINE void inc_properties_modified();
954 INLINE void inc_image_modified();
955 INLINE void inc_simple_image_modified();
956
957 Filename _filename;
958 Filename _alpha_filename;
959 Filename _fullpath;
960 Filename _alpha_fullpath;
961
962 // The number of channels of the primary file we use. 1, 2, 3, or 4.
963 int _primary_file_num_channels;
964
965 // If we have a separate alpha file, this designates which channel in the
966 // alpha file provides the alpha channel. 0 indicates the combined
967 // grayscale value of rgb; otherwise, 1, 2, 3, or 4 are valid.
968 int _alpha_file_channel;
969
970 int _x_size;
971 int _y_size;
972 int _z_size;
973 int _num_views;
974 int _num_components;
975 int _component_width;
976 TextureType _texture_type;
977 Format _format;
978 ComponentType _component_type;
979 GeomEnums::UsageHint _usage_hint;
980
981 bool _loaded_from_image;
982 bool _loaded_from_txo;
983 bool _has_read_pages;
984 bool _has_read_mipmaps;
985 int _num_mipmap_levels_read;
986
987 SamplerState _default_sampler;
988 bool _keep_ram_image;
989 LColor _border_color;
990 CompressionMode _compression;
991 bool _render_to_texture;
992 bool _match_framebuffer_format;
993 bool _post_load_store_cache;
994 QualityLevel _quality_level;
995
996 int _pad_x_size;
997 int _pad_y_size;
998 int _pad_z_size;
999
1000 int _orig_file_x_size;
1001 int _orig_file_y_size;
1002
1003 AutoTextureScale _auto_texture_scale;
1004 CompressionMode _ram_image_compression;
1005
1006 // There is usually one RamImage for the mipmap level 0 (the base image).
1007 // There may or may not also be additional images for the additional
1008 // mipmap levels.
1009 RamImages _ram_images;
1010
1011 // This is the simple image, which may be loaded before the texture is
1012 // loaded from disk. It exists only for 2-d textures.
1013 RamImage _simple_ram_image;
1014 int _simple_x_size;
1015 int _simple_y_size;
1016 int32_t _simple_image_date_generated;
1017
1018 // This is the color that should be used when no image was given.
1019 bool _has_clear_color;
1020 LColor _clear_color;
1021
1022 UpdateSeq _properties_modified;
1023 UpdateSeq _image_modified;
1024 UpdateSeq _simple_image_modified;
1025
1026 public:
1027 static TypeHandle get_class_type() {
1028 return _type_handle;
1029 }
1030 static void init_type() {
1031 register_type(_type_handle, "Texture::CData");
1032 }
1033
1034 private:
1035 static TypeHandle _type_handle;
1036 };
1037
1038 PipelineCycler<CData> _cycler;
1039 typedef CycleDataLockedReader<CData> CDLockedReader;
1040 typedef CycleDataReader<CData> CDReader;
1041 typedef CycleDataWriter<CData> CDWriter;
1042 typedef CycleDataStageReader<CData> CDStageReader;
1043 typedef CycleDataStageWriter<CData> CDStageWriter;
1044
1045 // Protects the remaining members of this class.
1046 Mutex _lock;
1047
1048 // Used to implement unlocked_reload_ram_image().
1049 ConditionVarFull _cvar; // condition: _reloading is true.
1050 bool _reloading;
1051
1052 // A Texture keeps a list (actually, a map) of all the
1053 // PreparedGraphicsObjects tables that it has been prepared into. Each PGO
1054 // conversely keeps a list (a set) of all the Textures that have been
1055 // prepared there. When either destructs, it removes itself from the
1056 // other's list.
1057 typedef pmap<int, TextureContext *> Contexts;
1058 typedef pmap<PreparedGraphicsObjects *, Contexts> PreparedViews;
1059 PreparedViews _prepared_views;
1060
1061 // It is common, when using normal maps, specular maps, gloss maps, and
1062 // such, to use a file naming convention where the filenames of the special
1063 // maps are derived by concatenating a suffix to the name of the diffuse
1064 // map. The following table enables lookup of the special maps given the
1065 // diffuse map and the suffix.
1066 typedef pmap<CPT(InternalName), PT(Texture)> RelatedTextures;
1067 RelatedTextures _related_textures;
1068
1069 // The TexturePool finds this useful.
1070 Filename _texture_pool_key;
1071
1072private:
1073 // The auxiliary data is not recorded to a bam file.
1074 typedef pmap<std::string, PT(TypedReferenceCount) > AuxData;
1075 AuxData _aux_data;
1076
1077 static AutoTextureScale _textures_power_2;
1078 static PStatCollector _texture_read_pcollector;
1079
1080 // Datagram stuff
1081public:
1082 static void register_with_read_factory();
1083 virtual void write_datagram(BamWriter *manager, Datagram &me);
1084
1085 virtual void finalize(BamReader *manager);
1086
1087protected:
1088 void do_write_datagram_header(CData *cdata, BamWriter *manager, Datagram &me, bool &has_rawdata);
1089 virtual void do_write_datagram_body(CData *cdata, BamWriter *manager, Datagram &me);
1090 virtual void do_write_datagram_rawdata(CData *cdata, BamWriter *manager, Datagram &me);
1091 static TypedWritable *make_from_bam(const FactoryParams &params);
1092 virtual TypedWritable *make_this_from_bam(const FactoryParams &params);
1093 virtual void do_fillin_body(CData *cdata, DatagramIterator &scan, BamReader *manager);
1094 virtual void do_fillin_rawdata(CData *cdata, DatagramIterator &scan, BamReader *manager);
1095 virtual void do_fillin_from(CData *cdata, const Texture *dummy);
1096
1097public:
1098 static TypeHandle get_class_type() {
1099 return _type_handle;
1100 }
1101 static void init_type() {
1102 TypedWritableReferenceCount::init_type();
1103 register_type(_type_handle, "Texture",
1104 TypedWritableReferenceCount::get_class_type());
1105 CData::init_type();
1106 }
1107 virtual TypeHandle get_type() const {
1108 return get_class_type();
1109 }
1110 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
1111
1112private:
1113
1114 static TypeHandle _type_handle;
1115
1116 friend class Extension<Texture>;
1117 friend class TextureContext;
1118 friend class PreparedGraphicsObjects;
1119 friend class TexturePool;
1120 friend class TexturePeeker;
1121};
1122
1123extern EXPCL_PANDA_GOBJ ConfigVariableEnum<Texture::QualityLevel> texture_quality_level;
1124
1125EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, Texture::TextureType tt);
1126EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, Texture::ComponentType ct);
1127EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, Texture::Format f);
1128
1129EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, Texture::CompressionMode cm);
1130EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, Texture::QualityLevel tql);
1131EXPCL_PANDA_GOBJ std::istream &operator >> (std::istream &in, Texture::QualityLevel &tql);
1132
1133#include "texture.I"
1134
1135#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class represents a thread-safe handle to a promised future result of an asynchronous operation,...
Definition asyncFuture.h:61
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
This class specializes ConfigVariable as an enumerated type.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
A single page of data maintained by a PipelineCycler.
Definition cycleData.h:50
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Encodes a string name in a hash table, mapping it to a pointer.
Specifies parameters that may be passed to the loader.
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
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component,...
Definition pfmFile.h:31
A table of objects that are saved within the graphics context for reference by handle later.
Represents a set of settings that indicate how a texture is sampled.
This is a special class object that holds all the information returned by a particular GSG to indicat...
An instance of this object is returned by Texture::peek().
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
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
void setup_2d_texture()
Sets the texture as an empty 2-d texture with no dimensions.
Definition texture.I:88
CPTA_uchar get_ram_image_as(const std::string &requested_format)
Returns the uncompressed system-RAM image data associated with the texture.
Definition texture.cxx:7397
static TextureType string_texture_type(const std::string &str)
Returns the TextureType corresponding to the indicated string word.
Definition texture.cxx:2103
virtual void ensure_loader_type(const Filename &filename)
May be called prior to calling read_txo() or any bam-related Texture- creating callback,...
Definition texture.cxx:2836
get_post_load_store_cache
Returns the setting of the post_load_store_cache flag.
Definition texture.h:597
set_compression
Requests that this particular Texture be compressed when it is loaded into texture memory.
Definition texture.h:414
set_alpha_fullpath
Sets the full pathname to the file that contains the image's alpha channel contents,...
Definition texture.h:339
static PT(Texture) make_from_txo(std bool write_txo(std::ostream &out, const std::string &filename="") const
Writes the texture to a Panda texture object.
Definition texture.cxx:928
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
get_format
Returns the format of the texture, which represents both the semantic meaning of the texels and,...
Definition texture.h:371
get_minfilter
Returns the filter mode of the texture for minification.
Definition texture.h:392
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
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
has_filename
Returns true if the filename has been set and is available.
Definition texture.h:321
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
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
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
void clear_image()
Clears the texture data without changing its format or resolution.
Definition texture.I:231
PTA_uchar modify_ram_image()
Returns a modifiable pointer to the system-RAM image.
Definition texture.I:1383
TextureContext * prepare_now(int view, PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg)
Creates a context for the texture on the particular GSG, if it does not already exist.
Definition texture.cxx:1981
void setup_cube_map_array(int num_cube_maps)
Sets the texture as cube map array with N cube maps.
Definition texture.I:183
static std::string format_component_type(ComponentType ct)
Returns the indicated ComponentType converted to a string word.
Definition texture.cxx:2129
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
get_alpha_fullpath
Returns the alpha_fullpath that has been set.
Definition texture.h:339
Texture(const std::string &name=std::string())
Constructs an empty texture.
Definition texture.cxx:375
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
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
bool get_resident(PreparedGraphicsObjects *prepared_objects) const
Returns true if this Texture is reported to be resident within graphics memory for the indicated GSG.
Definition texture.cxx:1546
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 * load_related(const InternalName *suffix) const
Loads a texture whose filename is derived by concatenating a suffix to the filename of this texture.
Definition texture.cxx:973
static CompressionMode string_compression_mode(const std::string &str)
Returns the CompressionMode value associated with the given string representation.
Definition texture.cxx:2462
set_z_size
Changes the z size indicated for the texture.
Definition texture.h:351
set_num_views
Sets the number of "views" within a texture.
Definition texture.h:355
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
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
PTA_uchar new_simple_ram_image(int x_size, int y_size)
Creates an empty array for the simple ram image of the indicated size, and returns a modifiable point...
Definition texture.cxx:1303
static bool is_specific(CompressionMode compression)
Returns true if the indicated compression mode is one of the specific compression types,...
Definition texture.cxx:2616
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
get_num_views
Returns the number of "views" in the texture.
Definition texture.h:355
get_compression
Returns the compression mode requested for this particular texture, or CM_off if the texture is not t...
Definition texture.h:414
get_wrap_w
Returns the wrap mode of the texture in the W direction.
Definition texture.h:387
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
static std::string format_quality_level(QualityLevel tql)
Returns the indicated QualityLevel converted to a string word.
Definition texture.cxx:2505
size_t estimate_texture_memory() const
Estimates the amount of texture memory that will be consumed by loading this texture.
Definition texture.cxx:675
bool read(const Filename &fullpath, const LoaderOptions &options=LoaderOptions())
Reads the named filename into the texture.
Definition texture.cxx:551
void consider_rescale(PNMImage &pnmimage)
Asks the PNMImage to change its scale when it reads the image, according to the whims of the Config....
Definition texture.cxx:2039
get_texture_type
Returns the overall interpretation of the texture.
Definition texture.h:366
bool write(const Filename &fullpath)
Writes the texture to the named filename.
Definition texture.I:299
static bool has_binary_alpha(Format format)
Returns true if the indicated format includes a binary alpha only, false otherwise.
Definition texture.cxx:2663
get_filename
Returns the filename that has been set.
Definition texture.h:321
get_default_sampler
This returns the default sampler state for this texture, containing the wrap and filter properties sp...
Definition texture.h:422
int get_pad_y_size() const
Returns size of the pad region.
Definition texture.I:630
void * get_ram_mipmap_pointer(int n) const
Similiar to get_ram_mipmap_image(), however, in this case the void pointer for the given ram image is...
Definition texture.cxx:1228
CPTA_uchar get_ram_image()
Returns the system-RAM image data associated with the texture.
Definition texture.I:1357
static std::string format_compression_mode(CompressionMode cm)
Returns the indicated CompressionMode converted to a string word.
Definition texture.cxx:2420
get_simple_ram_image
Returns the image data associated with the "simple" texture image.
Definition texture.h:520
get_aux_data
Returns a record previously recorded via set_aux_data().
Definition texture.h:555
has_fullpath
Returns true if the fullpath has been set and is available.
Definition texture.h:333
static bool is_srgb(Format format)
Returns true if the indicated format is in the sRGB color space, false otherwise.
Definition texture.cxx:2678
get_ram_image_compression
Returns the compression mode in which the ram image is already stored pre- compressed.
Definition texture.h:472
get_effective_anisotropic_degree
Returns the degree of anisotropic filtering that should be applied to the texture.
Definition texture.h:405
set_format
Changes the format value for the texture components.
Definition texture.h:371
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
get_component_width
Returns the number of bytes stored for each color component of a texel.
Definition texture.h:365
void set_orig_file_size(int x, int y, int z=1)
Specifies the size of the texture as it exists in its original disk file, before any Panda scaling.
Definition texture.cxx:1961
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
get_alpha_filename
Returns the alpha_filename that has been set.
Definition texture.h:327
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
bool get_active(PreparedGraphicsObjects *prepared_objects) const
Returns true if this Texture was rendered in the most recent frame within the indicated GSG.
Definition texture.cxx:1519
bool load(const PNMImage &pnmimage, const LoaderOptions &options=LoaderOptions())
Replaces the texture with the indicated image.
Definition texture.I:358
clear_fullpath
Removes the fullpath, if it was previously set.
Definition texture.h:333
bool reload()
Re-reads the Texture from its disk file.
Definition texture.I:473
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
void clear_simple_ram_image()
Discards the current "simple" image.
Definition texture.I:1780
get_effective_minfilter
Returns the filter mode of the texture for minification, with special treatment for FT_default.
Definition texture.h:393
bool rescale_texture()
This method is similar to consider_rescale(), but instead of scaling a separate PNMImage,...
Definition texture.I:2144
get_keep_ram_image
Returns the flag that indicates whether this Texture is eligible to have its main RAM copy of the tex...
Definition texture.h:473
bool read_dds(std::istream &in, const std::string &filename="", bool header_only=false)
Reads the texture from a DDS file object.
Definition texture.cxx:943
set_anisotropic_degree
Specifies the level of anisotropic filtering to apply to the texture.
Definition texture.h:404
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
set_loaded_from_image
Sets the flag that indicates the texture has been loaded from a disk file or PNMImage.
Definition texture.h:583
set_quality_level
Sets a hint to the renderer about the desired performance / quality tradeoff for this particular text...
Definition texture.h:428
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
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
void generate_normalization_cube_map(int size)
Generates a special cube map image in the texture that can be used to apply bump mapping effects: for...
Definition texture.cxx:424
clear_alpha_fullpath
Removes the alpha fullpath, if it was previously set.
Definition texture.h:339
void setup_cube_map()
Sets the texture as an empty cube map texture with no dimensions.
Definition texture.I:156
get_anisotropic_degree
Returns the degree of anisotropic filtering that should be applied to the texture.
Definition texture.h:404
has_alpha_fullpath
Returns true if the alpha_fullpath has been set and is available.
Definition texture.h:339
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
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
get_properties_modified
Returns a sequence number which is guaranteed to change at least every time the texture properties (u...
Definition texture.h:527
clear_alpha_filename
Removes the alpha filename, if it was previously set.
Definition texture.h:327
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
static QualityLevel string_quality_level(const std::string &str)
Returns the QualityLevel value associated with the given string representation.
Definition texture.cxx:2525
get_y_size
Returns the height of the texture image in texels.
Definition texture.h:347
void generate_alpha_scale_map()
Generates a special 256x1 1-d texture that can be used to apply an arbitrary alpha scale to objects b...
Definition texture.cxx:526
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
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
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
get_magfilter
Returns the filter mode of the texture for magnification.
Definition texture.h:398
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
get_z_size
Returns the depth of the texture image in texels.
Definition texture.h:351
bool read_txo(std::istream &in, const std::string &filename="")
Reads the texture from a Panda texture object.
Definition texture.cxx:845
int get_pad_x_size() const
Returns size of the pad region.
Definition texture.I:621
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
set_x_size
Changes the x size indicated for the texture.
Definition texture.h:343
get_quality_level
Returns the current quality_level hint.
Definition texture.h:428
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
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
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
void setup_1d_texture()
Sets the texture as an empty 1-d texture with no dimensions.
Definition texture.I:67
static ComponentType string_component_type(const std::string &str)
Returns the ComponentType corresponding to the indicated string word.
Definition texture.cxx:2158
set_minfilter
Sets the filtering method that should be used when viewing the texture from a distance.
Definition texture.h:392
get_effective_magfilter
Returns the filter mode of the texture for magnification, with special treatment for FT_default.
Definition texture.h:399
static bool adjust_size(int &x_size, int &y_size, const std::string &name, bool for_padding, AutoTextureScale auto_texture_scale=ATS_unspecified)
Computes the proper size of the texture, based on the original size, the filename,...
Definition texture.cxx:2726
has_alpha_filename
Returns true if the alpha_filename has been set and is available.
Definition texture.h:327
static int up_to_power_2(int value)
Returns the smallest power of 2 greater than or equal to value.
Definition texture.cxx:2008
set_magfilter
Sets the filtering method that should be used when viewing the texture up close.
Definition texture.h:398
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
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
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
int get_pad_z_size() const
Returns size of the pad region.
Definition texture.I:639
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
get_loaded_from_image
Returns the flag that indicates the texture has been loaded from a disk file or PNMImage.
Definition texture.h:583
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
void set_ram_mipmap_pointer_from_int(long long pointer, int n, int page_size)
Accepts a raw pointer cast as an int, which is then passed to set_ram_mipmap_pointer(); see the docum...
Definition texture.cxx:1269
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
void set_pad_size(int x=0, int y=0, int z=0)
Sets the size of the pad region.
Definition texture.I:678
static int down_to_power_2(int value)
Returns the largest power of 2 less than or equal to value.
Definition texture.cxx:2020
bool release(PreparedGraphicsObjects *prepared_objects)
Frees the texture context only on the indicated object, if it exists there.
Definition texture.cxx:1573
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
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
Definition texture.cxx:2574
void set_simple_ram_image(CPTA_uchar image, int x_size, int y_size)
Replaces the internal "simple" texture image.
Definition texture.I:1771
get_num_components
Returns the number of color components for each texel of the texture image.
Definition texture.h:364
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
void clear_ram_image()
Discards the current system-RAM image.
Definition texture.I:1440
bool uses_mipmaps() const
Returns true if the minfilter settings on this texture indicate the use of mipmapping,...
Definition texture.I:1128
static std::string format_texture_type(TextureType tt)
Returns the indicated TextureType converted to a string word.
Definition texture.cxx:2077
get_fullpath
Returns the fullpath that has been set.
Definition texture.h:333
set_default_sampler
This sets the default sampler state for this texture, containing the wrap and filter properties speci...
Definition texture.h:422
has_clear_color
Returns true if a color was previously set using set_clear_color.
Definition texture.h:279
get_wrap_u
Returns the wrap mode of the texture in the U direction.
Definition texture.h:379
set_loaded_from_txo
Sets the flag that indicates the texture has been loaded from a txo file.
Definition texture.h:587
get_num_pages
Returns the total number of pages in the texture.
Definition texture.h:363
has_simple_ram_image
Returns true if the Texture has a "simple" image available in main RAM.
Definition texture.h:520
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
static bool is_integer(Format format)
Returns true if the indicated format is an integer format, false otherwise.
Definition texture.cxx:2695
PTA_uchar modify_simple_ram_image()
Returns a modifiable pointer to the internal "simple" texture image.
Definition texture.cxx:1292
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
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
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
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
void clear_ram_mipmap_image(int n)
Discards the current system-RAM image for the nth mipmap level.
Definition texture.cxx:1277
bool was_image_modified(PreparedGraphicsObjects *prepared_objects) const
Returns true if the texture needs to be re-loaded onto the indicated GSG, either because its image da...
Definition texture.cxx:1460
bool read_ktx(std::istream &in, const std::string &filename="", bool header_only=false)
Reads the texture from a KTX file object.
Definition texture.cxx:960
get_x_size
Returns the width of the texture image in texels.
Definition texture.h:343
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
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
clear_clear_color
The opposite of set_clear_color.
Definition texture.h:279
size_t get_data_size_bytes(PreparedGraphicsObjects *prepared_objects) const
Returns the number of bytes which the texture is reported to consume within graphics memory,...
Definition texture.cxx:1492
get_simple_y_size
Returns the height of the "simple" image in texels.
Definition texture.h:519
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
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
virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
Definition texture.cxx:2588
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
bool uncompress_ram_image()
Attempts to uncompress the texture's RAM image internally.
Definition texture.I:1499
set_y_size
Changes the y size indicated for the texture.
Definition texture.h:347
bool is_prepared(PreparedGraphicsObjects *prepared_objects) const
Returns true if the texture has already been prepared or enqueued for preparation on the indicated GS...
Definition texture.cxx:1444
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
set_post_load_store_cache
Sets the post_load_store_cache flag.
Definition texture.h:597
void set_ram_image_as(CPTA_uchar image, const std::string &provided_format)
Replaces the current system-RAM image with the new data, converting it first if necessary from the in...
Definition texture.cxx:1025
void set_ram_mipmap_pointer(int n, void *image, size_t page_size=0)
Sets an explicit void pointer as the texture's mipmap image for the indicated level.
Definition texture.cxx:1247
set_aux_data
Records an arbitrary object in the Texture, associated with a specified key.
Definition texture.h:555
set_wrap_w
The W wrap direction is only used for 3-d textures.
Definition texture.h:387
void texture_uploaded()
This method is called by the GraphicsEngine at the beginning of the frame *after* a texture has been ...
Definition texture.cxx:2551
void set_size_padded(int x=1, int y=1, int z=1)
Changes the size of the texture, padding if necessary, and setting the pad region as well.
Definition texture.cxx:1932
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
static bool has_alpha(Format format)
Returns true if the indicated format includes alpha, false otherwise.
Definition texture.cxx:2632
get_component_type
Returns the numeric interpretation of each component of the texture.
Definition texture.h:375
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
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
get_simple_x_size
Returns the width of the "simple" image in texels.
Definition texture.h:518
get_loaded_from_txo
Returns the flag that indicates the texture has been loaded from a txo file.
Definition texture.h:587
get_num_loadable_ram_mipmap_images
Returns the number of contiguous mipmap levels that exist in RAM, up until the first gap in the seque...
Definition texture.h:505
get_wrap_v
Returns the wrap mode of the texture in the V direction.
Definition texture.h:383
void generate_simple_ram_image()
Computes the "simple" ram image by loading the main RAM image, if it is not already available,...
Definition texture.cxx:1324
static Format string_format(const std::string &str)
Returns the Format corresponding to the indicated string word.
Definition texture.cxx:2302
get_border_color
Returns the solid color of the texture's border.
Definition texture.h:409
clear_aux_data
Removes a record previously recorded via set_aux_data().
Definition texture.h:555
int release_all()
Frees the context allocated on all objects for which the texture has been declared.
Definition texture.cxx:1599
CPTA_uchar get_ram_mipmap_image(int n) const
Returns the system-RAM image data associated with the nth mipmap level, if present.
Definition texture.cxx:1214
get_clear_color
Returns the color that was previously set using set_clear_color.
Definition texture.h:279
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
clear_filename
Removes the filename, if it was previously set.
Definition texture.h:321
set_border_color
Specifies the solid color of the texture's border.
Definition texture.h:409
static std::string format_format(Format f)
Returns the indicated Format converted to a string word.
Definition texture.cxx:2188
is_cacheable
Returns true if there is enough information in this Texture object to write it to the bam cache succe...
Definition texture.h:474
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
set_alpha_filename
Sets the name of the file that contains the image's alpha channel contents.
Definition texture.h:327
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
set_filename
Sets the name of the file that contains the image's contents.
Definition texture.h:321
bool store(PNMImage &pnmimage) const
Saves the texture to the indicated PNMImage, but does not write it to disk.
Definition texture.I:433
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
set_component_type
Changes the data value for the texture components.
Definition texture.h:375
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
get_num_ram_mipmap_images
Returns the maximum number of mipmap level images available in system memory.
Definition texture.h:504
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
static bool is_unsigned(ComponentType ctype)
Returns true if the indicated component type is unsigned, false otherwise.
Definition texture.cxx:2604
get_usage_hint
Returns the usage hint specified for buffer textures, or UH_unspecified for all other texture types.
Definition texture.h:367
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Base class for objects that can be written to and read from Bam files.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
This is a sequence number that increments monotonically.
Definition updateSeq.h:37
This is our own Panda specialization on the default STL list.
Definition plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.