Panda3D
Loading...
Searching...
No Matches
geomVertexFormat.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file geomVertexFormat.h
10 * @author drose
11 * @date 2005-03-07
12 */
13
14#ifndef GEOMVERTEXFORMAT_H
15#define GEOMVERTEXFORMAT_H
16
17#include "pandabase.h"
21#include "geomEnums.h"
22#include "internalName.h"
23#include "luse.h"
24#include "pointerTo.h"
25#include "pmap.h"
26#include "pset.h"
27#include "pvector.h"
28#include "indirectCompareTo.h"
29#include "lightReMutex.h"
30
31class FactoryParams;
32class GeomVertexData;
33class GeomMunger;
34
35/**
36 * This class defines the physical layout of the vertex data stored within a
37 * Geom. The layout consists of a list of named columns, each of which has a
38 * numeric type and a size.
39 *
40 * The columns are typically interleaved within a single array, but they may
41 * also be distributed among multiple different arrays; at the extreme, each
42 * column may be alone within its own array (which amounts to a parallel-array
43 * definition).
44 *
45 * Thus, a GeomVertexFormat is really a list of GeomVertexArrayFormats, each
46 * of which contains a list of columns. However, a particular column name
47 * should not appear more than once in the format, even between different
48 * arrays.
49 *
50 * There are a handful of standard pre-defined GeomVertexFormat objects, or
51 * you may define your own as needed. You may record any combination of
52 * standard and/or user-defined columns in your custom GeomVertexFormat
53 * constructions.
54 */
55class EXPCL_PANDA_GOBJ GeomVertexFormat final : public TypedWritableReferenceCount, public GeomEnums {
56PUBLISHED:
57 GeomVertexFormat();
58 GeomVertexFormat(const GeomVertexArrayFormat *array_format);
59 GeomVertexFormat(const GeomVertexFormat &copy);
60 void operator = (const GeomVertexFormat &copy);
61 virtual ~GeomVertexFormat();
62
63 virtual bool unref() const;
64
65 INLINE bool is_registered() const;
66 INLINE static CPT(GeomVertexFormat) register_format(const GeomVertexFormat *format);
67 INLINE static CPT(GeomVertexFormat) register_format(const GeomVertexArrayFormat *format);
68 MAKE_PROPERTY(registered, is_registered);
69
70 INLINE const GeomVertexAnimationSpec &get_animation() const;
71 INLINE void set_animation(const GeomVertexAnimationSpec &animation);
72 MAKE_PROPERTY(animation, get_animation, set_animation);
73
74 CPT(GeomVertexFormat) get_post_animated_format() const;
75 CPT(GeomVertexFormat) get_union_format(const GeomVertexFormat *other) const;
76
77 INLINE size_t get_num_arrays() const;
78 INLINE const GeomVertexArrayFormat *get_array(size_t array) const;
79 MAKE_SEQ(get_arrays, get_num_arrays, get_array);
81 void set_array(size_t array, const GeomVertexArrayFormat *format);
82 void remove_array(size_t array);
83 size_t add_array(const GeomVertexArrayFormat *array_format);
84 void insert_array(size_t array, const GeomVertexArrayFormat *array_format);
85 void clear_arrays();
87
88 size_t get_num_columns() const;
89 int get_array_with(size_t i) const;
90 const GeomVertexColumn *get_column(size_t i) const;
91
92 int get_array_with(const InternalName *name) const;
93 const GeomVertexColumn *get_column(const InternalName *name) const;
94 INLINE bool has_column(const InternalName *name) const;
95 const InternalName *get_column_name(size_t i) const;
96
97 MAKE_SEQ(get_columns, get_num_columns, get_column);
98
99 void remove_column(const InternalName *name, bool keep_empty_array = false);
100 void pack_columns();
103
104 INLINE size_t get_num_points() const;
105 INLINE const InternalName *get_point(size_t n) const;
106 MAKE_SEQ(get_points, get_num_points, get_point);
107
108 INLINE size_t get_num_vectors() const;
109 INLINE const InternalName *get_vector(size_t n) const;
110 MAKE_SEQ(get_vectors, get_num_vectors, get_vector);
111
112 INLINE size_t get_num_texcoords() const;
113 INLINE const InternalName *get_texcoord(size_t n) const;
114 MAKE_SEQ(get_texcoords, get_num_texcoords, get_texcoord);
115
116 INLINE size_t get_num_morphs() const;
117 INLINE const InternalName *get_morph_slider(size_t n) const;
118 INLINE const InternalName *get_morph_base(size_t n) const;
119 INLINE const InternalName *get_morph_delta(size_t n) const;
120 MAKE_SEQ(get_morph_sliders, get_num_morphs, get_morph_slider);
121 MAKE_SEQ(get_morph_bases, get_num_morphs, get_morph_base);
122 MAKE_SEQ(get_morph_deltas, get_num_morphs, get_morph_delta);
123
125 MAKE_SEQ_PROPERTY(points, get_num_points, get_point);
126 MAKE_SEQ_PROPERTY(vectors, get_num_vectors, get_vector);
127
128 // We also define this as a mapping interface, for lookups by name.
129 MAKE_MAP_PROPERTY(columns, has_column, get_column);
130 MAKE_MAP_KEYS_SEQ(columns, get_num_columns, get_column_name);
131
132 void output(std::ostream &out) const;
133 void write(std::ostream &out, int indent_level = 0) const;
134 void write_with_data(std::ostream &out, int indent_level,
135 const GeomVertexData *data) const;
136
137 INLINE static const GeomVertexFormat *get_empty();
138
139 // Some standard vertex formats. No particular requirement to use one of
140 // these, but the DirectX renderers can use these formats directly, whereas
141 // any other format will have to be converted first.
142 INLINE static const GeomVertexFormat *get_v3();
143 INLINE static const GeomVertexFormat *get_v3n3();
144 INLINE static const GeomVertexFormat *get_v3t2();
145 INLINE static const GeomVertexFormat *get_v3n3t2();
146
147 // These formats, with the DirectX-style packed color, may not be supported
148 // directly by OpenGL. If you use them and the driver does not support
149 // them, the GLGraphicsStateGuardian will automatically convert to native
150 // OpenGL form (with a small runtime overhead).
151 INLINE static const GeomVertexFormat *get_v3cp();
152 INLINE static const GeomVertexFormat *get_v3cpt2();
153 INLINE static const GeomVertexFormat *get_v3n3cp();
154 INLINE static const GeomVertexFormat *get_v3n3cpt2();
155
156 // These formats, with an OpenGL-style four-byte color, are not supported
157 // directly by DirectX. If you use them, the DXGraphicsStateGuardian will
158 // automatically convert to DirectX form (with a larger runtime overhead,
159 // since DirectX8, and old DirectX9 drivers, require everything to be
160 // interleaved together).
161 INLINE static const GeomVertexFormat *get_v3c4();
162 INLINE static const GeomVertexFormat *get_v3c4t2();
163 INLINE static const GeomVertexFormat *get_v3n3c4();
164 INLINE static const GeomVertexFormat *get_v3n3c4t2();
165
166public:
167 bool get_array_info(const InternalName *name,
168 int &array_index,
169 const GeomVertexColumn *&column) const;
170
171 INLINE int get_vertex_array_index() const;
172 INLINE const GeomVertexColumn *get_vertex_column() const;
173 INLINE int get_normal_array_index() const;
174 INLINE const GeomVertexColumn *get_normal_column() const;
175 INLINE int get_color_array_index() const;
176 INLINE const GeomVertexColumn *get_color_column() const;
177
178 int compare_to(const GeomVertexFormat &other) const;
179
180private:
181 class Registry;
182 INLINE static Registry *get_registry();
183 static void make_registry();
184
185 void do_register();
186 void do_unregister();
187
188 bool _is_registered;
189
190 GeomVertexAnimationSpec _animation;
191
192 typedef pvector< PT(GeomVertexArrayFormat) > Arrays;
193 Arrays _arrays;
194
195 class DataTypeRecord {
196 public:
197 int _array_index;
198 int _column_index;
199 };
200
201 typedef pmap<const InternalName *, DataTypeRecord> DataTypesByName;
202 DataTypesByName _columns_by_name;
203
204 int _vertex_array_index;
205 const GeomVertexColumn *_vertex_column;
206 int _normal_array_index;
207 const GeomVertexColumn *_normal_column;
208 int _color_array_index;
209 const GeomVertexColumn *_color_column;
210
211 typedef pvector<CPT_InternalName> Columns;
212 Columns _points;
213 Columns _vectors;
214 Columns _texcoords;
215
216 class MorphRecord {
217 public:
218 CPT_InternalName _slider;
219 CPT_InternalName _base;
220 CPT_InternalName _delta;
221 };
222 typedef pvector<MorphRecord> Morphs;
223 Morphs _morphs;
224
225 const GeomVertexFormat *_post_animated_format;
226
227 // This is the global registry of all currently-in-use formats.
228 typedef pset<GeomVertexFormat *, IndirectCompareTo<GeomVertexFormat> > Formats;
229 class EXPCL_PANDA_GOBJ Registry {
230 public:
231 Registry();
232 void make_standard_formats();
233
234 CPT(GeomVertexFormat) register_format(GeomVertexFormat *format);
235 INLINE CPT(GeomVertexFormat) register_format(GeomVertexArrayFormat *format);
236 void unregister_format(GeomVertexFormat *format);
237
238 Formats _formats;
239 LightReMutex _lock;
240
241 CPT(GeomVertexFormat) _empty;
242
243 CPT(GeomVertexFormat) _v3;
244 CPT(GeomVertexFormat) _v3n3;
245 CPT(GeomVertexFormat) _v3t2;
246 CPT(GeomVertexFormat) _v3n3t2;
247
248 CPT(GeomVertexFormat) _v3cp;
249 CPT(GeomVertexFormat) _v3n3cp;
250 CPT(GeomVertexFormat) _v3cpt2;
251 CPT(GeomVertexFormat) _v3n3cpt2;
252
253 CPT(GeomVertexFormat) _v3c4;
254 CPT(GeomVertexFormat) _v3n3c4;
255 CPT(GeomVertexFormat) _v3c4t2;
256 CPT(GeomVertexFormat) _v3n3c4t2;
257 };
258
259 static Registry *_registry;
260
261
262public:
263 static void register_with_read_factory();
264 virtual void write_datagram(BamWriter *manager, Datagram &dg);
265 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
266
267protected:
268 static TypedWritable *make_from_bam(const FactoryParams &params);
269 void fillin(DatagramIterator &scan, BamReader *manager);
270
271public:
272 static TypeHandle get_class_type() {
273 return _type_handle;
274 }
275 static void init_type() {
276 TypedWritableReferenceCount::init_type();
277 register_type(_type_handle, "GeomVertexFormat",
278 TypedWritableReferenceCount::get_class_type());
279 }
280 virtual TypeHandle get_type() const {
281 return get_class_type();
282 }
283 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
284
285private:
286 static TypeHandle _type_handle;
287
288 friend class GeomVertexFormat::Registry;
289 friend class GeomMunger;
290};
291
292INLINE std::ostream &operator << (std::ostream &out, const GeomVertexFormat &obj);
293
294#include "geomVertexFormat.I"
295
296#endif
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
This class exists just to provide scoping for the various enumerated types used by Geom,...
Definition geomEnums.h:24
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
Definition geomMunger.h:50
This object describes how the vertex animation, if any, represented in a GeomVertexData is encoded.
This describes the structure of a single array within a Geom data.
This defines how a single column is interleaved within a vertex array stored within a Geom.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This class defines the physical layout of the vertex data stored within a Geom.
void align_columns_for_animation()
Reprocesses the columns in the format to align the C_point and C_vector columns to 16-byte boundaries...
get_morph_base
Returns the name of the base column that the nth morph modifies.
get_morph_slider
Returns the slider name associated with the nth morph column.
get_num_morphs
Returns the number of columns within the format that represent morph deltas.
get_num_points
Returns the number of columns within the format that represent points in space.
static const GeomVertexFormat * get_v3n3c4t2()
Returns a standard vertex format with a 2-component texture coordinate pair, a 4-component color,...
static const GeomVertexFormat * get_v3n3c4()
Returns a standard vertex format with a 4-component color, a 3-component normal, and a 3-component ve...
static const GeomVertexFormat * get_v3n3cpt2()
Returns a standard vertex format with a 2-component texture coordinate pair, a packed color,...
static const GeomVertexFormat * get_v3n3cp()
Returns a standard vertex format with a packed color, a 3-component normal, and a 3-component vertex ...
static const GeomVertexFormat * get_empty()
Returns a standard vertex format containing no arrays at all, useful for pull-style vertex rendering.
get_animation
Returns the GeomVertexAnimationSpec that indicates how this format's vertices are set up for animatio...
static const GeomVertexFormat * get_v3cpt2()
Returns a standard vertex format with a 2-component texture coordinate pair, a packed color,...
set_animation
Resets the GeomVertexAnimationSpec that indicates how this format's vertices are set up for animation...
void maybe_align_columns_for_animation()
Calls align_columns_for_animation() if this format's AnimationSpec indicates that it contains animate...
void remove_empty_arrays()
Removes the arrays that define no columns.
get_num_arrays
Returns the number of individual arrays required by the format.
static const GeomVertexFormat * get_v3t2()
Returns a standard vertex format with a 2-component texture coordinate pair and a 3-component vertex ...
void pack_columns()
Removes wasted space between columns.
int get_array_with(size_t i) const
Returns the index number of the array with the ith column.
static const GeomVertexFormat * get_v3cp()
Returns a standard vertex format with a packed color and a 3-component vertex position.
get_texcoord
Returns the name of the nth texcoord column.
static const GeomVertexFormat * get_v3c4()
Returns a standard vertex format with a 4-component color and a 3-component vertex position.
static const GeomVertexFormat * get_v3n3t2()
Returns a standard vertex format with a 2-component texture coordinate pair, a 3-component normal,...
get_num_texcoords
Returns the number of columns within the format that represent texture coordinates.
int get_color_array_index() const
Returns the array index of the array including the "color" column, or -1 if there is no such array.
get_morph_delta
Returns the name of the column that defines the nth morph.
int get_vertex_array_index() const
Returns the array index of the array including the "vertex" column, or -1 if there is no such array.
static const GeomVertexFormat * get_v3c4t2()
Returns a standard vertex format with a 2-component texture coordinate pair, a 4-component color,...
int get_normal_array_index() const
Returns the array index of the array including the "normal" column, or -1 if there is no such array.
set_array
Replaces the definition of the indicated array.
static const GeomVertexFormat * get_v3()
Returns a standard vertex format with just a 3-component vertex position.
const GeomVertexColumn * get_normal_column() const
Returns the column definition of the "normal" column, or NULL if there is no such column.
get_array
Returns the description of the nth array used by the format.
is_registered
Returns true if this format has been registered, false if it has not.
get_num_vectors
Returns the number of columns within the format that represent directional vectors.
void clear_arrays()
Removes all of the array definitions from the format and starts over.
const GeomVertexColumn * get_vertex_column() const
Returns the column definition of the "vertex" column, or NULL if there is no such column.
size_t add_array(const GeomVertexArrayFormat *array_format)
Adds the indicated array definition to the list of arrays included within this vertex format definiti...
has_column
Returns true if the format has the named column, false otherwise.
GeomVertexArrayFormat * modify_array(size_t array)
Returns a modifiable pointer to the indicated array.
get_num_columns
Returns the total number of different columns in the specification, across all arrays.
remove_array
Removes the nth array from the format.
bool get_array_info(const InternalName *name, int &array_index, const GeomVertexColumn *&column) const
Quickly looks up the indicated column within all of the nested arrays and sets array_index and column...
get_point
Returns the name of the nth point column.
insert_array
Adds the indicated array definition to the list of arrays at the indicated position.
get_column_name
Returns the name of the ith column, across all arrays.
const GeomVertexColumn * get_color_column() const
Returns the column definition of the "color" column, or NULL if there is no such column.
get_vector
Returns the name of the nth vector column.
static const GeomVertexFormat * get_v3n3()
Returns a standard vertex format with a 3-component normal and a 3-component vertex position.
get_column
Returns the ith column of the specification, across all arrays.
void remove_column(const InternalName *name, bool keep_empty_array=false)
Removes the named column from the format, from whichever array it exists in.
Encodes a string name in a hash table, mapping it to a pointer.
virtual bool unref() const
Explicitly decrements the reference count.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
STL class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.