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