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