Panda3D
|
00001 // Filename: depthTestAttrib.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 "depthTestAttrib.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 DepthTestAttrib::_type_handle; 00024 int DepthTestAttrib::_attrib_slot; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: DepthTestAttrib::make 00028 // Access: Published, Static 00029 // Description: Constructs a new DepthTestAttrib object. 00030 //////////////////////////////////////////////////////////////////// 00031 CPT(RenderAttrib) DepthTestAttrib:: 00032 make(DepthTestAttrib::PandaCompareFunc mode) { 00033 DepthTestAttrib *attrib = new DepthTestAttrib(mode); 00034 return return_new(attrib); 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: DepthTestAttrib::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) DepthTestAttrib:: 00045 make_default() { 00046 return return_new(new DepthTestAttrib); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: DepthTestAttrib::output 00051 // Access: Public, Virtual 00052 // Description: 00053 //////////////////////////////////////////////////////////////////// 00054 void DepthTestAttrib:: 00055 output(ostream &out) const { 00056 out << get_type() << ":"; 00057 output_comparefunc(out,_mode); 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: DepthTestAttrib::compare_to_impl 00062 // Access: Protected, Virtual 00063 // Description: Intended to be overridden by derived DepthTestAttrib 00064 // types to return a unique number indicating whether 00065 // this DepthTestAttrib is equivalent to the other one. 00066 // 00067 // This should return 0 if the two DepthTestAttrib objects 00068 // are equivalent, a number less than zero if this one 00069 // should be sorted before the other one, and a number 00070 // greater than zero otherwise. 00071 // 00072 // This will only be called with two DepthTestAttrib 00073 // objects whose get_type() functions return the same. 00074 //////////////////////////////////////////////////////////////////// 00075 int DepthTestAttrib:: 00076 compare_to_impl(const RenderAttrib *other) const { 00077 const DepthTestAttrib *ta; 00078 DCAST_INTO_R(ta, other, 0); 00079 return (int)_mode - (int)ta->_mode; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: DepthTestAttrib::get_hash_impl 00084 // Access: Protected, Virtual 00085 // Description: Intended to be overridden by derived RenderAttrib 00086 // types to return a unique hash for these particular 00087 // properties. RenderAttribs that compare the same with 00088 // compare_to_impl(), above, should return the same 00089 // hash; RenderAttribs that compare differently should 00090 // return a different hash. 00091 //////////////////////////////////////////////////////////////////// 00092 size_t DepthTestAttrib:: 00093 get_hash_impl() const { 00094 size_t hash = 0; 00095 hash = int_hash::add_hash(hash, (int)_mode); 00096 return hash; 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: DepthTestAttrib::register_with_read_factory 00101 // Access: Public, Static 00102 // Description: Tells the BamReader how to create objects of type 00103 // DepthTestAttrib. 00104 //////////////////////////////////////////////////////////////////// 00105 void DepthTestAttrib:: 00106 register_with_read_factory() { 00107 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: DepthTestAttrib::write_datagram 00112 // Access: Public, Virtual 00113 // Description: Writes the contents of this object to the datagram 00114 // for shipping out to a Bam file. 00115 //////////////////////////////////////////////////////////////////// 00116 void DepthTestAttrib:: 00117 write_datagram(BamWriter *manager, Datagram &dg) { 00118 RenderAttrib::write_datagram(manager, dg); 00119 00120 dg.add_int8(_mode); 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: DepthTestAttrib::make_from_bam 00125 // Access: Protected, Static 00126 // Description: This function is called by the BamReader's factory 00127 // when a new object of type DepthTestAttrib is encountered 00128 // in the Bam file. It should create the DepthTestAttrib 00129 // and extract its information from the file. 00130 //////////////////////////////////////////////////////////////////// 00131 TypedWritable *DepthTestAttrib:: 00132 make_from_bam(const FactoryParams ¶ms) { 00133 DepthTestAttrib *attrib = new DepthTestAttrib; 00134 DatagramIterator scan; 00135 BamReader *manager; 00136 00137 parse_params(params, scan, manager); 00138 attrib->fillin(scan, manager); 00139 00140 return attrib; 00141 } 00142 00143 //////////////////////////////////////////////////////////////////// 00144 // Function: DepthTestAttrib::fillin 00145 // Access: Protected 00146 // Description: This internal function is called by make_from_bam to 00147 // read in all of the relevant data from the BamFile for 00148 // the new DepthTestAttrib. 00149 //////////////////////////////////////////////////////////////////// 00150 void DepthTestAttrib:: 00151 fillin(DatagramIterator &scan, BamReader *manager) { 00152 RenderAttrib::fillin(scan, manager); 00153 00154 _mode = (PandaCompareFunc)scan.get_int8(); 00155 }