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