Panda3D
|
00001 // Filename: geomVertexFormat.I 00002 // Created by: drose (07Mar05) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 INLINE ostream & 00017 operator << (ostream &out, const GeomVertexFormat &obj) { 00018 obj.output(out); 00019 return out; 00020 } 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: GeomVertexFormat::is_registered 00024 // Access: Published 00025 // Description: Returns true if this format has been registered, 00026 // false if it has not. It may not be used for a Geom 00027 // until it has been registered, but once registered, it 00028 // may no longer be modified. 00029 //////////////////////////////////////////////////////////////////// 00030 INLINE bool GeomVertexFormat:: 00031 is_registered() const { 00032 return _is_registered; 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: GeomVertexFormat::register_format 00037 // Access: Published, Static 00038 // Description: Adds the indicated format to the registry, if there 00039 // is not an equivalent format already there; in either 00040 // case, returns the pointer to the equivalent format 00041 // now in the registry. 00042 // 00043 // This must be called before a format may be used in a 00044 // Geom. After this call, you should discard the 00045 // original pointer you passed in (which may or may not 00046 // now be invalid) and let its reference count decrement 00047 // normally; you should use only the returned value from 00048 // this point on. 00049 //////////////////////////////////////////////////////////////////// 00050 INLINE CPT(GeomVertexFormat) GeomVertexFormat:: 00051 register_format(const GeomVertexFormat *format) { 00052 return get_registry()->register_format((GeomVertexFormat *)format); 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: GeomVertexFormat::register_format 00057 // Access: Published, Static 00058 // Description: This flavor of register_format() implicitly creates a 00059 // one-array vertex format from the array definition. 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE CPT(GeomVertexFormat) GeomVertexFormat:: 00062 register_format(const GeomVertexArrayFormat *format) { 00063 return register_format(new GeomVertexFormat(format)); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: GeomVertexFormat::get_animation 00068 // Access: Published 00069 // Description: Returns the GeomVertexAnimationSpec that indicates 00070 // how this format's vertices are set up for animation. 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE const GeomVertexAnimationSpec &GeomVertexFormat:: 00073 get_animation() const { 00074 return _animation; 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: GeomVertexFormat::set_animation 00079 // Access: Published 00080 // Description: Resets the GeomVertexAnimationSpec that indicates 00081 // how this format's vertices are set up for animation. 00082 // You should also, of course, change the columns in the 00083 // tables accordingly. 00084 // 00085 // This may not be called once the format has been 00086 // registered. 00087 //////////////////////////////////////////////////////////////////// 00088 INLINE void GeomVertexFormat:: 00089 set_animation(const GeomVertexAnimationSpec &animation) { 00090 nassertv(!_is_registered); 00091 _animation = animation; 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: GeomVertexFormat::get_num_arrays 00096 // Access: Published 00097 // Description: Returns the number of individual arrays required by 00098 // the format. If the array data is completely 00099 // interleaved, this will be 1; if it is completely 00100 // parallel, this will be the same as the number of data 00101 // types. 00102 //////////////////////////////////////////////////////////////////// 00103 INLINE int GeomVertexFormat:: 00104 get_num_arrays() const { 00105 return _arrays.size(); 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: GeomVertexFormat::get_array 00110 // Access: Published 00111 // Description: Returns the description of the nth array used by the 00112 // format. 00113 //////////////////////////////////////////////////////////////////// 00114 INLINE const GeomVertexArrayFormat *GeomVertexFormat:: 00115 get_array(int array) const { 00116 nassertr(array >= 0 && array < (int)_arrays.size(), NULL); 00117 return _arrays[array]; 00118 } 00119 00120 //////////////////////////////////////////////////////////////////// 00121 // Function: GeomVertexFormat::has_column 00122 // Access: Published 00123 // Description: Returns true if the format has the named column, 00124 // false otherwise. 00125 //////////////////////////////////////////////////////////////////// 00126 INLINE bool GeomVertexFormat:: 00127 has_column(const InternalName *name) const { 00128 return (get_column(name) != (GeomVertexColumn *)NULL); 00129 } 00130 00131 //////////////////////////////////////////////////////////////////// 00132 // Function: GeomVertexFormat::get_num_points 00133 // Access: Published 00134 // Description: Returns the number of columns within the format 00135 // that represent points in space. 00136 // 00137 // This may only be called after the format has been 00138 // registered. 00139 //////////////////////////////////////////////////////////////////// 00140 INLINE int GeomVertexFormat:: 00141 get_num_points() const { 00142 nassertr(_is_registered, 0); 00143 return _points.size(); 00144 } 00145 00146 //////////////////////////////////////////////////////////////////// 00147 // Function: GeomVertexFormat::get_point 00148 // Access: Published 00149 // Description: Returns the name of the nth point column. This 00150 // represents a point in space, which should be 00151 // transformed by any spatial transform matrix. 00152 // 00153 // This may only be called after the format has been 00154 // registered. 00155 //////////////////////////////////////////////////////////////////// 00156 INLINE const InternalName *GeomVertexFormat:: 00157 get_point(int n) const { 00158 nassertr(_is_registered, NULL); 00159 nassertr(n >= 0 && n < (int)_points.size(), NULL); 00160 return _points[n]; 00161 } 00162 00163 //////////////////////////////////////////////////////////////////// 00164 // Function: GeomVertexFormat::get_num_vectors 00165 // Access: Published 00166 // Description: Returns the number of columns within the format 00167 // that represent directional vectors. 00168 // 00169 // This may only be called after the format has been 00170 // registered. 00171 //////////////////////////////////////////////////////////////////// 00172 INLINE int GeomVertexFormat:: 00173 get_num_vectors() const { 00174 nassertr(_is_registered, 0); 00175 return _vectors.size(); 00176 } 00177 00178 //////////////////////////////////////////////////////////////////// 00179 // Function: GeomVertexFormat::get_vector 00180 // Access: Published 00181 // Description: Returns the name of the nth vector column. This 00182 // represents a directional vector, which should be 00183 // transformed by any spatial transform matrix as a 00184 // vector. 00185 // 00186 // This may only be called after the format has been 00187 // registered. 00188 //////////////////////////////////////////////////////////////////// 00189 INLINE const InternalName *GeomVertexFormat:: 00190 get_vector(int n) const { 00191 nassertr(_is_registered, NULL); 00192 nassertr(n >= 0 && n < (int)_vectors.size(), NULL); 00193 return _vectors[n]; 00194 } 00195 00196 //////////////////////////////////////////////////////////////////// 00197 // Function: GeomVertexFormat::get_num_texcoords 00198 // Access: Published 00199 // Description: Returns the number of columns within the format 00200 // that represent texture coordinates. 00201 // 00202 // This may only be called after the format has been 00203 // registered. 00204 //////////////////////////////////////////////////////////////////// 00205 INLINE int GeomVertexFormat:: 00206 get_num_texcoords() const { 00207 nassertr(_is_registered, 0); 00208 return _texcoords.size(); 00209 } 00210 00211 //////////////////////////////////////////////////////////////////// 00212 // Function: GeomVertexFormat::get_texcoord 00213 // Access: Published 00214 // Description: Returns the name of the nth texcoord column. This 00215 // represents a texture coordinate. 00216 // 00217 // This may only be called after the format has been 00218 // registered. 00219 //////////////////////////////////////////////////////////////////// 00220 INLINE const InternalName *GeomVertexFormat:: 00221 get_texcoord(int n) const { 00222 nassertr(_is_registered, NULL); 00223 nassertr(n >= 0 && n < (int)_texcoords.size(), NULL); 00224 return _texcoords[n]; 00225 } 00226 00227 //////////////////////////////////////////////////////////////////// 00228 // Function: GeomVertexFormat::get_num_morphs 00229 // Access: Published 00230 // Description: Returns the number of columns within the format 00231 // that represent morph deltas. 00232 // 00233 // This may only be called after the format has been 00234 // registered. 00235 //////////////////////////////////////////////////////////////////// 00236 INLINE int GeomVertexFormat:: 00237 get_num_morphs() const { 00238 nassertr(_is_registered, 0); 00239 00240 return _morphs.size(); 00241 } 00242 00243 //////////////////////////////////////////////////////////////////// 00244 // Function: GeomVertexFormat::get_morph_slider 00245 // Access: Published 00246 // Description: Returns the slider name associated with the nth morph 00247 // column. This is the name of the slider that will 00248 // control the morph, and should be defined within the 00249 // SliderTable associated with the GeomVertexData. 00250 // 00251 // This may only be called after the format has been 00252 // registered. 00253 //////////////////////////////////////////////////////////////////// 00254 INLINE const InternalName *GeomVertexFormat:: 00255 get_morph_slider(int n) const { 00256 nassertr(_is_registered, NULL); 00257 nassertr(n >= 0 && n < (int)_morphs.size(), NULL); 00258 00259 return _morphs[n]._slider; 00260 } 00261 00262 //////////////////////////////////////////////////////////////////// 00263 // Function: GeomVertexFormat::get_morph_base 00264 // Access: Published 00265 // Description: Returns the name of the base column that the nth 00266 // morph modifies. This column will also be defined 00267 // within the format, and can be retrieved via 00268 // get_array_with() and/or get_column(). 00269 // 00270 // This may only be called after the format has been 00271 // registered. 00272 //////////////////////////////////////////////////////////////////// 00273 INLINE const InternalName *GeomVertexFormat:: 00274 get_morph_base(int n) const { 00275 nassertr(_is_registered, NULL); 00276 nassertr(n >= 0 && n < (int)_morphs.size(), NULL); 00277 00278 return _morphs[n]._base; 00279 } 00280 00281 //////////////////////////////////////////////////////////////////// 00282 // Function: GeomVertexFormat::get_morph_delta 00283 // Access: Published 00284 // Description: Returns the name of the column that defines the 00285 // nth morph. This contains the delta offsets that are 00286 // to be applied to the column defined by 00287 // get_morph_base(). This column will be defined 00288 // within the format, and can be retrieved via 00289 // get_array_with() and/or get_column(). 00290 // 00291 // This may only be called after the format has been 00292 // registered. 00293 //////////////////////////////////////////////////////////////////// 00294 INLINE const InternalName *GeomVertexFormat:: 00295 get_morph_delta(int n) const { 00296 nassertr(_is_registered, NULL); 00297 nassertr(n >= 0 && n < (int)_morphs.size(), NULL); 00298 00299 return _morphs[n]._delta; 00300 } 00301 00302 //////////////////////////////////////////////////////////////////// 00303 // Function: GeomVertexFormat::get_v3 00304 // Access: Published, Static 00305 // Description: Returns a standard vertex format with just a 00306 // 3-component vertex position. 00307 //////////////////////////////////////////////////////////////////// 00308 INLINE const GeomVertexFormat *GeomVertexFormat:: 00309 get_v3() { 00310 return get_registry()->_v3; 00311 } 00312 00313 //////////////////////////////////////////////////////////////////// 00314 // Function: GeomVertexFormat::get_v3n3 00315 // Access: Published, Static 00316 // Description: Returns a standard vertex format with a 3-component 00317 // normal and a 3-component vertex position. 00318 //////////////////////////////////////////////////////////////////// 00319 INLINE const GeomVertexFormat *GeomVertexFormat:: 00320 get_v3n3() { 00321 return get_registry()->_v3n3; 00322 } 00323 00324 //////////////////////////////////////////////////////////////////// 00325 // Function: GeomVertexFormat::get_v3t2 00326 // Access: Published, Static 00327 // Description: Returns a standard vertex format with a 2-component 00328 // texture coordinate pair and a 3-component vertex 00329 // position. 00330 //////////////////////////////////////////////////////////////////// 00331 INLINE const GeomVertexFormat *GeomVertexFormat:: 00332 get_v3t2() { 00333 return get_registry()->_v3t2; 00334 } 00335 00336 //////////////////////////////////////////////////////////////////// 00337 // Function: GeomVertexFormat::get_v3n3t2 00338 // Access: Published, Static 00339 // Description: Returns a standard vertex format with a 2-component 00340 // texture coordinate pair, a 3-component normal, and a 00341 // 3-component vertex position. 00342 //////////////////////////////////////////////////////////////////// 00343 INLINE const GeomVertexFormat *GeomVertexFormat:: 00344 get_v3n3t2() { 00345 return get_registry()->_v3n3t2; 00346 } 00347 00348 //////////////////////////////////////////////////////////////////// 00349 // Function: GeomVertexFormat::get_v3cp 00350 // Access: Published, Static 00351 // Description: Returns a standard vertex format with a packed 00352 // color and a 3-component vertex position. 00353 //////////////////////////////////////////////////////////////////// 00354 INLINE const GeomVertexFormat *GeomVertexFormat:: 00355 get_v3cp() { 00356 return get_registry()->_v3cp; 00357 } 00358 00359 //////////////////////////////////////////////////////////////////// 00360 // Function: GeomVertexFormat::get_v3n3cp 00361 // Access: Published, Static 00362 // Description: Returns a standard vertex format with a packed 00363 // color, a 3-component normal, and a 3-component vertex 00364 // position. 00365 //////////////////////////////////////////////////////////////////// 00366 INLINE const GeomVertexFormat *GeomVertexFormat:: 00367 get_v3n3cp() { 00368 return get_registry()->_v3n3cp; 00369 } 00370 00371 //////////////////////////////////////////////////////////////////// 00372 // Function: GeomVertexFormat::get_v3cpt2 00373 // Access: Published, Static 00374 // Description: Returns a standard vertex format with a 2-component 00375 // texture coordinate pair, a packed color, and a 00376 // 3-component vertex position. 00377 //////////////////////////////////////////////////////////////////// 00378 INLINE const GeomVertexFormat *GeomVertexFormat:: 00379 get_v3cpt2() { 00380 return get_registry()->_v3cpt2; 00381 } 00382 00383 //////////////////////////////////////////////////////////////////// 00384 // Function: GeomVertexFormat::get_v3n3cpt2 00385 // Access: Published, Static 00386 // Description: Returns a standard vertex format with a 2-component 00387 // texture coordinate pair, a packed color, a 00388 // 3-component normal, and a 3-component vertex 00389 // position. 00390 //////////////////////////////////////////////////////////////////// 00391 INLINE const GeomVertexFormat *GeomVertexFormat:: 00392 get_v3n3cpt2() { 00393 return get_registry()->_v3n3cpt2; 00394 } 00395 00396 //////////////////////////////////////////////////////////////////// 00397 // Function: GeomVertexFormat::get_v3c4 00398 // Access: Published, Static 00399 // Description: Returns a standard vertex format with a 4-component 00400 // color and a 3-component vertex position. 00401 //////////////////////////////////////////////////////////////////// 00402 INLINE const GeomVertexFormat *GeomVertexFormat:: 00403 get_v3c4() { 00404 return get_registry()->_v3c4; 00405 } 00406 00407 //////////////////////////////////////////////////////////////////// 00408 // Function: GeomVertexFormat::get_v3n3c4 00409 // Access: Published, Static 00410 // Description: Returns a standard vertex format with a 4-component 00411 // color, a 3-component normal, and a 3-component vertex 00412 // position. 00413 //////////////////////////////////////////////////////////////////// 00414 INLINE const GeomVertexFormat *GeomVertexFormat:: 00415 get_v3n3c4() { 00416 return get_registry()->_v3n3c4; 00417 } 00418 00419 //////////////////////////////////////////////////////////////////// 00420 // Function: GeomVertexFormat::get_v3c4t2 00421 // Access: Published, Static 00422 // Description: Returns a standard vertex format with a 2-component 00423 // texture coordinate pair, a 4-component color, and a 00424 // 3-component vertex position. 00425 //////////////////////////////////////////////////////////////////// 00426 INLINE const GeomVertexFormat *GeomVertexFormat:: 00427 get_v3c4t2() { 00428 return get_registry()->_v3c4t2; 00429 } 00430 00431 //////////////////////////////////////////////////////////////////// 00432 // Function: GeomVertexFormat::get_v3n3c4t2 00433 // Access: Published, Static 00434 // Description: Returns a standard vertex format with a 2-component 00435 // texture coordinate pair, a 4-component color, a 00436 // 3-component normal, and a 3-component vertex 00437 // position. 00438 //////////////////////////////////////////////////////////////////// 00439 INLINE const GeomVertexFormat *GeomVertexFormat:: 00440 get_v3n3c4t2() { 00441 return get_registry()->_v3n3c4t2; 00442 } 00443 00444 //////////////////////////////////////////////////////////////////// 00445 // Function: GeomVertexFormat::get_vertex_array_index 00446 // Access: Public 00447 // Description: Returns the array index of the array including the 00448 // "vertex" column, or -1 if there is no such array. 00449 // 00450 // This may only be called after the format has been 00451 // registered. 00452 //////////////////////////////////////////////////////////////////// 00453 INLINE int GeomVertexFormat:: 00454 get_vertex_array_index() const { 00455 nassertr(_is_registered, -1); 00456 return _vertex_array_index; 00457 } 00458 00459 //////////////////////////////////////////////////////////////////// 00460 // Function: GeomVertexFormat::get_vertex_column 00461 // Access: Public 00462 // Description: Returns the column definition of the "vertex" column, 00463 // or NULL if there is no such column. 00464 // 00465 // This may only be called after the format has been 00466 // registered. 00467 //////////////////////////////////////////////////////////////////// 00468 INLINE const GeomVertexColumn *GeomVertexFormat:: 00469 get_vertex_column() const { 00470 nassertr(_is_registered, NULL); 00471 return _vertex_column; 00472 } 00473 00474 //////////////////////////////////////////////////////////////////// 00475 // Function: GeomVertexFormat::get_normal_array_index 00476 // Access: Public 00477 // Description: Returns the array index of the array including the 00478 // "normal" column, or -1 if there is no such array. 00479 // 00480 // This may only be called after the format has been 00481 // registered. 00482 //////////////////////////////////////////////////////////////////// 00483 INLINE int GeomVertexFormat:: 00484 get_normal_array_index() const { 00485 nassertr(_is_registered, -1); 00486 return _normal_array_index; 00487 } 00488 00489 //////////////////////////////////////////////////////////////////// 00490 // Function: GeomVertexFormat::get_normal_column 00491 // Access: Public 00492 // Description: Returns the column definition of the "normal" column, 00493 // or NULL if there is no such column. 00494 // 00495 // This may only be called after the format has been 00496 // registered. 00497 //////////////////////////////////////////////////////////////////// 00498 INLINE const GeomVertexColumn *GeomVertexFormat:: 00499 get_normal_column() const { 00500 nassertr(_is_registered, NULL); 00501 return _normal_column; 00502 } 00503 00504 //////////////////////////////////////////////////////////////////// 00505 // Function: GeomVertexFormat::get_color_array_index 00506 // Access: Public 00507 // Description: Returns the array index of the array including the 00508 // "color" column, or -1 if there is no such array. 00509 // 00510 // This may only be called after the format has been 00511 // registered. 00512 //////////////////////////////////////////////////////////////////// 00513 INLINE int GeomVertexFormat:: 00514 get_color_array_index() const { 00515 nassertr(_is_registered, -1); 00516 return _color_array_index; 00517 } 00518 00519 //////////////////////////////////////////////////////////////////// 00520 // Function: GeomVertexFormat::get_color_column 00521 // Access: Public 00522 // Description: Returns the column definition of the "color" column, 00523 // or NULL if there is no such column. 00524 // 00525 // This may only be called after the format has been 00526 // registered. 00527 //////////////////////////////////////////////////////////////////// 00528 INLINE const GeomVertexColumn *GeomVertexFormat:: 00529 get_color_column() const { 00530 nassertr(_is_registered, NULL); 00531 return _color_column; 00532 } 00533 00534 //////////////////////////////////////////////////////////////////// 00535 // Function: GeomVertexFormat::get_registry 00536 // Access: Private 00537 // Description: Returns the global registry object. 00538 //////////////////////////////////////////////////////////////////// 00539 INLINE GeomVertexFormat::Registry *GeomVertexFormat:: 00540 get_registry() { 00541 if (_registry == (Registry *)NULL) { 00542 make_registry(); 00543 } 00544 return _registry; 00545 } 00546 00547 //////////////////////////////////////////////////////////////////// 00548 // Function: GeomVertexFormat::Registry::register_format 00549 // Access: Public 00550 // Description: This flavor of register_format() implicitly creates a 00551 // one-array vertex format from the array definition. 00552 //////////////////////////////////////////////////////////////////// 00553 INLINE CPT(GeomVertexFormat) GeomVertexFormat::Registry:: 00554 register_format(GeomVertexArrayFormat *format) { 00555 return register_format(new GeomVertexFormat(format)); 00556 }