Panda3D

geomVertexColumn.cxx

00001 // Filename: geomVertexColumn.cxx
00002 // Created by:  drose (06Mar05)
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 "geomVertexColumn.h"
00016 #include "geomVertexData.h"
00017 #include "bamReader.h"
00018 #include "bamWriter.h"
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: GeomVertexColumn::Copy Assignment Operator
00022 //       Access: Published
00023 //  Description: 
00024 ////////////////////////////////////////////////////////////////////
00025 void GeomVertexColumn::
00026 operator = (const GeomVertexColumn &copy) {
00027   _name = copy._name;
00028   _num_components = copy._num_components;
00029   _numeric_type = copy._numeric_type;
00030   _contents = copy._contents;
00031   _start = copy._start;
00032 
00033   delete _packer;
00034   _packer = NULL;
00035 
00036   setup();
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: GeomVertexColumn::output
00041 //       Access: Published
00042 //  Description: 
00043 ////////////////////////////////////////////////////////////////////
00044 void GeomVertexColumn::
00045 output(ostream &out) const {
00046   out << *get_name() << "(" << get_num_components();
00047   switch (get_numeric_type()) {
00048   case NT_uint8:
00049     out << "b";
00050     break;
00051 
00052   case NT_uint16:
00053     out << "s";
00054     break;
00055 
00056   case NT_uint32:
00057     out << "l";
00058     break;
00059 
00060   case NT_packed_dcba:
00061     out << "p-";
00062     break;
00063 
00064   case NT_packed_dabc:
00065     out << "p";
00066     break;
00067 
00068   case NT_float32:
00069     out << "f";
00070   }
00071 
00072   out << ")";
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: GeomVertexColumn::setup
00077 //       Access: Private
00078 //  Description: Called once at construction time (or at bam-reading
00079 //               time) to initialize the internal dependent values.
00080 ////////////////////////////////////////////////////////////////////
00081 void GeomVertexColumn::
00082 setup() {
00083   nassertv(_num_components > 0 && _start >= 0);
00084 
00085   _num_values = _num_components;
00086 
00087   switch (_numeric_type) {
00088   case NT_uint16:
00089     _component_bytes = 2;  // sizeof(PN_uint16)
00090     break;
00091 
00092   case NT_uint32:
00093     _component_bytes = 4;  // sizeof(PN_uint32)
00094     break;
00095 
00096   case NT_uint8:
00097     _component_bytes = 1;
00098     break;
00099 
00100   case NT_packed_dcba:
00101   case NT_packed_dabc:
00102     _component_bytes = 4;  // sizeof(PN_uint32)
00103     _num_values *= 4;
00104     break;
00105 
00106   case NT_float32:
00107     _component_bytes = 4;  // sizeof(PN_float32)
00108     break;
00109   }
00110 
00111   _total_bytes = _component_bytes * _num_components;
00112 
00113   _packer = make_packer();
00114   _packer->_column = this;
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: GeomVertexColumn::make_packer
00119 //       Access: Private
00120 //  Description: Returns a newly-allocated Packer object suitable for
00121 //               packing and unpacking this column.  The _column
00122 //               member of the packer is not filled in.
00123 ////////////////////////////////////////////////////////////////////
00124 GeomVertexColumn::Packer *GeomVertexColumn::
00125 make_packer() const {
00126   switch (get_contents()) {
00127   case C_point:
00128   case C_clip_point:
00129   case C_texcoord:
00130     // These types are read as a 4-d homogeneous point.
00131     switch (get_numeric_type()) {
00132     case NT_float32:
00133       if (sizeof(float) == sizeof(PN_float32)) {
00134         // Use the native float type implementation for a tiny bit
00135         // more optimization.
00136         switch (get_num_components()) {
00137         case 2:
00138           return new Packer_point_nativefloat_2;
00139         case 3:
00140           return new Packer_point_nativefloat_3;
00141         case 4:
00142           return new Packer_point_nativefloat_4;
00143         }
00144       } else {
00145         switch (get_num_components()) {
00146         case 2:
00147           return new Packer_point_float32_2;
00148         case 3:
00149           return new Packer_point_float32_3;
00150         case 4:
00151           return new Packer_point_float32_4;
00152         }
00153       }
00154       break;
00155     default:
00156       break;
00157     }
00158     return new Packer_point;
00159 
00160   case C_color:
00161     switch (get_numeric_type()) {
00162     case NT_uint8:
00163       switch (get_num_components()) {
00164       case 4:
00165         return new Packer_rgba_uint8_4;
00166         
00167       default:
00168         break;
00169       }
00170       break;
00171     case NT_packed_dabc:
00172       switch (get_num_components()) {
00173       case 1:
00174         return new Packer_argb_packed;
00175         
00176       default:
00177         break;
00178       }
00179       break;
00180     case NT_float32:
00181       switch (get_num_components()) {
00182       case 4:
00183         if (sizeof(float) == sizeof(PN_float32)) {
00184           // Use the native float type implementation for a tiny bit
00185           // more optimization.
00186           return new Packer_rgba_nativefloat_4;
00187         } else {
00188           return new Packer_rgba_float32_4;
00189         }
00190         
00191       default:
00192         break;
00193       }
00194       break;
00195     default:
00196       break;
00197     }
00198     return new Packer_color;
00199 
00200   default:
00201     // Otherwise, we just read it as a generic value.
00202     switch (get_numeric_type()) {
00203     case NT_float32:
00204       switch (get_num_components()) {
00205       case 3:
00206         if (sizeof(float) == sizeof(PN_float32)) {
00207           // Use the native float type implementation for a tiny bit
00208           // more optimization.
00209           return new Packer_nativefloat_3;
00210         } else {
00211           return new Packer_float32_3;
00212         }
00213 
00214       default:
00215         break;
00216       }
00217       break;
00218     default:
00219       break;
00220     }
00221     return new Packer;
00222   }
00223 }
00224 
00225 ////////////////////////////////////////////////////////////////////
00226 //     Function: GeomVertexColumn::write_datagram
00227 //       Access: Public
00228 //  Description: Writes the contents of this object to the datagram
00229 //               for shipping out to a Bam file.
00230 ////////////////////////////////////////////////////////////////////
00231 void GeomVertexColumn::
00232 write_datagram(BamWriter *manager, Datagram &dg) {
00233   manager->write_pointer(dg, _name);
00234   dg.add_uint8(_num_components);
00235   dg.add_uint8(_numeric_type);
00236   dg.add_uint8(_contents);
00237   dg.add_uint16(_start);
00238 }
00239 
00240 ////////////////////////////////////////////////////////////////////
00241 //     Function: GeomVertexColumn::complete_pointers
00242 //       Access: Public
00243 //  Description: Receives an array of pointers, one for each time
00244 //               manager->read_pointer() was called in fillin().
00245 //               Returns the number of pointers processed.
00246 ////////////////////////////////////////////////////////////////////
00247 int GeomVertexColumn::
00248 complete_pointers(TypedWritable **p_list, BamReader *manager) {
00249   int pi = 0;
00250 
00251   _name = DCAST(InternalName, p_list[pi++]);
00252 
00253   return pi;
00254 }
00255 
00256 ////////////////////////////////////////////////////////////////////
00257 //     Function: GeomVertexColumn::fillin
00258 //       Access: Protected
00259 //  Description: This internal function is called by make_from_bam to
00260 //               read in all of the relevant data from the BamFile for
00261 //               the new GeomVertexColumn.
00262 ////////////////////////////////////////////////////////////////////
00263 void GeomVertexColumn::
00264 fillin(DatagramIterator &scan, BamReader *manager) {
00265   manager->read_pointer(scan);
00266 
00267   _num_components = scan.get_uint8();
00268   _numeric_type = (NumericType)scan.get_uint8();
00269   _contents = (Contents)scan.get_uint8();
00270   _start = scan.get_uint16();
00271 
00272   setup();
00273 }
00274 
00275 ////////////////////////////////////////////////////////////////////
00276 //     Function: GeomVertexColumn::Packer::Destructor
00277 //       Access: Public, Virtual
00278 //  Description: 
00279 ////////////////////////////////////////////////////////////////////
00280 GeomVertexColumn::Packer::
00281 ~Packer() {
00282 }
00283 
00284 ////////////////////////////////////////////////////////////////////
00285 //     Function: GeomVertexColumn::Packer::get_data1f
00286 //       Access: Public, Virtual
00287 //  Description: 
00288 ////////////////////////////////////////////////////////////////////
00289 float GeomVertexColumn::Packer::
00290 get_data1f(const unsigned char *pointer) {
00291   switch (_column->get_numeric_type()) {
00292   case NT_uint8:
00293     return maybe_scale_color(*pointer);
00294 
00295   case NT_uint16:
00296     return *(const PN_uint16 *)pointer;
00297 
00298   case NT_uint32:
00299     return *(const PN_uint32 *)pointer;
00300 
00301   case NT_packed_dcba:
00302     {
00303       PN_uint32 dword = *(const PN_uint32 *)pointer;
00304       return maybe_scale_color(GeomVertexData::unpack_abcd_d(dword));
00305     }
00306 
00307   case NT_packed_dabc:
00308     {
00309       PN_uint32 dword = *(const PN_uint32 *)pointer;
00310       return maybe_scale_color(GeomVertexData::unpack_abcd_b(dword));
00311     }
00312 
00313   case NT_float32:
00314     return *(const PN_float32 *)pointer;
00315   }
00316 
00317   return 0.0f;
00318 }
00319 
00320 ////////////////////////////////////////////////////////////////////
00321 //     Function: GeomVertexColumn::Packer::get_data2f
00322 //       Access: Public, Virtual
00323 //  Description: 
00324 ////////////////////////////////////////////////////////////////////
00325 const LVecBase2f &GeomVertexColumn::Packer::
00326 get_data2f(const unsigned char *pointer) {
00327   if (_column->get_num_values() == 1) {
00328     _v2.set(get_data1f(pointer), 0.0f);
00329     return _v2;
00330 
00331   } else {
00332     switch (_column->get_numeric_type()) {
00333     case NT_uint8:
00334       maybe_scale_color(pointer[0], pointer[1]);
00335       return _v2;
00336       
00337     case NT_uint16:
00338       {
00339         const PN_uint16 *pi = (const PN_uint16 *)pointer;
00340         _v2.set(pi[0], pi[1]);
00341       }
00342       return _v2;
00343       
00344     case NT_uint32:
00345       {
00346         const PN_uint32 *pi = (const PN_uint32 *)pointer;
00347         _v2.set(pi[0], pi[1]);
00348       }
00349       return _v2;
00350       
00351     case NT_packed_dcba:
00352       {
00353         PN_uint32 dword = *(const PN_uint32 *)pointer;
00354         maybe_scale_color(GeomVertexData::unpack_abcd_d(dword),
00355                           GeomVertexData::unpack_abcd_c(dword));
00356       }
00357       return _v2;
00358       
00359     case NT_packed_dabc:
00360       {
00361         PN_uint32 dword = *(const PN_uint32 *)pointer;
00362         maybe_scale_color(GeomVertexData::unpack_abcd_b(dword),
00363                           GeomVertexData::unpack_abcd_c(dword));
00364       }
00365       return _v2;
00366       
00367     case NT_float32:
00368       {
00369         const PN_float32 *pi = (const PN_float32 *)pointer;
00370         _v2.set(pi[0], pi[1]);
00371       }
00372       return _v2;
00373     }
00374   }
00375 
00376   return _v2;
00377 }
00378 
00379 ////////////////////////////////////////////////////////////////////
00380 //     Function: GeomVertexColumn::Packer::get_data3f
00381 //       Access: Public, Virtual
00382 //  Description: 
00383 ////////////////////////////////////////////////////////////////////
00384 const LVecBase3f &GeomVertexColumn::Packer::
00385 get_data3f(const unsigned char *pointer) {
00386   switch (_column->get_num_values()) {
00387   case 1:
00388     _v3.set(get_data1f(pointer), 0.0f, 0.0f);
00389     return _v3;
00390 
00391   case 2:
00392     {
00393       const LVecBase2f &v2 = get_data2f(pointer);
00394       _v3.set(v2[0], v2[1], 0.0f);
00395     }
00396     return _v3;
00397 
00398   default:
00399     switch (_column->get_numeric_type()) {
00400     case NT_uint8:
00401       maybe_scale_color(pointer[0], pointer[1], pointer[2]);
00402       return _v3;
00403       
00404     case NT_uint16:
00405       {
00406         const PN_uint16 *pi = (const PN_uint16 *)pointer;
00407         _v3.set(pi[0], pi[1], pi[2]);
00408       }
00409       return _v3;
00410       
00411     case NT_uint32:
00412       {
00413         const PN_uint32 *pi = (const PN_uint32 *)pointer;
00414         _v3.set(pi[0], pi[1], pi[2]);
00415       }
00416       return _v3;
00417       
00418     case NT_packed_dcba:
00419       {
00420         PN_uint32 dword = *(const PN_uint32 *)pointer;
00421         maybe_scale_color(GeomVertexData::unpack_abcd_d(dword),
00422                           GeomVertexData::unpack_abcd_c(dword),
00423                           GeomVertexData::unpack_abcd_b(dword));
00424       }
00425       return _v3;
00426       
00427     case NT_packed_dabc:
00428       {
00429         PN_uint32 dword = *(const PN_uint32 *)pointer;
00430         maybe_scale_color(GeomVertexData::unpack_abcd_b(dword),
00431                           GeomVertexData::unpack_abcd_c(dword),
00432                           GeomVertexData::unpack_abcd_d(dword));
00433       }
00434       return _v3;
00435       
00436     case NT_float32:
00437       {
00438         const PN_float32 *pi = (const PN_float32 *)pointer;
00439         _v3.set(pi[0], pi[1], pi[2]);
00440       }
00441       return _v3;
00442     }
00443   }
00444 
00445   return _v3;
00446 }
00447 
00448 ////////////////////////////////////////////////////////////////////
00449 //     Function: GeomVertexColumn::Packer::get_data4f
00450 //       Access: Public, Virtual
00451 //  Description: 
00452 ////////////////////////////////////////////////////////////////////
00453 const LVecBase4f &GeomVertexColumn::Packer::
00454 get_data4f(const unsigned char *pointer) {
00455   switch (_column->get_num_values()) {
00456   case 1:
00457     _v4.set(get_data1f(pointer), 0.0f, 0.0f, 0.0f);
00458     return _v4;
00459 
00460   case 2:
00461     {
00462       const LVecBase2f &v2 = get_data2f(pointer);
00463       _v4.set(v2[0], v2[1], 0.0f, 0.0f);
00464     }
00465     return _v4;
00466 
00467   case 3:
00468     {
00469       const LVecBase3f &v3 = get_data3f(pointer);
00470       _v4.set(v3[0], v3[1], v3[2], 0.0f);
00471     }
00472     return _v4;
00473 
00474   default:
00475     switch (_column->get_numeric_type()) {
00476     case NT_uint8:
00477       maybe_scale_color(pointer[0], pointer[1], pointer[2], pointer[3]);
00478       return _v4;
00479       
00480     case NT_uint16:
00481       {
00482         const PN_uint16 *pi = (const PN_uint16 *)pointer;
00483         _v4.set(pi[0], pi[1], pi[2], pi[3]);
00484       }
00485       return _v4;
00486       
00487     case NT_uint32:
00488       {
00489         const PN_uint32 *pi = (const PN_uint32 *)pointer;
00490         _v4.set(pi[0], pi[1], pi[2], pi[3]);
00491       }
00492       return _v4;
00493       
00494     case NT_packed_dcba:
00495       {
00496         PN_uint32 dword = *(const PN_uint32 *)pointer;
00497         maybe_scale_color(GeomVertexData::unpack_abcd_d(dword),
00498                           GeomVertexData::unpack_abcd_c(dword),
00499                           GeomVertexData::unpack_abcd_b(dword),
00500                           GeomVertexData::unpack_abcd_a(dword));
00501       }
00502       return _v4;
00503       
00504     case NT_packed_dabc:
00505       {
00506         PN_uint32 dword = *(const PN_uint32 *)pointer;
00507         maybe_scale_color(GeomVertexData::unpack_abcd_b(dword),
00508                           GeomVertexData::unpack_abcd_c(dword),
00509                           GeomVertexData::unpack_abcd_d(dword),
00510                           GeomVertexData::unpack_abcd_a(dword));
00511       }
00512       return _v4;
00513       
00514     case NT_float32:
00515       {
00516         const PN_float32 *pi = (const PN_float32 *)pointer;
00517         _v4.set(pi[0], pi[1], pi[2], pi[3]);
00518       }
00519       return _v4;
00520     }
00521   }
00522 
00523   return _v4;
00524 }
00525 
00526 ////////////////////////////////////////////////////////////////////
00527 //     Function: GeomVertexColumn::Packer::get_data1i
00528 //       Access: Public, Virtual
00529 //  Description: 
00530 ////////////////////////////////////////////////////////////////////
00531 int GeomVertexColumn::Packer::
00532 get_data1i(const unsigned char *pointer) {
00533   switch (_column->get_numeric_type()) {
00534   case NT_uint8:
00535     return *pointer;
00536 
00537   case NT_uint16:
00538     return *(const PN_uint16 *)pointer;
00539 
00540   case NT_uint32:
00541     return *(const PN_uint32 *)pointer;
00542 
00543   case NT_packed_dcba:
00544     {
00545       PN_uint32 dword = *(const PN_uint32 *)pointer;
00546       return GeomVertexData::unpack_abcd_d(dword);
00547     }
00548 
00549   case NT_packed_dabc:
00550     {
00551       PN_uint32 dword = *(const PN_uint32 *)pointer;
00552       return GeomVertexData::unpack_abcd_b(dword);
00553     }
00554 
00555   case NT_float32:
00556     return (int)*(const PN_float32 *)pointer;
00557   }
00558 
00559   return 0;
00560 }
00561 
00562 ////////////////////////////////////////////////////////////////////
00563 //     Function: GeomVertexColumn::Packer::get_data2i
00564 //       Access: Public, Virtual
00565 //  Description: 
00566 ////////////////////////////////////////////////////////////////////
00567 const int *GeomVertexColumn::Packer::
00568 get_data2i(const unsigned char *pointer) {
00569   switch (_column->get_num_values()) {
00570   case 1:
00571     _i[0] = get_data1i(pointer);
00572     _i[1] = 0;
00573     return _i;
00574 
00575   default:
00576     switch (_column->get_numeric_type()) {
00577     case NT_uint8:
00578       _i[0] = pointer[0];
00579       _i[1] = pointer[1];
00580       return _i;
00581       
00582     case NT_uint16:
00583       {
00584         const PN_uint16 *pi = (const PN_uint16 *)pointer;
00585         _i[0] = pi[0];
00586         _i[1] = pi[1];
00587       }
00588       return _i;
00589       
00590     case NT_uint32:
00591       {
00592         const PN_uint32 *pi = (const PN_uint32 *)pointer;
00593         _i[0] = pi[0];
00594         _i[1] = pi[1];
00595       }
00596       return _i;
00597       
00598     case NT_packed_dcba:
00599       {
00600         PN_uint32 dword = *(const PN_uint32 *)pointer;
00601         _i[0] = GeomVertexData::unpack_abcd_d(dword);
00602         _i[1] = GeomVertexData::unpack_abcd_c(dword);
00603       }
00604       return _i;
00605       
00606     case NT_packed_dabc:
00607       {
00608         PN_uint32 dword = *(const PN_uint32 *)pointer;
00609         _i[0] = GeomVertexData::unpack_abcd_b(dword);
00610         _i[1] = GeomVertexData::unpack_abcd_c(dword);
00611       }
00612       return _i;
00613       
00614     case NT_float32:
00615       {
00616         const PN_float32 *pi = (const PN_float32 *)pointer;
00617         _i[0] = (int)pi[0];
00618         _i[1] = (int)pi[1];
00619       }
00620       return _i;
00621     }
00622   }
00623 
00624   return _i;
00625 }
00626 
00627 ////////////////////////////////////////////////////////////////////
00628 //     Function: GeomVertexColumn::Packer::get_data3i
00629 //       Access: Public, Virtual
00630 //  Description: 
00631 ////////////////////////////////////////////////////////////////////
00632 const int *GeomVertexColumn::Packer::
00633 get_data3i(const unsigned char *pointer) {
00634   switch (_column->get_num_values()) {
00635   case 1:
00636     _i[0] = get_data1i(pointer);
00637     _i[1] = 0;
00638     _i[2] = 0;
00639     return _i;
00640 
00641   case 2:
00642     {
00643       const int *i = get_data2i(pointer);
00644       _i[0] = i[0];
00645       _i[1] = i[1];
00646       _i[2] = 0;
00647     }
00648     return _i;
00649 
00650   default:
00651     switch (_column->get_numeric_type()) {
00652     case NT_uint8:
00653       _i[0] = pointer[0];
00654       _i[1] = pointer[1];
00655       _i[2] = pointer[2];
00656       return _i;
00657       
00658     case NT_uint16:
00659       {
00660         const PN_uint16 *pi = (const PN_uint16 *)pointer;
00661         _i[0] = pi[0];
00662         _i[1] = pi[1];
00663         _i[2] = pi[2];
00664       }
00665       return _i;
00666       
00667     case NT_uint32:
00668       {
00669         const PN_uint32 *pi = (const PN_uint32 *)pointer;
00670         _i[0] = pi[0];
00671         _i[1] = pi[1];
00672         _i[2] = pi[2];
00673       }
00674       return _i;
00675       
00676     case NT_packed_dcba:
00677       {
00678         PN_uint32 dword = *(const PN_uint32 *)pointer;
00679         _i[0] = GeomVertexData::unpack_abcd_d(dword);
00680         _i[1] = GeomVertexData::unpack_abcd_c(dword);
00681         _i[2] = GeomVertexData::unpack_abcd_b(dword);
00682       }
00683       return _i;
00684       
00685     case NT_packed_dabc:
00686       {
00687         PN_uint32 dword = *(const PN_uint32 *)pointer;
00688         _i[0] = GeomVertexData::unpack_abcd_b(dword);
00689         _i[1] = GeomVertexData::unpack_abcd_c(dword);
00690         _i[2] = GeomVertexData::unpack_abcd_d(dword);
00691       }
00692       return _i;
00693       
00694     case NT_float32:
00695       {
00696         const PN_float32 *pi = (const PN_float32 *)pointer;
00697         _i[0] = (int)pi[0];
00698         _i[1] = (int)pi[1];
00699         _i[2] = (int)pi[2];
00700       }
00701       return _i;
00702     }
00703   }
00704 
00705   return _i;
00706 }
00707 
00708 ////////////////////////////////////////////////////////////////////
00709 //     Function: GeomVertexColumn::Packer::get_data4i
00710 //       Access: Public, Virtual
00711 //  Description: 
00712 ////////////////////////////////////////////////////////////////////
00713 const int *GeomVertexColumn::Packer::
00714 get_data4i(const unsigned char *pointer) {
00715   switch (_column->get_num_values()) {
00716   case 1:
00717     _i[0] = get_data1i(pointer);
00718     _i[1] = 0;
00719     _i[2] = 0;
00720     _i[3] = 0;
00721     return _i;
00722 
00723   case 2:
00724     {
00725       const int *i = get_data2i(pointer);
00726       _i[0] = i[0];
00727       _i[1] = i[1];
00728       _i[2] = 0;
00729       _i[3] = 0;
00730     }
00731     return _i;
00732 
00733   case 3:
00734     {
00735       const int *i = get_data3i(pointer);
00736       _i[0] = i[0];
00737       _i[1] = i[1];
00738       _i[2] = i[2];
00739       _i[3] = 0;
00740     }
00741     return _i;
00742 
00743   default:
00744     switch (_column->get_numeric_type()) {
00745     case NT_uint8:
00746       _i[0] = pointer[0];
00747       _i[1] = pointer[1];
00748       _i[2] = pointer[2];
00749       _i[3] = pointer[3];
00750       return _i;
00751       
00752     case NT_uint16:
00753       {
00754         const PN_uint16 *pi = (const PN_uint16 *)pointer;
00755         _i[0] = pi[0];
00756         _i[1] = pi[1];
00757         _i[2] = pi[2];
00758         _i[3] = pi[3];
00759       }
00760       return _i;
00761       
00762     case NT_uint32:
00763       {
00764         const PN_uint32 *pi = (const PN_uint32 *)pointer;
00765         _i[0] = pi[0];
00766         _i[1] = pi[1];
00767         _i[2] = pi[2];
00768         _i[3] = pi[3];
00769       }
00770       return _i;
00771       
00772     case NT_packed_dcba:
00773       {
00774         PN_uint32 dword = *(const PN_uint32 *)pointer;
00775         _i[0] = GeomVertexData::unpack_abcd_d(dword);
00776         _i[1] = GeomVertexData::unpack_abcd_c(dword);
00777         _i[2] = GeomVertexData::unpack_abcd_b(dword);
00778         _i[3] = GeomVertexData::unpack_abcd_a(dword);
00779       }
00780       return _i;
00781       
00782     case NT_packed_dabc:
00783       {
00784         PN_uint32 dword = *(const PN_uint32 *)pointer;
00785         _i[0] = GeomVertexData::unpack_abcd_b(dword);
00786         _i[1] = GeomVertexData::unpack_abcd_c(dword);
00787         _i[2] = GeomVertexData::unpack_abcd_d(dword);
00788         _i[3] = GeomVertexData::unpack_abcd_a(dword);
00789       }
00790       return _i;
00791       
00792     case NT_float32:
00793       {
00794         const PN_float32 *pi = (const PN_float32 *)pointer;
00795         _i[0] = (int)pi[0];
00796         _i[1] = (int)pi[1];
00797         _i[2] = (int)pi[2];
00798         _i[3] = (int)pi[3];
00799       }
00800       return _i;
00801     }
00802   }
00803 
00804   return _i;
00805 }
00806 
00807 ////////////////////////////////////////////////////////////////////
00808 //     Function: GeomVertexColumn::Packer::set_data1f
00809 //       Access: Public, Virtual
00810 //  Description: 
00811 ////////////////////////////////////////////////////////////////////
00812 void GeomVertexColumn::Packer::
00813 set_data1f(unsigned char *pointer, float data) {
00814   switch (_column->get_num_values()) {
00815   case 1:
00816     switch (_column->get_numeric_type()) {
00817     case NT_uint8:
00818       *pointer = maybe_unscale_color(data);
00819       break;
00820       
00821     case NT_uint16:
00822       *(PN_uint16 *)pointer = (unsigned int)data;
00823       break;
00824       
00825     case NT_uint32:
00826       *(PN_uint32 *)pointer = (unsigned int)data;
00827       break;
00828       
00829     case NT_packed_dcba:
00830     case NT_packed_dabc:
00831       nassertv(false);
00832       break;
00833       
00834     case NT_float32:
00835       *(PN_float32 *)pointer = data;
00836       break;
00837     }
00838     break;
00839 
00840   case 2:
00841     set_data2f(pointer, LVecBase2f(data, 0.0f));
00842     break;
00843 
00844   case 3:
00845     set_data3f(pointer, LVecBase3f(data, 0.0f, 0.0f));
00846     break;
00847 
00848   case 4:
00849     set_data4f(pointer, LVecBase4f(data, 0.0f, 0.0f, 0.0f));
00850     break;
00851   }
00852 }
00853 
00854 ////////////////////////////////////////////////////////////////////
00855 //     Function: GeomVertexColumn::Packer::set_data2f
00856 //       Access: Public, Virtual
00857 //  Description: 
00858 ////////////////////////////////////////////////////////////////////
00859 void GeomVertexColumn::Packer::
00860 set_data2f(unsigned char *pointer, const LVecBase2f &data) {
00861   switch (_column->get_num_values()) {
00862   case 1:
00863     set_data1f(pointer, data[0]);
00864 
00865   case 2:
00866     switch (_column->get_numeric_type()) {
00867     case NT_uint8:
00868       maybe_unscale_color(data);
00869       pointer[0] = _a;
00870       pointer[1] = _b;
00871       break;
00872       
00873     case NT_uint16:
00874       {
00875         PN_uint16 *pi = (PN_uint16 *)pointer;
00876         pi[0] = (unsigned int)data[0];
00877         pi[1] = (unsigned int)data[1];
00878       }
00879       break;
00880       
00881     case NT_uint32:
00882       {
00883         PN_uint32 *pi = (PN_uint32 *)pointer;
00884         pi[0] = (unsigned int)data[0];
00885         pi[1] = (unsigned int)data[1];
00886       }
00887       break;
00888       
00889     case NT_packed_dcba:
00890     case NT_packed_dabc:
00891       nassertv(false);
00892       break;
00893       
00894     case NT_float32:
00895       {
00896         PN_float32 *pi = (PN_float32 *)pointer;
00897         pi[0] = data[0];
00898         pi[1] = data[1];
00899       }
00900       break;
00901     }
00902     break;
00903 
00904   case 3:
00905     set_data3f(pointer, LVecBase3f(data[0], data[1], 0.0f));
00906     break;
00907 
00908   default:
00909     set_data4f(pointer, LVecBase4f(data[0], data[1], 0.0f, 0.0f));
00910     break;
00911   }
00912 }
00913 
00914 ////////////////////////////////////////////////////////////////////
00915 //     Function: GeomVertexColumn::Packer::set_data3f
00916 //       Access: Public, Virtual
00917 //  Description: 
00918 ////////////////////////////////////////////////////////////////////
00919 void GeomVertexColumn::Packer::
00920 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
00921   switch (_column->get_num_values()) {
00922   case 1:
00923     set_data1f(pointer, data[0]);
00924     break;
00925 
00926   case 2:
00927     set_data2f(pointer, LVecBase2f(data[0], data[1]));
00928     break;
00929     
00930   case 3:
00931     switch (_column->get_numeric_type()) {
00932     case NT_uint8:
00933       maybe_unscale_color(data);
00934       pointer[0] = _a;
00935       pointer[1] = _b;
00936       pointer[2] = _c;
00937       break;
00938       
00939     case NT_uint16:
00940       {
00941         PN_uint16 *pi = (PN_uint16 *)pointer;
00942         pi[0] = (unsigned int)data[0];
00943         pi[1] = (unsigned int)data[1];
00944         pi[2] = (unsigned int)data[2];
00945       }
00946       break;
00947       
00948     case NT_uint32:
00949       {
00950         PN_uint32 *pi = (PN_uint32 *)pointer;
00951         pi[0] = (unsigned int)data[0];
00952         pi[1] = (unsigned int)data[1];
00953         pi[2] = (unsigned int)data[2];
00954       }
00955       break;
00956       
00957     case NT_packed_dcba:
00958     case NT_packed_dabc:
00959       nassertv(false);
00960       break;
00961       
00962     case NT_float32:
00963       {
00964         PN_float32 *pi = (PN_float32 *)pointer;
00965         pi[0] = data[0];
00966         pi[1] = data[1];
00967         pi[2] = data[2];
00968       }
00969       break;
00970     }
00971     break;
00972 
00973   default:
00974     set_data4f(pointer, LVecBase4f(data[0], data[1], data[2], 0.0f));
00975     break;
00976   }
00977 }
00978 
00979 ////////////////////////////////////////////////////////////////////
00980 //     Function: GeomVertexColumn::Packer::set_data4f
00981 //       Access: Public, Virtual
00982 //  Description: 
00983 ////////////////////////////////////////////////////////////////////
00984 void GeomVertexColumn::Packer::
00985 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
00986   switch (_column->get_num_values()) {
00987   case 1:
00988     set_data1f(pointer, data[0]);
00989     break;
00990 
00991   case 2:
00992     set_data2f(pointer, LVecBase2f(data[0], data[1]));
00993     break;
00994 
00995   case 3:
00996     set_data3f(pointer, LVecBase3f(data[0], data[1], data[2]));
00997     break;
00998 
00999   default:
01000     switch (_column->get_numeric_type()) {
01001     case NT_uint8:
01002       maybe_unscale_color(data);
01003       pointer[0] = _a;
01004       pointer[1] = _b;
01005       pointer[2] = _c;
01006       pointer[3] = _d;
01007       break;
01008 
01009     case NT_uint16:
01010       {
01011         PN_uint16 *pi = (PN_uint16 *)pointer;
01012         pi[0] = (unsigned int)data[0];
01013         pi[1] = (unsigned int)data[1];
01014         pi[2] = (unsigned int)data[2];
01015         pi[3] = (unsigned int)data[3];
01016       }
01017       break;
01018 
01019     case NT_uint32:
01020       {
01021         PN_uint32 *pi = (PN_uint32 *)pointer;
01022         pi[0] = (unsigned int)data[0];
01023         pi[1] = (unsigned int)data[1];
01024         pi[2] = (unsigned int)data[2];
01025         pi[3] = (unsigned int)data[3];
01026       }
01027       break;
01028       
01029     case NT_packed_dcba:
01030       maybe_unscale_color(data);
01031       *(PN_uint32 *)pointer = GeomVertexData::pack_abcd(_d, _c, _b, _a);
01032       break;
01033       
01034     case NT_packed_dabc:
01035       maybe_unscale_color(data);
01036       *(PN_uint32 *)pointer = GeomVertexData::pack_abcd(_d, _a, _b, _c);
01037       break;
01038       
01039     case NT_float32:
01040       {
01041         PN_float32 *pi = (PN_float32 *)pointer;
01042         pi[0] = data[0];
01043         pi[1] = data[1];
01044         pi[2] = data[2];
01045         pi[3] = data[3];
01046       }
01047       break;
01048     }
01049     break;
01050   }
01051 }
01052 
01053 ////////////////////////////////////////////////////////////////////
01054 //     Function: GeomVertexColumn::Packer::set_data1i
01055 //       Access: Public, Virtual
01056 //  Description: 
01057 ////////////////////////////////////////////////////////////////////
01058 void GeomVertexColumn::Packer::
01059 set_data1i(unsigned char *pointer, int a) {
01060   switch (_column->get_num_values()) {
01061   case 1:
01062     switch (_column->get_numeric_type()) {
01063     case NT_uint8:
01064       *pointer = a;
01065       nassertv((*pointer) == a);
01066       break;
01067       
01068     case NT_uint16:
01069       *(PN_uint16 *)pointer = a;
01070       nassertv(*(PN_uint16 *)pointer == a);
01071       break;
01072       
01073     case NT_uint32:
01074       *(PN_uint32 *)pointer = a;
01075       break;
01076       
01077     case NT_packed_dcba:
01078     case NT_packed_dabc:
01079       nassertv(false);
01080       break;
01081       
01082     case NT_float32:
01083       *(PN_float32 *)pointer = (float)a;
01084       break;
01085     }
01086     break;
01087 
01088   case 2:
01089     set_data2i(pointer, a, 0);
01090     break;
01091 
01092   case 3:
01093     set_data3i(pointer, a, 0, 0);
01094     break;
01095 
01096   default:
01097     set_data4i(pointer, a, 0, 0, 0);
01098     break;
01099   }
01100 }
01101 
01102 ////////////////////////////////////////////////////////////////////
01103 //     Function: GeomVertexColumn::Packer::set_data2i
01104 //       Access: Public, Virtual
01105 //  Description: 
01106 ////////////////////////////////////////////////////////////////////
01107 void GeomVertexColumn::Packer::
01108 set_data2i(unsigned char *pointer, int a, int b) {
01109   switch (_column->get_num_values()) {
01110   case 1:
01111     set_data1i(pointer, a);
01112     break;
01113 
01114   case 2:
01115     switch (_column->get_numeric_type()) {
01116     case NT_uint8:
01117       pointer[0] = a;
01118       pointer[1] = b;
01119       break;
01120 
01121     case NT_uint16:
01122       {
01123         PN_uint16 *pi = (PN_uint16 *)pointer;
01124         pi[0] = a;
01125         pi[1] = b;
01126       }
01127       break;
01128 
01129     case NT_uint32:
01130       {
01131         PN_uint32 *pi = (PN_uint32 *)pointer;
01132         pi[0] = a;
01133         pi[1] = b;
01134       }
01135       break;
01136       
01137     case NT_packed_dcba:
01138     case NT_packed_dabc:
01139       nassertv(false);
01140       break;
01141       
01142     case NT_float32:
01143       {
01144         PN_float32 *pi = (PN_float32 *)pointer;
01145         pi[0] = a;
01146         pi[1] = b;
01147       }
01148       break;
01149     }
01150     break;
01151 
01152   case 3:
01153     set_data3i(pointer, a, b, 0);
01154     break;
01155 
01156   default:
01157     set_data4i(pointer, a, b, 0, 0);
01158     break;
01159   }
01160 }
01161 
01162 ////////////////////////////////////////////////////////////////////
01163 //     Function: GeomVertexColumn::Packer::set_data3i
01164 //       Access: Public, Virtual
01165 //  Description: 
01166 ////////////////////////////////////////////////////////////////////
01167 void GeomVertexColumn::Packer::
01168 set_data3i(unsigned char *pointer, int a, int b, int c) {
01169   switch (_column->get_num_values()) {
01170   case 1:
01171     set_data1i(pointer, a);
01172     break;
01173 
01174   case 2:
01175     set_data2i(pointer, a, b);
01176     break;
01177 
01178   case 3:
01179     switch (_column->get_numeric_type()) {
01180     case NT_uint8:
01181       pointer[0] = a;
01182       pointer[1] = b;
01183       pointer[2] = c;
01184       break;
01185 
01186     case NT_uint16:
01187       {
01188         PN_uint16 *pi = (PN_uint16 *)pointer;
01189         pi[0] = a;
01190         pi[1] = b;
01191         pi[2] = c;
01192       }
01193       break;
01194 
01195     case NT_uint32:
01196       {
01197         PN_uint32 *pi = (PN_uint32 *)pointer;
01198         pi[0] = a;
01199         pi[1] = b;
01200         pi[2] = c;
01201       }
01202       break;
01203       
01204     case NT_packed_dcba:
01205     case NT_packed_dabc:
01206       nassertv(false);
01207       break;
01208       
01209     case NT_float32:
01210       {
01211         PN_float32 *pi = (PN_float32 *)pointer;
01212         pi[0] = a;
01213         pi[1] = b;
01214         pi[2] = c;
01215       }
01216       break;
01217     }
01218     break;
01219 
01220   default:
01221     set_data4i(pointer, a, b, c, 0);
01222     break;
01223   }
01224 }
01225 
01226 ////////////////////////////////////////////////////////////////////
01227 //     Function: GeomVertexColumn::Packer::set_data4i
01228 //       Access: Public, Virtual
01229 //  Description: 
01230 ////////////////////////////////////////////////////////////////////
01231 void GeomVertexColumn::Packer::
01232 set_data4i(unsigned char *pointer, int a, int b, int c, int d) {
01233   switch (_column->get_num_values()) {
01234   case 1:
01235     set_data1i(pointer, a);
01236     break;
01237 
01238   case 2:
01239     set_data2i(pointer, a, b);
01240     break;
01241 
01242   case 3:
01243     set_data3i(pointer, a, b, c);
01244     break;
01245 
01246   default:
01247     switch (_column->get_numeric_type()) {
01248     case NT_uint8:
01249       pointer[0] = a;
01250       pointer[1] = b;
01251       pointer[2] = c;
01252       pointer[3] = d;
01253       break;
01254 
01255     case NT_uint16:
01256       {
01257         PN_uint16 *pi = (PN_uint16 *)pointer;
01258         pi[0] = a;
01259         pi[1] = b;
01260         pi[2] = c;
01261         pi[3] = d;
01262       }
01263       break;
01264 
01265     case NT_uint32:
01266       {
01267         PN_uint32 *pi = (PN_uint32 *)pointer;
01268         pi[0] = a;
01269         pi[1] = b;
01270         pi[2] = c;
01271         pi[3] = d;
01272       }
01273       break;
01274       
01275     case NT_packed_dcba:
01276       *(PN_uint32 *)pointer = GeomVertexData::pack_abcd(d, c, b, a);
01277       break;
01278       
01279     case NT_packed_dabc:
01280       *(PN_uint32 *)pointer = GeomVertexData::pack_abcd(d, a, b, c);
01281       break;
01282       
01283     case NT_float32:
01284       {
01285         PN_float32 *pi = (PN_float32 *)pointer;
01286         pi[0] = a;
01287         pi[1] = b;
01288         pi[2] = c;
01289         pi[3] = d;
01290       }
01291       break;
01292     }
01293     break;
01294   }
01295 }
01296 
01297 ////////////////////////////////////////////////////////////////////
01298 //     Function: GeomVertexColumn::Packer_point::get_data1f
01299 //       Access: Public, Virtual
01300 //  Description: 
01301 ////////////////////////////////////////////////////////////////////
01302 float GeomVertexColumn::Packer_point::
01303 get_data1f(const unsigned char *pointer) {
01304   if (_column->get_num_values() == 4) {
01305     const LVecBase4f &v4 = get_data4f(pointer);
01306     return v4[0] / v4[3];
01307   } else {
01308     return Packer::get_data1f(pointer);
01309   }
01310 }
01311 
01312 ////////////////////////////////////////////////////////////////////
01313 //     Function: GeomVertexColumn::Packer_point::get_data2f
01314 //       Access: Public, Virtual
01315 //  Description: 
01316 ////////////////////////////////////////////////////////////////////
01317 const LVecBase2f &GeomVertexColumn::Packer_point::
01318 get_data2f(const unsigned char *pointer) {
01319   if (_column->get_num_values() == 4) {
01320     const LVecBase4f &v4 = get_data4f(pointer);
01321     _v2.set(v4[0] / v4[3], v4[1] / v4[3]);
01322     return _v2;
01323   } else {
01324     return Packer::get_data2f(pointer);
01325   }
01326 }
01327 
01328 ////////////////////////////////////////////////////////////////////
01329 //     Function: GeomVertexColumn::Packer_point::get_data3f
01330 //       Access: Public, Virtual
01331 //  Description: 
01332 ////////////////////////////////////////////////////////////////////
01333 const LVecBase3f &GeomVertexColumn::Packer_point::
01334 get_data3f(const unsigned char *pointer) {
01335   if (_column->get_num_values() == 4) {
01336     const LVecBase4f &v4 = get_data4f(pointer);
01337     _v3.set(v4[0] / v4[3], v4[1] / v4[3], v4[2] / v4[3]);
01338     return _v3;
01339   } else {
01340     return Packer::get_data3f(pointer);
01341   }
01342 }
01343 
01344 ////////////////////////////////////////////////////////////////////
01345 //     Function: GeomVertexColumn::Packer_point::get_data4f
01346 //       Access: Public, Virtual
01347 //  Description: 
01348 ////////////////////////////////////////////////////////////////////
01349 const LVecBase4f &GeomVertexColumn::Packer_point::
01350 get_data4f(const unsigned char *pointer) {
01351   switch (_column->get_num_values()) {
01352   case 1:
01353     _v4.set(get_data1i(pointer), 0.0f, 0.0f, 1.0f);
01354     return _v4;
01355 
01356   case 2:
01357     {
01358       const LVecBase2f &v2 = get_data2f(pointer);
01359       _v4.set(v2[0], v2[1], 0.0f, 1.0f);
01360     }
01361     return _v4;
01362 
01363   case 3:
01364     {
01365       const LVecBase3f &v3 = get_data3f(pointer);
01366       _v4.set(v3[0], v3[1], v3[2], 1.0f);
01367     }
01368     return _v4;
01369 
01370   default:
01371     switch (_column->get_numeric_type()) {
01372     case NT_uint8:
01373       maybe_scale_color(pointer[0], pointer[1], pointer[2], pointer[3]);
01374       return _v4;
01375       
01376     case NT_uint16:
01377       {
01378         const PN_uint16 *pi = (const PN_uint16 *)pointer;
01379         _v4.set(pi[0], pi[1], pi[2], pi[3]);
01380       }
01381       return _v4;
01382       
01383     case NT_uint32:
01384       {
01385         const PN_uint32 *pi = (const PN_uint32 *)pointer;
01386         _v4.set(pi[0], pi[1], pi[2], pi[3]);
01387       }
01388       return _v4;
01389       
01390     case NT_packed_dcba:
01391       {
01392         PN_uint32 dword = *(const PN_uint32 *)pointer;
01393         maybe_scale_color(GeomVertexData::unpack_abcd_d(dword),
01394                           GeomVertexData::unpack_abcd_c(dword),
01395                           GeomVertexData::unpack_abcd_b(dword),
01396                           GeomVertexData::unpack_abcd_a(dword));
01397       }
01398       return _v4;
01399       
01400     case NT_packed_dabc:
01401       {
01402         PN_uint32 dword = *(const PN_uint32 *)pointer;
01403         maybe_scale_color(GeomVertexData::unpack_abcd_b(dword),
01404                           GeomVertexData::unpack_abcd_c(dword),
01405                           GeomVertexData::unpack_abcd_d(dword),
01406                           GeomVertexData::unpack_abcd_a(dword));
01407       }
01408       return _v4;
01409       
01410     case NT_float32:
01411       {
01412         const PN_float32 *pi = (const PN_float32 *)pointer;
01413         _v4.set(pi[0], pi[1], pi[2], pi[3]);
01414       }
01415       return _v4;
01416     }
01417   }
01418 
01419   return _v4;
01420 }
01421 
01422 ////////////////////////////////////////////////////////////////////
01423 //     Function: GeomVertexColumn::Packer_point::set_data1f
01424 //       Access: Public, Virtual
01425 //  Description: 
01426 ////////////////////////////////////////////////////////////////////
01427 void GeomVertexColumn::Packer_point::
01428 set_data1f(unsigned char *pointer, float data) {
01429   if (_column->get_num_values() == 4) {
01430     set_data4f(pointer, LVecBase4f(data, 0.0f, 0.0f, 1.0f));
01431   } else {
01432     Packer::set_data1f(pointer, data);
01433   }
01434 }
01435 
01436 ////////////////////////////////////////////////////////////////////
01437 //     Function: GeomVertexColumn::Packer_point::set_data2f
01438 //       Access: Public, Virtual
01439 //  Description: 
01440 ////////////////////////////////////////////////////////////////////
01441 void GeomVertexColumn::Packer_point::
01442 set_data2f(unsigned char *pointer, const LVecBase2f &data) {
01443   if (_column->get_num_values() == 4) {
01444     set_data4f(pointer, LVecBase4f(data[0], data[1], 0.0f, 1.0f));
01445   } else {
01446     Packer::set_data2f(pointer, data);
01447   }
01448 }
01449 
01450 ////////////////////////////////////////////////////////////////////
01451 //     Function: GeomVertexColumn::Packer_point::set_data3f
01452 //       Access: Public, Virtual
01453 //  Description: 
01454 ////////////////////////////////////////////////////////////////////
01455 void GeomVertexColumn::Packer_point::
01456 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
01457   if (_column->get_num_values() == 4) {
01458     set_data4f(pointer, LVecBase4f(data[0], data[1], data[2], 1.0f));
01459   } else {
01460     Packer::set_data3f(pointer, data);
01461   }
01462 }
01463 
01464 ////////////////////////////////////////////////////////////////////
01465 //     Function: GeomVertexColumn::Packer_point::set_data4f
01466 //       Access: Public, Virtual
01467 //  Description: 
01468 ////////////////////////////////////////////////////////////////////
01469 void GeomVertexColumn::Packer_point::
01470 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
01471   switch (_column->get_num_values()) {
01472   case 1:
01473     set_data1f(pointer, data[0] / data[3]);
01474     break;
01475 
01476   case 2:
01477     set_data2f(pointer, LVecBase2f(data[0] / data[3], data[1] / data[3]));
01478     break;
01479 
01480   case 3:
01481     set_data3f(pointer, LVecBase3f(data[0] / data[3], data[1] / data[3], data[2] / data[3]));
01482     break;
01483 
01484   default:
01485     switch (_column->get_numeric_type()) {
01486     case NT_uint8:
01487       maybe_unscale_color(data);
01488       pointer[0] = _a;
01489       pointer[1] = _b;
01490       pointer[2] = _c;
01491       pointer[3] = _d;
01492       break;
01493 
01494     case NT_uint16:
01495       {
01496         PN_uint16 *pi = (PN_uint16 *)pointer;
01497         pi[0] = (unsigned int)data[0];
01498         pi[1] = (unsigned int)data[1];
01499         pi[2] = (unsigned int)data[2];
01500         pi[3] = (unsigned int)data[3];
01501       }
01502       break;
01503 
01504     case NT_uint32:
01505       {
01506         PN_uint32 *pi = (PN_uint32 *)pointer;
01507         pi[0] = (unsigned int)data[0];
01508         pi[1] = (unsigned int)data[1];
01509         pi[2] = (unsigned int)data[2];
01510         pi[3] = (unsigned int)data[3];
01511       }
01512       break;
01513       
01514     case NT_packed_dcba:
01515       maybe_unscale_color(data);
01516       *(PN_uint32 *)pointer = GeomVertexData::pack_abcd(_d, _c, _b, _a);
01517       break;
01518       
01519     case NT_packed_dabc:
01520       maybe_unscale_color(data);
01521       *(PN_uint32 *)pointer = GeomVertexData::pack_abcd(_d, _a, _b, _c);
01522       break;
01523       
01524     case NT_float32:
01525       {
01526         PN_float32 *pi = (PN_float32 *)pointer;
01527         pi[0] = data[0];
01528         pi[1] = data[1];
01529         pi[2] = data[2];
01530         pi[3] = data[3];
01531       }
01532       break;
01533     }
01534     break;
01535   }
01536 }
01537 
01538 ////////////////////////////////////////////////////////////////////
01539 //     Function: GeomVertexColumn::Packer_color::get_data4f
01540 //       Access: Public, Virtual
01541 //  Description: 
01542 ////////////////////////////////////////////////////////////////////
01543 const LVecBase4f &GeomVertexColumn::Packer_color::
01544 get_data4f(const unsigned char *pointer) {
01545   switch (_column->get_num_values()) {
01546   case 1:
01547     _v4.set(get_data1i(pointer), 0.0f, 0.0f, 1.0f);
01548     return _v4;
01549 
01550   case 2:
01551     {
01552       const LVecBase2f &v2 = get_data2f(pointer);
01553       _v4.set(v2[0], v2[1], 0.0f, 1.0f);
01554     }
01555     return _v4;
01556 
01557   case 3:
01558     {
01559       const LVecBase3f &v3 = get_data3f(pointer);
01560       _v4.set(v3[0], v3[1], v3[2], 1.0f);
01561     }
01562     return _v4;
01563 
01564   default:
01565     switch (_column->get_numeric_type()) {
01566     case NT_uint8:
01567       maybe_scale_color(pointer[0], pointer[1], pointer[2], pointer[3]);
01568       return _v4;
01569       
01570     case NT_uint16:
01571       {
01572         const PN_uint16 *pi = (const PN_uint16 *)pointer;
01573         _v4.set(pi[0], pi[1], pi[2], pi[3]);
01574       }
01575       return _v4;
01576       
01577     case NT_uint32:
01578       {
01579         const PN_uint32 *pi = (const PN_uint32 *)pointer;
01580         _v4.set(pi[0], pi[1], pi[2], pi[3]);
01581       }
01582       return _v4;
01583       
01584     case NT_packed_dcba:
01585       {
01586         PN_uint32 dword = *(const PN_uint32 *)pointer;
01587         maybe_scale_color(GeomVertexData::unpack_abcd_d(dword),
01588                           GeomVertexData::unpack_abcd_c(dword),
01589                           GeomVertexData::unpack_abcd_b(dword),
01590                           GeomVertexData::unpack_abcd_a(dword));
01591       }
01592       return _v4;
01593       
01594     case NT_packed_dabc:
01595       {
01596         PN_uint32 dword = *(const PN_uint32 *)pointer;
01597         maybe_scale_color(GeomVertexData::unpack_abcd_b(dword),
01598                           GeomVertexData::unpack_abcd_c(dword),
01599                           GeomVertexData::unpack_abcd_d(dword),
01600                           GeomVertexData::unpack_abcd_a(dword));
01601       }
01602       return _v4;
01603       
01604     case NT_float32:
01605       {
01606         const PN_float32 *pi = (const PN_float32 *)pointer;
01607         _v4.set(pi[0], pi[1], pi[2], pi[3]);
01608       }
01609       return _v4;
01610     }
01611   }
01612 
01613   return _v4;
01614 }
01615 
01616 ////////////////////////////////////////////////////////////////////
01617 //     Function: GeomVertexColumn::Packer_color::set_data1f
01618 //       Access: Public, Virtual
01619 //  Description: 
01620 ////////////////////////////////////////////////////////////////////
01621 void GeomVertexColumn::Packer_color::
01622 set_data1f(unsigned char *pointer, float data) {
01623   if (_column->get_num_values() == 4) {
01624     set_data4f(pointer, LVecBase4f(data, 0.0f, 0.0f, 1.0f));
01625   } else {
01626     Packer::set_data1f(pointer, data);
01627   }
01628 }
01629 
01630 ////////////////////////////////////////////////////////////////////
01631 //     Function: GeomVertexColumn::Packer_color::set_data2f
01632 //       Access: Public, Virtual
01633 //  Description: 
01634 ////////////////////////////////////////////////////////////////////
01635 void GeomVertexColumn::Packer_color::
01636 set_data2f(unsigned char *pointer, const LVecBase2f &data) {
01637   if (_column->get_num_values() == 4) {
01638     set_data4f(pointer, LVecBase4f(data[0], data[1], 0.0f, 1.0f));
01639   } else {
01640     Packer::set_data2f(pointer, data);
01641   }
01642 }
01643 
01644 ////////////////////////////////////////////////////////////////////
01645 //     Function: GeomVertexColumn::Packer_color::set_data3f
01646 //       Access: Public, Virtual
01647 //  Description: 
01648 ////////////////////////////////////////////////////////////////////
01649 void GeomVertexColumn::Packer_color::
01650 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
01651   if (_column->get_num_values() == 4) {
01652     set_data4f(pointer, LVecBase4f(data[0], data[1], data[2], 1.0f));
01653   } else {
01654     Packer::set_data3f(pointer, data);
01655   }
01656 }
01657 
01658 ////////////////////////////////////////////////////////////////////
01659 //     Function: GeomVertexColumn::Packer_float32_3::get_data3f
01660 //       Access: Public, Virtual
01661 //  Description: 
01662 ////////////////////////////////////////////////////////////////////
01663 const LVecBase3f &GeomVertexColumn::Packer_float32_3::
01664 get_data3f(const unsigned char *pointer) {
01665   const PN_float32 *pi = (const PN_float32 *)pointer;
01666   _v3.set(pi[0], pi[1], pi[2]);
01667   return _v3;
01668 }
01669 
01670 ////////////////////////////////////////////////////////////////////
01671 //     Function: GeomVertexColumn::Packer_float32_3::set_data3f
01672 //       Access: Public, Virtual
01673 //  Description: 
01674 ////////////////////////////////////////////////////////////////////
01675 void GeomVertexColumn::Packer_float32_3::
01676 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
01677   PN_float32 *pi = (PN_float32 *)pointer;
01678   pi[0] = data[0];
01679   pi[1] = data[1];
01680   pi[2] = data[2];
01681 }
01682 
01683 ////////////////////////////////////////////////////////////////////
01684 //     Function: GeomVertexColumn::Packer_point_float32_2::get_data2f
01685 //       Access: Public, Virtual
01686 //  Description: 
01687 ////////////////////////////////////////////////////////////////////
01688 const LVecBase2f &GeomVertexColumn::Packer_point_float32_2::
01689 get_data2f(const unsigned char *pointer) {
01690   const PN_float32 *pi = (const PN_float32 *)pointer;
01691   _v2.set(pi[0], pi[1]);
01692   return _v2;
01693 }
01694 
01695 ////////////////////////////////////////////////////////////////////
01696 //     Function: GeomVertexColumn::Packer_point_float32_2::set_data2f
01697 //       Access: Public, Virtual
01698 //  Description: 
01699 ////////////////////////////////////////////////////////////////////
01700 void GeomVertexColumn::Packer_point_float32_2::
01701 set_data2f(unsigned char *pointer, const LVecBase2f &data) {
01702   PN_float32 *pi = (PN_float32 *)pointer;
01703   pi[0] = data[0];
01704   pi[1] = data[1];
01705 }
01706 
01707 ////////////////////////////////////////////////////////////////////
01708 //     Function: GeomVertexColumn::Packer_point_float32_3::get_data3f
01709 //       Access: Public, Virtual
01710 //  Description: 
01711 ////////////////////////////////////////////////////////////////////
01712 const LVecBase3f &GeomVertexColumn::Packer_point_float32_3::
01713 get_data3f(const unsigned char *pointer) {
01714   const PN_float32 *pi = (const PN_float32 *)pointer;
01715   _v3.set(pi[0], pi[1], pi[2]);
01716   return _v3;
01717 }
01718 
01719 ////////////////////////////////////////////////////////////////////
01720 //     Function: GeomVertexColumn::Packer_point_float32_3::set_data3f
01721 //       Access: Public, Virtual
01722 //  Description: 
01723 ////////////////////////////////////////////////////////////////////
01724 void GeomVertexColumn::Packer_point_float32_3::
01725 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
01726   PN_float32 *pi = (PN_float32 *)pointer;
01727   pi[0] = data[0];
01728   pi[1] = data[1];
01729   pi[2] = data[2];
01730 }
01731 
01732 ////////////////////////////////////////////////////////////////////
01733 //     Function: GeomVertexColumn::Packer_point_float32_4::get_data4f
01734 //       Access: Public, Virtual
01735 //  Description: 
01736 ////////////////////////////////////////////////////////////////////
01737 const LVecBase4f &GeomVertexColumn::Packer_point_float32_4::
01738 get_data4f(const unsigned char *pointer) {
01739   const PN_float32 *pi = (const PN_float32 *)pointer;
01740   _v4.set(pi[0], pi[1], pi[2], pi[3]);
01741   return _v4;
01742 }
01743 
01744 ////////////////////////////////////////////////////////////////////
01745 //     Function: GeomVertexColumn::Packer_point_float32_4::set_data4f
01746 //       Access: Public, Virtual
01747 //  Description: 
01748 ////////////////////////////////////////////////////////////////////
01749 void GeomVertexColumn::Packer_point_float32_4::
01750 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
01751   PN_float32 *pi = (PN_float32 *)pointer;
01752   pi[0] = data[0];
01753   pi[1] = data[1];
01754   pi[2] = data[2];
01755   pi[3] = data[3];
01756 }
01757 
01758 ////////////////////////////////////////////////////////////////////
01759 //     Function: GeomVertexColumn::Packer_nativefloat_3::get_data3f
01760 //       Access: Public, Virtual
01761 //  Description: 
01762 ////////////////////////////////////////////////////////////////////
01763 const LVecBase3f &GeomVertexColumn::Packer_nativefloat_3::
01764 get_data3f(const unsigned char *pointer) {
01765   return *(const LVecBase3f *)pointer;
01766 }
01767 
01768 ////////////////////////////////////////////////////////////////////
01769 //     Function: GeomVertexColumn::Packer_point_nativefloat_2::get_data2f
01770 //       Access: Public, Virtual
01771 //  Description: 
01772 ////////////////////////////////////////////////////////////////////
01773 const LVecBase2f &GeomVertexColumn::Packer_point_nativefloat_2::
01774 get_data2f(const unsigned char *pointer) {
01775   return *(const LVecBase2f *)pointer;
01776 }
01777 
01778 ////////////////////////////////////////////////////////////////////
01779 //     Function: GeomVertexColumn::Packer_point_nativefloat_3::get_data3f
01780 //       Access: Public, Virtual
01781 //  Description: 
01782 ////////////////////////////////////////////////////////////////////
01783 const LVecBase3f &GeomVertexColumn::Packer_point_nativefloat_3::
01784 get_data3f(const unsigned char *pointer) {
01785   return *(const LVecBase3f *)pointer;
01786 }
01787 
01788 ////////////////////////////////////////////////////////////////////
01789 //     Function: GeomVertexColumn::Packer_point_nativefloat_4::get_data4f
01790 //       Access: Public, Virtual
01791 //  Description: 
01792 ////////////////////////////////////////////////////////////////////
01793 const LVecBase4f &GeomVertexColumn::Packer_point_nativefloat_4::
01794 get_data4f(const unsigned char *pointer) {
01795   return *(const LVecBase4f *)pointer;
01796 }
01797 
01798 ////////////////////////////////////////////////////////////////////
01799 //     Function: GeomVertexColumn::Packer_argb_packed::get_data4f
01800 //       Access: Public, Virtual
01801 //  Description: 
01802 ////////////////////////////////////////////////////////////////////
01803 const LVecBase4f &GeomVertexColumn::Packer_argb_packed::
01804 get_data4f(const unsigned char *pointer) {
01805   PN_uint32 dword = *(const PN_uint32 *)pointer;
01806   _v4.set((float)GeomVertexData::unpack_abcd_b(dword) / 255.0f,
01807           (float)GeomVertexData::unpack_abcd_c(dword) / 255.0f,
01808           (float)GeomVertexData::unpack_abcd_d(dword) / 255.0f,
01809           (float)GeomVertexData::unpack_abcd_a(dword) / 255.0f);
01810   return _v4;
01811 }
01812 
01813 ////////////////////////////////////////////////////////////////////
01814 //     Function: GeomVertexColumn::Packer_argb_packed::set_data4f
01815 //       Access: Public, Virtual
01816 //  Description: 
01817 ////////////////////////////////////////////////////////////////////
01818 void GeomVertexColumn::Packer_argb_packed::
01819 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
01820   // when packing an argb, we want to make sure we cap 
01821   // the input values at 1 since going above one will cause 
01822   // the value to be truncated.
01823   float newData[4];
01824   for (int i = 0; i < 4; i++) {
01825     if (data[i] > 1.0)
01826       newData[i] = 1.0;
01827     else
01828       newData[i] = data[i];
01829   }
01830   *(PN_uint32 *)pointer = GeomVertexData::pack_abcd
01831     ((unsigned int)(newData[3] * 255.0f),
01832      (unsigned int)(newData[0] * 255.0f),
01833      (unsigned int)(newData[1] * 255.0f),
01834      (unsigned int)(newData[2] * 255.0f));
01835 }
01836 
01837 ////////////////////////////////////////////////////////////////////
01838 //     Function: GeomVertexColumn::Packer_rgba_uint8_4::get_data4f
01839 //       Access: Public, Virtual
01840 //  Description: 
01841 ////////////////////////////////////////////////////////////////////
01842 const LVecBase4f &GeomVertexColumn::Packer_rgba_uint8_4::
01843 get_data4f(const unsigned char *pointer) {
01844   _v4.set((float)pointer[0] / 255.0f,
01845           (float)pointer[1] / 255.0f,
01846           (float)pointer[2] / 255.0f,
01847           (float)pointer[3] / 255.0f);
01848   return _v4;
01849 }
01850 
01851 ////////////////////////////////////////////////////////////////////
01852 //     Function: GeomVertexColumn::Packer_rgba_uint8_4::set_data4f
01853 //       Access: Public, Virtual
01854 //  Description: 
01855 ////////////////////////////////////////////////////////////////////
01856 void GeomVertexColumn::Packer_rgba_uint8_4::
01857 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
01858   pointer[0] = (unsigned int)(data[0] * 255.0f);
01859   pointer[1] = (unsigned int)(data[1] * 255.0f);
01860   pointer[2] = (unsigned int)(data[2] * 255.0f);
01861   pointer[3] = (unsigned int)(data[3] * 255.0f);
01862 }
01863 
01864 ////////////////////////////////////////////////////////////////////
01865 //     Function: GeomVertexColumn::Packer_rgba_float32_4::get_data4f
01866 //       Access: Public, Virtual
01867 //  Description: 
01868 ////////////////////////////////////////////////////////////////////
01869 const LVecBase4f &GeomVertexColumn::Packer_rgba_float32_4::
01870 get_data4f(const unsigned char *pointer) {
01871   const PN_float32 *pi = (const PN_float32 *)pointer;
01872   _v4.set(pi[0], pi[1], pi[2], pi[3]);
01873   return _v4;
01874 }
01875 
01876 ////////////////////////////////////////////////////////////////////
01877 //     Function: GeomVertexColumn::Packer_rgba_float32_4::set_data4f
01878 //       Access: Public, Virtual
01879 //  Description: 
01880 ////////////////////////////////////////////////////////////////////
01881 void GeomVertexColumn::Packer_rgba_float32_4::
01882 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
01883   PN_float32 *pi = (PN_float32 *)pointer;
01884   pi[0] = data[0];
01885   pi[1] = data[1];
01886   pi[2] = data[2];
01887   pi[3] = data[3];
01888 }
01889 
01890 ////////////////////////////////////////////////////////////////////
01891 //     Function: GeomVertexColumn::Packer_rgba_nativefloat_4::get_data4f
01892 //       Access: Public, Virtual
01893 //  Description: 
01894 ////////////////////////////////////////////////////////////////////
01895 const LVecBase4f &GeomVertexColumn::Packer_rgba_nativefloat_4::
01896 get_data4f(const unsigned char *pointer) {
01897   return *(const LVecBase4f *)pointer;
01898 }
01899 
01900 ////////////////////////////////////////////////////////////////////
01901 //     Function: GeomVertexColumn::Packer_uint16_1::get_data1i
01902 //       Access: Public, Virtual
01903 //  Description: 
01904 ////////////////////////////////////////////////////////////////////
01905 int GeomVertexColumn::Packer_uint16_1::
01906 get_data1i(const unsigned char *pointer) {
01907   return *(const PN_uint16 *)pointer;
01908 }
01909 
01910 ////////////////////////////////////////////////////////////////////
01911 //     Function: GeomVertexColumn::Packer_uint16_1::set_data1i
01912 //       Access: Public, Virtual
01913 //  Description: 
01914 ////////////////////////////////////////////////////////////////////
01915 void GeomVertexColumn::Packer_uint16_1::
01916 set_data1i(unsigned char *pointer, int data) {
01917   *(PN_uint16 *)pointer = data;
01918   nassertv(*(PN_uint16 *)pointer == data);
01919 }
 All Classes Functions Variables Enumerations