00001 // Filename: depthWriteAttrib.cxx 00002 // Created by: drose (04Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "depthWriteAttrib.h" 00020 #include "graphicsStateGuardianBase.h" 00021 #include "dcast.h" 00022 #include "bamReader.h" 00023 #include "bamWriter.h" 00024 #include "datagram.h" 00025 #include "datagramIterator.h" 00026 00027 TypeHandle DepthWriteAttrib::_type_handle; 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: DepthWriteAttrib::make 00031 // Access: Published, Static 00032 // Description: Constructs a new DepthWriteAttrib object. 00033 //////////////////////////////////////////////////////////////////// 00034 CPT(RenderAttrib) DepthWriteAttrib:: 00035 make(DepthWriteAttrib::Mode mode) { 00036 DepthWriteAttrib *attrib = new DepthWriteAttrib(mode); 00037 return return_new(attrib); 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: DepthWriteAttrib::issue 00042 // Access: Public, Virtual 00043 // Description: Calls the appropriate method on the indicated GSG 00044 // to issue the graphics commands appropriate to the 00045 // given attribute. This is normally called 00046 // (indirectly) only from 00047 // GraphicsStateGuardian::set_state() or modify_state(). 00048 //////////////////////////////////////////////////////////////////// 00049 void DepthWriteAttrib:: 00050 issue(GraphicsStateGuardianBase *gsg) const { 00051 gsg->issue_depth_write(this); 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: DepthWriteAttrib::output 00056 // Access: Public, Virtual 00057 // Description: 00058 //////////////////////////////////////////////////////////////////// 00059 void DepthWriteAttrib:: 00060 output(ostream &out) const { 00061 out << get_type() << ":"; 00062 switch (get_mode()) { 00063 case M_off: 00064 out << "off"; 00065 break; 00066 case M_on: 00067 out << "on"; 00068 break; 00069 } 00070 } 00071 00072 //////////////////////////////////////////////////////////////////// 00073 // Function: DepthWriteAttrib::compare_to_impl 00074 // Access: Protected, Virtual 00075 // Description: Intended to be overridden by derived DepthWriteAttrib 00076 // types to return a unique number indicating whether 00077 // this DepthWriteAttrib is equivalent to the other one. 00078 // 00079 // This should return 0 if the two DepthWriteAttrib objects 00080 // are equivalent, a number less than zero if this one 00081 // should be sorted before the other one, and a number 00082 // greater than zero otherwise. 00083 // 00084 // This will only be called with two DepthWriteAttrib 00085 // objects whose get_type() functions return the same. 00086 //////////////////////////////////////////////////////////////////// 00087 int DepthWriteAttrib:: 00088 compare_to_impl(const RenderAttrib *other) const { 00089 const DepthWriteAttrib *ta; 00090 DCAST_INTO_R(ta, other, 0); 00091 return (int)_mode - (int)ta->_mode; 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: DepthWriteAttrib::make_default_impl 00096 // Access: Protected, Virtual 00097 // Description: Intended to be overridden by derived DepthWriteAttrib 00098 // types to specify what the default property for a 00099 // DepthWriteAttrib of this type should be. 00100 // 00101 // This should return a newly-allocated DepthWriteAttrib of 00102 // the same type that corresponds to whatever the 00103 // standard default for this kind of DepthWriteAttrib is. 00104 //////////////////////////////////////////////////////////////////// 00105 RenderAttrib *DepthWriteAttrib:: 00106 make_default_impl() const { 00107 return new DepthWriteAttrib; 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: DepthWriteAttrib::register_with_read_factory 00112 // Access: Public, Static 00113 // Description: Tells the BamReader how to create objects of type 00114 // DepthWriteAttrib. 00115 //////////////////////////////////////////////////////////////////// 00116 void DepthWriteAttrib:: 00117 register_with_read_factory() { 00118 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: DepthWriteAttrib::write_datagram 00123 // Access: Public, Virtual 00124 // Description: Writes the contents of this object to the datagram 00125 // for shipping out to a Bam file. 00126 //////////////////////////////////////////////////////////////////// 00127 void DepthWriteAttrib:: 00128 write_datagram(BamWriter *manager, Datagram &dg) { 00129 RenderAttrib::write_datagram(manager, dg); 00130 00131 dg.add_int8(_mode); 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: DepthWriteAttrib::make_from_bam 00136 // Access: Protected, Static 00137 // Description: This function is called by the BamReader's factory 00138 // when a new object of type DepthWriteAttrib is encountered 00139 // in the Bam file. It should create the DepthWriteAttrib 00140 // and extract its information from the file. 00141 //////////////////////////////////////////////////////////////////// 00142 TypedWritable *DepthWriteAttrib:: 00143 make_from_bam(const FactoryParams ¶ms) { 00144 DepthWriteAttrib *attrib = new DepthWriteAttrib; 00145 DatagramIterator scan; 00146 BamReader *manager; 00147 00148 parse_params(params, scan, manager); 00149 attrib->fillin(scan, manager); 00150 00151 return attrib; 00152 } 00153 00154 //////////////////////////////////////////////////////////////////// 00155 // Function: DepthWriteAttrib::fillin 00156 // Access: Protected 00157 // Description: This internal function is called by make_from_bam to 00158 // read in all of the relevant data from the BamFile for 00159 // the new DepthWriteAttrib. 00160 //////////////////////////////////////////////////////////////////// 00161 void DepthWriteAttrib:: 00162 fillin(DatagramIterator &scan, BamReader *manager) { 00163 RenderAttrib::fillin(scan, manager); 00164 00165 _mode = (Mode)scan.get_int8(); 00166 }