Panda3D

eggRenderMode.cxx

00001 // Filename: eggRenderMode.cxx
00002 // Created by:  drose (20Jan99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "eggRenderMode.h"
00016 #include "indent.h"
00017 #include "string_utils.h"
00018 #include "pnotify.h"
00019 
00020 TypeHandle EggRenderMode::_type_handle;
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: EggRenderMode::Constructor
00024 //       Access: Public
00025 //  Description:
00026 ////////////////////////////////////////////////////////////////////
00027 EggRenderMode::
00028 EggRenderMode() {
00029   _alpha_mode = AM_unspecified;
00030   _depth_write_mode = DWM_unspecified;
00031   _depth_test_mode = DTM_unspecified;
00032   _visibility_mode = VM_unspecified;
00033   _depth_offset = 0;
00034   _has_depth_offset = false;
00035   _draw_order = 0;
00036   _has_draw_order = false;
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: EggRenderMode::Copy assignment operator
00041 //       Access: Public
00042 //  Description:
00043 ////////////////////////////////////////////////////////////////////
00044 EggRenderMode &EggRenderMode::
00045 operator = (const EggRenderMode &copy) {
00046   _alpha_mode = copy._alpha_mode;
00047   _depth_write_mode = copy._depth_write_mode;
00048   _depth_test_mode = copy._depth_test_mode;
00049   _visibility_mode = copy._visibility_mode;
00050   _depth_offset = copy._depth_offset;
00051   _has_depth_offset = copy._has_depth_offset;
00052   _draw_order = copy._draw_order;
00053   _has_draw_order = copy._has_draw_order;
00054   return *this;
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: EggRenderMode::write
00059 //       Access: Public
00060 //  Description: Writes the attributes to the indicated output stream in
00061 //               Egg format.
00062 ////////////////////////////////////////////////////////////////////
00063 void EggRenderMode::
00064 write(ostream &out, int indent_level) const {
00065   if (get_alpha_mode() != AM_unspecified) {
00066     indent(out, indent_level)
00067       << "<Scalar> alpha { " << get_alpha_mode() << " }\n";
00068   }
00069   if (get_depth_write_mode() != DWM_unspecified) {
00070     indent(out, indent_level)
00071       << "<Scalar> depth_write { " << get_depth_write_mode() << " }\n";
00072   }
00073   if (get_depth_test_mode() != DTM_unspecified) {
00074     indent(out, indent_level)
00075       << "<Scalar> depth_test { " << get_depth_test_mode() << " }\n";
00076   }
00077   if (get_visibility_mode() != VM_unspecified) {
00078     indent(out, indent_level)
00079       << "<Scalar> visibility { " << get_visibility_mode() << " }\n";
00080   }
00081   if (has_depth_offset()) {
00082     indent(out, indent_level)
00083       << "<Scalar> depth-offset { " << get_depth_offset() << " }\n";
00084   }
00085   if (has_draw_order()) {
00086     indent(out, indent_level)
00087       << "<Scalar> draw-order { " << get_draw_order() << " }\n";
00088   }
00089   if (has_bin()) {
00090     indent(out, indent_level)
00091       << "<Scalar> bin { " << get_bin() << " }\n";
00092   }
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: EggRenderMode::Equality Operator
00097 //       Access: Public
00098 //  Description:
00099 ////////////////////////////////////////////////////////////////////
00100 bool EggRenderMode::
00101 operator == (const EggRenderMode &other) const {
00102   if (_alpha_mode != other._alpha_mode ||
00103       _depth_write_mode != other._depth_write_mode ||
00104       _depth_test_mode != other._depth_test_mode ||
00105       _visibility_mode != other._visibility_mode ||
00106       _has_depth_offset != other._has_depth_offset ||
00107       _has_draw_order != other._has_draw_order) {
00108     return false;
00109   }
00110 
00111   if (_has_depth_offset) {
00112     if (_depth_offset != other._depth_offset) {
00113       return false;
00114     }
00115   }
00116 
00117   if (_has_draw_order) {
00118     if (_draw_order != other._draw_order) {
00119       return false;
00120     }
00121   }
00122 
00123   if (_bin != other._bin) {
00124     return false;
00125   }
00126 
00127   return true;
00128 }
00129 
00130 ////////////////////////////////////////////////////////////////////
00131 //     Function: EggRenderMode::Ordering Operator
00132 //       Access: Public
00133 //  Description:
00134 ////////////////////////////////////////////////////////////////////
00135 bool EggRenderMode::
00136 operator < (const EggRenderMode &other) const {
00137   if (_alpha_mode != other._alpha_mode) {
00138     return (int)_alpha_mode < (int)other._alpha_mode;
00139   }
00140   if (_depth_write_mode != other._depth_write_mode) {
00141     return (int)_depth_write_mode < (int)other._depth_write_mode;
00142   }
00143   if (_depth_test_mode != other._depth_test_mode) {
00144     return (int)_depth_test_mode < (int)other._depth_test_mode;
00145   }
00146   if (_visibility_mode != other._visibility_mode) {
00147     return (int)_visibility_mode < (int)other._visibility_mode;
00148   }
00149 
00150   if (_has_depth_offset != other._has_depth_offset) {
00151     return (int)_has_depth_offset < (int)other._has_depth_offset;
00152   }
00153   if (_has_draw_order != other._has_draw_order) {
00154     return (int)_has_draw_order < (int)other._has_draw_order;
00155   }
00156 
00157   if (_has_depth_offset) {
00158     if (_depth_offset != other._depth_offset) {
00159       return _depth_offset < other._depth_offset;
00160     }
00161   }
00162   if (_has_draw_order) {
00163     if (_draw_order != other._draw_order) {
00164       return _draw_order < other._draw_order;
00165     }
00166   }
00167 
00168   if (_bin != other._bin) {
00169     return _bin < other._bin;
00170   }
00171 
00172   return false;
00173 }
00174 
00175 ////////////////////////////////////////////////////////////////////
00176 //     Function: EggRenderMode::string_alpha_mode
00177 //       Access: Public
00178 //  Description: Returns the AlphaMode value associated with the given
00179 //               string representation, or AM_unspecified if the string
00180 //               does not match any known AlphaMode value.
00181 ////////////////////////////////////////////////////////////////////
00182 EggRenderMode::AlphaMode EggRenderMode::
00183 string_alpha_mode(const string &string) {
00184   if (cmp_nocase_uh(string, "off") == 0) {
00185     return AM_off;
00186   } else if (cmp_nocase_uh(string, "on") == 0) {
00187     return AM_on;
00188   } else if (cmp_nocase_uh(string, "blend") == 0) {
00189     return AM_blend;
00190   } else if (cmp_nocase_uh(string, "blend_no_occlude") == 0) {
00191     return AM_blend_no_occlude;
00192   } else if (cmp_nocase_uh(string, "ms") == 0) {
00193     return AM_ms;
00194   } else if (cmp_nocase_uh(string, "ms_mask") == 0) {
00195     return AM_ms_mask;
00196   } else if (cmp_nocase_uh(string, "binary") == 0) {
00197     return AM_binary;
00198   } else if (cmp_nocase_uh(string, "dual") == 0) {
00199     return AM_dual;
00200   } else {
00201     return AM_unspecified;
00202   }
00203 }
00204 
00205 ////////////////////////////////////////////////////////////////////
00206 //     Function: EggRenderMode::string_depth_write_mode
00207 //       Access: Public
00208 //  Description: Returns the DepthWriteMode value associated with the
00209 //               given string representation, or DWM_unspecified if
00210 //               the string does not match any known DepthWriteMode
00211 //               value.
00212 ////////////////////////////////////////////////////////////////////
00213 EggRenderMode::DepthWriteMode EggRenderMode::
00214 string_depth_write_mode(const string &string) {
00215   if (cmp_nocase_uh(string, "off") == 0) {
00216     return DWM_off;
00217   } else if (cmp_nocase_uh(string, "on") == 0) {
00218     return DWM_on;
00219   } else {
00220     return DWM_unspecified;
00221   }
00222 }
00223 
00224 ////////////////////////////////////////////////////////////////////
00225 //     Function: EggRenderMode::string_depth_test_mode
00226 //       Access: Public
00227 //  Description: Returns the DepthTestMode value associated with the
00228 //               given string representation, or DTM_unspecified if
00229 //               the string does not match any known DepthTestMode
00230 //               value.
00231 ////////////////////////////////////////////////////////////////////
00232 EggRenderMode::DepthTestMode EggRenderMode::
00233 string_depth_test_mode(const string &string) {
00234   if (cmp_nocase_uh(string, "off") == 0) {
00235     return DTM_off;
00236   } else if (cmp_nocase_uh(string, "on") == 0) {
00237     return DTM_on;
00238   } else {
00239     return DTM_unspecified;
00240   }
00241 }
00242 
00243 ////////////////////////////////////////////////////////////////////
00244 //     Function: EggRenderMode::string_visibility_mode
00245 //       Access: Public
00246 //  Description: Returns the HiddenMode value associated with the
00247 //               given string representation, or VM_unspecified if
00248 //               the string does not match any known HiddenMode
00249 //               value.
00250 ////////////////////////////////////////////////////////////////////
00251 EggRenderMode::VisibilityMode EggRenderMode::
00252 string_visibility_mode(const string &string) {
00253   if (cmp_nocase_uh(string, "hidden") == 0) {
00254     return VM_hidden;
00255   } else if (cmp_nocase_uh(string, "normal") == 0) {
00256     return VM_normal;
00257   } else {
00258     return VM_unspecified;
00259   }
00260 }
00261 
00262 
00263 ////////////////////////////////////////////////////////////////////
00264 //     Function: AlphaMode output operator
00265 //  Description:
00266 ////////////////////////////////////////////////////////////////////
00267 ostream &operator << (ostream &out, EggRenderMode::AlphaMode mode) {
00268   switch (mode) {
00269   case EggRenderMode::AM_unspecified:
00270     return out << "unspecified";
00271   case EggRenderMode::AM_off:
00272     return out << "off";
00273   case EggRenderMode::AM_on:
00274     return out << "on";
00275   case EggRenderMode::AM_blend:
00276     return out << "blend";
00277   case EggRenderMode::AM_blend_no_occlude:
00278     return out << "blend_no_occlude";
00279   case EggRenderMode::AM_ms:
00280     return out << "ms";
00281   case EggRenderMode::AM_ms_mask:
00282     return out << "ms_mask";
00283   case EggRenderMode::AM_binary:
00284     return out << "binary";
00285   case EggRenderMode::AM_dual:
00286     return out << "dual";
00287   }
00288 
00289   nassertr(false, out);
00290   return out << "(**invalid**)";
00291 }
00292 
00293 ////////////////////////////////////////////////////////////////////
00294 //     Function: AlphaMode input operator
00295 //  Description:
00296 ////////////////////////////////////////////////////////////////////
00297 istream &operator >> (istream &in, EggRenderMode::AlphaMode &mode) {
00298   string word;
00299   in >> word;
00300   mode = EggRenderMode::string_alpha_mode(word);
00301   return in;
00302 }
00303 
00304 ////////////////////////////////////////////////////////////////////
00305 //     Function: DepthWriteMode output operator
00306 //  Description:
00307 ////////////////////////////////////////////////////////////////////
00308 ostream &operator << (ostream &out, EggRenderMode::DepthWriteMode mode) {
00309   switch (mode) {
00310   case EggRenderMode::DWM_unspecified:
00311     return out << "unspecified";
00312   case EggRenderMode::DWM_off:
00313     return out << "off";
00314   case EggRenderMode::DWM_on:
00315     return out << "on";
00316   }
00317 
00318   nassertr(false, out);
00319   return out << "(**invalid**)";
00320 }
00321 
00322 ////////////////////////////////////////////////////////////////////
00323 //     Function: DepthTestMode output operator
00324 //  Description:
00325 ////////////////////////////////////////////////////////////////////
00326 ostream &operator << (ostream &out, EggRenderMode::DepthTestMode mode) {
00327   switch (mode) {
00328   case EggRenderMode::DTM_unspecified:
00329     return out << "unspecified";
00330   case EggRenderMode::DTM_off:
00331     return out << "off";
00332   case EggRenderMode::DTM_on:
00333     return out << "on";
00334   }
00335 
00336   nassertr(false, out);
00337   return out << "(**invalid**)";
00338 }
00339 
00340 
00341 
00342 ////////////////////////////////////////////////////////////////////
00343 //     Function: VisibilityMode output operator
00344 //  Description:
00345 ////////////////////////////////////////////////////////////////////
00346 ostream &operator << (ostream &out, EggRenderMode::VisibilityMode mode) {
00347   switch (mode) {
00348   case EggRenderMode::VM_unspecified:
00349     return out << "unspecified";
00350   case EggRenderMode::VM_hidden:
00351     return out << "hidden";
00352   case EggRenderMode::VM_normal:
00353     return out << "normal";
00354   }
00355 
00356   nassertr(false, out);
00357   return out << "(**invalid**)";
00358 }
00359 
00360 
 All Classes Functions Variables Enumerations