00001 // Filename: geomSprite.cxx 00002 // Created by: charles (13Jul00) 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 <datagram.h> 00020 #include <datagramIterator.h> 00021 #include <bamReader.h> 00022 #include <bamWriter.h> 00023 #include <ioPtaDatagramShort.h> 00024 #include <ioPtaDatagramInt.h> 00025 #include <ioPtaDatagramFloat.h> 00026 #include <ioPtaDatagramLinMath.h> 00027 #include <graphicsStateGuardianBase.h> 00028 00029 #include "geomSprite.h" 00030 00031 TypeHandle GeomSprite::_type_handle; 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: GeomSprite 00035 // Access: public 00036 // Description: constructor 00037 //////////////////////////////////////////////////////////////////// 00038 GeomSprite:: 00039 GeomSprite(Texture *tex, bool alpha_disable) : 00040 _texture(tex), _alpha_disable(alpha_disable) 00041 { 00042 _ll_uv.set(0.0f, 0.0f); 00043 _ur_uv.set(1.0f, 1.0f); 00044 _x_texel_ratio.clear(); 00045 _y_texel_ratio.clear(); 00046 00047 _theta_bind_type = G_OFF; 00048 // note that the other bind types are intentionally left 00049 // uninitialized; the arrays themselves can not be set without a 00050 // bind type. 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: GeomSprite::make_copy 00055 // Access: Public, Virtual 00056 // Description: Returns a newly-allocated Geom that is a shallow copy 00057 // of this one. It will be a different Geom pointer, 00058 // but its internal data may or may not be shared with 00059 // that of the original Geom. 00060 //////////////////////////////////////////////////////////////////// 00061 Geom *GeomSprite:: 00062 make_copy() const { 00063 return new GeomSprite(*this); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: GeomSprite::print_draw_immediate 00068 // Access: 00069 // Description: 00070 //////////////////////////////////////////////////////////////////// 00071 void GeomSprite:: 00072 print_draw_immediate(void) const { 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: GeomSprite::draw_immediate 00077 // Access: 00078 // Description: 00079 //////////////////////////////////////////////////////////////////// 00080 void GeomSprite:: 00081 draw_immediate(GraphicsStateGuardianBase *gsg, GeomContext *gc) { 00082 gsg->draw_sprite(this, gc); 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: GeomSprite::write_datagram 00087 // Access: Public 00088 // Description: Function to write the important information in 00089 // the particular object to a Datagram 00090 //////////////////////////////////////////////////////////////////// 00091 void GeomSprite:: 00092 write_datagram(BamWriter *manager, Datagram &me) { 00093 Geom::write_datagram(manager, me); 00094 WRITE_PTA(manager, me, IPD_float::write_datagram, _x_texel_ratio); 00095 WRITE_PTA(manager, me, IPD_float::write_datagram, _y_texel_ratio); 00096 me.add_uint8(_x_bind_type); 00097 me.add_uint8(_y_bind_type); 00098 me.add_uint8(_alpha_disable); 00099 manager->write_pointer(me, _texture); 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: GeomSprite::make_GeomSprite 00104 // Access: Protected 00105 // Description: Factory method to generate a GeomSprite object 00106 //////////////////////////////////////////////////////////////////// 00107 TypedWritable* GeomSprite:: 00108 make_GeomSprite(const FactoryParams ¶ms) { 00109 GeomSprite *me = new GeomSprite; 00110 DatagramIterator scan; 00111 BamReader *manager; 00112 00113 parse_params(params, scan, manager); 00114 me->fillin(scan, manager); 00115 me->make_dirty(); 00116 me->config(); 00117 return me; 00118 } 00119 00120 //////////////////////////////////////////////////////////////////// 00121 // Function: GeomSprite::fillin 00122 // Access: Protected 00123 // Description: Function that reads out of the datagram (or asks 00124 // manager to read) all of the data that is needed to 00125 // re-create this object and stores it in the appropiate 00126 // place 00127 //////////////////////////////////////////////////////////////////// 00128 void GeomSprite:: 00129 fillin(DatagramIterator& scan, BamReader* manager) { 00130 Geom::fillin(scan, manager); 00131 READ_PTA(manager, scan, IPD_float::read_datagram, _x_texel_ratio); 00132 READ_PTA(manager, scan, IPD_float::read_datagram, _y_texel_ratio); 00133 _x_bind_type = (GeomBindType) scan.get_uint8(); 00134 _y_bind_type = (GeomBindType) scan.get_uint8(); 00135 _alpha_disable = (scan.get_uint8() !=0); 00136 manager->read_pointer(scan); 00137 } 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: GeomSprite::register_with_factory 00141 // Access: Public, Static 00142 // Description: Factory method to generate a GeomSprite object 00143 //////////////////////////////////////////////////////////////////// 00144 void GeomSprite:: 00145 register_with_read_factory(void) { 00146 BamReader::get_factory()->register_factory(get_class_type(), make_GeomSprite); 00147 } 00148 00149 //////////////////////////////////////////////////////////////////// 00150 // Function: GeomSprite::complete_pointers 00151 // Access: Public, Static 00152 // Description: 00153 //////////////////////////////////////////////////////////////////// 00154 int GeomSprite:: 00155 complete_pointers(TypedWritable **p_list, BamReader *manager) { 00156 int index = Geom::complete_pointers(p_list, manager); 00157 _texture = DCAST(Texture, p_list[index]); 00158 00159 return index + 1; 00160 }