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);
270 void generate_alpha_scale_map();
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,
279 set_clear_color, clear_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();
321 MAKE_PROPERTY2(filename, has_filename, get_filename, set_filename, 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();
327 MAKE_PROPERTY2(alpha_filename, has_alpha_filename, get_alpha_filename, set_alpha_filename, 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();
333 MAKE_PROPERTY2(fullpath, has_fullpath, get_fullpath, set_fullpath, 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();
339 MAKE_PROPERTY2(alpha_fullpath, has_alpha_fullpath, get_alpha_fullpath, set_alpha_fullpath, 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;
485 int get_num_loadable_ram_mipmap_images() 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);
515 void generate_simple_ram_image();
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;
526 INLINE UpdateSeq get_simple_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,
535 set_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,
555 set_aux_data, clear_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,
592 set_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,
597 set_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 implements a condition variable; see ConditionVar for a brief introduction to this class.
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,...
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This class is similar to CycleDataReader, except it allows reading from a particular stage of the pip...
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
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
The default class template does not define any methods.
Definition extension.h:34
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.
A standard mutex, or mutual exclusion lock.
Definition pmutex.h:40
A base class for all things which can have a name.
Definition namable.h:26
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
A lightweight class that represents a single element that may be timed and/or counted via stats.
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().
This is the preferred interface for loading textures from image files.
Definition texturePool.h:37
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
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.
A base class for things which need to inherit from both TypedWritable 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
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
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.
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.