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