Panda3D
geomVertexFormat.I
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.I
10  * @author drose
11  * @date 2005-03-07
12  */
13 
14 INLINE std::ostream &
15 operator << (std::ostream &out, const GeomVertexFormat &obj) {
16  obj.output(out);
17  return out;
18 }
19 
20 /**
21  * Returns true if this format has been registered, false if it has not. It
22  * may not be used for a Geom until it has been registered, but once
23  * registered, it may no longer be modified.
24  */
25 INLINE bool GeomVertexFormat::
26 is_registered() const {
27  return _is_registered;
28 }
29 
30 /**
31  * Adds the indicated format to the registry, if there is not an equivalent
32  * format already there; in either case, returns the pointer to the equivalent
33  * format now in the registry.
34  *
35  * This must be called before a format may be used in a Geom. After this
36  * call, you should discard the original pointer you passed in (which may or
37  * may not now be invalid) and let its reference count decrement normally; you
38  * should use only the returned value from this point on.
39  */
40 INLINE CPT(GeomVertexFormat) GeomVertexFormat::
41 register_format(const GeomVertexFormat *format) {
42  return get_registry()->register_format((GeomVertexFormat *)format);
43 }
44 
45 /**
46  * This flavor of register_format() implicitly creates a one-array vertex
47  * format from the array definition.
48  */
49 INLINE CPT(GeomVertexFormat) GeomVertexFormat::
50 register_format(const GeomVertexArrayFormat *format) {
51  return register_format(new GeomVertexFormat(format));
52 }
53 
54 /**
55  * Returns the GeomVertexAnimationSpec that indicates how this format's
56  * vertices are set up for animation.
57  */
58 INLINE const GeomVertexAnimationSpec &GeomVertexFormat::
59 get_animation() const {
60  return _animation;
61 }
62 
63 /**
64  * Resets the GeomVertexAnimationSpec that indicates how this format's
65  * vertices are set up for animation. You should also, of course, change the
66  * columns in the tables accordingly.
67  *
68  * This may not be called once the format has been registered.
69  */
70 INLINE void GeomVertexFormat::
71 set_animation(const GeomVertexAnimationSpec &animation) {
72  nassertv(!_is_registered);
73  _animation = animation;
74 }
75 
76 /**
77  * Returns the number of individual arrays required by the format. If the
78  * array data is completely interleaved, this will be 1; if it is completely
79  * parallel, this will be the same as the number of data types.
80  */
81 INLINE size_t GeomVertexFormat::
82 get_num_arrays() const {
83  return _arrays.size();
84 }
85 
86 /**
87  * Returns the description of the nth array used by the format.
88  */
90 get_array(size_t array) const {
91  nassertr(array < _arrays.size(), nullptr);
92  return _arrays[array];
93 }
94 
95 /**
96  * Returns true if the format has the named column, false otherwise.
97  */
98 INLINE bool GeomVertexFormat::
99 has_column(const InternalName *name) const {
100  return (get_column(name) != nullptr);
101 }
102 
103 /**
104  * Returns the number of columns within the format that represent points in
105  * space.
106  *
107  * This may only be called after the format has been registered.
108  */
109 INLINE size_t GeomVertexFormat::
110 get_num_points() const {
111  nassertr(_is_registered, 0);
112  return _points.size();
113 }
114 
115 /**
116  * Returns the name of the nth point column. This represents a point in
117  * space, which should be transformed by any spatial transform matrix.
118  *
119  * This may only be called after the format has been registered.
120  */
121 INLINE const InternalName *GeomVertexFormat::
122 get_point(size_t n) const {
123  nassertr(_is_registered, nullptr);
124  nassertr(n < _points.size(), nullptr);
125  return _points[n];
126 }
127 
128 /**
129  * Returns the number of columns within the format that represent directional
130  * vectors.
131  *
132  * This may only be called after the format has been registered.
133  */
134 INLINE size_t GeomVertexFormat::
135 get_num_vectors() const {
136  nassertr(_is_registered, 0);
137  return _vectors.size();
138 }
139 
140 /**
141  * Returns the name of the nth vector column. This represents a directional
142  * vector, which should be transformed by any spatial transform matrix as a
143  * vector.
144  *
145  * This may only be called after the format has been registered.
146  */
147 INLINE const InternalName *GeomVertexFormat::
148 get_vector(size_t n) const {
149  nassertr(_is_registered, nullptr);
150  nassertr(n < _vectors.size(), nullptr);
151  return _vectors[n];
152 }
153 
154 /**
155  * Returns the number of columns within the format that represent texture
156  * coordinates.
157  *
158  * This may only be called after the format has been registered.
159  */
160 INLINE size_t GeomVertexFormat::
161 get_num_texcoords() const {
162  nassertr(_is_registered, 0);
163  return _texcoords.size();
164 }
165 
166 /**
167  * Returns the name of the nth texcoord column. This represents a texture
168  * coordinate.
169  *
170  * This may only be called after the format has been registered.
171  */
172 INLINE const InternalName *GeomVertexFormat::
173 get_texcoord(size_t n) const {
174  nassertr(_is_registered, nullptr);
175  nassertr(n < _texcoords.size(), nullptr);
176  return _texcoords[n];
177 }
178 
179 /**
180  * Returns the number of columns within the format that represent morph
181  * deltas.
182  *
183  * This may only be called after the format has been registered.
184  */
185 INLINE size_t GeomVertexFormat::
186 get_num_morphs() const {
187  nassertr(_is_registered, 0);
188 
189  return _morphs.size();
190 }
191 
192 /**
193  * Returns the slider name associated with the nth morph column. This is the
194  * name of the slider that will control the morph, and should be defined
195  * within the SliderTable associated with the GeomVertexData.
196  *
197  * This may only be called after the format has been registered.
198  */
199 INLINE const InternalName *GeomVertexFormat::
200 get_morph_slider(size_t n) const {
201  nassertr(_is_registered, nullptr);
202  nassertr(n < _morphs.size(), nullptr);
203 
204  return _morphs[n]._slider;
205 }
206 
207 /**
208  * Returns the name of the base column that the nth morph modifies. This
209  * column will also be defined within the format, and can be retrieved via
210  * get_array_with() and/or get_column().
211  *
212  * This may only be called after the format has been registered.
213  */
214 INLINE const InternalName *GeomVertexFormat::
215 get_morph_base(size_t n) const {
216  nassertr(_is_registered, nullptr);
217  nassertr(n < _morphs.size(), nullptr);
218 
219  return _morphs[n]._base;
220 }
221 
222 /**
223  * Returns the name of the column that defines the nth morph. This contains
224  * the delta offsets that are to be applied to the column defined by
225  * get_morph_base(). This column will be defined within the format, and can
226  * be retrieved via get_array_with() and/or get_column().
227  *
228  * This may only be called after the format has been registered.
229  */
230 INLINE const InternalName *GeomVertexFormat::
231 get_morph_delta(size_t n) const {
232  nassertr(_is_registered, nullptr);
233  nassertr(n < _morphs.size(), nullptr);
234 
235  return _morphs[n]._delta;
236 }
237 
238 /**
239  * Returns a standard vertex format containing no arrays at all, useful for
240  * pull-style vertex rendering.
241  */
244  return get_registry()->_empty;
245 }
246 
247 /**
248  * Returns a standard vertex format with just a 3-component vertex position.
249  */
252  return get_registry()->_v3;
253 }
254 
255 /**
256  * Returns a standard vertex format with a 3-component normal and a
257  * 3-component vertex position.
258  */
261  return get_registry()->_v3n3;
262 }
263 
264 /**
265  * Returns a standard vertex format with a 2-component texture coordinate pair
266  * and a 3-component vertex position.
267  */
270  return get_registry()->_v3t2;
271 }
272 
273 /**
274  * Returns a standard vertex format with a 2-component texture coordinate
275  * pair, a 3-component normal, and a 3-component vertex position.
276  */
279  return get_registry()->_v3n3t2;
280 }
281 
282 /**
283  * Returns a standard vertex format with a packed color and a 3-component
284  * vertex position.
285  */
288  return get_registry()->_v3cp;
289 }
290 
291 /**
292  * Returns a standard vertex format with a packed color, a 3-component normal,
293  * and a 3-component vertex position.
294  */
297  return get_registry()->_v3n3cp;
298 }
299 
300 /**
301  * Returns a standard vertex format with a 2-component texture coordinate
302  * pair, a packed color, and a 3-component vertex position.
303  */
306  return get_registry()->_v3cpt2;
307 }
308 
309 /**
310  * Returns a standard vertex format with a 2-component texture coordinate
311  * pair, a packed color, a 3-component normal, and a 3-component vertex
312  * position.
313  */
316  return get_registry()->_v3n3cpt2;
317 }
318 
319 /**
320  * Returns a standard vertex format with a 4-component color and a 3-component
321  * vertex position.
322  */
325  return get_registry()->_v3c4;
326 }
327 
328 /**
329  * Returns a standard vertex format with a 4-component color, a 3-component
330  * normal, and a 3-component vertex position.
331  */
334  return get_registry()->_v3n3c4;
335 }
336 
337 /**
338  * Returns a standard vertex format with a 2-component texture coordinate
339  * pair, a 4-component color, and a 3-component vertex position.
340  */
343  return get_registry()->_v3c4t2;
344 }
345 
346 /**
347  * Returns a standard vertex format with a 2-component texture coordinate
348  * pair, a 4-component color, a 3-component normal, and a 3-component vertex
349  * position.
350  */
353  return get_registry()->_v3n3c4t2;
354 }
355 
356 /**
357  * Returns the array index of the array including the "vertex" column, or -1
358  * if there is no such array.
359  *
360  * This may only be called after the format has been registered.
361  */
362 INLINE int GeomVertexFormat::
364  nassertr(_is_registered, -1);
365  return _vertex_array_index;
366 }
367 
368 /**
369  * Returns the column definition of the "vertex" column, or NULL if there is
370  * no such column.
371  *
372  * This may only be called after the format has been registered.
373  */
376  nassertr(_is_registered, nullptr);
377  return _vertex_column;
378 }
379 
380 /**
381  * Returns the array index of the array including the "normal" column, or -1
382  * if there is no such array.
383  *
384  * This may only be called after the format has been registered.
385  */
386 INLINE int GeomVertexFormat::
388  nassertr(_is_registered, -1);
389  return _normal_array_index;
390 }
391 
392 /**
393  * Returns the column definition of the "normal" column, or NULL if there is
394  * no such column.
395  *
396  * This may only be called after the format has been registered.
397  */
400  nassertr(_is_registered, nullptr);
401  return _normal_column;
402 }
403 
404 /**
405  * Returns the array index of the array including the "color" column, or -1 if
406  * there is no such array.
407  *
408  * This may only be called after the format has been registered.
409  */
410 INLINE int GeomVertexFormat::
412  nassertr(_is_registered, -1);
413  return _color_array_index;
414 }
415 
416 /**
417  * Returns the column definition of the "color" column, or NULL if there is no
418  * such column.
419  *
420  * This may only be called after the format has been registered.
421  */
424  nassertr(_is_registered, nullptr);
425  return _color_column;
426 }
427 
428 /**
429  * Returns the global registry object.
430  */
431 INLINE GeomVertexFormat::Registry *GeomVertexFormat::
432 get_registry() {
433  if (_registry == nullptr) {
434  make_registry();
435  }
436  return _registry;
437 }
438 
439 /**
440  * This flavor of register_format() implicitly creates a one-array vertex
441  * format from the array definition.
442  */
443 INLINE CPT(GeomVertexFormat) GeomVertexFormat::Registry::
444 register_format(GeomVertexArrayFormat *format) {
445  return register_format(new GeomVertexFormat(format));
446 }
get_vector
Returns the name of the nth vector column.
get_morph_slider
Returns the slider name associated with the nth morph column.
const GeomVertexColumn * get_color_column() const
Returns the column definition of the "color" column, or NULL if there is no such column.
set_animation
Resets the GeomVertexAnimationSpec that indicates how this format's vertices are set up for animation...
This object describes how the vertex animation, if any, represented in a GeomVertexData is encoded.
static const GeomVertexFormat * get_v3cp()
Returns a standard vertex format with a packed color and a 3-component vertex position.
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,...
This defines how a single column is interleaved within a vertex array stored within a Geom.
const GeomVertexColumn * get_normal_column() const
Returns the column definition of the "normal" column, or NULL if there is no such column.
static const GeomVertexFormat * get_v3n3cp()
Returns a standard vertex format with a packed color, a 3-component normal, and a 3-component vertex ...
const GeomVertexColumn * get_vertex_column() const
Returns the column definition of the "vertex" column, or NULL if there is no such column.
CPT(GeomVertexFormat) GeomVertexFormat
Adds the indicated format to the registry, if there is not an equivalent format already there; in eit...
static const GeomVertexFormat * get_v3cpt2()
Returns a standard vertex format with a 2-component texture coordinate pair, a packed color,...
static const GeomVertexFormat * get_empty()
Returns a standard vertex format containing no arrays at all, useful for pull-style vertex rendering.
get_column
Returns the ith column of the specification, across all arrays.
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_v3n3c4t2()
Returns a standard vertex format with a 2-component texture coordinate pair, a 4-component color,...
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.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
This class defines the physical layout of the vertex data stored within a Geom.
get_morph_delta
Returns the name of the column that defines the nth morph.
static const GeomVertexFormat * get_v3n3()
Returns a standard vertex format with a 3-component normal and a 3-component vertex position.
get_morph_base
Returns the name of the base column that the nth morph modifies.
This describes the structure of a single array within a Geom data.
static const GeomVertexFormat * get_v3c4t2()
Returns a standard vertex format with a 2-component texture coordinate pair, a 4-component color,...
get_point
Returns the name of the nth point column.
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_v3n3cpt2()
Returns a standard vertex format with a 2-component texture coordinate pair, a packed color,...
static const GeomVertexFormat * get_v3t2()
Returns a standard vertex format with a 2-component texture coordinate pair and a 3-component vertex ...
get_texcoord
Returns the name of the nth texcoord column.
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.
static const GeomVertexFormat * get_v3()
Returns a standard vertex format with just a 3-component vertex position.
get_array
Returns the description of the nth array used by the format.
has_column
Returns true if the format has the named column, false otherwise.