00001 // Filename: geomVertexReader.I 00002 // Created by: drose (25Mar05) 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 //////////////////////////////////////////////////////////////////// 00017 // Function: GeomVertexReader::Default Constructor 00018 // Access: Published 00019 // Description: Constructs an invalid GeomVertexReader. You must use 00020 // the assignment operator to assign a valid 00021 // GeomVertexReader to this object before you can use 00022 // it. 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE GeomVertexReader:: 00025 GeomVertexReader(Thread *current_thread) : 00026 _vertex_data(NULL), 00027 _current_thread(current_thread) 00028 { 00029 initialize(); 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: GeomVertexReader::Constructor 00034 // Access: Published 00035 // Description: Constructs a new reader to process the vertices of 00036 // the indicated data object. 00037 //////////////////////////////////////////////////////////////////// 00038 INLINE GeomVertexReader:: 00039 GeomVertexReader(const GeomVertexData *vertex_data, 00040 Thread *current_thread) : 00041 _vertex_data(vertex_data), 00042 _current_thread(current_thread) 00043 { 00044 initialize(); 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: GeomVertexReader::Constructor 00049 // Access: Published 00050 // Description: Constructs a new reader to process the vertices of 00051 // the indicated data object. This flavor creates the 00052 // reader specifically to process the named data type. 00053 //////////////////////////////////////////////////////////////////// 00054 INLINE GeomVertexReader:: 00055 GeomVertexReader(const GeomVertexData *vertex_data, const string &name, 00056 Thread *current_thread) : 00057 _vertex_data(vertex_data), 00058 _current_thread(current_thread) 00059 { 00060 initialize(); 00061 set_column(name); 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: GeomVertexReader::Constructor 00066 // Access: Published 00067 // Description: Constructs a new reader to process the vertices of 00068 // the indicated data object. This flavor creates the 00069 // reader specifically to process the named data type. 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE GeomVertexReader:: 00072 GeomVertexReader(const GeomVertexData *vertex_data, 00073 const InternalName *name, 00074 Thread *current_thread) : 00075 _vertex_data(vertex_data), 00076 _current_thread(current_thread) 00077 { 00078 initialize(); 00079 set_column(name); 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: GeomVertexReader::Constructor 00084 // Access: Published 00085 // Description: Constructs a new reader to process the vertices of 00086 // the indicated array only. 00087 //////////////////////////////////////////////////////////////////// 00088 INLINE GeomVertexReader:: 00089 GeomVertexReader(const GeomVertexArrayData *array_data, 00090 Thread *current_thread) : 00091 _array_data(array_data), 00092 _current_thread(current_thread) 00093 { 00094 initialize(); 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: GeomVertexReader::Constructor 00099 // Access: Published 00100 // Description: Constructs a new reader to process the vertices of 00101 // the indicated array only. 00102 //////////////////////////////////////////////////////////////////// 00103 INLINE GeomVertexReader:: 00104 GeomVertexReader(const GeomVertexArrayData *array_data, int column, 00105 Thread *current_thread) : 00106 _array_data(array_data), 00107 _current_thread(current_thread) 00108 { 00109 initialize(); 00110 set_column(column); 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: GeomVertexReader::Constructor 00115 // Access: Public 00116 // Description: Constructs a new reader to process the vertices of 00117 // the indicated data object. This flavor creates the 00118 // reader specifically to process the named data type. 00119 //////////////////////////////////////////////////////////////////// 00120 INLINE GeomVertexReader:: 00121 GeomVertexReader(const GeomVertexDataPipelineReader *data_reader, 00122 const InternalName *name, bool force) : 00123 _vertex_data(data_reader->get_object()), 00124 _current_thread(data_reader->get_current_thread()) 00125 { 00126 initialize(); 00127 _force = force; 00128 const GeomVertexFormat *format = data_reader->get_format(); 00129 set_vertex_column(format->get_array_with(name), 00130 format->get_column(name), 00131 data_reader); 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: GeomVertexReader::Copy Constructor 00136 // Access: Published 00137 // Description: 00138 //////////////////////////////////////////////////////////////////// 00139 INLINE GeomVertexReader:: 00140 GeomVertexReader(const GeomVertexReader ©) : 00141 _vertex_data(copy._vertex_data), 00142 _array(copy._array), 00143 _array_data(copy._array_data), 00144 _current_thread(copy._current_thread), 00145 _packer(copy._packer), 00146 _stride(copy._stride), 00147 _handle(copy._handle), 00148 _pointer_begin(copy._pointer_begin), 00149 _pointer_end(copy._pointer_end), 00150 _pointer(copy._pointer), 00151 _start_row(copy._start_row), 00152 _force(copy._force) 00153 { 00154 } 00155 00156 //////////////////////////////////////////////////////////////////// 00157 // Function: GeomVertexReader::Copy Assignment Operator 00158 // Access: Published 00159 // Description: 00160 //////////////////////////////////////////////////////////////////// 00161 INLINE void GeomVertexReader:: 00162 operator = (const GeomVertexReader ©) { 00163 _vertex_data = copy._vertex_data; 00164 _array = copy._array; 00165 _array_data = copy._array_data; 00166 _current_thread = copy._current_thread; 00167 _packer = copy._packer; 00168 _stride = copy._stride; 00169 _handle = copy._handle; 00170 _pointer_begin = copy._pointer_begin; 00171 _pointer_end = copy._pointer_end; 00172 _pointer = copy._pointer; 00173 _start_row = copy._start_row; 00174 _force = copy._force; 00175 } 00176 00177 //////////////////////////////////////////////////////////////////// 00178 // Function: GeomVertexReader::Destructor 00179 // Access: Published 00180 // Description: 00181 //////////////////////////////////////////////////////////////////// 00182 INLINE GeomVertexReader:: 00183 ~GeomVertexReader() { 00184 } 00185 00186 //////////////////////////////////////////////////////////////////// 00187 // Function: GeomVertexReader::get_vertex_data 00188 // Access: Published 00189 // Description: Returns the vertex data object that the 00190 // reader is processing. This may return NULL if the 00191 // reader was constructed with just an array pointer. 00192 //////////////////////////////////////////////////////////////////// 00193 INLINE const GeomVertexData *GeomVertexReader:: 00194 get_vertex_data() const { 00195 return _vertex_data; 00196 } 00197 00198 //////////////////////////////////////////////////////////////////// 00199 // Function: GeomVertexReader::get_array_data 00200 // Access: Published 00201 // Description: Returns the particular array object that the 00202 // reader is currently processing. 00203 //////////////////////////////////////////////////////////////////// 00204 INLINE const GeomVertexArrayData *GeomVertexReader:: 00205 get_array_data() const { 00206 return _array_data; 00207 } 00208 00209 //////////////////////////////////////////////////////////////////// 00210 // Function: GeomVertexReader::get_array_handle 00211 // Access: Published 00212 // Description: Returns the read handle to the array object that the 00213 // read is currently processing. This low-level call 00214 // should be used with caution. 00215 //////////////////////////////////////////////////////////////////// 00216 INLINE const GeomVertexArrayDataHandle *GeomVertexReader:: 00217 get_array_handle() const { 00218 return _handle; 00219 } 00220 00221 //////////////////////////////////////////////////////////////////// 00222 // Function: GeomVertexReader::get_stride 00223 // Access: Published 00224 // Description: Returns the per-row stride (bytes between consecutive 00225 // rows) of the underlying vertex array. This low-level 00226 // information is normally not needed to use the 00227 // GeomVertexReader directly. 00228 //////////////////////////////////////////////////////////////////// 00229 INLINE size_t GeomVertexReader:: 00230 get_stride() const { 00231 return _stride; 00232 } 00233 00234 //////////////////////////////////////////////////////////////////// 00235 // Function: GeomVertexReader::get_current_thread 00236 // Access: Published 00237 // Description: Returns the Thread pointer of the currently-executing 00238 // thread, as passed to the constructor of this object. 00239 //////////////////////////////////////////////////////////////////// 00240 INLINE Thread *GeomVertexReader:: 00241 get_current_thread() const { 00242 return _current_thread; 00243 } 00244 00245 //////////////////////////////////////////////////////////////////// 00246 // Function: GeomVertexReader::set_force 00247 // Access: Published 00248 // Description: Sets the value of the force flag. When this is true 00249 // (the default), vertex data will be paged in from disk 00250 // if necessary. When this is false, the GeomVertexData 00251 // will simply return a failure code when attempting to 00252 // read vertex data that is not resident (but will put 00253 // it on the queue to become resident later). 00254 // 00255 // Normally, vertex data is always resident, so this 00256 // will not be an issue. It is only possible for vertex 00257 // data to be nonresident if you have enabled vertex 00258 // paging via the GeomVertexArrayData and VertexDataPage 00259 // interfaces. 00260 //////////////////////////////////////////////////////////////////// 00261 INLINE void GeomVertexReader:: 00262 set_force(bool force) { 00263 _force = force; 00264 } 00265 00266 //////////////////////////////////////////////////////////////////// 00267 // Function: GeomVertexReader::get_force 00268 // Access: Published 00269 // Description: Returns the value of the force flag. See 00270 // set_force(). 00271 //////////////////////////////////////////////////////////////////// 00272 INLINE bool GeomVertexReader:: 00273 get_force() const { 00274 return _force; 00275 } 00276 00277 //////////////////////////////////////////////////////////////////// 00278 // Function: GeomVertexReader::set_column 00279 // Access: Published 00280 // Description: Sets up the reader to use the nth data type of the 00281 // GeomVertexFormat, numbering from 0. 00282 // 00283 // This also resets the read row number to the start row 00284 // (the same value passed to a previous call to 00285 // set_row(), or 0 if set_row() was never called.) 00286 // 00287 // The return value is true if the data type is valid, 00288 // false otherwise. 00289 //////////////////////////////////////////////////////////////////// 00290 INLINE bool GeomVertexReader:: 00291 set_column(int column) { 00292 if (_vertex_data != (const GeomVertexData *)NULL) { 00293 GeomVertexDataPipelineReader reader(_vertex_data, _current_thread); 00294 reader.check_array_readers(); 00295 const GeomVertexFormat *format = reader.get_format(); 00296 return set_vertex_column(format->get_array_with(column), 00297 format->get_column(column), 00298 &reader); 00299 } 00300 if (_array_data != (const GeomVertexArrayData *)NULL) { 00301 return set_array_column(_array_data->get_array_format()->get_column(column)); 00302 } 00303 return false; 00304 } 00305 00306 //////////////////////////////////////////////////////////////////// 00307 // Function: GeomVertexReader::set_column 00308 // Access: Published 00309 // Description: Sets up the reader to use the data type with the 00310 // indicated name. 00311 // 00312 // This also resets the read row number to the start row 00313 // (the same value passed to a previous call to 00314 // set_row(), or 0 if set_row() was never called.) 00315 // 00316 // The return value is true if the data type is valid, 00317 // false otherwise. 00318 //////////////////////////////////////////////////////////////////// 00319 INLINE bool GeomVertexReader:: 00320 set_column(const string &name) { 00321 return set_column(InternalName::make(name)); 00322 } 00323 00324 //////////////////////////////////////////////////////////////////// 00325 // Function: GeomVertexReader::set_column 00326 // Access: Published 00327 // Description: Sets up the reader to use the data type with the 00328 // indicated name. 00329 // 00330 // This also resets the read row number to the start row 00331 // (the same value passed to a previous call to 00332 // set_row(), or 0 if set_row() was never called.) 00333 // 00334 // The return value is true if the data type is valid, 00335 // false otherwise. 00336 //////////////////////////////////////////////////////////////////// 00337 INLINE bool GeomVertexReader:: 00338 set_column(const InternalName *name) { 00339 if (_vertex_data != (const GeomVertexData *)NULL) { 00340 GeomVertexDataPipelineReader reader(_vertex_data, _current_thread); 00341 reader.check_array_readers(); 00342 const GeomVertexFormat *format = reader.get_format(); 00343 return set_vertex_column(format->get_array_with(name), 00344 format->get_column(name), 00345 &reader); 00346 } 00347 if (_array_data != (const GeomVertexArrayData *)NULL) { 00348 return set_array_column(_array_data->get_array_format()->get_column(name)); 00349 } 00350 00351 return false; 00352 } 00353 00354 //////////////////////////////////////////////////////////////////// 00355 // Function: GeomVertexReader::clear 00356 // Access: Published 00357 // Description: Resets the GeomVertexReader to the initial state. 00358 //////////////////////////////////////////////////////////////////// 00359 INLINE void GeomVertexReader:: 00360 clear() { 00361 (*this) = GeomVertexReader(_current_thread); 00362 } 00363 00364 //////////////////////////////////////////////////////////////////// 00365 // Function: GeomVertexReader::has_column 00366 // Access: Published 00367 // Description: Returns true if a valid data type has been 00368 // successfully set, or false if the data type does not 00369 // exist (or if get_force() is false and the vertex data 00370 // is nonresident). 00371 //////////////////////////////////////////////////////////////////// 00372 INLINE bool GeomVertexReader:: 00373 has_column() const { 00374 return (_packer != (GeomVertexColumn::Packer *)NULL); 00375 } 00376 00377 //////////////////////////////////////////////////////////////////// 00378 // Function: GeomVertexReader::get_array 00379 // Access: Published 00380 // Description: Returns the array index containing the data type that 00381 // the reader is working on. 00382 //////////////////////////////////////////////////////////////////// 00383 INLINE int GeomVertexReader:: 00384 get_array() const { 00385 return _array; 00386 } 00387 00388 //////////////////////////////////////////////////////////////////// 00389 // Function: GeomVertexReader::get_column 00390 // Access: Published 00391 // Description: Returns the description of the data type that the 00392 // reader is working on. 00393 //////////////////////////////////////////////////////////////////// 00394 INLINE const GeomVertexColumn *GeomVertexReader:: 00395 get_column() const { 00396 if (_packer != (GeomVertexColumn::Packer *)NULL) { 00397 return _packer->_column; 00398 } 00399 return NULL; 00400 } 00401 00402 //////////////////////////////////////////////////////////////////// 00403 // Function: GeomVertexReader::set_row_unsafe 00404 // Access: Published 00405 // Description: Sets the start row to the indicated value, without 00406 // internal checks. This is the same as set_row(), but 00407 // it does not check for the possibility that the array 00408 // has been reallocated internally for some reason; use 00409 // only when you are confident that the array is 00410 // unchanged and you really need every bit of available 00411 // performance. 00412 //////////////////////////////////////////////////////////////////// 00413 INLINE void GeomVertexReader:: 00414 set_row_unsafe(int row) { 00415 _start_row = row; 00416 if (has_column()) { 00417 quick_set_pointer(_start_row); 00418 } 00419 } 00420 00421 //////////////////////////////////////////////////////////////////// 00422 // Function: GeomVertexReader::set_row 00423 // Access: Published 00424 // Description: Sets the start row to the indicated value. The 00425 // reader will begin reading from the indicated row; 00426 // each subsequent get_data*() call will return the data 00427 // from the subsequent row. If set_column() is called, 00428 // the reader will return to this row. 00429 //////////////////////////////////////////////////////////////////// 00430 INLINE void GeomVertexReader:: 00431 set_row(int row) { 00432 _start_row = row; 00433 if (has_column()) { 00434 bool result = set_pointer(_start_row); 00435 nassertv(result); 00436 } 00437 } 00438 00439 //////////////////////////////////////////////////////////////////// 00440 // Function: GeomVertexReader::get_start_row 00441 // Access: Published 00442 // Description: Returns the row index at which the reader started. 00443 // It will return to this row if you reset the current 00444 // column. 00445 //////////////////////////////////////////////////////////////////// 00446 INLINE int GeomVertexReader:: 00447 get_start_row() const { 00448 return _start_row; 00449 } 00450 00451 //////////////////////////////////////////////////////////////////// 00452 // Function: GeomVertexReader::get_read_row 00453 // Access: Published 00454 // Description: Returns the row index from which the data will be 00455 // retrieved by the next call to get_data*(). 00456 //////////////////////////////////////////////////////////////////// 00457 INLINE int GeomVertexReader:: 00458 get_read_row() const { 00459 return (int)(_pointer - _pointer_begin) / _stride; 00460 } 00461 00462 //////////////////////////////////////////////////////////////////// 00463 // Function: GeomVertexReader::is_at_end 00464 // Access: Published 00465 // Description: Returns true if the reader is currently at the end of 00466 // the list of vertices, false otherwise. If this is 00467 // true, another call to get_data*() will result in a 00468 // crash. 00469 //////////////////////////////////////////////////////////////////// 00470 INLINE bool GeomVertexReader:: 00471 is_at_end() const { 00472 return _pointer >= _pointer_end; 00473 } 00474 00475 //////////////////////////////////////////////////////////////////// 00476 // Function: GeomVertexReader::get_data1f 00477 // Access: Published 00478 // Description: Returns the data associated with the read row, 00479 // expressed as a 1-component value, and advances the 00480 // read row. 00481 //////////////////////////////////////////////////////////////////// 00482 INLINE float GeomVertexReader:: 00483 get_data1f() { 00484 nassertr(has_column(), 0.0f); 00485 return _packer->get_data1f(inc_pointer()); 00486 } 00487 00488 //////////////////////////////////////////////////////////////////// 00489 // Function: GeomVertexReader::get_data2f 00490 // Access: Published 00491 // Description: Returns the data associated with the read row, 00492 // expressed as a 2-component value, and advances the 00493 // read row. 00494 //////////////////////////////////////////////////////////////////// 00495 INLINE const LVecBase2f &GeomVertexReader:: 00496 get_data2f() { 00497 nassertr(has_column(), LVecBase2f::zero()); 00498 return _packer->get_data2f(inc_pointer()); 00499 } 00500 00501 //////////////////////////////////////////////////////////////////// 00502 // Function: GeomVertexReader::get_data3f 00503 // Access: Published 00504 // Description: Returns the data associated with the read row, 00505 // expressed as a 3-component value, and advances the 00506 // read row. 00507 //////////////////////////////////////////////////////////////////// 00508 INLINE const LVecBase3f &GeomVertexReader:: 00509 get_data3f() { 00510 nassertr(has_column(), LVecBase3f::zero()); 00511 return _packer->get_data3f(inc_pointer()); 00512 } 00513 00514 //////////////////////////////////////////////////////////////////// 00515 // Function: GeomVertexReader::get_data4f 00516 // Access: Published 00517 // Description: Returns the data associated with the read row, 00518 // expressed as a 4-component value, and advances the 00519 // read row. 00520 //////////////////////////////////////////////////////////////////// 00521 INLINE const LVecBase4f &GeomVertexReader:: 00522 get_data4f() { 00523 nassertr(has_column(), LVecBase4f::zero()); 00524 return _packer->get_data4f(inc_pointer()); 00525 } 00526 00527 //////////////////////////////////////////////////////////////////// 00528 // Function: GeomVertexReader::get_data1d 00529 // Access: Published 00530 // Description: Returns the data associated with the read row, 00531 // expressed as a 1-component value, and advances the 00532 // read row. 00533 //////////////////////////////////////////////////////////////////// 00534 INLINE double GeomVertexReader:: 00535 get_data1d() { 00536 nassertr(has_column(), 0.0f); 00537 return _packer->get_data1d(inc_pointer()); 00538 } 00539 00540 //////////////////////////////////////////////////////////////////// 00541 // Function: GeomVertexReader::get_data2d 00542 // Access: Published 00543 // Description: Returns the data associated with the read row, 00544 // expressed as a 2-component value, and advances the 00545 // read row. 00546 //////////////////////////////////////////////////////////////////// 00547 INLINE const LVecBase2d &GeomVertexReader:: 00548 get_data2d() { 00549 nassertr(has_column(), LVecBase2d::zero()); 00550 return _packer->get_data2d(inc_pointer()); 00551 } 00552 00553 //////////////////////////////////////////////////////////////////// 00554 // Function: GeomVertexReader::get_data3d 00555 // Access: Published 00556 // Description: Returns the data associated with the read row, 00557 // expressed as a 3-component value, and advances the 00558 // read row. 00559 //////////////////////////////////////////////////////////////////// 00560 INLINE const LVecBase3d &GeomVertexReader:: 00561 get_data3d() { 00562 nassertr(has_column(), LVecBase3d::zero()); 00563 return _packer->get_data3d(inc_pointer()); 00564 } 00565 00566 //////////////////////////////////////////////////////////////////// 00567 // Function: GeomVertexReader::get_data4d 00568 // Access: Published 00569 // Description: Returns the data associated with the read row, 00570 // expressed as a 4-component value, and advances the 00571 // read row. 00572 //////////////////////////////////////////////////////////////////// 00573 INLINE const LVecBase4d &GeomVertexReader:: 00574 get_data4d() { 00575 nassertr(has_column(), LVecBase4d::zero()); 00576 return _packer->get_data4d(inc_pointer()); 00577 } 00578 00579 //////////////////////////////////////////////////////////////////// 00580 // Function: GeomVertexReader::get_data1 00581 // Access: Published 00582 // Description: Returns the data associated with the read row, 00583 // expressed as a 1-component value, and advances the 00584 // read row. 00585 //////////////////////////////////////////////////////////////////// 00586 INLINE PN_stdfloat GeomVertexReader:: 00587 get_data1() { 00588 #ifndef STDFLOAT_DOUBLE 00589 return get_data1f(); 00590 #else 00591 return get_data1d(); 00592 #endif 00593 } 00594 00595 //////////////////////////////////////////////////////////////////// 00596 // Function: GeomVertexReader::get_data2 00597 // Access: Published 00598 // Description: Returns the data associated with the read row, 00599 // expressed as a 2-component value, and advances the 00600 // read row. 00601 //////////////////////////////////////////////////////////////////// 00602 INLINE const LVecBase2 &GeomVertexReader:: 00603 get_data2() { 00604 #ifndef STDFLOAT_DOUBLE 00605 return get_data2f(); 00606 #else 00607 return get_data2d(); 00608 #endif 00609 } 00610 00611 //////////////////////////////////////////////////////////////////// 00612 // Function: GeomVertexReader::get_data3 00613 // Access: Published 00614 // Description: Returns the data associated with the read row, 00615 // expressed as a 3-component value, and advances the 00616 // read row. 00617 //////////////////////////////////////////////////////////////////// 00618 INLINE const LVecBase3 &GeomVertexReader:: 00619 get_data3() { 00620 #ifndef STDFLOAT_DOUBLE 00621 return get_data3f(); 00622 #else 00623 return get_data3d(); 00624 #endif 00625 } 00626 00627 //////////////////////////////////////////////////////////////////// 00628 // Function: GeomVertexReader::get_data4 00629 // Access: Published 00630 // Description: Returns the data associated with the read row, 00631 // expressed as a 4-component value, and advances the 00632 // read row. 00633 //////////////////////////////////////////////////////////////////// 00634 INLINE const LVecBase4 &GeomVertexReader:: 00635 get_data4() { 00636 #ifndef STDFLOAT_DOUBLE 00637 return get_data4f(); 00638 #else 00639 return get_data4d(); 00640 #endif 00641 } 00642 00643 //////////////////////////////////////////////////////////////////// 00644 // Function: GeomVertexReader::get_data1i 00645 // Access: Published 00646 // Description: Returns the data associated with the read row, 00647 // expressed as a 1-component value, and advances the 00648 // read row. 00649 //////////////////////////////////////////////////////////////////// 00650 INLINE int GeomVertexReader:: 00651 get_data1i() { 00652 nassertr(has_column(), 0); 00653 return _packer->get_data1i(inc_pointer()); 00654 } 00655 00656 //////////////////////////////////////////////////////////////////// 00657 // Function: GeomVertexReader::get_data2i 00658 // Access: Published 00659 // Description: Returns the data associated with the read row, 00660 // expressed as a 2-component value, and advances the 00661 // read row. 00662 //////////////////////////////////////////////////////////////////// 00663 INLINE const int *GeomVertexReader:: 00664 get_data2i() { 00665 nassertr(has_column(), 0); 00666 return _packer->get_data2i(inc_pointer()); 00667 } 00668 00669 //////////////////////////////////////////////////////////////////// 00670 // Function: GeomVertexReader::get_data3i 00671 // Access: Published 00672 // Description: Returns the data associated with the read row, 00673 // expressed as a 3-component value, and advances the 00674 // read row. 00675 //////////////////////////////////////////////////////////////////// 00676 INLINE const int *GeomVertexReader:: 00677 get_data3i() { 00678 nassertr(has_column(), 0); 00679 return _packer->get_data3i(inc_pointer()); 00680 } 00681 00682 //////////////////////////////////////////////////////////////////// 00683 // Function: GeomVertexReader::get_data4i 00684 // Access: Published 00685 // Description: Returns the data associated with the read row, 00686 // expressed as a 4-component value, and advances the 00687 // read row. 00688 //////////////////////////////////////////////////////////////////// 00689 INLINE const int *GeomVertexReader:: 00690 get_data4i() { 00691 nassertr(has_column(), 0); 00692 return _packer->get_data4i(inc_pointer()); 00693 } 00694 00695 //////////////////////////////////////////////////////////////////// 00696 // Function: GeomVertexReader::get_packer 00697 // Access: Protected 00698 // Description: Returns the reader's Packer object. 00699 //////////////////////////////////////////////////////////////////// 00700 INLINE GeomVertexColumn::Packer *GeomVertexReader:: 00701 get_packer() const { 00702 return _packer; 00703 } 00704 00705 //////////////////////////////////////////////////////////////////// 00706 // Function: GeomVertexReader::set_pointer 00707 // Access: Private 00708 // Description: Sets up the array pointers freshly from the source 00709 // object (in case they have been reallocated recently), 00710 // and sets the internal pointer to the indicated row. 00711 // 00712 // Returns true if successful, or false if the vertex 00713 // data is not resident. If it returns false, the 00714 // reader's internal column spec is cleared. It is only 00715 // possible to return false if get_force() is false. 00716 //////////////////////////////////////////////////////////////////// 00717 INLINE bool GeomVertexReader:: 00718 set_pointer(int row) { 00719 _pointer_begin = _handle->get_read_pointer(_force); 00720 if (_pointer_begin == NULL && _handle->get_data_size_bytes() != 0) { 00721 // Vertex data is not resident. 00722 set_column(0, NULL); 00723 return false; 00724 } 00725 00726 // Vertex data is resident, or just empty. 00727 _pointer_end = _pointer_begin + _handle->get_data_size_bytes(); 00728 quick_set_pointer(row); 00729 return true; 00730 } 00731 00732 //////////////////////////////////////////////////////////////////// 00733 // Function: GeomVertexReader::quick_set_pointer 00734 // Access: Private 00735 // Description: Sets up the internal pointer to the indicated row, 00736 // without first verifying that arrays haven't been 00737 // reallocated. 00738 //////////////////////////////////////////////////////////////////// 00739 INLINE void GeomVertexReader:: 00740 quick_set_pointer(int row) { 00741 nassertv(has_column() && (_pointer_begin != NULL || row == 0)); 00742 00743 #if defined(_DEBUG) 00744 // Make sure we still have the same pointer as stored in the array. 00745 nassertv(_pointer_begin == _handle->get_read_pointer(true)); 00746 #endif 00747 00748 _pointer = _pointer_begin + _packer->_column->get_start() + _stride * row; 00749 00750 #if defined(_DEBUG) 00751 // We have to allow the pointer to exceed the end by up to one row's 00752 // width. This wouldn't be legal on a plain GeomVertexReader, but 00753 // it *is* legal for a GeomVertexRewriter. 00754 nassertv(_pointer_begin == _pointer_end || (_pointer - _packer->_column->get_start()) <= _pointer_end); 00755 #endif 00756 } 00757 00758 //////////////////////////////////////////////////////////////////// 00759 // Function: GeomVertexReader::inc_pointer 00760 // Access: Private 00761 // Description: Increments to the next row, and returns the data 00762 // pointer as it was before incrementing. 00763 //////////////////////////////////////////////////////////////////// 00764 INLINE const unsigned char *GeomVertexReader:: 00765 inc_pointer() { 00766 #if defined(_DEBUG) 00767 nassertr(_pointer < _pointer_end, empty_buffer); 00768 // Make sure we still have the same pointer as stored in the array. 00769 nassertr(_pointer_begin == _handle->get_read_pointer(true), empty_buffer); 00770 nassertr(_pointer < _pointer_begin + _handle->get_data_size_bytes(), empty_buffer); 00771 #endif 00772 00773 const unsigned char *orig_pointer = _pointer; 00774 _pointer += _stride; 00775 return orig_pointer; 00776 }