Panda3D

geomVertexColumn.h

00001 // Filename: geomVertexColumn.h
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 #ifndef GEOMVERTEXCOLUMN_H
00016 #define GEOMVERTEXCOLUMN_H
00017 
00018 #include "pandabase.h"
00019 #include "geomEnums.h"
00020 #include "internalName.h"
00021 #include "pointerTo.h"
00022 #include "luse.h"
00023 
00024 class TypedWritable;
00025 class BamWriter;
00026 class BamReader;
00027 class Datagram;
00028 class DatagramIterator;
00029 
00030 class GeomVertexReader;
00031 class GeomVertexWriter;
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //       Class : GeomVertexColumn
00035 // Description : This defines how a single column is interleaved
00036 //               within a vertex array stored within a Geom.  The
00037 //               GeomVertexArrayFormat class maintains a list of these
00038 //               to completely define a particular array structure.
00039 ////////////////////////////////////////////////////////////////////
00040 class EXPCL_PANDA_GOBJ GeomVertexColumn : public GeomEnums {
00041 PUBLISHED:
00042 private:
00043   INLINE GeomVertexColumn();
00044 PUBLISHED:
00045   INLINE GeomVertexColumn(InternalName *name, int num_components,
00046                           NumericType numeric_type, Contents contents,
00047                           int start, int column_alignment = 0);
00048   INLINE GeomVertexColumn(const GeomVertexColumn &copy);
00049   void operator = (const GeomVertexColumn &copy);
00050   INLINE ~GeomVertexColumn();
00051 
00052   INLINE InternalName *get_name() const;
00053   INLINE int get_num_components() const;
00054   INLINE int get_num_values() const;
00055   INLINE NumericType get_numeric_type() const;
00056   INLINE Contents get_contents() const;
00057   INLINE int get_start() const;
00058   INLINE int get_column_alignment() const;
00059   INLINE int get_component_bytes() const;
00060   INLINE int get_total_bytes() const;
00061   INLINE bool has_homogeneous_coord() const;
00062 
00063   INLINE bool overlaps_with(int start_byte, int num_bytes) const;
00064   INLINE bool is_bytewise_equivalent(const GeomVertexColumn &other) const;
00065 
00066   void output(ostream &out) const;
00067 
00068 public:
00069   INLINE bool is_packed_argb() const;
00070   INLINE bool is_uint8_rgba() const;
00071 
00072   INLINE int compare_to(const GeomVertexColumn &other) const;
00073   INLINE bool operator == (const GeomVertexColumn &other) const;
00074   INLINE bool operator != (const GeomVertexColumn &other) const;
00075   INLINE bool operator < (const GeomVertexColumn &other) const;
00076 
00077 private:
00078   class Packer;
00079 
00080   void setup();
00081   Packer *make_packer() const;
00082 
00083 public:
00084   void write_datagram(BamWriter *manager, Datagram &dg);
00085   int complete_pointers(TypedWritable **plist, BamReader *manager);
00086   void fillin(DatagramIterator &scan, BamReader *manager);
00087 
00088 private:
00089   PT(InternalName) _name;
00090   int _num_components;
00091   int _num_values;
00092   NumericType _numeric_type;
00093   Contents _contents;
00094   int _start;
00095   int _column_alignment;
00096   int _component_bytes;
00097   int _total_bytes;
00098   Packer *_packer;
00099 
00100   // This nested class provides the implementation for packing and
00101   // unpacking data in a very general way, but also provides the hooks
00102   // for implementing the common, very direct code paths (for
00103   // instance, 3-component float32 to LVecBase3f) as quickly as
00104   // possible.
00105   class Packer : public MemoryBase {
00106   public:
00107     virtual ~Packer();
00108 
00109     virtual float get_data1f(const unsigned char *pointer);
00110     virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
00111     virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
00112     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00113 
00114     virtual double get_data1d(const unsigned char *pointer);
00115     virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
00116     virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
00117     virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
00118 
00119     virtual int get_data1i(const unsigned char *pointer);
00120     virtual const int *get_data2i(const unsigned char *pointer);
00121     virtual const int *get_data3i(const unsigned char *pointer);
00122     virtual const int *get_data4i(const unsigned char *pointer);
00123 
00124     virtual void set_data1f(unsigned char *pointer, float data);
00125     virtual void set_data2f(unsigned char *pointer, const LVecBase2f &data);
00126     virtual void set_data3f(unsigned char *pointer, const LVecBase3f &data);
00127     virtual void set_data4f(unsigned char *pointer, const LVecBase4f &data);
00128 
00129     virtual void set_data1d(unsigned char *pointer, double data);
00130     virtual void set_data2d(unsigned char *pointer, const LVecBase2d &data);
00131     virtual void set_data3d(unsigned char *pointer, const LVecBase3d &data);
00132     virtual void set_data4d(unsigned char *pointer, const LVecBase4d &data);
00133     
00134     virtual void set_data1i(unsigned char *pointer, int a);
00135     virtual void set_data2i(unsigned char *pointer, int a, int b);
00136     virtual void set_data3i(unsigned char *pointer, int a, int b, int c);
00137     virtual void set_data4i(unsigned char *pointer, int a, int b, int c, int d);
00138 
00139     virtual const char *get_name() const {
00140       return "Packer";
00141     }
00142 
00143     INLINE float maybe_scale_color_f(unsigned int value);
00144     INLINE void maybe_scale_color_f(unsigned int a, unsigned int b);
00145     INLINE void maybe_scale_color_f(unsigned int a, unsigned int b,
00146                                     unsigned int c);
00147     INLINE void maybe_scale_color_f(unsigned int a, unsigned int b,
00148                                     unsigned int c, unsigned int d);
00149 
00150     INLINE unsigned int maybe_unscale_color_f(float data);
00151     INLINE void maybe_unscale_color_f(const LVecBase2f &data);
00152     INLINE void maybe_unscale_color_f(const LVecBase3f &data);
00153     INLINE void maybe_unscale_color_f(const LVecBase4f &data);
00154 
00155     INLINE double maybe_scale_color_d(unsigned int value);
00156     INLINE void maybe_scale_color_d(unsigned int a, unsigned int b);
00157     INLINE void maybe_scale_color_d(unsigned int a, unsigned int b,
00158                                     unsigned int c);
00159     INLINE void maybe_scale_color_d(unsigned int a, unsigned int b,
00160                                     unsigned int c, unsigned int d);
00161 
00162     INLINE unsigned int maybe_unscale_color_d(double data);
00163     INLINE void maybe_unscale_color_d(const LVecBase2d &data);
00164     INLINE void maybe_unscale_color_d(const LVecBase3d &data);
00165     INLINE void maybe_unscale_color_d(const LVecBase4d &data);
00166 
00167     const GeomVertexColumn *_column;
00168     LVecBase2f _v2;
00169     LVecBase3f _v3;
00170     LVecBase4f _v4;
00171     LVecBase2d _v2d;
00172     LVecBase3d _v3d;
00173     LVecBase4d _v4d;
00174     int _i[4];
00175     unsigned int _a, _b, _c, _d;
00176   };
00177 
00178 
00179   // This is a specialization on the generic Packer that handles
00180   // points, which are special because the fourth component, if not
00181   // present in the data, is implicitly 1.0; and if it is present,
00182   // than any three-component or smaller return is implicitly divided
00183   // by the fourth component.
00184   class Packer_point : public Packer {
00185   public:
00186     virtual float get_data1f(const unsigned char *pointer);
00187     virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
00188     virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
00189     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00190     virtual double get_data1d(const unsigned char *pointer);
00191     virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
00192     virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
00193     virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
00194     virtual void set_data1f(unsigned char *pointer, float data);
00195     virtual void set_data2f(unsigned char *pointer, const LVecBase2f &data);
00196     virtual void set_data3f(unsigned char *pointer, const LVecBase3f &data);
00197     virtual void set_data4f(unsigned char *pointer, const LVecBase4f &data);
00198     virtual void set_data1d(unsigned char *pointer, double data);
00199     virtual void set_data2d(unsigned char *pointer, const LVecBase2d &data);
00200     virtual void set_data3d(unsigned char *pointer, const LVecBase3d &data);
00201     virtual void set_data4d(unsigned char *pointer, const LVecBase4d &data);
00202 
00203     virtual const char *get_name() const {
00204       return "Packer_point";
00205     }
00206   };
00207 
00208   // This is similar to Packer_point, in that the fourth component is
00209   // implicitly 1.0 if it is not present in the data, but we never
00210   // divide by alpha.
00211   class Packer_color : public Packer {
00212   public:
00213     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00214     virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
00215     virtual void set_data1f(unsigned char *pointer, float data);
00216     virtual void set_data2f(unsigned char *pointer, const LVecBase2f &data);
00217     virtual void set_data3f(unsigned char *pointer, const LVecBase3f &data);
00218     virtual void set_data1d(unsigned char *pointer, double data);
00219     virtual void set_data2d(unsigned char *pointer, const LVecBase2d &data);
00220     virtual void set_data3d(unsigned char *pointer, const LVecBase3d &data);
00221 
00222     virtual const char *get_name() const {
00223       return "Packer_color";
00224     }
00225   };
00226 
00227 
00228   // These are the specializations on the generic Packer that handle
00229   // the direct code paths.
00230 
00231   class Packer_float32_3 : public Packer {
00232   public:
00233     virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
00234     virtual void set_data3f(unsigned char *pointer, const LVecBase3f &value);
00235 
00236     virtual const char *get_name() const {
00237       return "Packer_float32_3";
00238     }
00239   };
00240 
00241   class Packer_point_float32_2 : public Packer_point {
00242   public:
00243     virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
00244     virtual void set_data2f(unsigned char *pointer, const LVecBase2f &value);
00245 
00246     virtual const char *get_name() const {
00247       return "Packer_point_float32_2";
00248     }
00249   };
00250 
00251   class Packer_point_float32_3 : public Packer_point {
00252   public:
00253     virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
00254     virtual void set_data3f(unsigned char *pointer, const LVecBase3f &value);
00255 
00256     virtual const char *get_name() const {
00257       return "Packer_point_float32_3";
00258     }
00259   };
00260 
00261   class Packer_point_float32_4 : public Packer_point {
00262   public:
00263     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00264     virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value);
00265 
00266     virtual const char *get_name() const {
00267       return "Packer_point_float32_4";
00268     }
00269   };
00270 
00271   class Packer_nativefloat_3 : public Packer_float32_3 {
00272   public:
00273     virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
00274 
00275     virtual const char *get_name() const {
00276       return "Packer_nativefloat_3";
00277     }
00278   };
00279 
00280   class Packer_point_nativefloat_2 : public Packer_point_float32_2 {
00281   public:
00282     virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
00283 
00284     virtual const char *get_name() const {
00285       return "Packer_nativefloat_2";
00286     }
00287   };
00288 
00289   class Packer_point_nativefloat_3 : public Packer_point_float32_3 {
00290   public:
00291     virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
00292 
00293     virtual const char *get_name() const {
00294       return "Packer_point_nativefloat_3";
00295     }
00296   };
00297 
00298   class Packer_point_nativefloat_4 : public Packer_point_float32_4 {
00299   public:
00300     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00301 
00302     virtual const char *get_name() const {
00303       return "Packer_point_nativefloat_4";
00304     }
00305   };
00306 
00307   class Packer_float64_3 : public Packer {
00308   public:
00309     virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
00310     virtual void set_data3d(unsigned char *pointer, const LVecBase3d &value);
00311 
00312     virtual const char *get_name() const {
00313       return "Packer_float64_3";
00314     }
00315   };
00316 
00317   class Packer_point_float64_2 : public Packer_point {
00318   public:
00319     virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
00320     virtual void set_data2d(unsigned char *pointer, const LVecBase2d &value);
00321 
00322     virtual const char *get_name() const {
00323       return "Packer_point_float64_2";
00324     }
00325   };
00326 
00327   class Packer_point_float64_3 : public Packer_point {
00328   public:
00329     virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
00330     virtual void set_data3d(unsigned char *pointer, const LVecBase3d &value);
00331 
00332     virtual const char *get_name() const {
00333       return "Packer_point_float64_3";
00334     }
00335   };
00336 
00337   class Packer_point_float64_4 : public Packer_point {
00338   public:
00339     virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
00340     virtual void set_data4d(unsigned char *pointer, const LVecBase4d &value);
00341 
00342     virtual const char *get_name() const {
00343       return "Packer_point_float64_4";
00344     }
00345   };
00346 
00347   class Packer_nativedouble_3 : public Packer_float64_3 {
00348   public:
00349     virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
00350 
00351     virtual const char *get_name() const {
00352       return "Packer_nativedouble_3";
00353     }
00354   };
00355 
00356   class Packer_point_nativedouble_2 : public Packer_point_float64_2 {
00357   public:
00358     virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
00359 
00360     virtual const char *get_name() const {
00361       return "Packer_nativedouble_2";
00362     }
00363   };
00364 
00365   class Packer_point_nativedouble_3 : public Packer_point_float64_3 {
00366   public:
00367     virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
00368 
00369     virtual const char *get_name() const {
00370       return "Packer_point_nativedouble_3";
00371     }
00372   };
00373 
00374   class Packer_point_nativedouble_4 : public Packer_point_float64_4 {
00375   public:
00376     virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
00377 
00378     virtual const char *get_name() const {
00379       return "Packer_point_nativedouble_4";
00380     }
00381   };
00382 
00383   class Packer_argb_packed : public Packer_color {
00384   public:
00385     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00386     virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value);
00387 
00388     virtual const char *get_name() const {
00389       return "Packer_argb_packed";
00390     }
00391   };
00392 
00393   class Packer_rgba_uint8_4 : public Packer_color {
00394   public:
00395     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00396     virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value);
00397 
00398     virtual const char *get_name() const {
00399       return "Packer_rgba_uint8_4";
00400     }
00401   };
00402 
00403   class Packer_rgba_float32_4 : public Packer_color {
00404   public:
00405     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00406     virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value);
00407 
00408     virtual const char *get_name() const {
00409       return "Packer_rgba_float32_4";
00410     }
00411   };
00412 
00413   class Packer_rgba_nativefloat_4 : public Packer_rgba_float32_4 {
00414   public:
00415     virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
00416 
00417     virtual const char *get_name() const {
00418       return "Packer_rgba_nativefloat_4";
00419     }
00420   };
00421 
00422   class Packer_uint16_1 : public Packer {
00423   public:
00424     virtual int get_data1i(const unsigned char *pointer);
00425     virtual void set_data1i(unsigned char *pointer, int value);
00426 
00427     virtual const char *get_name() const {
00428       return "Packer_uint16_1";
00429     }
00430   };
00431 
00432   friend class GeomVertexArrayFormat;
00433   friend class GeomVertexReader;
00434   friend class GeomVertexWriter;
00435 };
00436 
00437 INLINE ostream &operator << (ostream &out, const GeomVertexColumn &obj);
00438 
00439 #include "geomVertexColumn.I"
00440 
00441 #endif
 All Classes Functions Variables Enumerations