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