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