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