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::get_hash_impl 00091 // Access: Protected, Virtual 00092 // Description: Intended to be overridden by derived RenderAttrib 00093 // types to return a unique hash for these particular 00094 // properties. RenderAttribs that compare the same with 00095 // compare_to_impl(), above, should return the same 00096 // hash; RenderAttribs that compare differently should 00097 // return a different hash. 00098 //////////////////////////////////////////////////////////////////// 00099 size_t DepthWriteAttrib:: 00100 get_hash_impl() const { 00101 size_t hash = 0; 00102 hash = int_hash::add_hash(hash, (int)_mode); 00103 return hash; 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: DepthWriteAttrib::register_with_read_factory 00108 // Access: Public, Static 00109 // Description: Tells the BamReader how to create objects of type 00110 // DepthWriteAttrib. 00111 //////////////////////////////////////////////////////////////////// 00112 void DepthWriteAttrib:: 00113 register_with_read_factory() { 00114 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00115 } 00116 00117 //////////////////////////////////////////////////////////////////// 00118 // Function: DepthWriteAttrib::write_datagram 00119 // Access: Public, Virtual 00120 // Description: Writes the contents of this object to the datagram 00121 // for shipping out to a Bam file. 00122 //////////////////////////////////////////////////////////////////// 00123 void DepthWriteAttrib:: 00124 write_datagram(BamWriter *manager, Datagram &dg) { 00125 RenderAttrib::write_datagram(manager, dg); 00126 00127 dg.add_int8(_mode); 00128 } 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Function: DepthWriteAttrib::make_from_bam 00132 // Access: Protected, Static 00133 // Description: This function is called by the BamReader's factory 00134 // when a new object of type DepthWriteAttrib is encountered 00135 // in the Bam file. It should create the DepthWriteAttrib 00136 // and extract its information from the file. 00137 //////////////////////////////////////////////////////////////////// 00138 TypedWritable *DepthWriteAttrib:: 00139 make_from_bam(const FactoryParams ¶ms) { 00140 DepthWriteAttrib *attrib = new DepthWriteAttrib; 00141 DatagramIterator scan; 00142 BamReader *manager; 00143 00144 parse_params(params, scan, manager); 00145 attrib->fillin(scan, manager); 00146 00147 return attrib; 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function: DepthWriteAttrib::fillin 00152 // Access: Protected 00153 // Description: This internal function is called by make_from_bam to 00154 // read in all of the relevant data from the BamFile for 00155 // the new DepthWriteAttrib. 00156 //////////////////////////////////////////////////////////////////// 00157 void DepthWriteAttrib:: 00158 fillin(DatagramIterator &scan, BamReader *manager) { 00159 RenderAttrib::fillin(scan, manager); 00160 00161 _mode = (Mode)scan.get_int8(); 00162 }