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