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 */
19INLINE 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 */
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 */
42INLINE 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 * You should avoid arrays with stride higher than 2048, which is the typical
53 * limit supported by graphics hardware.
54 */
55INLINE void GeomVertexArrayFormat::
56 set_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 */
69INLINE int GeomVertexArrayFormat::
70 get_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 */
81INLINE void GeomVertexArrayFormat::
82 set_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 */
94INLINE int GeomVertexArrayFormat::
95 get_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::
105 set_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 */
114INLINE int GeomVertexArrayFormat::
115 get_total_bytes() const {
116 return _total_bytes;
117}
118
119/**
120 * Returns the number of different columns in the array.
121 */
122INLINE int GeomVertexArrayFormat::
123 get_num_columns() const {
124 return (int)_columns.size();
125}
126
127/**
128 * Returns the ith column of the array.
129 */
130INLINE const GeomVertexColumn *GeomVertexArrayFormat::
131 get_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 */
140INLINE bool GeomVertexArrayFormat::
141 has_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}
GeomVertexArrayFormat
This describes the structure of a single array within a Geom data.
Definition geomVertexArrayFormat.h:47
GeomVertexArrayFormat::get_column
get_column
Returns the specification with the indicated name, or NULL if the name is not used.
Definition geomVertexArrayFormat.h:106
GeomVertexArrayFormat::has_column
bool has_column(const InternalName *name) const
Returns true if the array has the named column, false otherwise.
Definition geomVertexArrayFormat.I:141
GeomVertexArrayFormat::get_num_columns
get_num_columns
Returns the number of different columns in the array.
Definition geomVertexArrayFormat.h:106
GeomVertexArrayFormat::set_stride
set_stride
Changes the total number of bytes reserved in the array for each vertex.
Definition geomVertexArrayFormat.h:82
GeomVertexArrayFormat::get_total_bytes
get_total_bytes
Returns the total number of bytes used by the data types within the format, including gaps between el...
Definition geomVertexArrayFormat.h:93
GeomVertexArrayFormat::set_pad_to
set_pad_to
Explicitly sets the byte divisor to which the data record must be padded to meet hardware limitations...
Definition geomVertexArrayFormat.h:86
GeomVertexArrayFormat::get_stride
get_stride
Returns the total number of bytes reserved in the array for each vertex.
Definition geomVertexArrayFormat.h:82
GeomVertexArrayFormat::get_pad_to
get_pad_to
Returns the byte divisor to which the data record must be padded to meet hardware limitations.
Definition geomVertexArrayFormat.h:86
GeomVertexArrayFormat::is_registered
is_registered
Returns true if this format has been registered, false if it has not.
Definition geomVertexArrayFormat.h:78
GeomVertexArrayFormat::get_divisor
get_divisor
Returns the divisor attribute for the data in this array.
Definition geomVertexArrayFormat.h:90
GeomVertexArrayFormat::set_divisor
set_divisor
Set this to 0 to indicate that this array contains per-vertex data, or to 1 to indicate that it conta...
Definition geomVertexArrayFormat.h:90
GeomVertexColumn
This defines how a single column is interleaved within a vertex array stored within a Geom.
Definition geomVertexColumn.h:37
InternalName
Encodes a string name in a hash table, mapping it to a pointer.
Definition internalName.h:38