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