Panda3D
eggRenderMode.cxx
1 // Filename: eggRenderMode.cxx
2 // Created by: drose (20Jan99)
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 #include "eggRenderMode.h"
16 #include "indent.h"
17 #include "string_utils.h"
18 #include "pnotify.h"
19 
20 TypeHandle EggRenderMode::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: EggRenderMode::Constructor
24 // Access: Public
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 EggRenderMode::
28 EggRenderMode() {
29  _alpha_mode = AM_unspecified;
30  _depth_write_mode = DWM_unspecified;
31  _depth_test_mode = DTM_unspecified;
32  _visibility_mode = VM_unspecified;
33  _depth_offset = 0;
34  _has_depth_offset = false;
35  _draw_order = 0;
36  _has_draw_order = false;
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: EggRenderMode::Copy assignment operator
41 // Access: Public
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 EggRenderMode &EggRenderMode::
45 operator = (const EggRenderMode &copy) {
46  _alpha_mode = copy._alpha_mode;
47  _depth_write_mode = copy._depth_write_mode;
48  _depth_test_mode = copy._depth_test_mode;
49  _visibility_mode = copy._visibility_mode;
50  _depth_offset = copy._depth_offset;
51  _has_depth_offset = copy._has_depth_offset;
52  _draw_order = copy._draw_order;
53  _has_draw_order = copy._has_draw_order;
54  return *this;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: EggRenderMode::write
59 // Access: Public
60 // Description: Writes the attributes to the indicated output stream in
61 // Egg format.
62 ////////////////////////////////////////////////////////////////////
63 void EggRenderMode::
64 write(ostream &out, int indent_level) const {
65  if (get_alpha_mode() != AM_unspecified) {
66  indent(out, indent_level)
67  << "<Scalar> alpha { " << get_alpha_mode() << " }\n";
68  }
69  if (get_depth_write_mode() != DWM_unspecified) {
70  indent(out, indent_level)
71  << "<Scalar> depth_write { " << get_depth_write_mode() << " }\n";
72  }
73  if (get_depth_test_mode() != DTM_unspecified) {
74  indent(out, indent_level)
75  << "<Scalar> depth_test { " << get_depth_test_mode() << " }\n";
76  }
77  if (get_visibility_mode() != VM_unspecified) {
78  indent(out, indent_level)
79  << "<Scalar> visibility { " << get_visibility_mode() << " }\n";
80  }
81  if (has_depth_offset()) {
82  indent(out, indent_level)
83  << "<Scalar> depth-offset { " << get_depth_offset() << " }\n";
84  }
85  if (has_draw_order()) {
86  indent(out, indent_level)
87  << "<Scalar> draw-order { " << get_draw_order() << " }\n";
88  }
89  if (has_bin()) {
90  indent(out, indent_level)
91  << "<Scalar> bin { " << get_bin() << " }\n";
92  }
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: EggRenderMode::Equality Operator
97 // Access: Public
98 // Description:
99 ////////////////////////////////////////////////////////////////////
100 bool EggRenderMode::
101 operator == (const EggRenderMode &other) const {
102  if (_alpha_mode != other._alpha_mode ||
103  _depth_write_mode != other._depth_write_mode ||
104  _depth_test_mode != other._depth_test_mode ||
105  _visibility_mode != other._visibility_mode ||
106  _has_depth_offset != other._has_depth_offset ||
107  _has_draw_order != other._has_draw_order) {
108  return false;
109  }
110 
111  if (_has_depth_offset) {
112  if (_depth_offset != other._depth_offset) {
113  return false;
114  }
115  }
116 
117  if (_has_draw_order) {
118  if (_draw_order != other._draw_order) {
119  return false;
120  }
121  }
122 
123  if (_bin != other._bin) {
124  return false;
125  }
126 
127  return true;
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: EggRenderMode::Ordering Operator
132 // Access: Public
133 // Description:
134 ////////////////////////////////////////////////////////////////////
135 bool EggRenderMode::
136 operator < (const EggRenderMode &other) const {
137  if (_alpha_mode != other._alpha_mode) {
138  return (int)_alpha_mode < (int)other._alpha_mode;
139  }
140  if (_depth_write_mode != other._depth_write_mode) {
141  return (int)_depth_write_mode < (int)other._depth_write_mode;
142  }
143  if (_depth_test_mode != other._depth_test_mode) {
144  return (int)_depth_test_mode < (int)other._depth_test_mode;
145  }
146  if (_visibility_mode != other._visibility_mode) {
147  return (int)_visibility_mode < (int)other._visibility_mode;
148  }
149 
150  if (_has_depth_offset != other._has_depth_offset) {
151  return (int)_has_depth_offset < (int)other._has_depth_offset;
152  }
153  if (_has_draw_order != other._has_draw_order) {
154  return (int)_has_draw_order < (int)other._has_draw_order;
155  }
156 
157  if (_has_depth_offset) {
158  if (_depth_offset != other._depth_offset) {
159  return _depth_offset < other._depth_offset;
160  }
161  }
162  if (_has_draw_order) {
163  if (_draw_order != other._draw_order) {
164  return _draw_order < other._draw_order;
165  }
166  }
167 
168  if (_bin != other._bin) {
169  return _bin < other._bin;
170  }
171 
172  return false;
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: EggRenderMode::string_alpha_mode
177 // Access: Public
178 // Description: Returns the AlphaMode value associated with the given
179 // string representation, or AM_unspecified if the string
180 // does not match any known AlphaMode value.
181 ////////////////////////////////////////////////////////////////////
182 EggRenderMode::AlphaMode EggRenderMode::
183 string_alpha_mode(const string &string) {
184  if (cmp_nocase_uh(string, "off") == 0) {
185  return AM_off;
186  } else if (cmp_nocase_uh(string, "on") == 0) {
187  return AM_on;
188  } else if (cmp_nocase_uh(string, "blend") == 0) {
189  return AM_blend;
190  } else if (cmp_nocase_uh(string, "blend_no_occlude") == 0) {
191  return AM_blend_no_occlude;
192  } else if (cmp_nocase_uh(string, "ms") == 0) {
193  return AM_ms;
194  } else if (cmp_nocase_uh(string, "ms_mask") == 0) {
195  return AM_ms_mask;
196  } else if (cmp_nocase_uh(string, "binary") == 0) {
197  return AM_binary;
198  } else if (cmp_nocase_uh(string, "dual") == 0) {
199  return AM_dual;
200  } else {
201  return AM_unspecified;
202  }
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: EggRenderMode::string_depth_write_mode
207 // Access: Public
208 // Description: Returns the DepthWriteMode value associated with the
209 // given string representation, or DWM_unspecified if
210 // the string does not match any known DepthWriteMode
211 // value.
212 ////////////////////////////////////////////////////////////////////
213 EggRenderMode::DepthWriteMode EggRenderMode::
214 string_depth_write_mode(const string &string) {
215  if (cmp_nocase_uh(string, "off") == 0) {
216  return DWM_off;
217  } else if (cmp_nocase_uh(string, "on") == 0) {
218  return DWM_on;
219  } else {
220  return DWM_unspecified;
221  }
222 }
223 
224 ////////////////////////////////////////////////////////////////////
225 // Function: EggRenderMode::string_depth_test_mode
226 // Access: Public
227 // Description: Returns the DepthTestMode value associated with the
228 // given string representation, or DTM_unspecified if
229 // the string does not match any known DepthTestMode
230 // value.
231 ////////////////////////////////////////////////////////////////////
232 EggRenderMode::DepthTestMode EggRenderMode::
233 string_depth_test_mode(const string &string) {
234  if (cmp_nocase_uh(string, "off") == 0) {
235  return DTM_off;
236  } else if (cmp_nocase_uh(string, "on") == 0) {
237  return DTM_on;
238  } else {
239  return DTM_unspecified;
240  }
241 }
242 
243 ////////////////////////////////////////////////////////////////////
244 // Function: EggRenderMode::string_visibility_mode
245 // Access: Public
246 // Description: Returns the HiddenMode value associated with the
247 // given string representation, or VM_unspecified if
248 // the string does not match any known HiddenMode
249 // value.
250 ////////////////////////////////////////////////////////////////////
251 EggRenderMode::VisibilityMode EggRenderMode::
252 string_visibility_mode(const string &string) {
253  if (cmp_nocase_uh(string, "hidden") == 0) {
254  return VM_hidden;
255  } else if (cmp_nocase_uh(string, "normal") == 0) {
256  return VM_normal;
257  } else {
258  return VM_unspecified;
259  }
260 }
261 
262 
263 ////////////////////////////////////////////////////////////////////
264 // Function: AlphaMode output operator
265 // Description:
266 ////////////////////////////////////////////////////////////////////
267 ostream &operator << (ostream &out, EggRenderMode::AlphaMode mode) {
268  switch (mode) {
269  case EggRenderMode::AM_unspecified:
270  return out << "unspecified";
271  case EggRenderMode::AM_off:
272  return out << "off";
273  case EggRenderMode::AM_on:
274  return out << "on";
275  case EggRenderMode::AM_blend:
276  return out << "blend";
277  case EggRenderMode::AM_blend_no_occlude:
278  return out << "blend_no_occlude";
279  case EggRenderMode::AM_ms:
280  return out << "ms";
281  case EggRenderMode::AM_ms_mask:
282  return out << "ms_mask";
283  case EggRenderMode::AM_binary:
284  return out << "binary";
285  case EggRenderMode::AM_dual:
286  return out << "dual";
287  }
288 
289  nassertr(false, out);
290  return out << "(**invalid**)";
291 }
292 
293 ////////////////////////////////////////////////////////////////////
294 // Function: AlphaMode input operator
295 // Description:
296 ////////////////////////////////////////////////////////////////////
297 istream &operator >> (istream &in, EggRenderMode::AlphaMode &mode) {
298  string word;
299  in >> word;
301  return in;
302 }
303 
304 ////////////////////////////////////////////////////////////////////
305 // Function: DepthWriteMode output operator
306 // Description:
307 ////////////////////////////////////////////////////////////////////
308 ostream &operator << (ostream &out, EggRenderMode::DepthWriteMode mode) {
309  switch (mode) {
310  case EggRenderMode::DWM_unspecified:
311  return out << "unspecified";
312  case EggRenderMode::DWM_off:
313  return out << "off";
314  case EggRenderMode::DWM_on:
315  return out << "on";
316  }
317 
318  nassertr(false, out);
319  return out << "(**invalid**)";
320 }
321 
322 ////////////////////////////////////////////////////////////////////
323 // Function: DepthTestMode output operator
324 // Description:
325 ////////////////////////////////////////////////////////////////////
326 ostream &operator << (ostream &out, EggRenderMode::DepthTestMode mode) {
327  switch (mode) {
328  case EggRenderMode::DTM_unspecified:
329  return out << "unspecified";
330  case EggRenderMode::DTM_off:
331  return out << "off";
332  case EggRenderMode::DTM_on:
333  return out << "on";
334  }
335 
336  nassertr(false, out);
337  return out << "(**invalid**)";
338 }
339 
340 
341 
342 ////////////////////////////////////////////////////////////////////
343 // Function: VisibilityMode output operator
344 // Description:
345 ////////////////////////////////////////////////////////////////////
346 ostream &operator << (ostream &out, EggRenderMode::VisibilityMode mode) {
347  switch (mode) {
348  case EggRenderMode::VM_unspecified:
349  return out << "unspecified";
350  case EggRenderMode::VM_hidden:
351  return out << "hidden";
352  case EggRenderMode::VM_normal:
353  return out << "normal";
354  }
355 
356  nassertr(false, out);
357  return out << "(**invalid**)";
358 }
359 
360 
AlphaMode get_alpha_mode() const
Returns the alpha mode that was set, or AM_unspecified if nothing was set.
VisibilityMode get_visibility_mode() const
Returns the visibility mode that was set, or VM_unspecified if nothing was set.
Definition: eggRenderMode.I:99
static DepthTestMode string_depth_test_mode(const string &string)
Returns the DepthTestMode value associated with the given string representation, or DTM_unspecified i...
static AlphaMode string_alpha_mode(const string &string)
Returns the AlphaMode value associated with the given string representation, or AM_unspecified if the...
bool has_bin() const
Returns true if a bin name has been set for this particular object.
int get_draw_order() const
Returns the "draw-order" flag as set for this particular object.
static VisibilityMode string_visibility_mode(const string &string)
Returns the HiddenMode value associated with the given string representation, or VM_unspecified if th...
DepthWriteMode get_depth_write_mode() const
Returns the depth_write mode that was set, or DWM_unspecified if nothing was set. ...
Definition: eggRenderMode.I:47
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
static DepthWriteMode string_depth_write_mode(const string &string)
Returns the DepthWriteMode value associated with the given string representation, or DWM_unspecified ...
bool has_draw_order() const
Returns true if the draw-order flag has been set for this particular object.
string get_bin() const
Returns the bin name that has been set for this particular object, if any.
void write(ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
bool has_depth_offset() const
Returns true if the depth-offset flag has been set for this particular object.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
int get_depth_offset() const
Returns the "depth-offset" flag as set for this particular object.
DepthTestMode get_depth_test_mode() const
Returns the depth_test mode that was set, or DTM_unspecified if nothing was set.
Definition: eggRenderMode.I:73