Panda3D
geomVertexFormat.I
1 // Filename: geomVertexFormat.I
2 // Created by: drose (07Mar05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 INLINE ostream &
17 operator << (ostream &out, const GeomVertexFormat &obj) {
18  obj.output(out);
19  return out;
20 }
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: GeomVertexFormat::is_registered
24 // Access: Published
25 // Description: Returns true if this format has been registered,
26 // false if it has not. It may not be used for a Geom
27 // until it has been registered, but once registered, it
28 // may no longer be modified.
29 ////////////////////////////////////////////////////////////////////
30 INLINE bool GeomVertexFormat::
31 is_registered() const {
32  return _is_registered;
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: GeomVertexFormat::register_format
37 // Access: Published, Static
38 // Description: Adds the indicated format to the registry, if there
39 // is not an equivalent format already there; in either
40 // case, returns the pointer to the equivalent format
41 // now in the registry.
42 //
43 // This must be called before a format may be used in a
44 // Geom. After this call, you should discard the
45 // original pointer you passed in (which may or may not
46 // now be invalid) and let its reference count decrement
47 // normally; you should use only the returned value from
48 // this point on.
49 ////////////////////////////////////////////////////////////////////
50 INLINE CPT(GeomVertexFormat) GeomVertexFormat::
51 register_format(const GeomVertexFormat *format) {
52  return get_registry()->register_format((GeomVertexFormat *)format);
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: GeomVertexFormat::register_format
57 // Access: Published, Static
58 // Description: This flavor of register_format() implicitly creates a
59 // one-array vertex format from the array definition.
60 ////////////////////////////////////////////////////////////////////
61 INLINE CPT(GeomVertexFormat) GeomVertexFormat::
62 register_format(const GeomVertexArrayFormat *format) {
63  return register_format(new GeomVertexFormat(format));
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: GeomVertexFormat::get_animation
68 // Access: Published
69 // Description: Returns the GeomVertexAnimationSpec that indicates
70 // how this format's vertices are set up for animation.
71 ////////////////////////////////////////////////////////////////////
72 INLINE const GeomVertexAnimationSpec &GeomVertexFormat::
73 get_animation() const {
74  return _animation;
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: GeomVertexFormat::set_animation
79 // Access: Published
80 // Description: Resets the GeomVertexAnimationSpec that indicates
81 // how this format's vertices are set up for animation.
82 // You should also, of course, change the columns in the
83 // tables accordingly.
84 //
85 // This may not be called once the format has been
86 // registered.
87 ////////////////////////////////////////////////////////////////////
88 INLINE void GeomVertexFormat::
89 set_animation(const GeomVertexAnimationSpec &animation) {
90  nassertv(!_is_registered);
91  _animation = animation;
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: GeomVertexFormat::get_num_arrays
96 // Access: Published
97 // Description: Returns the number of individual arrays required by
98 // the format. If the array data is completely
99 // interleaved, this will be 1; if it is completely
100 // parallel, this will be the same as the number of data
101 // types.
102 ////////////////////////////////////////////////////////////////////
103 INLINE int GeomVertexFormat::
104 get_num_arrays() const {
105  return _arrays.size();
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: GeomVertexFormat::get_array
110 // Access: Published
111 // Description: Returns the description of the nth array used by the
112 // format.
113 ////////////////////////////////////////////////////////////////////
114 INLINE const GeomVertexArrayFormat *GeomVertexFormat::
115 get_array(int array) const {
116  nassertr(array >= 0 && array < (int)_arrays.size(), NULL);
117  return _arrays[array];
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: GeomVertexFormat::has_column
122 // Access: Published
123 // Description: Returns true if the format has the named column,
124 // false otherwise.
125 ////////////////////////////////////////////////////////////////////
126 INLINE bool GeomVertexFormat::
127 has_column(const InternalName *name) const {
128  return (get_column(name) != (GeomVertexColumn *)NULL);
129 }
130 
131 ////////////////////////////////////////////////////////////////////
132 // Function: GeomVertexFormat::get_num_points
133 // Access: Published
134 // Description: Returns the number of columns within the format
135 // that represent points in space.
136 //
137 // This may only be called after the format has been
138 // registered.
139 ////////////////////////////////////////////////////////////////////
140 INLINE int GeomVertexFormat::
141 get_num_points() const {
142  nassertr(_is_registered, 0);
143  return _points.size();
144 }
145 
146 ////////////////////////////////////////////////////////////////////
147 // Function: GeomVertexFormat::get_point
148 // Access: Published
149 // Description: Returns the name of the nth point column. This
150 // represents a point in space, which should be
151 // transformed by any spatial transform matrix.
152 //
153 // This may only be called after the format has been
154 // registered.
155 ////////////////////////////////////////////////////////////////////
156 INLINE const InternalName *GeomVertexFormat::
157 get_point(int n) const {
158  nassertr(_is_registered, NULL);
159  nassertr(n >= 0 && n < (int)_points.size(), NULL);
160  return _points[n];
161 }
162 
163 ////////////////////////////////////////////////////////////////////
164 // Function: GeomVertexFormat::get_num_vectors
165 // Access: Published
166 // Description: Returns the number of columns within the format
167 // that represent directional vectors.
168 //
169 // This may only be called after the format has been
170 // registered.
171 ////////////////////////////////////////////////////////////////////
172 INLINE int GeomVertexFormat::
173 get_num_vectors() const {
174  nassertr(_is_registered, 0);
175  return _vectors.size();
176 }
177 
178 ////////////////////////////////////////////////////////////////////
179 // Function: GeomVertexFormat::get_vector
180 // Access: Published
181 // Description: Returns the name of the nth vector column. This
182 // represents a directional vector, which should be
183 // transformed by any spatial transform matrix as a
184 // vector.
185 //
186 // This may only be called after the format has been
187 // registered.
188 ////////////////////////////////////////////////////////////////////
189 INLINE const InternalName *GeomVertexFormat::
190 get_vector(int n) const {
191  nassertr(_is_registered, NULL);
192  nassertr(n >= 0 && n < (int)_vectors.size(), NULL);
193  return _vectors[n];
194 }
195 
196 ////////////////////////////////////////////////////////////////////
197 // Function: GeomVertexFormat::get_num_texcoords
198 // Access: Published
199 // Description: Returns the number of columns within the format
200 // that represent texture coordinates.
201 //
202 // This may only be called after the format has been
203 // registered.
204 ////////////////////////////////////////////////////////////////////
205 INLINE int GeomVertexFormat::
206 get_num_texcoords() const {
207  nassertr(_is_registered, 0);
208  return _texcoords.size();
209 }
210 
211 ////////////////////////////////////////////////////////////////////
212 // Function: GeomVertexFormat::get_texcoord
213 // Access: Published
214 // Description: Returns the name of the nth texcoord column. This
215 // represents a texture coordinate.
216 //
217 // This may only be called after the format has been
218 // registered.
219 ////////////////////////////////////////////////////////////////////
220 INLINE const InternalName *GeomVertexFormat::
221 get_texcoord(int n) const {
222  nassertr(_is_registered, NULL);
223  nassertr(n >= 0 && n < (int)_texcoords.size(), NULL);
224  return _texcoords[n];
225 }
226 
227 ////////////////////////////////////////////////////////////////////
228 // Function: GeomVertexFormat::get_num_morphs
229 // Access: Published
230 // Description: Returns the number of columns within the format
231 // that represent morph deltas.
232 //
233 // This may only be called after the format has been
234 // registered.
235 ////////////////////////////////////////////////////////////////////
236 INLINE int GeomVertexFormat::
237 get_num_morphs() const {
238  nassertr(_is_registered, 0);
239 
240  return _morphs.size();
241 }
242 
243 ////////////////////////////////////////////////////////////////////
244 // Function: GeomVertexFormat::get_morph_slider
245 // Access: Published
246 // Description: Returns the slider name associated with the nth morph
247 // column. This is the name of the slider that will
248 // control the morph, and should be defined within the
249 // SliderTable associated with the GeomVertexData.
250 //
251 // This may only be called after the format has been
252 // registered.
253 ////////////////////////////////////////////////////////////////////
254 INLINE const InternalName *GeomVertexFormat::
255 get_morph_slider(int n) const {
256  nassertr(_is_registered, NULL);
257  nassertr(n >= 0 && n < (int)_morphs.size(), NULL);
258 
259  return _morphs[n]._slider;
260 }
261 
262 ////////////////////////////////////////////////////////////////////
263 // Function: GeomVertexFormat::get_morph_base
264 // Access: Published
265 // Description: Returns the name of the base column that the nth
266 // morph modifies. This column will also be defined
267 // within the format, and can be retrieved via
268 // get_array_with() and/or get_column().
269 //
270 // This may only be called after the format has been
271 // registered.
272 ////////////////////////////////////////////////////////////////////
273 INLINE const InternalName *GeomVertexFormat::
274 get_morph_base(int n) const {
275  nassertr(_is_registered, NULL);
276  nassertr(n >= 0 && n < (int)_morphs.size(), NULL);
277 
278  return _morphs[n]._base;
279 }
280 
281 ////////////////////////////////////////////////////////////////////
282 // Function: GeomVertexFormat::get_morph_delta
283 // Access: Published
284 // Description: Returns the name of the column that defines the
285 // nth morph. This contains the delta offsets that are
286 // to be applied to the column defined by
287 // get_morph_base(). This column will be defined
288 // within the format, and can be retrieved via
289 // get_array_with() and/or get_column().
290 //
291 // This may only be called after the format has been
292 // registered.
293 ////////////////////////////////////////////////////////////////////
294 INLINE const InternalName *GeomVertexFormat::
295 get_morph_delta(int n) const {
296  nassertr(_is_registered, NULL);
297  nassertr(n >= 0 && n < (int)_morphs.size(), NULL);
298 
299  return _morphs[n]._delta;
300 }
301 
302 ////////////////////////////////////////////////////////////////////
303 // Function: GeomVertexFormat::get_v3
304 // Access: Published, Static
305 // Description: Returns a standard vertex format with just a
306 // 3-component vertex position.
307 ////////////////////////////////////////////////////////////////////
308 INLINE const GeomVertexFormat *GeomVertexFormat::
309 get_v3() {
310  return get_registry()->_v3;
311 }
312 
313 ////////////////////////////////////////////////////////////////////
314 // Function: GeomVertexFormat::get_v3n3
315 // Access: Published, Static
316 // Description: Returns a standard vertex format with a 3-component
317 // normal and a 3-component vertex position.
318 ////////////////////////////////////////////////////////////////////
319 INLINE const GeomVertexFormat *GeomVertexFormat::
320 get_v3n3() {
321  return get_registry()->_v3n3;
322 }
323 
324 ////////////////////////////////////////////////////////////////////
325 // Function: GeomVertexFormat::get_v3t2
326 // Access: Published, Static
327 // Description: Returns a standard vertex format with a 2-component
328 // texture coordinate pair and a 3-component vertex
329 // position.
330 ////////////////////////////////////////////////////////////////////
331 INLINE const GeomVertexFormat *GeomVertexFormat::
332 get_v3t2() {
333  return get_registry()->_v3t2;
334 }
335 
336 ////////////////////////////////////////////////////////////////////
337 // Function: GeomVertexFormat::get_v3n3t2
338 // Access: Published, Static
339 // Description: Returns a standard vertex format with a 2-component
340 // texture coordinate pair, a 3-component normal, and a
341 // 3-component vertex position.
342 ////////////////////////////////////////////////////////////////////
343 INLINE const GeomVertexFormat *GeomVertexFormat::
344 get_v3n3t2() {
345  return get_registry()->_v3n3t2;
346 }
347 
348 ////////////////////////////////////////////////////////////////////
349 // Function: GeomVertexFormat::get_v3cp
350 // Access: Published, Static
351 // Description: Returns a standard vertex format with a packed
352 // color and a 3-component vertex position.
353 ////////////////////////////////////////////////////////////////////
354 INLINE const GeomVertexFormat *GeomVertexFormat::
355 get_v3cp() {
356  return get_registry()->_v3cp;
357 }
358 
359 ////////////////////////////////////////////////////////////////////
360 // Function: GeomVertexFormat::get_v3n3cp
361 // Access: Published, Static
362 // Description: Returns a standard vertex format with a packed
363 // color, a 3-component normal, and a 3-component vertex
364 // position.
365 ////////////////////////////////////////////////////////////////////
366 INLINE const GeomVertexFormat *GeomVertexFormat::
367 get_v3n3cp() {
368  return get_registry()->_v3n3cp;
369 }
370 
371 ////////////////////////////////////////////////////////////////////
372 // Function: GeomVertexFormat::get_v3cpt2
373 // Access: Published, Static
374 // Description: Returns a standard vertex format with a 2-component
375 // texture coordinate pair, a packed color, and a
376 // 3-component vertex position.
377 ////////////////////////////////////////////////////////////////////
378 INLINE const GeomVertexFormat *GeomVertexFormat::
379 get_v3cpt2() {
380  return get_registry()->_v3cpt2;
381 }
382 
383 ////////////////////////////////////////////////////////////////////
384 // Function: GeomVertexFormat::get_v3n3cpt2
385 // Access: Published, Static
386 // Description: Returns a standard vertex format with a 2-component
387 // texture coordinate pair, a packed color, a
388 // 3-component normal, and a 3-component vertex
389 // position.
390 ////////////////////////////////////////////////////////////////////
391 INLINE const GeomVertexFormat *GeomVertexFormat::
392 get_v3n3cpt2() {
393  return get_registry()->_v3n3cpt2;
394 }
395 
396 ////////////////////////////////////////////////////////////////////
397 // Function: GeomVertexFormat::get_v3c4
398 // Access: Published, Static
399 // Description: Returns a standard vertex format with a 4-component
400 // color and a 3-component vertex position.
401 ////////////////////////////////////////////////////////////////////
402 INLINE const GeomVertexFormat *GeomVertexFormat::
403 get_v3c4() {
404  return get_registry()->_v3c4;
405 }
406 
407 ////////////////////////////////////////////////////////////////////
408 // Function: GeomVertexFormat::get_v3n3c4
409 // Access: Published, Static
410 // Description: Returns a standard vertex format with a 4-component
411 // color, a 3-component normal, and a 3-component vertex
412 // position.
413 ////////////////////////////////////////////////////////////////////
414 INLINE const GeomVertexFormat *GeomVertexFormat::
415 get_v3n3c4() {
416  return get_registry()->_v3n3c4;
417 }
418 
419 ////////////////////////////////////////////////////////////////////
420 // Function: GeomVertexFormat::get_v3c4t2
421 // Access: Published, Static
422 // Description: Returns a standard vertex format with a 2-component
423 // texture coordinate pair, a 4-component color, and a
424 // 3-component vertex position.
425 ////////////////////////////////////////////////////////////////////
426 INLINE const GeomVertexFormat *GeomVertexFormat::
427 get_v3c4t2() {
428  return get_registry()->_v3c4t2;
429 }
430 
431 ////////////////////////////////////////////////////////////////////
432 // Function: GeomVertexFormat::get_v3n3c4t2
433 // Access: Published, Static
434 // Description: Returns a standard vertex format with a 2-component
435 // texture coordinate pair, a 4-component color, a
436 // 3-component normal, and a 3-component vertex
437 // position.
438 ////////////////////////////////////////////////////////////////////
439 INLINE const GeomVertexFormat *GeomVertexFormat::
440 get_v3n3c4t2() {
441  return get_registry()->_v3n3c4t2;
442 }
443 
444 ////////////////////////////////////////////////////////////////////
445 // Function: GeomVertexFormat::get_vertex_array_index
446 // Access: Public
447 // Description: Returns the array index of the array including the
448 // "vertex" column, or -1 if there is no such array.
449 //
450 // This may only be called after the format has been
451 // registered.
452 ////////////////////////////////////////////////////////////////////
453 INLINE int GeomVertexFormat::
454 get_vertex_array_index() const {
455  nassertr(_is_registered, -1);
456  return _vertex_array_index;
457 }
458 
459 ////////////////////////////////////////////////////////////////////
460 // Function: GeomVertexFormat::get_vertex_column
461 // Access: Public
462 // Description: Returns the column definition of the "vertex" column,
463 // or NULL if there is no such column.
464 //
465 // This may only be called after the format has been
466 // registered.
467 ////////////////////////////////////////////////////////////////////
468 INLINE const GeomVertexColumn *GeomVertexFormat::
469 get_vertex_column() const {
470  nassertr(_is_registered, NULL);
471  return _vertex_column;
472 }
473 
474 ////////////////////////////////////////////////////////////////////
475 // Function: GeomVertexFormat::get_normal_array_index
476 // Access: Public
477 // Description: Returns the array index of the array including the
478 // "normal" column, or -1 if there is no such array.
479 //
480 // This may only be called after the format has been
481 // registered.
482 ////////////////////////////////////////////////////////////////////
483 INLINE int GeomVertexFormat::
484 get_normal_array_index() const {
485  nassertr(_is_registered, -1);
486  return _normal_array_index;
487 }
488 
489 ////////////////////////////////////////////////////////////////////
490 // Function: GeomVertexFormat::get_normal_column
491 // Access: Public
492 // Description: Returns the column definition of the "normal" column,
493 // or NULL if there is no such column.
494 //
495 // This may only be called after the format has been
496 // registered.
497 ////////////////////////////////////////////////////////////////////
498 INLINE const GeomVertexColumn *GeomVertexFormat::
499 get_normal_column() const {
500  nassertr(_is_registered, NULL);
501  return _normal_column;
502 }
503 
504 ////////////////////////////////////////////////////////////////////
505 // Function: GeomVertexFormat::get_color_array_index
506 // Access: Public
507 // Description: Returns the array index of the array including the
508 // "color" column, or -1 if there is no such array.
509 //
510 // This may only be called after the format has been
511 // registered.
512 ////////////////////////////////////////////////////////////////////
513 INLINE int GeomVertexFormat::
514 get_color_array_index() const {
515  nassertr(_is_registered, -1);
516  return _color_array_index;
517 }
518 
519 ////////////////////////////////////////////////////////////////////
520 // Function: GeomVertexFormat::get_color_column
521 // Access: Public
522 // Description: Returns the column definition of the "color" column,
523 // or NULL if there is no such column.
524 //
525 // This may only be called after the format has been
526 // registered.
527 ////////////////////////////////////////////////////////////////////
528 INLINE const GeomVertexColumn *GeomVertexFormat::
529 get_color_column() const {
530  nassertr(_is_registered, NULL);
531  return _color_column;
532 }
533 
534 ////////////////////////////////////////////////////////////////////
535 // Function: GeomVertexFormat::get_registry
536 // Access: Private
537 // Description: Returns the global registry object.
538 ////////////////////////////////////////////////////////////////////
539 INLINE GeomVertexFormat::Registry *GeomVertexFormat::
540 get_registry() {
541  if (_registry == (Registry *)NULL) {
542  make_registry();
543  }
544  return _registry;
545 }
546 
547 ////////////////////////////////////////////////////////////////////
548 // Function: GeomVertexFormat::Registry::register_format
549 // Access: Public
550 // Description: This flavor of register_format() implicitly creates a
551 // one-array vertex format from the array definition.
552 ////////////////////////////////////////////////////////////////////
553 INLINE CPT(GeomVertexFormat) GeomVertexFormat::Registry::
554 register_format(GeomVertexArrayFormat *format) {
555  return register_format(new GeomVertexFormat(format));
556 }
This object describes how the vertex animation, if any, represented in a GeomVertexData is encoded...
This defines how a single column is interleaved within a vertex array stored within a Geom...