Panda3D
geomVertexArrayFormat.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 geomVertexArrayFormat.I
10  * @author drose
11  * @date 2005-03-06
12  */
13 
14 /**
15  * Returns true if this format has been registered, false if it has not. It
16  * may not be used for a Geom until it has been registered, but once
17  * registered, it may no longer be modified.
18  */
19 INLINE bool GeomVertexArrayFormat::
20 is_registered() const {
21  return _is_registered;
22 }
23 
24 /**
25  * Adds the indicated format to the registry, if there is not an equivalent
26  * format already there; in either case, returns the pointer to the equivalent
27  * format now in the registry.
28  *
29  * This is similar to GeomVertexFormat::register_format(), except that you
30  * generally need not call it explicitly. Calling
31  * GeomVertexFormat::register_format() automatically registers all of the
32  * nested array formats.
33  */
34 INLINE CPT(GeomVertexArrayFormat) GeomVertexArrayFormat::
35 register_format(const GeomVertexArrayFormat *format) {
36  return get_registry()->register_format((GeomVertexArrayFormat *)format);
37 }
38 
39 /**
40  * Returns the total number of bytes reserved in the array for each vertex.
41  */
42 INLINE int GeomVertexArrayFormat::
43 get_stride() const {
44  return _stride;
45 }
46 
47 /**
48  * Changes the total number of bytes reserved in the array for each vertex.
49  * You may not reduce this below get_total_bytes(), but you may increase it
50  * arbitrarily.
51  */
52 INLINE void GeomVertexArrayFormat::
53 set_stride(int stride) {
54  nassertv(!_is_registered);
55  nassertv(_stride >= _total_bytes);
56  _stride = stride;
57 }
58 
59 /**
60  * Returns the byte divisor to which the data record must be padded to meet
61  * hardware limitations. For instance, if this is 4, the stride will be
62  * automatically rounded up to the next multiple of 4 bytes. This value is
63  * automatically increased as needed to ensure the individual numeric
64  * components in the array are word-aligned.
65  */
66 INLINE int GeomVertexArrayFormat::
67 get_pad_to() const {
68  return _pad_to;
69 }
70 
71 /**
72  * Explicitly sets the byte divisor to which the data record must be padded to
73  * meet hardware limitations. See get_pad_to(). Normally it is not necessary
74  * to call this unless you have some specific requirements for row-to-row data
75  * alignment. Note that this value may be automatically increased at each
76  * subsequent call to add_column().
77  */
78 INLINE void GeomVertexArrayFormat::
79 set_pad_to(int pad_to) {
80  nassertv(pad_to >= 1);
81 
82  _pad_to = pad_to;
83  _stride = ((_stride + _pad_to - 1) / _pad_to) * _pad_to;
84 }
85 
86 /**
87  * Returns the divisor attribute for the data in this array. If 0, it
88  * contains per-vertex data. If 1, it contains per-instance data. If higher
89  * than 1, the read row is advanced for each n instances.
90  */
91 INLINE int GeomVertexArrayFormat::
92 get_divisor() const {
93  return _divisor;
94 }
95 
96 /**
97  * Set this to 0 to indicate that this array contains per-vertex data, or to 1
98  * to indicate that it contains per-instance data. If higher than 1, the read
99  * row is advanced for each n instances.
100  */
101 INLINE void GeomVertexArrayFormat::
102 set_divisor(int divisor) {
103  nassertv(divisor >= 0);
104  _divisor = divisor;
105 }
106 
107 /**
108  * Returns the total number of bytes used by the data types within the format,
109  * including gaps between elements.
110  */
111 INLINE int GeomVertexArrayFormat::
112 get_total_bytes() const {
113  return _total_bytes;
114 }
115 
116 /**
117  * Returns the number of different columns in the array.
118  */
119 INLINE int GeomVertexArrayFormat::
120 get_num_columns() const {
121  return (int)_columns.size();
122 }
123 
124 /**
125  * Returns the ith column of the array.
126  */
128 get_column(int i) const {
129  nassertr(i >= 0 && i < (int)_columns.size(), nullptr);
130  consider_sort_columns();
131  return _columns[(size_t)i];
132 }
133 
134 /**
135  * Returns true if the array has the named column, false otherwise.
136  */
137 INLINE bool GeomVertexArrayFormat::
138 has_column(const InternalName *name) const {
139  return (get_column(name) != nullptr);
140 }
141 
142 /**
143  * Returns the global registry object.
144  */
145 INLINE GeomVertexArrayFormat::Registry *GeomVertexArrayFormat::
146 get_registry() {
147  if (_registry == nullptr) {
148  make_registry();
149  }
150  return _registry;
151 }
152 
153 /**
154  * Resorts the _columns vector if necessary.
155  */
156 INLINE void GeomVertexArrayFormat::
157 consider_sort_columns() const {
158  if (_columns_unsorted) {
159  ((GeomVertexArrayFormat *)this)->sort_columns();
160  }
161 }
162 
163 INLINE std::ostream &
164 operator << (std::ostream &out, const GeomVertexArrayFormat &obj) {
165  obj.output(out);
166  return out;
167 }
CPT(GeomVertexArrayFormat) GeomVertexArrayFormat
Adds the indicated format to the registry, if there is not an equivalent format already there; in eit...
set_pad_to
Explicitly sets the byte divisor to which the data record must be padded to meet hardware limitations...
This defines how a single column is interleaved within a vertex array stored within a Geom.
set_divisor
Set this to 0 to indicate that this array contains per-vertex data, or to 1 to indicate that it conta...
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
This describes the structure of a single array within a Geom data.
bool has_column(const InternalName *name) const
Returns true if the array has the named column, false otherwise.
set_stride
Changes the total number of bytes reserved in the array for each vertex.
get_column
Returns the specification with the indicated name, or NULL if the name is not used.