00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 class EXPCL_PANDA_GOBJ GeomVertexArrayFormat : public TypedWritableReferenceCount, public GeomEnums {
00054 PUBLISHED:
00055 GeomVertexArrayFormat();
00056 GeomVertexArrayFormat(const GeomVertexArrayFormat ©);
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 ©);
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_pad_to() const;
00089 INLINE void set_pad_to(int pad_to);
00090
00091 INLINE int get_total_bytes() const;
00092
00093 int add_column(InternalName *name, int num_components,
00094 NumericType numeric_type, Contents contents,
00095 int start = -1, int column_alignment = 0);
00096 int add_column(const GeomVertexColumn &column);
00097 void remove_column(const InternalName *name);
00098 void clear_columns();
00099 void pack_columns();
00100 void align_columns_for_animation();
00101
00102 INLINE int get_num_columns() const;
00103 INLINE const GeomVertexColumn *get_column(int i) const;
00104 MAKE_SEQ(get_columns, get_num_columns, get_column);
00105
00106 const GeomVertexColumn *get_column(const InternalName *name) const;
00107 const GeomVertexColumn *get_column(int start_byte, int num_bytes) const;
00108 INLINE bool has_column(const InternalName *name) const;
00109
00110 bool is_data_subset_of(const GeomVertexArrayFormat &other) const;
00111 int count_unused_space() const;
00112
00113 void output(ostream &out) const;
00114 void write(ostream &out, int indent_level = 0) const;
00115 void write_with_data(ostream &out, int indent_level,
00116 const GeomVertexArrayData *array_data) const;
00117
00118 public:
00119 int compare_to(const GeomVertexArrayFormat &other) const;
00120
00121 private:
00122 class Registry;
00123 INLINE static Registry *get_registry();
00124 static void make_registry();
00125
00126 void do_register();
00127 void do_unregister();
00128
00129 INLINE void consider_sort_columns() const;
00130 void sort_columns();
00131
00132 bool _is_registered;
00133 int _stride;
00134 int _total_bytes;
00135 int _pad_to;
00136
00137 typedef pvector<GeomVertexColumn *> Columns;
00138 Columns _columns;
00139 bool _columns_unsorted;
00140
00141 typedef pmap<const InternalName *, GeomVertexColumn *> ColumnsByName;
00142 ColumnsByName _columns_by_name;
00143
00144
00145 typedef pset<GeomVertexArrayFormat *, IndirectCompareTo<GeomVertexArrayFormat> > ArrayFormats;
00146 class EXPCL_PANDA_GOBJ Registry {
00147 public:
00148 Registry();
00149 CPT(GeomVertexArrayFormat) register_format(GeomVertexArrayFormat *format);
00150 void unregister_format(GeomVertexArrayFormat *format);
00151
00152 ArrayFormats _formats;
00153 LightMutex _lock;
00154 };
00155
00156 static Registry *_registry;
00157
00158 public:
00159 static void register_with_read_factory();
00160 virtual void write_datagram(BamWriter *manager, Datagram &dg);
00161 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00162
00163 virtual void finalize(BamReader *manager);
00164
00165 protected:
00166 static TypedWritable *make_from_bam(const FactoryParams ¶ms);
00167 void fillin(DatagramIterator &scan, BamReader *manager);
00168
00169 public:
00170 static TypeHandle get_class_type() {
00171 return _type_handle;
00172 }
00173 static void init_type() {
00174 TypedWritableReferenceCount::init_type();
00175 register_type(_type_handle, "GeomVertexArrayFormat",
00176 TypedWritableReferenceCount::get_class_type());
00177 }
00178 virtual TypeHandle get_type() const {
00179 return get_class_type();
00180 }
00181 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00182
00183 private:
00184 static TypeHandle _type_handle;
00185
00186 friend class GeomVertexFormat;
00187 };
00188
00189 INLINE ostream &operator << (ostream &out, const GeomVertexArrayFormat &obj);
00190
00191 #include "geomVertexArrayFormat.I"
00192
00193 #endif