Panda3D
geomVertexColumn.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 geomVertexColumn.I
10  * @author drose
11  * @date 2005-03-06
12  */
13 
14 /**
15  * Creates an invalid column. Used only when constructing from a bam file.
16  */
17 INLINE GeomVertexColumn::
18 GeomVertexColumn() :
19  _packer(nullptr)
20 {
21 }
22 
23 /**
24  *
25  */
26 INLINE GeomVertexColumn::
27 GeomVertexColumn(CPT_InternalName name, int num_components,
28  NumericType numeric_type, Contents contents,
29  int start, int column_alignment, int num_elements,
30  int element_stride) :
31  _name(std::move(name)),
32  _num_components(num_components),
33  _numeric_type(numeric_type),
34  _contents(contents),
35  _start(start),
36  _column_alignment(column_alignment),
37  _num_elements(num_elements),
38  _element_stride(element_stride),
39  _packer(nullptr)
40 {
41  setup();
42 }
43 
44 /**
45  *
46  */
47 INLINE GeomVertexColumn::
48 GeomVertexColumn(const GeomVertexColumn &copy) :
49  _name(copy._name),
50  _num_components(copy._num_components),
51  _numeric_type(copy._numeric_type),
52  _contents(copy._contents),
53  _start(copy._start),
54  _column_alignment(copy._column_alignment),
55  _num_elements(copy._num_elements),
56  _element_stride(copy._element_stride),
57  _packer(nullptr)
58 {
59  setup();
60 }
61 
62 /**
63  *
64  */
65 INLINE GeomVertexColumn::
66 ~GeomVertexColumn() {
67  delete _packer;
68 }
69 
70 /**
71  * Returns the name of this particular data field, e.g. "vertex" or "normal".
72  * The name may be a user-defined string, or it may be one of the standard
73  * system-defined field types. Only the system-defined field types are used
74  * for the actual rendering.
75  */
76 INLINE const InternalName *GeomVertexColumn::
77 get_name() const {
78  return _name;
79 }
80 
81 /**
82  * Returns the number of components of the column: the number of instances of
83  * the NumericType in each element. This is usually, but not always, the same
84  * thing as get_num_values().
85  */
86 INLINE int GeomVertexColumn::
88  return _num_components;
89 }
90 
91 /**
92  * Returns the number of numeric values of the column: the number of distinct
93  * numeric values that go into each element. This is usually, but not always,
94  * the same thing as get_num_components(); the difference is in the case of a
95  * composite numeric type like NT_packed_dcba, which has four numeric values
96  * per component.
97  */
98 INLINE int GeomVertexColumn::
99 get_num_values() const {
100  return _num_values;
101 }
102 
103 /**
104  * Returns the number of times this column is repeated. This is usually 1,
105  * except for matrices.
106  */
107 INLINE int GeomVertexColumn::
109  return _num_elements;
110 }
111 
112 /**
113  * Returns the token representing the numeric type of the data storage.
114  */
115 INLINE GeomVertexColumn::NumericType GeomVertexColumn::
117  return _numeric_type;
118 }
119 
120 /**
121  * Returns the token representing the semantic meaning of the stored value.
122  */
123 INLINE GeomVertexColumn::Contents GeomVertexColumn::
124 get_contents() const {
125  return _contents;
126 }
127 
128 /**
129  * Returns the byte within the array record at which this column starts. This
130  * can be set to non-zero to implement interleaved arrays.
131  */
132 INLINE int GeomVertexColumn::
133 get_start() const {
134  return _start;
135 }
136 
137 /**
138  * Returns the alignment requirements for this column. If this is greater
139  * than 1, it restricts the column to appear only on memory addresses that are
140  * integer multiples of this value; this has implications for this column's
141  * start value, as well as the stride of the resulting array.
142  */
143 INLINE int GeomVertexColumn::
145  return _column_alignment;
146 }
147 
148 /**
149  * This value is only relevant for matrix types. Returns the number of bytes
150  * to add to access the next row of the matrix.
151  */
152 INLINE int GeomVertexColumn::
154  return _element_stride;
155 }
156 
157 /**
158  * Returns the number of bytes used by each component (that is, by one element
159  * of the numeric type).
160  */
161 INLINE int GeomVertexColumn::
163  return _component_bytes;
164 }
165 
166 /**
167  * Returns the number of bytes used by each element of the column:
168  * component_bytes * num_components.
169  */
170 INLINE int GeomVertexColumn::
172  return _total_bytes;
173 }
174 
175 /**
176  * Returns true if this Contents type is one that includes a homogeneous
177  * coordinate in the fourth component, or false otherwise. If this is true,
178  * correct operation on the vertex data may require scaling by the homogeneous
179  * coordinate from time to time (but in general this is handled automatically
180  * if you use the 3-component or smaller forms of get_data() and set_data()).
181  */
182 INLINE bool GeomVertexColumn::
184  switch (_contents) {
185  case C_point:
186  case C_texcoord:
187  return true;
188 
189  default:
190  return false;
191  }
192 }
193 
194 /**
195  * Returns true if this column overlaps with any of the bytes in the indicated
196  * range, false if it does not.
197  */
198 INLINE bool GeomVertexColumn::
199 overlaps_with(int start_byte, int num_bytes) const {
200  return (_start < start_byte + num_bytes &&
201  _start + _total_bytes > start_byte);
202 }
203 
204 /**
205  * Returns true if the data store of this column is exactly the same as that
206  * of the other, irrespective of name or start position within the record.
207  */
208 INLINE bool GeomVertexColumn::
210  // Not sure if the contents are relevant, but let's say that they are.
211  return (_num_components == other._num_components &&
212  _numeric_type == other._numeric_type &&
213  _contents == other._contents);
214 }
215 
216 /**
217  * Returns true if this column is the standard DirectX representation of
218  * 4-component color: C_color, in NT_packed_dabc, with 1 component (4 values).
219  */
220 INLINE bool GeomVertexColumn::
221 is_packed_argb() const {
222  return (_num_components == 1 &&
223  _numeric_type == NT_packed_dabc &&
224  _contents == C_color);
225 }
226 
227 /**
228  * Returns true if this column is the standard OpenGL representation of
229  * 4-component color: C_color, in NT_uint8, with 4 components.
230  */
231 INLINE bool GeomVertexColumn::
232 is_uint8_rgba() const {
233  return (_num_components == 4 &&
234  _numeric_type == NT_uint8 &&
235  _contents == C_color);
236 }
237 
238 /**
239  * This is used to unquify columns, and hence formats, for the
240  * GeomVertexFormat registry.
241  */
242 INLINE int GeomVertexColumn::
243 compare_to(const GeomVertexColumn &other) const {
244  if (_name != other._name) {
245  return _name < other._name ? -1 : 1;
246  }
247  if (_num_components != other._num_components) {
248  return _num_components - other._num_components;
249  }
250  if (_numeric_type != other._numeric_type) {
251  return (int)_numeric_type - (int)other._numeric_type;
252  }
253  if (_contents != other._contents) {
254  return (int)_contents - (int)other._contents;
255  }
256  if (_start != other._start) {
257  return _start - other._start;
258  }
259  if (_column_alignment != other._column_alignment) {
260  return _column_alignment - other._column_alignment;
261  }
262  if (_num_elements != other._num_elements) {
263  return _num_elements - other._num_elements;
264  }
265  if (_element_stride != other._element_stride) {
266  return _element_stride - other._element_stride;
267  }
268  return 0;
269 }
270 
271 /**
272  * Returns true if the two columns are exactly equivalent, false otherwise.
273  */
274 INLINE bool GeomVertexColumn::
275 operator == (const GeomVertexColumn &other) const {
276  return compare_to(other) == 0;
277 }
278 
279 /**
280  *
281  */
282 INLINE bool GeomVertexColumn::
283 operator != (const GeomVertexColumn &other) const {
284  return compare_to(other) != 0;
285 }
286 
287 /**
288  * This is used to put columns in order within a particular
289  * GeomVertexArrayFormat. Note that it is *not* in the same space as operator
290  * == and operator !=.
291  */
292 INLINE bool GeomVertexColumn::
293 operator < (const GeomVertexColumn &other) const {
294  if (_start != other._start) {
295  return _start < other._start;
296  }
297  if (_total_bytes < other._total_bytes) {
298  return _total_bytes < other._total_bytes;
299  }
300  return 0;
301 }
302 
303 INLINE std::ostream &
304 operator << (std::ostream &out, const GeomVertexColumn &obj) {
305  obj.output(out);
306  return out;
307 }
bool is_uint8_rgba() const
Returns true if this column is the standard OpenGL representation of 4-component color: C_color,...
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:193
bool overlaps_with(int start_byte, int num_bytes) const
Returns true if this column overlaps with any of the bytes in the indicated range,...
Contents get_contents() const
Returns the token representing the semantic meaning of the stored value.
NumericType get_numeric_type() const
Returns the token representing the numeric type of the data storage.
bool is_bytewise_equivalent(const GeomVertexColumn &other) const
Returns true if the data store of this column is exactly the same as that of the other,...
bool has_homogeneous_coord() const
Returns true if this Contents type is one that includes a homogeneous coordinate in the fourth compon...
bool is_packed_argb() const
Returns true if this column is the standard DirectX representation of 4-component color: C_color,...
This defines how a single column is interleaved within a vertex array stored within a Geom.
int get_num_elements() const
Returns the number of times this column is repeated.
bool operator==(const GeomVertexColumn &other) const
Returns true if the two columns are exactly equivalent, false otherwise.
int get_element_stride() const
This value is only relevant for matrix types.
int get_num_values() const
Returns the number of numeric values of the column: the number of distinct numeric values that go int...
bool operator<(const GeomVertexColumn &other) const
This is used to put columns in order within a particular GeomVertexArrayFormat.
int get_column_alignment() const
Returns the alignment requirements for this column.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
int get_start() const
Returns the byte within the array record at which this column starts.
int get_component_bytes() const
Returns the number of bytes used by each component (that is, by one element of the numeric type).
const InternalName * get_name() const
Returns the name of this particular data field, e.g.
int get_total_bytes() const
Returns the number of bytes used by each element of the column: component_bytes * num_components.
int get_num_components() const
Returns the number of components of the column: the number of instances of the NumericType in each el...
int compare_to(const GeomVertexColumn &other) const
This is used to unquify columns, and hence formats, for the GeomVertexFormat registry.