Panda3D
Loading...
Searching...
No Matches
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 */
20is_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 */
34INLINE CPT(GeomVertexArrayFormat) GeomVertexArrayFormat::
35register_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 */
43get_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 * You should avoid arrays with stride higher than 2048, which is the typical
53 * limit supported by graphics hardware.
54 */
56set_stride(int stride) {
57 nassertv(!_is_registered);
58 nassertv(_stride >= _total_bytes);
59 _stride = stride;
60}
61
62/**
63 * Returns the byte divisor to which the data record must be padded to meet
64 * hardware limitations. For instance, if this is 4, the stride will be
65 * automatically rounded up to the next multiple of 4 bytes. This value is
66 * automatically increased as needed to ensure the individual numeric
67 * components in the array are word-aligned.
68 */
70get_pad_to() const {
71 return _pad_to;
72}
73
74/**
75 * Explicitly sets the byte divisor to which the data record must be padded to
76 * meet hardware limitations. See get_pad_to(). Normally it is not necessary
77 * to call this unless you have some specific requirements for row-to-row data
78 * alignment. Note that this value may be automatically increased at each
79 * subsequent call to add_column().
80 */
82set_pad_to(int pad_to) {
83 nassertv(pad_to >= 1);
84
85 _pad_to = pad_to;
86 _stride = ((_stride + _pad_to - 1) / _pad_to) * _pad_to;
87}
88
89/**
90 * Returns the divisor attribute for the data in this array. If 0, it
91 * contains per-vertex data. If 1, it contains per-instance data. If higher
92 * than 1, the read row is advanced for each n instances.
93 */
95get_divisor() const {
96 return _divisor;
97}
98
99/**
100 * Set this to 0 to indicate that this array contains per-vertex data, or to 1
101 * to indicate that it contains per-instance data. If higher than 1, the read
102 * row is advanced for each n instances.
103 */
104INLINE void GeomVertexArrayFormat::
105set_divisor(int divisor) {
106 nassertv(divisor >= 0);
107 _divisor = divisor;
108}
109
110/**
111 * Returns the total number of bytes used by the data types within the format,
112 * including gaps between elements.
113 */
115get_total_bytes() const {
116 return _total_bytes;
117}
118
119/**
120 * Returns the number of different columns in the array.
121 */
123get_num_columns() const {
124 return (int)_columns.size();
125}
126
127/**
128 * Returns the ith column of the array.
129 */
131get_column(int i) const {
132 nassertr(i >= 0 && i < (int)_columns.size(), nullptr);
133 consider_sort_columns();
134 return _columns[(size_t)i];
135}
136
137/**
138 * Returns true if the array has the named column, false otherwise.
139 */
141has_column(const InternalName *name) const {
142 return (get_column(name) != nullptr);
143}
144
145/**
146 * Returns the global registry object.
147 */
148INLINE GeomVertexArrayFormat::Registry *GeomVertexArrayFormat::
149get_registry() {
150 if (_registry == nullptr) {
151 make_registry();
152 }
153 return _registry;
154}
155
156/**
157 * Resorts the _columns vector if necessary.
158 */
159INLINE void GeomVertexArrayFormat::
160consider_sort_columns() const {
161 if (_columns_unsorted) {
162 ((GeomVertexArrayFormat *)this)->sort_columns();
163 }
164}
165
166INLINE std::ostream &
167operator << (std::ostream &out, const GeomVertexArrayFormat &obj) {
168 obj.output(out);
169 return out;
170}
This describes the structure of a single array within a Geom data.
get_column
Returns the specification with the indicated name, or NULL if the name is not used.
bool has_column(const InternalName *name) const
Returns true if the array has the named column, false otherwise.
get_num_columns
Returns the number of different columns in the array.
set_stride
Changes the total number of bytes reserved in the array for each vertex.
get_total_bytes
Returns the total number of bytes used by the data types within the format, including gaps between el...
set_pad_to
Explicitly sets the byte divisor to which the data record must be padded to meet hardware limitations...
get_stride
Returns the total number of bytes reserved in the array for each vertex.
get_pad_to
Returns the byte divisor to which the data record must be padded to meet hardware limitations.
is_registered
Returns true if this format has been registered, false if it has not.
get_divisor
Returns the divisor attribute for the data in this array.
set_divisor
Set this to 0 to indicate that this array contains per-vertex data, or to 1 to indicate that it conta...
This defines how a single column is interleaved within a vertex array stored within a Geom.
Encodes a string name in a hash table, mapping it to a pointer.