Panda3D
eggTexture.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 eggTexture.h
10  * @author drose
11  * @date 1999-01-18
12  */
13 
14 #ifndef EGGTEXTURE_H
15 #define EGGTEXTURE_H
16 
17 #include "pandabase.h"
18 
19 #include "eggRenderMode.h"
20 #include "eggFilenameNode.h"
21 #include "eggTransform.h"
22 
23 #include "pset.h"
24 #include "luse.h"
25 
26 
27 /**
28  * Defines a texture map that may be applied to geometry.
29  */
30 class EXPCL_PANDA_EGG EggTexture : public EggFilenameNode, public EggRenderMode, public EggTransform {
31 PUBLISHED:
32  explicit EggTexture(const std::string &tref_name, const Filename &filename);
33  EggTexture(const EggTexture &copy);
34  EggTexture &operator = (const EggTexture &copy);
35  virtual ~EggTexture();
36 
37  virtual void write(std::ostream &out, int indent_level) const;
38 
39  enum Equivalence {
40  E_basename = 0x001,
41  E_extension = 0x002,
42  E_dirname = 0x004,
43  E_complete_filename = 0x007,
44  E_transform = 0x008,
45  E_attributes = 0x010,
46  E_tref_name = 0x020,
47  };
48 
49  bool is_equivalent_to(const EggTexture &other, int eq) const;
50  bool sorts_less_than(const EggTexture &other, int eq) const;
51 
52  bool has_alpha_channel(int num_components) const;
53 
54  enum TextureType {
55  TT_unspecified, TT_1d_texture,
56  TT_2d_texture, TT_3d_texture, TT_cube_map
57  };
58  enum Format {
59  F_unspecified,
60  F_rgba, F_rgbm, F_rgba12, F_rgba8, F_rgba4, F_rgba5,
61  F_rgb, F_rgb12, F_rgb8, F_rgb5, F_rgb332,
62  F_red, F_green, F_blue, F_alpha, F_luminance,
63  F_luminance_alpha, F_luminance_alphamask
64  };
65  enum CompressionMode {
66  CM_default, CM_off, CM_on,
67  CM_fxt1, CM_dxt1, CM_dxt2, CM_dxt3, CM_dxt4, CM_dxt5,
68  };
69  enum WrapMode {
70  WM_unspecified, WM_clamp, WM_repeat,
71  WM_mirror, WM_mirror_once, WM_border_color
72  };
73  enum FilterType {
74  // Note that these type values match up, name-for-name, with a similar
75  // enumerated type in Panda's Texture object. However, they do *not*
76  // match up numerically. You must convert between them using a switch
77  // statement.
78  FT_unspecified,
79 
80  // Mag Filter and Min Filter
81  FT_nearest,
82  FT_linear,
83 
84  // Min Filter Only
85  FT_nearest_mipmap_nearest, // "mipmap point"
86  FT_linear_mipmap_nearest, // "mipmap linear"
87  FT_nearest_mipmap_linear, // "mipmap bilinear"
88  FT_linear_mipmap_linear, // "mipmap trilinear"
89  };
90  enum EnvType {
91  ET_unspecified,
92  ET_modulate,
93  ET_decal,
94  ET_blend,
95  ET_replace,
96  ET_add,
97  ET_blend_color_scale,
98  ET_modulate_glow,
99  ET_modulate_gloss,
100  ET_normal,
101  ET_normal_height,
102  ET_glow,
103  ET_gloss,
104  ET_height,
105  ET_selector,
106  ET_normal_gloss,
107  };
108  enum CombineMode {
109  CM_unspecified,
110  CM_replace,
111  CM_modulate,
112  CM_add,
113  CM_add_signed,
114  CM_interpolate,
115  CM_subtract,
116  CM_dot3_rgb,
117  CM_dot3_rgba,
118  };
119  enum CombineChannel {
120  CC_rgb = 0,
121  CC_alpha = 1,
122  CC_num_channels = 2,
123  };
124  enum CombineIndex {
125  CI_num_indices = 3
126  };
127  enum CombineSource {
128  CS_unspecified,
129  CS_texture,
130  CS_constant,
131  CS_primary_color,
132  CS_previous,
133  CS_constant_color_scale,
134  CS_last_saved_result,
135  };
136  enum CombineOperand {
137  CO_unspecified,
138  CO_src_color,
139  CO_one_minus_src_color,
140  CO_src_alpha,
141  CO_one_minus_src_alpha,
142  };
143  enum TexGen {
144  TG_unspecified,
145 
146  TG_eye_sphere_map,
147 
148  TG_world_cube_map,
149  TG_eye_cube_map,
150 
151  TG_world_normal,
152  TG_eye_normal,
153 
154  TG_world_position,
155  TG_eye_position,
156 
157  TG_point_sprite,
158  };
159  enum QualityLevel {
160  QL_unspecified,
161  QL_default,
162  QL_fastest,
163  QL_normal,
164  QL_best,
165  };
166 
167  INLINE void set_texture_type(TextureType texture_type);
168  INLINE TextureType get_texture_type() const;
169 
170  INLINE void set_format(Format format);
171  INLINE Format get_format() const;
172 
173  INLINE void set_compression_mode(CompressionMode mode);
174  INLINE CompressionMode get_compression_mode() const;
175 
176  INLINE void set_wrap_mode(WrapMode mode);
177  INLINE WrapMode get_wrap_mode() const;
178 
179  INLINE void set_wrap_u(WrapMode mode);
180  INLINE WrapMode get_wrap_u() const;
181  INLINE WrapMode determine_wrap_u() const;
182 
183  INLINE void set_wrap_v(WrapMode mode);
184  INLINE WrapMode get_wrap_v() const;
185  INLINE WrapMode determine_wrap_v() const;
186 
187  INLINE void set_wrap_w(WrapMode mode);
188  INLINE WrapMode get_wrap_w() const;
189  INLINE WrapMode determine_wrap_w() const;
190 
191  INLINE void set_minfilter(FilterType type);
192  INLINE FilterType get_minfilter() const;
193 
194  INLINE void set_magfilter(FilterType type);
195  INLINE FilterType get_magfilter() const;
196 
197  INLINE void set_anisotropic_degree(int anisotropic_degree);
198  INLINE void clear_anisotropic_degree();
199  INLINE bool has_anisotropic_degree() const;
200  INLINE int get_anisotropic_degree() const;
201 
202  INLINE void set_env_type(EnvType type);
203  INLINE EnvType get_env_type() const;
204  bool affects_polygon_alpha() const;
205 
206  INLINE void set_combine_mode(CombineChannel channel, CombineMode cm);
207  INLINE CombineMode get_combine_mode(CombineChannel channel) const;
208  INLINE void set_combine_source(CombineChannel channel, int n, CombineSource cs);
209  INLINE CombineSource get_combine_source(CombineChannel channel, int n) const;
210  INLINE void set_combine_operand(CombineChannel channel, int n, CombineOperand co);
211  INLINE CombineOperand get_combine_operand(CombineChannel channel, int n) const;
212 
213  INLINE void set_saved_result(bool saved_result);
214  INLINE bool get_saved_result() const;
215 
216  INLINE void set_tex_gen(TexGen tex_gen);
217  INLINE TexGen get_tex_gen() const;
218 
219  INLINE void set_quality_level(QualityLevel quality_level);
220  INLINE QualityLevel get_quality_level() const;
221 
222  INLINE void set_stage_name(const std::string &stage_name);
223  INLINE void clear_stage_name();
224  INLINE bool has_stage_name() const;
225  INLINE const std::string &get_stage_name() const;
226 
227  INLINE void set_priority(int priority);
228  INLINE void clear_priority();
229  INLINE bool has_priority() const;
230  INLINE int get_priority() const;
231 
232  INLINE void set_color(const LColor &color);
233  INLINE void clear_color();
234  INLINE bool has_color() const;
235  INLINE const LColor &get_color() const;
236 
237  INLINE void set_border_color(const LColor &border_color);
238  INLINE void clear_border_color();
239  INLINE bool has_border_color() const;
240  INLINE const LColor &get_border_color() const;
241 
242  INLINE void set_uv_name(const std::string &uv_name);
243  INLINE void clear_uv_name();
244  INLINE bool has_uv_name() const;
245  INLINE const std::string &get_uv_name() const;
246 
247  INLINE void set_rgb_scale(int rgb_scale);
248  INLINE void clear_rgb_scale();
249  INLINE bool has_rgb_scale() const;
250  INLINE int get_rgb_scale() const;
251 
252  INLINE void set_alpha_scale(int alpha_scale);
253  INLINE void clear_alpha_scale();
254  INLINE bool has_alpha_scale() const;
255  INLINE int get_alpha_scale() const;
256 
257  INLINE void set_alpha_filename(const Filename &filename);
258  INLINE void clear_alpha_filename();
259  INLINE bool has_alpha_filename() const;
260  INLINE const Filename &get_alpha_filename() const;
261 
262  INLINE void set_alpha_fullpath(const Filename &fullpath);
263  INLINE const Filename &get_alpha_fullpath() const;
264 
265  INLINE void set_alpha_file_channel(int alpha_file_channel);
266  INLINE void clear_alpha_file_channel();
267  INLINE bool has_alpha_file_channel() const;
268  INLINE int get_alpha_file_channel() const;
269 
270  INLINE void set_multiview(bool multiview);
271  INLINE bool get_multiview() const;
272 
273  INLINE void set_num_views(int num_views);
274  INLINE void clear_num_views();
275  INLINE bool has_num_views() const;
276  INLINE int get_num_views() const;
277 
278  INLINE void set_read_mipmaps(bool read_mipmaps);
279  INLINE bool get_read_mipmaps() const;
280 
281  INLINE void set_min_lod(double min_lod);
282  INLINE void clear_min_lod();
283  INLINE bool has_min_lod() const;
284  INLINE double get_min_lod() const;
285 
286  INLINE void set_max_lod(double max_lod);
287  INLINE void clear_max_lod();
288  INLINE bool has_max_lod() const;
289  INLINE double get_max_lod() const;
290 
291  INLINE void set_lod_bias(double lod_bias);
292  INLINE void clear_lod_bias();
293  INLINE bool has_lod_bias() const;
294  INLINE double get_lod_bias() const;
295 
296  void clear_multitexture();
297  bool multitexture_over(EggTexture *other);
298  INLINE int get_multitexture_sort() const;
299 
300  static TextureType string_texture_type(const std::string &string);
301  static Format string_format(const std::string &string);
302  static CompressionMode string_compression_mode(const std::string &string);
303  static WrapMode string_wrap_mode(const std::string &string);
304  static FilterType string_filter_type(const std::string &string);
305  static EnvType string_env_type(const std::string &string);
306  static CombineMode string_combine_mode(const std::string &string);
307  static CombineSource string_combine_source(const std::string &string);
308  static CombineOperand string_combine_operand(const std::string &string);
309  static TexGen string_tex_gen(const std::string &string);
310  static QualityLevel string_quality_level(const std::string &string);
311 
312 PUBLISHED:
313  MAKE_PROPERTY(texture_type, get_texture_type, set_texture_type);
314  MAKE_PROPERTY(format, get_format, set_format);
315  MAKE_PROPERTY(compression_mode, get_compression_mode, set_compression_mode);
316  MAKE_PROPERTY(wrap_mode, get_wrap_mode, set_wrap_mode);
317  MAKE_PROPERTY(wrap_u, get_wrap_u, set_wrap_u);
318  MAKE_PROPERTY(wrap_v, get_wrap_v, set_wrap_v);
319  MAKE_PROPERTY(wrap_w, get_wrap_w, set_wrap_w);
320  MAKE_PROPERTY(minfilter, get_minfilter, set_minfilter);
321  MAKE_PROPERTY(magfilter, get_magfilter, set_magfilter);
322  MAKE_PROPERTY2(anisotropic_degree, has_anisotropic_degree, get_anisotropic_degree,
323  set_anisotropic_degree, clear_anisotropic_degree);
324  MAKE_PROPERTY(env_type, get_env_type, set_env_type);
325  MAKE_PROPERTY(saved_result, get_saved_result, set_saved_result);
326  MAKE_PROPERTY(tex_gen, get_tex_gen, set_tex_gen);
327  MAKE_PROPERTY(quality_level, get_quality_level, set_quality_level);
328  MAKE_PROPERTY2(stage_name, has_stage_name, get_stage_name,
329  set_stage_name, clear_stage_name);
330  MAKE_PROPERTY2(priority, has_priority, get_priority,
331  set_priority, clear_priority);
332  MAKE_PROPERTY2(color, has_color, get_color,
333  set_color, clear_color);
334  MAKE_PROPERTY2(border_color, has_border_color, get_border_color,
335  set_border_color, clear_border_color);
336  MAKE_PROPERTY2(uv_name, has_uv_name, get_uv_name,
337  set_uv_name, clear_uv_name);
338  MAKE_PROPERTY2(rgb_scale, has_rgb_scale, get_rgb_scale,
339  set_rgb_scale, clear_rgb_scale);
340  MAKE_PROPERTY2(alpha_scale, has_alpha_scale, get_alpha_scale,
341  set_alpha_scale, clear_alpha_scale);
342  MAKE_PROPERTY2(alpha_filename, has_alpha_filename, get_alpha_filename,
343  set_alpha_filename, clear_alpha_filename);
344  MAKE_PROPERTY(alpha_fullpath, get_alpha_fullpath, set_alpha_fullpath);
345  MAKE_PROPERTY2(alpha_file_channel, has_alpha_file_channel, get_alpha_file_channel,
346  set_alpha_file_channel, clear_alpha_file_channel);
347  MAKE_PROPERTY(multiview, get_multiview, set_multiview);
348  MAKE_PROPERTY2(num_views, has_num_views, get_num_views,
349  set_num_views, clear_num_views);
350  MAKE_PROPERTY(read_mipmaps, get_read_mipmaps, set_read_mipmaps);
351  MAKE_PROPERTY2(min_lod, has_min_lod, get_min_lod,
352  set_min_lod, clear_min_lod);
353  MAKE_PROPERTY2(max_lod, has_max_lod, get_max_lod,
354  set_max_lod, clear_max_lod);
355  MAKE_PROPERTY2(lod_bias, has_lod_bias, get_lod_bias,
356  set_lod_bias, clear_lod_bias);
357 
358  MAKE_PROPERTY(multitexture_sort, get_multitexture_sort);
359 
360 public:
361  virtual EggTransform *as_transform();
362 
363 protected:
364  virtual bool egg_start_parse_body();
365 
366 private:
368  bool r_min_multitexture_sort(int sort, MultiTextures &cycle_detector);
369 
370  enum Flags {
371  F_has_alpha_filename = 0x0002,
372  F_has_anisotropic_degree = 0x0004,
373  F_has_alpha_file_channel = 0x0008,
374  F_has_stage_name = 0x0010,
375  F_has_uv_name = 0x0020,
376  F_has_priority = 0x0040,
377  F_has_color = 0x0080,
378  F_has_rgb_scale = 0x0100,
379  F_has_alpha_scale = 0x0200,
380  F_has_border_color = 0x0400,
381  F_has_num_views = 0x0800,
382  F_has_min_lod = 0x1000,
383  F_has_max_lod = 0x2000,
384  F_has_lod_bias = 0x4000,
385  };
386 
387  TextureType _texture_type;
388  Format _format;
389  CompressionMode _compression_mode;
390  WrapMode _wrap_mode, _wrap_u, _wrap_v, _wrap_w;
391  FilterType _minfilter, _magfilter;
392  int _anisotropic_degree;
393  EnvType _env_type;
394  bool _saved_result;
395  bool _multiview;
396  int _num_views;
397  TexGen _tex_gen;
398  QualityLevel _quality_level;
399  std::string _stage_name;
400  int _priority;
401  LColor _color;
402  LColor _border_color;
403  std::string _uv_name;
404  int _rgb_scale;
405  int _alpha_scale;
406  int _flags;
407  Filename _alpha_filename;
408  Filename _alpha_fullpath;
409  int _alpha_file_channel;
410  bool _read_mipmaps;
411  int _multitexture_sort;
412  double _min_lod;
413  double _max_lod;
414  double _lod_bias;
415 
416  class SourceAndOperand {
417  public:
418  INLINE SourceAndOperand();
419  CombineSource _source;
420  CombineOperand _operand;
421  };
422 
423  class Combiner {
424  public:
425  INLINE Combiner();
426  CombineMode _mode;
427  SourceAndOperand _ops[CI_num_indices];
428  };
429 
430  Combiner _combiner[CC_num_channels];
431 
432  // This is the set of all of the textures that are multitextured on top of
433  // (and under) this one. This is filled in by multitexture_over().
434  MultiTextures _over_textures, _under_textures;
435 
436 public:
437  static TypeHandle get_class_type() {
438  return _type_handle;
439  }
440  static void init_type() {
441  EggFilenameNode::init_type();
442  EggRenderMode::init_type();
443  register_type(_type_handle, "EggTexture",
444  EggFilenameNode::get_class_type(),
445  EggRenderMode::get_class_type());
446  }
447  virtual TypeHandle get_type() const {
448  return get_class_type();
449  }
450  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
451 
452 private:
453  static TypeHandle _type_handle;
454 };
455 
456 /**
457  * An STL function object for sorting textures into order by properties.
458  * Returns true if the two referenced EggTexture pointers are in sorted order,
459  * false otherwise.
460  */
461 class EXPCL_PANDA_EGG UniqueEggTextures {
462 public:
463  INLINE UniqueEggTextures(int eq = ~0);
464  INLINE bool operator ()(const EggTexture *t1, const EggTexture *t2) const;
465 
466  int _eq;
467 };
468 
469 INLINE std::ostream &operator << (std::ostream &out, const EggTexture &n) {
470  return out << n.get_filename();
471 }
472 
473 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::TextureType texture_type);
474 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::Format format);
475 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CompressionMode mode);
476 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::WrapMode mode);
477 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::FilterType type);
478 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::EnvType type);
479 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CombineMode cm);
480 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CombineChannel cc);
481 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CombineSource cs);
482 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::CombineOperand co);
483 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::TexGen tex_gen);
484 EXPCL_PANDA_EGG std::ostream &operator << (std::ostream &out, EggTexture::QualityLevel quality_level);
485 
486 #include "eggTexture.I"
487 
488 #endif
const Filename & get_filename() const
Returns a nonmodifiable reference to the filename.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an egg node that contains a filename.
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:30
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.
This class stores miscellaneous rendering properties that is associated with geometry,...
Definition: eggRenderMode.h:31
virtual EggTransform * as_transform()
Returns this object cross-cast to an EggTransform pointer, if it inherits from EggTransform,...
Definition: eggObject.cxx:151
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An STL function object for sorting textures into order by properties.
Definition: eggTexture.h:461
void write(std::ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents the <Transform> entry of a group or texture node: a list of component transform opera...
Definition: eggTransform.h:29