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