00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GEOMVERTEXFORMAT_H
00016 #define GEOMVERTEXFORMAT_H
00017
00018 #include "pandabase.h"
00019 #include "typedWritableReferenceCount.h"
00020 #include "geomVertexAnimationSpec.h"
00021 #include "geomVertexArrayFormat.h"
00022 #include "geomEnums.h"
00023 #include "internalName.h"
00024 #include "luse.h"
00025 #include "pointerTo.h"
00026 #include "pmap.h"
00027 #include "pset.h"
00028 #include "pvector.h"
00029 #include "indirectCompareTo.h"
00030 #include "lightReMutex.h"
00031
00032 class FactoryParams;
00033 class GeomVertexData;
00034 class GeomMunger;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 class EXPCL_PANDA_GOBJ GeomVertexFormat : public TypedWritableReferenceCount, public GeomEnums {
00062 PUBLISHED:
00063 GeomVertexFormat();
00064 GeomVertexFormat(const GeomVertexArrayFormat *array_format);
00065 GeomVertexFormat(const GeomVertexFormat ©);
00066 void operator = (const GeomVertexFormat ©);
00067 virtual ~GeomVertexFormat();
00068
00069 virtual bool unref() const;
00070
00071 INLINE bool is_registered() const;
00072 INLINE static CPT(GeomVertexFormat) register_format(const GeomVertexFormat *format);
00073 INLINE static CPT(GeomVertexFormat) register_format(const GeomVertexArrayFormat *format);
00074
00075 INLINE const GeomVertexAnimationSpec &get_animation() const;
00076 INLINE void set_animation(const GeomVertexAnimationSpec &animation);
00077
00078 CPT(GeomVertexFormat) get_post_animated_format() const;
00079 CPT(GeomVertexFormat) get_union_format(const GeomVertexFormat *other) const;
00080
00081 INLINE int get_num_arrays() const;
00082 INLINE const GeomVertexArrayFormat *get_array(int array) const;
00083 MAKE_SEQ(get_arrays, get_num_arrays, get_array);
00084 GeomVertexArrayFormat *modify_array(int array);
00085 void set_array(int array, const GeomVertexArrayFormat *format);
00086 void remove_array(int array);
00087 int add_array(const GeomVertexArrayFormat *array_format);
00088 void insert_array(int array, const GeomVertexArrayFormat *array_format);
00089 void clear_arrays();
00090
00091 int get_num_columns() const;
00092 int get_array_with(int i) const;
00093 const GeomVertexColumn *get_column(int i) const;
00094
00095 int get_array_with(const InternalName *name) const;
00096 const GeomVertexColumn *get_column(const InternalName *name) const;
00097 INLINE bool has_column(const InternalName *name) const;
00098
00099 MAKE_SEQ(get_columns, get_num_columns, get_column);
00100
00101 void remove_column(const InternalName *name);
00102 void pack_columns();
00103 void align_columns_for_animation();
00104 void maybe_align_columns_for_animation();
00105
00106 INLINE int get_num_points() const;
00107 INLINE const InternalName *get_point(int n) const;
00108 MAKE_SEQ(get_points, get_num_points, get_point);
00109
00110 INLINE int get_num_vectors() const;
00111 INLINE const InternalName *get_vector(int n) const;
00112 MAKE_SEQ(get_vectors, get_num_vectors, get_vector);
00113
00114 INLINE int get_num_texcoords() const;
00115 INLINE const InternalName *get_texcoord(int n) const;
00116 MAKE_SEQ(get_texcoords, get_num_texcoords, get_texcoord);
00117
00118 INLINE int get_num_morphs() const;
00119 INLINE const InternalName *get_morph_slider(int n) const;
00120 INLINE const InternalName *get_morph_base(int n) const;
00121 INLINE const InternalName *get_morph_delta(int n) const;
00122 MAKE_SEQ(get_morph_sliders, get_num_morphs, get_morph_slider);
00123 MAKE_SEQ(get_morph_bases, get_num_morphs, get_morph_base);
00124 MAKE_SEQ(get_morph_deltas, get_num_morphs, get_morph_delta);
00125
00126 void output(ostream &out) const;
00127 void write(ostream &out, int indent_level = 0) const;
00128 void write_with_data(ostream &out, int indent_level,
00129 const GeomVertexData *data) const;
00130
00131
00132
00133
00134
00135 INLINE static const GeomVertexFormat *get_v3();
00136 INLINE static const GeomVertexFormat *get_v3n3();
00137 INLINE static const GeomVertexFormat *get_v3t2();
00138 INLINE static const GeomVertexFormat *get_v3n3t2();
00139
00140
00141
00142
00143
00144 INLINE static const GeomVertexFormat *get_v3cp();
00145 INLINE static const GeomVertexFormat *get_v3cpt2();
00146 INLINE static const GeomVertexFormat *get_v3n3cp();
00147 INLINE static const GeomVertexFormat *get_v3n3cpt2();
00148
00149
00150
00151
00152
00153
00154 INLINE static const GeomVertexFormat *get_v3c4();
00155 INLINE static const GeomVertexFormat *get_v3c4t2();
00156 INLINE static const GeomVertexFormat *get_v3n3c4();
00157 INLINE static const GeomVertexFormat *get_v3n3c4t2();
00158
00159 public:
00160 bool get_array_info(const InternalName *name,
00161 int &array_index,
00162 const GeomVertexColumn *&column) const;
00163
00164 INLINE int get_vertex_array_index() const;
00165 INLINE const GeomVertexColumn *get_vertex_column() const;
00166 INLINE int get_normal_array_index() const;
00167 INLINE const GeomVertexColumn *get_normal_column() const;
00168 INLINE int get_color_array_index() const;
00169 INLINE const GeomVertexColumn *get_color_column() const;
00170
00171 int compare_to(const GeomVertexFormat &other) const;
00172
00173 private:
00174 class Registry;
00175 INLINE static Registry *get_registry();
00176 static void make_registry();
00177
00178 void do_register();
00179 void do_unregister();
00180
00181 bool _is_registered;
00182
00183 GeomVertexAnimationSpec _animation;
00184
00185 typedef pvector< PT(GeomVertexArrayFormat) > Arrays;
00186 Arrays _arrays;
00187
00188 class DataTypeRecord {
00189 public:
00190 int _array_index;
00191 int _column_index;
00192 };
00193
00194 typedef pmap<const InternalName *, DataTypeRecord> DataTypesByName;
00195 DataTypesByName _columns_by_name;
00196
00197 int _vertex_array_index;
00198 const GeomVertexColumn *_vertex_column;
00199 int _normal_array_index;
00200 const GeomVertexColumn *_normal_column;
00201 int _color_array_index;
00202 const GeomVertexColumn *_color_column;
00203
00204 typedef pvector< CPT(InternalName) > Columns;
00205 Columns _points;
00206 Columns _vectors;
00207 Columns _texcoords;
00208
00209 class MorphRecord {
00210 public:
00211 CPT(InternalName) _slider;
00212 CPT(InternalName) _base;
00213 CPT(InternalName) _delta;
00214 };
00215 typedef pvector<MorphRecord> Morphs;
00216 Morphs _morphs;
00217
00218 const GeomVertexFormat *_post_animated_format;
00219
00220
00221 typedef pset<GeomVertexFormat *, IndirectCompareTo<GeomVertexFormat> > Formats;
00222 class EXPCL_PANDA_GOBJ Registry {
00223 public:
00224 Registry();
00225 void make_standard_formats();
00226
00227 CPT(GeomVertexFormat) register_format(GeomVertexFormat *format);
00228 INLINE CPT(GeomVertexFormat) register_format(GeomVertexArrayFormat *format);
00229 void unregister_format(GeomVertexFormat *format);
00230
00231 Formats _formats;
00232 LightReMutex _lock;
00233
00234 CPT(GeomVertexFormat) _v3;
00235 CPT(GeomVertexFormat) _v3n3;
00236 CPT(GeomVertexFormat) _v3t2;
00237 CPT(GeomVertexFormat) _v3n3t2;
00238
00239 CPT(GeomVertexFormat) _v3cp;
00240 CPT(GeomVertexFormat) _v3n3cp;
00241 CPT(GeomVertexFormat) _v3cpt2;
00242 CPT(GeomVertexFormat) _v3n3cpt2;
00243
00244 CPT(GeomVertexFormat) _v3c4;
00245 CPT(GeomVertexFormat) _v3n3c4;
00246 CPT(GeomVertexFormat) _v3c4t2;
00247 CPT(GeomVertexFormat) _v3n3c4t2;
00248 };
00249
00250 static Registry *_registry;
00251
00252
00253 public:
00254 static void register_with_read_factory();
00255 virtual void write_datagram(BamWriter *manager, Datagram &dg);
00256 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00257
00258 protected:
00259 static TypedWritable *make_from_bam(const FactoryParams ¶ms);
00260 void fillin(DatagramIterator &scan, BamReader *manager);
00261
00262 public:
00263 static TypeHandle get_class_type() {
00264 return _type_handle;
00265 }
00266 static void init_type() {
00267 TypedWritableReferenceCount::init_type();
00268 register_type(_type_handle, "GeomVertexFormat",
00269 TypedWritableReferenceCount::get_class_type());
00270 }
00271 virtual TypeHandle get_type() const {
00272 return get_class_type();
00273 }
00274 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00275
00276 private:
00277 static TypeHandle _type_handle;
00278
00279 friend class GeomVertexFormat::Registry;
00280 friend class GeomMunger;
00281 };
00282
00283 INLINE ostream &operator << (ostream &out, const GeomVertexFormat &obj);
00284
00285 #include "geomVertexFormat.I"
00286
00287 #endif