Panda3D
|
00001 // Filename: depthWriteAttrib.cxx 00002 // Created by: drose (04Mar02) 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 "depthWriteAttrib.h" 00016 #include "graphicsStateGuardianBase.h" 00017 #include "dcast.h" 00018 #include "bamReader.h" 00019 #include "bamWriter.h" 00020 #include "datagram.h" 00021 #include "datagramIterator.h" 00022 00023 TypeHandle DepthWriteAttrib::_type_handle; 00024 int DepthWriteAttrib::_attrib_slot; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: DepthWriteAttrib::make 00028 // Access: Published, Static 00029 // Description: Constructs a new DepthWriteAttrib object. 00030 //////////////////////////////////////////////////////////////////// 00031 CPT(RenderAttrib) DepthWriteAttrib:: 00032 make(DepthWriteAttrib::Mode mode) { 00033 DepthWriteAttrib *attrib = new DepthWriteAttrib(mode); 00034 return return_new(attrib); 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: DepthWriteAttrib::make_default 00039 // Access: Published, Static 00040 // Description: Returns a RenderAttrib that corresponds to whatever 00041 // the standard default properties for render attributes 00042 // of this type ought to be. 00043 //////////////////////////////////////////////////////////////////// 00044 CPT(RenderAttrib) DepthWriteAttrib:: 00045 make_default() { 00046 return return_new(new DepthWriteAttrib); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: DepthWriteAttrib::output 00051 // Access: Public, Virtual 00052 // Description: 00053 //////////////////////////////////////////////////////////////////// 00054 void DepthWriteAttrib:: 00055 output(ostream &out) const { 00056 out << get_type() << ":"; 00057 switch (get_mode()) { 00058 case M_off: 00059 out << "off"; 00060 break; 00061 case M_on: 00062 out << "on"; 00063 break; 00064 } 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: DepthWriteAttrib::compare_to_impl 00069 // Access: Protected, Virtual 00070 // Description: Intended to be overridden by derived DepthWriteAttrib 00071 // types to return a unique number indicating whether 00072 // this DepthWriteAttrib is equivalent to the other one. 00073 // 00074 // This should return 0 if the two DepthWriteAttrib objects 00075 // are equivalent, a number less than zero if this one 00076 // should be sorted before the other one, and a number 00077 // greater than zero otherwise. 00078 // 00079 // This will only be called with two DepthWriteAttrib 00080 // objects whose get_type() functions return the same. 00081 //////////////////////////////////////////////////////////////////// 00082 int DepthWriteAttrib:: 00083 compare_to_impl(const RenderAttrib *other) const { 00084 const DepthWriteAttrib *ta; 00085 DCAST_INTO_R(ta, other, 0); 00086 return (int)_mode - (int)ta->_mode; 00087 } 00088 00089 //////////////////////////////////////////////////////////////////// 00090 // Function: DepthWriteAttrib::register_with_read_factory 00091 // Access: Public, Static 00092 // Description: Tells the BamReader how to create objects of type 00093 // DepthWriteAttrib. 00094 //////////////////////////////////////////////////////////////////// 00095 void DepthWriteAttrib:: 00096 register_with_read_factory() { 00097 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: DepthWriteAttrib::write_datagram 00102 // Access: Public, Virtual 00103 // Description: Writes the contents of this object to the datagram 00104 // for shipping out to a Bam file. 00105 //////////////////////////////////////////////////////////////////// 00106 void DepthWriteAttrib:: 00107 write_datagram(BamWriter *manager, Datagram &dg) { 00108 RenderAttrib::write_datagram(manager, dg); 00109 00110 dg.add_int8(_mode); 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: DepthWriteAttrib::make_from_bam 00115 // Access: Protected, Static 00116 // Description: This function is called by the BamReader's factory 00117 // when a new object of type DepthWriteAttrib is encountered 00118 // in the Bam file. It should create the DepthWriteAttrib 00119 // and extract its information from the file. 00120 //////////////////////////////////////////////////////////////////// 00121 TypedWritable *DepthWriteAttrib:: 00122 make_from_bam(const FactoryParams ¶ms) { 00123 DepthWriteAttrib *attrib = new DepthWriteAttrib; 00124 DatagramIterator scan; 00125 BamReader *manager; 00126 00127 parse_params(params, scan, manager); 00128 attrib->fillin(scan, manager); 00129 00130 return attrib; 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: DepthWriteAttrib::fillin 00135 // Access: Protected 00136 // Description: This internal function is called by make_from_bam to 00137 // read in all of the relevant data from the BamFile for 00138 // the new DepthWriteAttrib. 00139 //////////////////////////////////////////////////////////////////// 00140 void DepthWriteAttrib:: 00141 fillin(DatagramIterator &scan, BamReader *manager) { 00142 RenderAttrib::fillin(scan, manager); 00143 00144 _mode = (Mode)scan.get_int8(); 00145 }