Panda3D

geomVertexArrayFormat.h

00001 // Filename: geomVertexArrayFormat.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 GEOMVERTEXARRAYFORMAT_H
00016 #define GEOMVERTEXARRAYFORMAT_H
00017 
00018 #include "pandabase.h"
00019 #include "typedWritableReferenceCount.h"
00020 #include "geomVertexColumn.h"
00021 #include "geomEnums.h"
00022 #include "indirectCompareTo.h"
00023 #include "pvector.h"
00024 #include "pmap.h"
00025 #include "lightMutex.h"
00026 
00027 class GeomVertexFormat;
00028 class GeomVertexData;
00029 class GeomVertexArrayData;
00030 class InternalName;
00031 class FactoryParams;
00032 class BamWriter;
00033 class BamReader;
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //       Class : GeomVertexArrayFormat
00037 // Description : This describes the structure of a single array within
00038 //               a Geom data.  See GeomVertexFormat for the parent
00039 //               class which collects together all of the individual
00040 //               GeomVertexArrayFormat objects.
00041 //
00042 //               A particular array may include any number of standard
00043 //               or user-defined columns.  All columns consist of a
00044 //               sequence of one or more numeric values, packed in any
00045 //               of a variety of formats; the semantic meaning of each
00046 //               column is defined in general with its contents
00047 //               member, and in particular by its name.  The standard
00048 //               array types used most often are named "vertex",
00049 //               "normal", "texcoord", and "color"; other kinds of
00050 //               data may be piggybacked into the data record simply
00051 //               by choosing a unique name.
00052 ////////////////////////////////////////////////////////////////////
00053 class EXPCL_PANDA_GOBJ GeomVertexArrayFormat : public TypedWritableReferenceCount, public GeomEnums {
00054 PUBLISHED:
00055   GeomVertexArrayFormat();
00056   GeomVertexArrayFormat(const GeomVertexArrayFormat &copy);
00057   GeomVertexArrayFormat(InternalName *name0, int num_components0,
00058                         NumericType numeric_type0, Contents contents0);
00059   GeomVertexArrayFormat(InternalName *name0, int num_components0,
00060                         NumericType numeric_type0, Contents contents0,
00061                         InternalName *name1, int num_components1,
00062                         NumericType numeric_type1, Contents contents1);
00063   GeomVertexArrayFormat(InternalName *name0, int num_components0,
00064                         NumericType numeric_type0, Contents contents0,
00065                         InternalName *name1, int num_components1,
00066                         NumericType numeric_type1, Contents contents1,
00067                         InternalName *name2, int num_components2,
00068                         NumericType numeric_type2, Contents contents2);
00069   GeomVertexArrayFormat(InternalName *name0, int num_components0,
00070                         NumericType numeric_type0, Contents contents0,
00071                         InternalName *name1, int num_components1,
00072                         NumericType numeric_type1, Contents contents1,
00073                         InternalName *name2, int num_components2,
00074                         NumericType numeric_type2, Contents contents2,
00075                         InternalName *name3, int num_components3,
00076                         NumericType numeric_type3, Contents contents3);
00077   void operator = (const GeomVertexArrayFormat &copy);
00078   ~GeomVertexArrayFormat();
00079 
00080   virtual bool unref() const;
00081 
00082   INLINE bool is_registered() const;
00083   INLINE static CPT(GeomVertexArrayFormat) register_format(const GeomVertexArrayFormat *format);
00084 
00085   INLINE int get_stride() const;
00086   INLINE void set_stride(int stride);
00087 
00088   INLINE int get_total_bytes() const;
00089   INLINE int get_pad_to() const;
00090 
00091   int add_column(InternalName *name, int num_components,
00092                  NumericType numeric_type, Contents contents,
00093                  int start = -1);
00094   int add_column(const GeomVertexColumn &column);
00095   void remove_column(const InternalName *name);
00096   void clear_columns();
00097   void pack_columns();
00098 
00099   INLINE int get_num_columns() const;
00100   INLINE const GeomVertexColumn *get_column(int i) const;
00101   MAKE_SEQ(get_columns, get_num_columns, get_column);
00102 
00103   const GeomVertexColumn *get_column(const InternalName *name) const;
00104   const GeomVertexColumn *get_column(int start_byte, int num_bytes) const;
00105   INLINE bool has_column(const InternalName *name) const;
00106 
00107   bool is_data_subset_of(const GeomVertexArrayFormat &other) const;
00108   int count_unused_space() const;
00109 
00110   void output(ostream &out) const;
00111   void write(ostream &out, int indent_level = 0) const;
00112   void write_with_data(ostream &out, int indent_level, 
00113                        const GeomVertexArrayData *array_data) const;
00114 
00115 public:
00116   int compare_to(const GeomVertexArrayFormat &other) const;
00117 
00118 private:
00119   class Registry;
00120   INLINE static Registry *get_registry();
00121   static void make_registry();
00122 
00123   void do_register();
00124   void do_unregister();
00125 
00126   INLINE void consider_sort_columns() const;
00127   void sort_columns();
00128 
00129   bool _is_registered;
00130   int _stride;
00131   int _total_bytes;
00132   int _pad_to;
00133 
00134   typedef pvector<GeomVertexColumn *> Columns;
00135   Columns _columns;
00136   bool _columns_unsorted;
00137 
00138   typedef pmap<const InternalName *, GeomVertexColumn *> ColumnsByName;
00139   ColumnsByName _columns_by_name;
00140 
00141   // This is the global registry of all currently-in-use array formats.
00142   typedef pset<GeomVertexArrayFormat *, IndirectCompareTo<GeomVertexArrayFormat> > ArrayFormats;
00143   class EXPCL_PANDA_GOBJ Registry {
00144   public:
00145     Registry();
00146     CPT(GeomVertexArrayFormat) register_format(GeomVertexArrayFormat *format);
00147     void unregister_format(GeomVertexArrayFormat *format);
00148 
00149     ArrayFormats _formats;
00150     LightMutex _lock;
00151   };
00152 
00153   static Registry *_registry;
00154 
00155 public:
00156   static void register_with_read_factory();
00157   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00158   virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00159 
00160   virtual void finalize(BamReader *manager);
00161 
00162 protected:
00163   static TypedWritable *make_from_bam(const FactoryParams &params);
00164   void fillin(DatagramIterator &scan, BamReader *manager);
00165 
00166 public:
00167   static TypeHandle get_class_type() {
00168     return _type_handle;
00169   }
00170   static void init_type() {
00171     TypedWritableReferenceCount::init_type();
00172     register_type(_type_handle, "GeomVertexArrayFormat",
00173                   TypedWritableReferenceCount::get_class_type());
00174   }
00175   virtual TypeHandle get_type() const {
00176     return get_class_type();
00177   }
00178   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00179 
00180 private:
00181   static TypeHandle _type_handle;
00182 
00183   friend class GeomVertexFormat;
00184 };
00185 
00186 INLINE ostream &operator << (ostream &out, const GeomVertexArrayFormat &obj);
00187 
00188 #include "geomVertexArrayFormat.I"
00189 
00190 #endif
 All Classes Functions Variables Enumerations