Panda3D
textureStage.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 textureStage.h
10  * @author drose
11  * @date 2004-07-14
12  */
13 
14 #ifndef TEXTURESTAGE_H
15 #define TEXTURESTAGE_H
16 
17 #include "pandabase.h"
18 
19 #include "internalName.h"
20 #include "pointerTo.h"
22 #include "updateSeq.h"
23 #include "luse.h"
25 
26 class FactoryParams;
27 
28 /**
29  * Defines the properties of a named stage of the multitexture pipeline. The
30  * TextureAttrib will associated a number of these stages with Texture
31  * objects, and the GSG will render geometry by sorting all of the currently
32  * active TextureStages in order and then issuing the appropriate rendering
33  * calls to activate them.
34  */
35 class EXPCL_PANDA_GOBJ TextureStage : public TypedWritableReferenceCount {
36 PUBLISHED:
37  explicit TextureStage(const std::string &name);
38  INLINE TextureStage(const TextureStage &copy);
39  void operator = (const TextureStage &copy);
40 
41  virtual ~TextureStage();
42 
43  enum Mode {
44  // Modes that pertain to the fixed-function pipeline.
45 
46  M_modulate,
47  M_decal,
48  M_blend,
49  M_replace,
50  M_add,
51  M_combine,
52  M_blend_color_scale,
53 
54  M_modulate_glow, // When fixed-function, equivalent to modulate.
55  M_modulate_gloss, // When fixed-function, equivalent to modulate.
56 
57  // Modes that are only relevant to shader-based rendering.
58 
59  M_normal,
60  M_normal_height,
61  M_glow, // Rarely used: modulate_glow is more efficient.
62  M_gloss, // Rarely used: modulate_gloss is more efficient.
63  M_height, // Rarely used: normal_height is more efficient.
64  M_selector,
65  M_normal_gloss,
66  };
67 
68  enum CombineMode {
69  CM_undefined,
70  CM_replace,
71  CM_modulate,
72  CM_add,
73  CM_add_signed,
74  CM_interpolate,
75  CM_subtract,
76 
77  // The following are valid only for combine_rgb, not combine_alpha.
78  CM_dot3_rgb,
79  CM_dot3_rgba,
80  };
81 
82  enum CombineSource {
83  CS_undefined,
84  CS_texture,
85  CS_constant,
86  CS_primary_color,
87  CS_previous,
88  CS_constant_color_scale,
89  CS_last_saved_result,
90  };
91 
92  enum CombineOperand {
93  CO_undefined,
94  CO_src_color,
95  CO_one_minus_src_color,
96  CO_src_alpha,
97  CO_one_minus_src_alpha,
98  };
99 
100  INLINE void set_name(const std::string &name);
101  INLINE const std::string &get_name() const;
102 
103  INLINE void set_sort(int sort);
104  INLINE int get_sort() const;
105 
106  INLINE void set_priority(int priority);
107  INLINE int get_priority() const;
108 
109  INLINE void set_texcoord_name(InternalName *name);
110  INLINE void set_texcoord_name(const std::string &texcoord_name);
111  INLINE InternalName *get_texcoord_name() const;
112  INLINE InternalName *get_tangent_name() const;
113  INLINE InternalName *get_binormal_name() const;
114 
115  INLINE void set_mode(Mode mode);
116  INLINE Mode get_mode() const;
117 
118  INLINE bool is_fixed_function() const;
119 
120  INLINE void set_color(const LColor &color);
121  INLINE LColor get_color() const;
122 
123  INLINE void set_rgb_scale(int rgb_scale);
124  INLINE int get_rgb_scale() const;
125 
126  INLINE void set_alpha_scale(int alpha_scale);
127  INLINE int get_alpha_scale() const;
128 
129  INLINE void set_saved_result(bool saved_result);
130  INLINE bool get_saved_result() const;
131 
132  INLINE void set_tex_view_offset(int tex_view_offset);
133  INLINE int get_tex_view_offset() const;
134 
135  INLINE void set_combine_rgb(CombineMode mode,
136  CombineSource source0, CombineOperand operand0);
137  INLINE void set_combine_rgb(CombineMode mode,
138  CombineSource source0, CombineOperand operand0,
139  CombineSource source1, CombineOperand operand1);
140  INLINE void set_combine_rgb(CombineMode mode,
141  CombineSource source0, CombineOperand operand0,
142  CombineSource source1, CombineOperand operand1,
143  CombineSource source2, CombineOperand operand2);
144  INLINE CombineMode get_combine_rgb_mode() const;
145  INLINE int get_num_combine_rgb_operands() const;
146  INLINE CombineSource get_combine_rgb_source0() const;
147  INLINE CombineOperand get_combine_rgb_operand0() const;
148  INLINE CombineSource get_combine_rgb_source1() const;
149  INLINE CombineOperand get_combine_rgb_operand1() const;
150  INLINE CombineSource get_combine_rgb_source2() const;
151  INLINE CombineOperand get_combine_rgb_operand2() const;
152 
153  INLINE void set_combine_alpha(CombineMode mode,
154  CombineSource source0, CombineOperand operand0);
155  INLINE void set_combine_alpha(CombineMode mode,
156  CombineSource source0, CombineOperand operand0,
157  CombineSource source1, CombineOperand operand1);
158  INLINE void set_combine_alpha(CombineMode mode,
159  CombineSource source0, CombineOperand operand0,
160  CombineSource source1, CombineOperand operand1,
161  CombineSource source2, CombineOperand operand2);
162  INLINE CombineMode get_combine_alpha_mode() const;
163  INLINE int get_num_combine_alpha_operands() const;
164  INLINE CombineSource get_combine_alpha_source0() const;
165  INLINE CombineOperand get_combine_alpha_operand0() const;
166  INLINE CombineSource get_combine_alpha_source1() const;
167  INLINE CombineOperand get_combine_alpha_operand1() const;
168  INLINE CombineSource get_combine_alpha_source2() const;
169  INLINE CombineOperand get_combine_alpha_operand2() const;
170 
171  INLINE bool involves_color_scale() const;
172  INLINE bool uses_color() const;
173  INLINE bool uses_primary_color() const;
174  INLINE bool uses_last_saved_result() const;
175 
176  INLINE bool operator == (const TextureStage &other) const;
177  INLINE bool operator != (const TextureStage &other) const;
178  INLINE bool operator < (const TextureStage &other) const;
179 
180  int compare_to(const TextureStage &other) const;
181 
182  void write(std::ostream &out) const;
183  void output(std::ostream &out) const;
184 
185  INLINE static TextureStage *get_default();
186 
187 PUBLISHED:
188  MAKE_PROPERTY(name, get_name, set_name);
189  MAKE_PROPERTY(sort, get_sort, set_sort);
190  MAKE_PROPERTY(priority, get_priority, set_priority);
191 
192  MAKE_PROPERTY(texcoord_name, get_texcoord_name, set_texcoord_name);
193  MAKE_PROPERTY(tangent_name, get_tangent_name);
194  MAKE_PROPERTY(binormal_name, get_binormal_name);
195 
196  MAKE_PROPERTY(mode, get_mode, set_mode);
197 
198  MAKE_PROPERTY(color, get_color, set_color);
199  MAKE_PROPERTY(rgb_scale, get_rgb_scale, set_rgb_scale);
200  MAKE_PROPERTY(alpha_scale, get_alpha_scale, set_alpha_scale);
201  MAKE_PROPERTY(saved_result, get_saved_result, set_saved_result);
202 
203  MAKE_PROPERTY(tex_view_offset, get_tex_view_offset, set_tex_view_offset);
204 
205  MAKE_PROPERTY(default, get_default);
206 
207 public:
208  INLINE static UpdateSeq get_sort_seq();
209 
210  INLINE void mark_used_by_auto_shader() const;
211 
212 private:
213  INLINE void update_color_flags();
214 
215  static int get_expected_num_combine_operands(CombineMode cm);
216  static bool operand_valid_for_rgb(CombineOperand co);
217  static bool operand_valid_for_alpha(CombineOperand co);
218 
219  std::string _name;
220  int _sort;
221  int _priority;
222  PT(InternalName) _texcoord_name;
223  Mode _mode;
224  LColor _color;
225  int _rgb_scale;
226  int _alpha_scale;
227  bool _saved_result;
228  int _tex_view_offset;
229  bool _involves_color_scale;
230  bool _uses_color;
231  bool _uses_primary_color;
232  bool _uses_last_saved_result;
233 
234  CombineMode _combine_rgb_mode;
235  int _num_combine_rgb_operands;
236  CombineSource _combine_rgb_source0;
237  CombineOperand _combine_rgb_operand0;
238  CombineSource _combine_rgb_source1;
239  CombineOperand _combine_rgb_operand1;
240  CombineSource _combine_rgb_source2;
241  CombineOperand _combine_rgb_operand2;
242 
243  CombineMode _combine_alpha_mode;
244  int _num_combine_alpha_operands;
245  CombineSource _combine_alpha_source0;
246  CombineOperand _combine_alpha_operand0;
247  CombineSource _combine_alpha_source1;
248  CombineOperand _combine_alpha_operand1;
249  CombineSource _combine_alpha_source2;
250  CombineOperand _combine_alpha_operand2;
251 
252  static PT(TextureStage) _default_stage;
253  static UpdateSeq _sort_seq;
254 
255  mutable bool _used_by_auto_shader;
256 
257 public:
258  // Datagram stuff
259  static void register_with_read_factory();
260  virtual void write_datagram(BamWriter *manager, Datagram &me);
261  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
262 
263  static TypedWritable *make_TextureStage(const FactoryParams &params);
264 
265 protected:
266  void fillin(DatagramIterator& scan, BamReader* manager);
267 
268 public:
269  static TypeHandle get_class_type() {
270  return _type_handle;
271  }
272  static void init_type() {
273  TypedWritableReferenceCount::init_type();
274  register_type(_type_handle, "TextureStage",
275  TypedWritableReferenceCount::get_class_type());
276  }
277  virtual TypeHandle get_type() const {
278  return get_class_type();
279  }
280  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
281 
282 private:
283  static TypeHandle _type_handle;
284 };
285 
286 INLINE std::ostream &operator << (std::ostream &out, const TextureStage &ts);
287 
288 EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStage::Mode mode);
289 EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStage::CombineMode cm);
290 EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStage::CombineSource cs);
291 EXPCL_PANDA_GOBJ std::ostream &operator << (std::ostream &out, TextureStage::CombineOperand co);
292 
293 
294 #include "textureStage.I"
295 
296 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
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
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.
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().
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
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:73
A class to retrieve the individual data elements previously stored in a Datagram.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:35
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38