Panda3D
Loading...
Searching...
No Matches
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
14INLINE std::ostream &
15operator << (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 */
25INLINE bool GeomVertexFormat::
26is_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 */
40INLINE CPT(GeomVertexFormat) GeomVertexFormat::
41register_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 */
49INLINE CPT(GeomVertexFormat) GeomVertexFormat::
50register_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 */
59get_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 */
70INLINE void GeomVertexFormat::
71set_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 */
81INLINE size_t GeomVertexFormat::
82get_num_arrays() const {
83 return _arrays.size();
84}
85
86/**
87 * Returns the description of the nth array used by the format.
88 */
90get_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 */
98INLINE bool GeomVertexFormat::
99has_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 */
109INLINE size_t GeomVertexFormat::
110get_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 */
122get_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 */
134INLINE size_t GeomVertexFormat::
135get_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 */
148get_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 */
160INLINE size_t GeomVertexFormat::
161get_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 */
173get_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 */
185INLINE size_t GeomVertexFormat::
186get_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 */
200get_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 */
215get_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 */
231get_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 */
243get_empty() {
244 return get_registry()->_empty;
245}
246
247/**
248 * Returns a standard vertex format with just a 3-component vertex position.
249 */
251get_v3() {
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 */
260get_v3n3() {
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 */
269get_v3t2() {
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 */
278get_v3n3t2() {
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 */
287get_v3cp() {
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 */
296get_v3n3cp() {
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 */
305get_v3cpt2() {
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 */
315get_v3n3cpt2() {
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 */
324get_v3c4() {
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 */
333get_v3n3c4() {
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 */
342get_v3c4t2() {
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 */
352get_v3n3c4t2() {
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 */
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 */
375get_vertex_column() const {
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 */
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 */
399get_normal_column() const {
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 */
411get_color_array_index() const {
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 */
423get_color_column() const {
424 nassertr(_is_registered, nullptr);
425 return _color_column;
426}
427
428/**
429 * Returns the global registry object.
430 */
431INLINE GeomVertexFormat::Registry *GeomVertexFormat::
432get_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 */
443INLINE CPT(GeomVertexFormat) GeomVertexFormat::Registry::
444register_format(GeomVertexArrayFormat *format) {
445 return register_format(new GeomVertexFormat(format));
446}
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 class defines the physical layout of the vertex data stored within a Geom.
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...
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 ...
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.
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.
const GeomVertexColumn * get_vertex_column() const
Returns the column definition of the "vertex" column, or NULL if there is no such column.
has_column
Returns true if the format has the named column, false otherwise.
get_point
Returns the name of the nth point column.
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.
Encodes a string name in a hash table, mapping it to a pointer.