Panda3D
 All Classes Functions Variables Enumerations
geomVertexArrayFormat.I
1 // Filename: geomVertexArrayFormat.I
2 // Created by: drose (06Mar05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: GeomVertexArrayFormat::is_registered
18 // Access: Published
19 // Description: Returns true if this format has been registered,
20 // false if it has not. It may not be used for a Geom
21 // until it has been registered, but once registered, it
22 // may no longer be modified.
23 ////////////////////////////////////////////////////////////////////
24 INLINE bool GeomVertexArrayFormat::
25 is_registered() const {
26  return _is_registered;
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: GeomVertexArrayFormat::register_format
31 // Access: Published, Static
32 // Description: Adds the indicated format to the registry, if there
33 // is not an equivalent format already there; in either
34 // case, returns the pointer to the equivalent format
35 // now in the registry.
36 //
37 // This is similar to
38 // GeomVertexFormat::register_format(), except that you
39 // generally need not call it explicitly. Calling
40 // GeomVertexFormat::register_format() automatically
41 // registers all of the nested array formats.
42 ////////////////////////////////////////////////////////////////////
43 INLINE CPT(GeomVertexArrayFormat) GeomVertexArrayFormat::
44 register_format(const GeomVertexArrayFormat *format) {
45  return get_registry()->register_format((GeomVertexArrayFormat *)format);
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: GeomVertexArrayFormat::get_stride
50 // Access: Published
51 // Description: Returns the total number of bytes reserved in the
52 // array for each vertex.
53 ////////////////////////////////////////////////////////////////////
54 INLINE int GeomVertexArrayFormat::
55 get_stride() const {
56  return _stride;
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: GeomVertexArrayFormat::set_stride
61 // Access: Published
62 // Description: Changes the total number of bytes reserved in the
63 // array for each vertex. You may not reduce this below
64 // get_total_bytes(), but you may increase it
65 // arbitrarily.
66 ////////////////////////////////////////////////////////////////////
67 INLINE void GeomVertexArrayFormat::
68 set_stride(int stride) {
69  nassertv(!_is_registered);
70  nassertv(_stride >= _total_bytes);
71  _stride = stride;
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: GeomVertexArrayFormat::get_pad_to
76 // Access: Published
77 // Description: Returns the byte divisor to which the data record
78 // must be padded to meet hardware limitations. For
79 // instance, if this is 4, the stride will be
80 // automatically rounded up to the next multiple of 4
81 // bytes. This value is automatically increased as
82 // needed to ensure the individual numeric components in
83 // the array are word-aligned.
84 ////////////////////////////////////////////////////////////////////
85 INLINE int GeomVertexArrayFormat::
86 get_pad_to() const {
87  return _pad_to;
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: GeomVertexArrayFormat::set_pad_to
92 // Access: Published
93 // Description: Explicitly sets the byte divisor to which the data
94 // record must be padded to meet hardware limitations.
95 // See get_pad_to(). Normally it is not necessary to
96 // call this unless you have some specific requirements
97 // for row-to-row data alignment. Note that this value
98 // may be automatically increased at each subsequent
99 // call to add_column().
100 ////////////////////////////////////////////////////////////////////
101 INLINE void GeomVertexArrayFormat::
102 set_pad_to(int pad_to) {
103  nassertv(pad_to >= 1);
104 
105  _pad_to = pad_to;
106  _stride = ((_stride + _pad_to - 1) / _pad_to) * _pad_to;
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: GeomVertexArrayFormat::get_divisor
111 // Access: Published
112 // Description: Returns the divisor attribute for the data in this
113 // array. If 0, it contains per-vertex data. If 1,
114 // it contains per-instance data. If higher than 1,
115 // the read row is advanced for each n instances.
116 ////////////////////////////////////////////////////////////////////
117 INLINE int GeomVertexArrayFormat::
118 get_divisor() const {
119  return _divisor;
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: GeomVertexArrayFormat::set_divisor
124 // Access: Published
125 // Description: Set this to 0 to indicate that this array contains
126 // per-vertex data, or to 1 to indicate that it
127 // contains per-instance data. If higher than 1,
128 // the read row is advanced for each n instances.
129 ////////////////////////////////////////////////////////////////////
130 INLINE void GeomVertexArrayFormat::
131 set_divisor(int divisor) {
132  nassertv(divisor >= 0);
133  _divisor = divisor;
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: GeomVertexArrayFormat::get_total_bytes
138 // Access: Published
139 // Description: Returns the total number of bytes used by the data
140 // types within the format, including gaps between
141 // elements.
142 ////////////////////////////////////////////////////////////////////
143 INLINE int GeomVertexArrayFormat::
144 get_total_bytes() const {
145  return _total_bytes;
146 }
147 
148 ////////////////////////////////////////////////////////////////////
149 // Function: GeomVertexArrayFormat::get_num_columns
150 // Access: Published
151 // Description: Returns the number of different columns in the
152 // array.
153 ////////////////////////////////////////////////////////////////////
154 INLINE int GeomVertexArrayFormat::
155 get_num_columns() const {
156  return (int)_columns.size();
157 }
158 
159 ////////////////////////////////////////////////////////////////////
160 // Function: GeomVertexArrayFormat::get_column
161 // Access: Published
162 // Description: Returns the ith column of the array.
163 ////////////////////////////////////////////////////////////////////
164 INLINE const GeomVertexColumn *GeomVertexArrayFormat::
165 get_column(int i) const {
166  nassertr(i >= 0 && i < (int)_columns.size(), NULL);
167  consider_sort_columns();
168  return _columns[i];
169 }
170 
171 ////////////////////////////////////////////////////////////////////
172 // Function: GeomVertexArrayFormat::has_column
173 // Access: Published
174 // Description: Returns true if the array has the named column,
175 // false otherwise.
176 ////////////////////////////////////////////////////////////////////
177 INLINE bool GeomVertexArrayFormat::
178 has_column(const InternalName *name) const {
179  return (get_column(name) != (GeomVertexColumn *)NULL);
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: GeomVertexArrayFormat::get_registry
184 // Access: Private
185 // Description: Returns the global registry object.
186 ////////////////////////////////////////////////////////////////////
187 INLINE GeomVertexArrayFormat::Registry *GeomVertexArrayFormat::
188 get_registry() {
189  if (_registry == (Registry *)NULL) {
190  make_registry();
191  }
192  return _registry;
193 }
194 
195 ////////////////////////////////////////////////////////////////////
196 // Function: GeomVertexArrayFormat::consider_sort_columns
197 // Access: Private
198 // Description: Resorts the _columns vector if necessary.
199 ////////////////////////////////////////////////////////////////////
200 INLINE void GeomVertexArrayFormat::
201 consider_sort_columns() const {
202  if (_columns_unsorted) {
203  ((GeomVertexArrayFormat *)this)->sort_columns();
204  }
205 }
206 
207 INLINE ostream &
208 operator << (ostream &out, const GeomVertexArrayFormat &obj) {
209  obj.output(out);
210  return out;
211 }
This defines how a single column is interleaved within a vertex array stored within a Geom...