Panda3D

geomVertexWriter.I

00001 // Filename: geomVertexWriter.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: GeomVertexWriter::Default Constructor
00018 //       Access: Published
00019 //  Description: Constructs an invalid GeomVertexWriter.  You must use
00020 //               the assignment operator to assign a valid
00021 //               GeomVertexWriter to this object before you can use
00022 //               it.
00023 ////////////////////////////////////////////////////////////////////
00024 INLINE GeomVertexWriter::
00025 GeomVertexWriter(Thread *current_thread) :
00026   _vertex_data(NULL),
00027   _current_thread(current_thread)
00028 {
00029   initialize();
00030 }
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: GeomVertexWriter::Constructor
00034 //       Access: Published
00035 //  Description: Constructs a new writer to process the vertices of
00036 //               the indicated data object.
00037 ////////////////////////////////////////////////////////////////////
00038 INLINE GeomVertexWriter::
00039 GeomVertexWriter(GeomVertexData *vertex_data, Thread *current_thread) :
00040   _vertex_data(vertex_data),
00041   _current_thread(current_thread)
00042 {
00043   initialize();
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: GeomVertexWriter::Constructor
00048 //       Access: Published
00049 //  Description: Constructs a new writer to process the vertices of
00050 //               the indicated data object.  This flavor creates the
00051 //               writer specifically to process the named data type.
00052 ////////////////////////////////////////////////////////////////////
00053 INLINE GeomVertexWriter::
00054 GeomVertexWriter(GeomVertexData *vertex_data, const string &name,
00055                  Thread *current_thread) :
00056   _vertex_data(vertex_data),
00057   _current_thread(current_thread)
00058 {
00059   initialize();
00060   set_column(name);
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: GeomVertexWriter::Constructor
00065 //       Access: Published
00066 //  Description: Constructs a new writer to process the vertices of
00067 //               the indicated data object.  This flavor creates the
00068 //               writer specifically to process the named data type.
00069 ////////////////////////////////////////////////////////////////////
00070 INLINE GeomVertexWriter::
00071 GeomVertexWriter(GeomVertexData *vertex_data, const InternalName *name,
00072                  Thread *current_thread) :
00073   _vertex_data(vertex_data),
00074   _current_thread(current_thread)
00075 {
00076   initialize();
00077   set_column(name);
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: GeomVertexWriter::Constructor
00082 //       Access: Published
00083 //  Description: Constructs a new writer to process the vertices of
00084 //               the indicated array only.
00085 ////////////////////////////////////////////////////////////////////
00086 INLINE GeomVertexWriter::
00087 GeomVertexWriter(GeomVertexArrayData *array_data,
00088                  Thread *current_thread) :
00089   _array_data(array_data),
00090   _current_thread(current_thread)
00091 {
00092   initialize();
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: GeomVertexWriter::Constructor
00097 //       Access: Published
00098 //  Description: Constructs a new writer to process the vertices of
00099 //               the indicated array only.
00100 ////////////////////////////////////////////////////////////////////
00101 INLINE GeomVertexWriter::
00102 GeomVertexWriter(GeomVertexArrayData *array_data, int column,
00103                  Thread *current_thread) :
00104   _array_data(array_data),
00105   _current_thread(current_thread)
00106 {
00107   initialize();
00108   set_column(column);
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: GeomVertexWriter::Constructor
00113 //       Access: Public
00114 //  Description: Constructs a new writer to process the vertices of
00115 //               the indicated data object.  This flavor creates the
00116 //               writer specifically to process the named data type.
00117 ////////////////////////////////////////////////////////////////////
00118 INLINE GeomVertexWriter::
00119 GeomVertexWriter(GeomVertexDataPipelineWriter *data_writer,
00120                  const InternalName *name) :
00121   _vertex_data(data_writer->get_object()),
00122   _current_thread(data_writer->get_current_thread())
00123 {
00124   initialize();
00125   const GeomVertexFormat *format = data_writer->get_format();
00126   set_vertex_column(format->get_array_with(name),
00127                     format->get_column(name),
00128                     data_writer);
00129 }
00130 
00131 ////////////////////////////////////////////////////////////////////
00132 //     Function: GeomVertexWriter::Copy Constructor
00133 //       Access: Published
00134 //  Description: 
00135 ////////////////////////////////////////////////////////////////////
00136 INLINE GeomVertexWriter::
00137 GeomVertexWriter(const GeomVertexWriter &copy) :
00138   _vertex_data(copy._vertex_data),
00139   _array(copy._array),
00140   _array_data(copy._array_data),
00141   _current_thread(copy._current_thread),
00142   _packer(copy._packer),
00143   _stride(copy._stride),
00144   _handle(copy._handle),
00145   _pointer_begin(copy._pointer_begin),
00146   _pointer_end(copy._pointer_end),
00147   _pointer(copy._pointer),
00148   _start_row(copy._start_row)
00149 {
00150 }
00151 
00152 ////////////////////////////////////////////////////////////////////
00153 //     Function: GeomVertexWriter::Copy Assignment Operator
00154 //       Access: Published
00155 //  Description: 
00156 ////////////////////////////////////////////////////////////////////
00157 INLINE void GeomVertexWriter::
00158 operator = (const GeomVertexWriter &copy) {
00159   _vertex_data = copy._vertex_data;
00160   _array = copy._array;
00161   _array_data = copy._array_data;
00162   _current_thread = copy._current_thread;
00163   _packer = copy._packer;
00164   _stride = copy._stride;
00165   _handle = copy._handle;
00166   _pointer_begin = copy._pointer_begin;
00167   _pointer_end = copy._pointer_end;
00168   _pointer = copy._pointer;
00169   _start_row = copy._start_row;
00170 }
00171 
00172 ////////////////////////////////////////////////////////////////////
00173 //     Function: GeomVertexWriter::Destructor
00174 //       Access: Published
00175 //  Description: 
00176 ////////////////////////////////////////////////////////////////////
00177 INLINE GeomVertexWriter::
00178 ~GeomVertexWriter() {
00179 }
00180 
00181 ////////////////////////////////////////////////////////////////////
00182 //     Function: GeomVertexWriter::get_vertex_data
00183 //       Access: Published
00184 //  Description: Returns the vertex data object that the
00185 //               writer is processing.  This may return NULL if the
00186 //               writer was constructed with just an array pointer.
00187 ////////////////////////////////////////////////////////////////////
00188 INLINE GeomVertexData *GeomVertexWriter::
00189 get_vertex_data() const {
00190   return _vertex_data;
00191 }
00192 
00193 ////////////////////////////////////////////////////////////////////
00194 //     Function: GeomVertexWriter::get_array_data
00195 //       Access: Published
00196 //  Description: Returns the particular array object that the
00197 //               writer is currently processing.
00198 ////////////////////////////////////////////////////////////////////
00199 INLINE GeomVertexArrayData *GeomVertexWriter::
00200 get_array_data() const {
00201   return _array_data;
00202 }
00203 
00204 ////////////////////////////////////////////////////////////////////
00205 //     Function: GeomVertexWriter::get_current_thread
00206 //       Access: Published
00207 //  Description: Returns the Thread pointer of the currently-executing
00208 //               thread, as passed to the constructor of this object.
00209 ////////////////////////////////////////////////////////////////////
00210 INLINE Thread *GeomVertexWriter::
00211 get_current_thread() const {
00212   return _current_thread;
00213 }
00214 
00215 ////////////////////////////////////////////////////////////////////
00216 //     Function: GeomVertexWriter::set_column
00217 //       Access: Published
00218 //  Description: Sets up the writer to use the nth data type of the
00219 //               GeomVertexFormat, numbering from 0.
00220 //
00221 //               This also resets the write row number to the start
00222 //               row (the same value passed to a previous call to
00223 //               set_row(), or 0 if set_row() was never called.)
00224 //
00225 //               The return value is true if the data type is valid,
00226 //               false otherwise.
00227 ////////////////////////////////////////////////////////////////////
00228 INLINE bool GeomVertexWriter::
00229 set_column(int column) {
00230   if (_vertex_data != (GeomVertexData *)NULL) {
00231     GeomVertexDataPipelineWriter writer(_vertex_data, true, _current_thread);
00232     writer.check_array_writers();
00233     const GeomVertexFormat *format = writer.get_format();
00234     return set_vertex_column(format->get_array_with(column),
00235                              format->get_column(column),
00236                              &writer);
00237   }
00238   if (_array_data != (GeomVertexArrayData *)NULL) {
00239     return set_array_column(_array_data->get_array_format()->get_column(column));
00240   }
00241   return false;
00242 }
00243 
00244 ////////////////////////////////////////////////////////////////////
00245 //     Function: GeomVertexWriter::set_column
00246 //       Access: Published
00247 //  Description: Sets up the writer to use the data type with the
00248 //               indicated name.
00249 //
00250 //               This also resets the write row number to the start
00251 //               row (the same value passed to a previous call to
00252 //               set_row(), or 0 if set_row() was never called.)
00253 //
00254 //               The return value is true if the data type is valid,
00255 //               false otherwise.
00256 ////////////////////////////////////////////////////////////////////
00257 INLINE bool GeomVertexWriter::
00258 set_column(const string &name) {
00259   return set_column(InternalName::make(name));
00260 }
00261 
00262 ////////////////////////////////////////////////////////////////////
00263 //     Function: GeomVertexWriter::set_column
00264 //       Access: Published
00265 //  Description: Sets up the writer to use the data type with the
00266 //               indicated name.
00267 //
00268 //               This also resets the write number to the start row
00269 //               (the same value passed to a previous call to
00270 //               set_row(), or 0 if set_row() was never called.)
00271 //
00272 //               The return value is true if the data type is valid,
00273 //               false otherwise.
00274 ////////////////////////////////////////////////////////////////////
00275 INLINE bool GeomVertexWriter::
00276 set_column(const InternalName *name) {
00277   if (_vertex_data != (GeomVertexData *)NULL) {
00278     GeomVertexDataPipelineWriter writer(_vertex_data, true, _current_thread);
00279     writer.check_array_writers();
00280     const GeomVertexFormat *format = writer.get_format();
00281     return set_vertex_column(format->get_array_with(name),
00282                              format->get_column(name),
00283                              &writer);
00284   }
00285   if (_array_data != (GeomVertexArrayData *)NULL) {
00286     return set_array_column(_array_data->get_array_format()->get_column(name));
00287   }
00288   return false;
00289 }
00290 
00291 ////////////////////////////////////////////////////////////////////
00292 //     Function: GeomVertexWriter::clear
00293 //       Access: Published
00294 //  Description: Resets the GeomVertexWriter to the initial state.
00295 ////////////////////////////////////////////////////////////////////
00296 INLINE void GeomVertexWriter::
00297 clear() {
00298   (*this) = GeomVertexWriter(_current_thread);
00299 }
00300 
00301 ////////////////////////////////////////////////////////////////////
00302 //     Function: GeomVertexWriter::has_column
00303 //       Access: Published
00304 //  Description: Returns true if a valid data type has been
00305 //               successfully set, or false if the data type does not
00306 //               exist.
00307 ////////////////////////////////////////////////////////////////////
00308 INLINE bool GeomVertexWriter::
00309 has_column() const {
00310   return (_packer != (GeomVertexColumn::Packer *)NULL);
00311 }
00312 
00313 ////////////////////////////////////////////////////////////////////
00314 //     Function: GeomVertexWriter::get_array
00315 //       Access: Published
00316 //  Description: Returns the array index containing the data type that
00317 //               the writer is working on.
00318 ////////////////////////////////////////////////////////////////////
00319 INLINE int GeomVertexWriter::
00320 get_array() const {
00321   return _array;
00322 }
00323 
00324 ////////////////////////////////////////////////////////////////////
00325 //     Function: GeomVertexWriter::get_column
00326 //       Access: Published
00327 //  Description: Returns the description of the data type that the
00328 //               writer is working on.
00329 ////////////////////////////////////////////////////////////////////
00330 INLINE const GeomVertexColumn *GeomVertexWriter::
00331 get_column() const {
00332   if (_packer != (GeomVertexColumn::Packer *)NULL) {
00333     return _packer->_column;
00334   }
00335   return NULL;
00336 }
00337 
00338 ////////////////////////////////////////////////////////////////////
00339 //     Function: GeomVertexWriter::set_row
00340 //       Access: Published
00341 //  Description: Sets the start row to the indicated value.  The
00342 //               writer will begin writing to the indicated row;
00343 //               each subsequent set_data*() call will store the data
00344 //               into the subsequent row.  If set_column() is called,
00345 //               the writer will return to this row.
00346 ////////////////////////////////////////////////////////////////////
00347 INLINE void GeomVertexWriter::
00348 set_row(int row) {
00349   _start_row = row;
00350   if (has_column()) {
00351     quick_set_pointer(_start_row);
00352   }
00353 }
00354 
00355 ////////////////////////////////////////////////////////////////////
00356 //     Function: GeomVertexWriter::get_start_row
00357 //       Access: Published
00358 //  Description: Returns the row index at which the writer
00359 //               started.  It will return to this row if you reset
00360 //               the current column.
00361 ////////////////////////////////////////////////////////////////////
00362 INLINE int GeomVertexWriter::
00363 get_start_row() const {
00364   return _start_row;
00365 }
00366 
00367 ////////////////////////////////////////////////////////////////////
00368 //     Function: GeomVertexWriter::get_write_row
00369 //       Access: Published
00370 //  Description: Returns the row index to which the data will be
00371 //               written at the next call to set_data*() or
00372 //               add_data*().
00373 ////////////////////////////////////////////////////////////////////
00374 INLINE int GeomVertexWriter::
00375 get_write_row() const {
00376   return (int)(_pointer - _pointer_begin) / _stride;
00377 }
00378 
00379 ////////////////////////////////////////////////////////////////////
00380 //     Function: GeomVertexWriter::is_at_end
00381 //       Access: Published
00382 //  Description: Returns true if the writer is currently at the end of
00383 //               the list of vertices, false otherwise.  If this is
00384 //               true, another call to set_data*() will result in a
00385 //               crash, but another call to add_data*() will add a new
00386 //               row.
00387 ////////////////////////////////////////////////////////////////////
00388 INLINE bool GeomVertexWriter::
00389 is_at_end() const {
00390   return _pointer >= _pointer_end;
00391 }
00392 
00393 ////////////////////////////////////////////////////////////////////
00394 //     Function: GeomVertexWriter::set_data1f
00395 //       Access: Published
00396 //  Description: Sets the write row to a particular 1-component
00397 //               value, and advances the write row.
00398 //
00399 //               It is an error for the write row to advance past
00400 //               the end of data.
00401 ////////////////////////////////////////////////////////////////////
00402 INLINE void GeomVertexWriter::
00403 set_data1f(float data) {
00404   nassertv(has_column());
00405   _packer->set_data1f(inc_pointer(), data);
00406 }
00407 
00408 ////////////////////////////////////////////////////////////////////
00409 //     Function: GeomVertexWriter::set_data2f
00410 //       Access: Published
00411 //  Description: Sets the write row to a particular 2-component
00412 //               value, and advances the write row.
00413 //
00414 //               It is an error for the write row to advance past
00415 //               the end of data.
00416 ////////////////////////////////////////////////////////////////////
00417 INLINE void GeomVertexWriter::
00418 set_data2f(float x, float y) {
00419   set_data2f(LVecBase2f(x, y));
00420 }
00421 
00422 ////////////////////////////////////////////////////////////////////
00423 //     Function: GeomVertexWriter::set_data2f
00424 //       Access: Published
00425 //  Description: Sets the write row to a particular 2-component
00426 //               value, and advances the write row.
00427 //
00428 //               It is an error for the write row to advance past
00429 //               the end of data.
00430 ////////////////////////////////////////////////////////////////////
00431 INLINE void GeomVertexWriter::
00432 set_data2f(const LVecBase2f &data) {
00433   nassertv(has_column());
00434   _packer->set_data2f(inc_pointer(), data);
00435 }
00436 
00437 ////////////////////////////////////////////////////////////////////
00438 //     Function: GeomVertexWriter::set_data3f
00439 //       Access: Published
00440 //  Description: Sets the write row to a particular 3-component
00441 //               value, and advances the write row.
00442 //
00443 //               It is an error for the write row to advance past
00444 //               the end of data.
00445 ////////////////////////////////////////////////////////////////////
00446 INLINE void GeomVertexWriter::
00447 set_data3f(float x, float y, float z) {
00448   set_data3f(LVecBase3f(x, y, z));
00449 }
00450 
00451 ////////////////////////////////////////////////////////////////////
00452 //     Function: GeomVertexWriter::set_data3f
00453 //       Access: Published
00454 //  Description: Sets the write row to a particular 3-component
00455 //               value, and advances the write row.
00456 //
00457 //               It is an error for the write row to advance past
00458 //               the end of data.
00459 ////////////////////////////////////////////////////////////////////
00460 INLINE void GeomVertexWriter::
00461 set_data3f(const LVecBase3f &data) {
00462   nassertv(has_column());
00463   _packer->set_data3f(inc_pointer(), data);
00464 }
00465 
00466 ////////////////////////////////////////////////////////////////////
00467 //     Function: GeomVertexWriter::set_data4f
00468 //       Access: Published
00469 //  Description: Sets the write row to a particular 4-component
00470 //               value, and advances the write row.
00471 //
00472 //               It is an error for the write row to advance past
00473 //               the end of data.
00474 ////////////////////////////////////////////////////////////////////
00475 INLINE void GeomVertexWriter::
00476 set_data4f(float x, float y, float z, float w) {
00477   set_data4f(LVecBase4f(x, y, z, w));
00478 }
00479 
00480 ////////////////////////////////////////////////////////////////////
00481 //     Function: GeomVertexWriter::set_data4f
00482 //       Access: Published
00483 //  Description: Sets the write row to a particular 4-component
00484 //               value, and advances the write row.
00485 //
00486 //               It is an error for the write row to advance past
00487 //               the end of data.
00488 ////////////////////////////////////////////////////////////////////
00489 INLINE void GeomVertexWriter::
00490 set_data4f(const LVecBase4f &data) {
00491   nassertv(has_column());
00492   _packer->set_data4f(inc_pointer(), data);
00493 }
00494 
00495 ////////////////////////////////////////////////////////////////////
00496 //     Function: GeomVertexWriter::set_data1i
00497 //       Access: Published
00498 //  Description: Sets the write row to a particular 1-component
00499 //               value, and advances the write row.
00500 //
00501 //               It is an error for the write row to advance past
00502 //               the end of data.
00503 ////////////////////////////////////////////////////////////////////
00504 INLINE void GeomVertexWriter::
00505 set_data1i(int data) {
00506   nassertv(has_column());
00507   _packer->set_data1i(inc_pointer(), data);
00508 }
00509 
00510 ////////////////////////////////////////////////////////////////////
00511 //     Function: GeomVertexWriter::set_data2i
00512 //       Access: Published
00513 //  Description: Sets the write row to a particular 2-component
00514 //               value, and advances the write row.
00515 //
00516 //               It is an error for the write row to advance past
00517 //               the end of data.
00518 ////////////////////////////////////////////////////////////////////
00519 INLINE void GeomVertexWriter::
00520 set_data2i(int a, int b) {
00521   nassertv(has_column());
00522   _packer->set_data2i(inc_pointer(), a, b);
00523 }
00524 
00525 ////////////////////////////////////////////////////////////////////
00526 //     Function: GeomVertexWriter::set_data2i
00527 //       Access: Published
00528 //  Description: Sets the write row to a particular 2-component
00529 //               value, and advances the write row.
00530 //
00531 //               It is an error for the write row to advance past
00532 //               the end of data.
00533 ////////////////////////////////////////////////////////////////////
00534 INLINE void GeomVertexWriter::
00535 set_data2i(const int data[2]) {
00536   set_data2i(data[0], data[1]);
00537 }
00538 
00539 ////////////////////////////////////////////////////////////////////
00540 //     Function: GeomVertexWriter::set_data3i
00541 //       Access: Published
00542 //  Description: Sets the write row to a particular 3-component
00543 //               value, and advances the write row.
00544 //
00545 //               It is an error for the write row to advance past
00546 //               the end of data.
00547 ////////////////////////////////////////////////////////////////////
00548 INLINE void GeomVertexWriter::
00549 set_data3i(int a, int b, int c) {
00550   nassertv(has_column());
00551   _packer->set_data3i(inc_pointer(), a, b, c);
00552 }
00553 
00554 ////////////////////////////////////////////////////////////////////
00555 //     Function: GeomVertexWriter::set_data3i
00556 //       Access: Published
00557 //  Description: Sets the write row to a particular 3-component
00558 //               value, and advances the write row.
00559 //
00560 //               It is an error for the write row to advance past
00561 //               the end of data.
00562 ////////////////////////////////////////////////////////////////////
00563 INLINE void GeomVertexWriter::
00564 set_data3i(const int data[3]) {
00565   set_data3i(data[0], data[1], data[2]);
00566 }
00567 
00568 ////////////////////////////////////////////////////////////////////
00569 //     Function: GeomVertexWriter::set_data4i
00570 //       Access: Published
00571 //  Description: Sets the write row to a particular 4-component
00572 //               value, and advances the write row.
00573 //
00574 //               It is an error for the write row to advance past
00575 //               the end of data.
00576 ////////////////////////////////////////////////////////////////////
00577 INLINE void GeomVertexWriter::
00578 set_data4i(int a, int b, int c, int d) {
00579   nassertv(has_column());
00580   _packer->set_data4i(inc_pointer(), a, b, c, d);
00581 }
00582 
00583 ////////////////////////////////////////////////////////////////////
00584 //     Function: GeomVertexWriter::set_data4i
00585 //       Access: Published
00586 //  Description: Sets the write row to a particular 4-component
00587 //               value, and advances the write row.
00588 //
00589 //               It is an error for the write row to advance past
00590 //               the end of data.
00591 ////////////////////////////////////////////////////////////////////
00592 INLINE void GeomVertexWriter::
00593 set_data4i(const int data[4]) {
00594   set_data4i(data[0], data[1], data[2], data[3]);
00595 }
00596 
00597 ////////////////////////////////////////////////////////////////////
00598 //     Function: GeomVertexWriter::add_data1f
00599 //       Access: Published
00600 //  Description: Sets the write row to a particular 1-component
00601 //               value, and advances the write row.
00602 //
00603 //               If the write row advances past the end of data,
00604 //               implicitly adds a new row to the data.
00605 ////////////////////////////////////////////////////////////////////
00606 INLINE void GeomVertexWriter::
00607 add_data1f(float data) {
00608   nassertv(has_column());
00609   _packer->set_data1f(inc_add_pointer(), data);
00610 }
00611 
00612 ////////////////////////////////////////////////////////////////////
00613 //     Function: GeomVertexWriter::add_data2f
00614 //       Access: Published
00615 //  Description: Sets the write row to a particular 2-component
00616 //               value, and advances the write row.
00617 //
00618 //               If the write row advances past the end of data,
00619 //               implicitly adds a new row to the data.
00620 ////////////////////////////////////////////////////////////////////
00621 INLINE void GeomVertexWriter::
00622 add_data2f(float x, float y) {
00623   add_data2f(LVecBase2f(x, y));
00624 }
00625 
00626 ////////////////////////////////////////////////////////////////////
00627 //     Function: GeomVertexWriter::add_data2f
00628 //       Access: Published
00629 //  Description: Sets the write row to a particular 2-component
00630 //               value, and advances the write row.
00631 //
00632 //               If the write row advances past the end of data,
00633 //               implicitly adds a new row to the data.
00634 ////////////////////////////////////////////////////////////////////
00635 INLINE void GeomVertexWriter::
00636 add_data2f(const LVecBase2f &data) {
00637   nassertv(has_column());
00638   _packer->set_data2f(inc_add_pointer(), data);
00639 }
00640 
00641 ////////////////////////////////////////////////////////////////////
00642 //     Function: GeomVertexWriter::add_data3f
00643 //       Access: Published
00644 //  Description: Sets the write row to a particular 3-component
00645 //               value, and advances the write row.
00646 //
00647 //               If the write row advances past the end of data,
00648 //               implicitly adds a new row to the data.
00649 ////////////////////////////////////////////////////////////////////
00650 INLINE void GeomVertexWriter::
00651 add_data3f(float x, float y, float z) {
00652   add_data3f(LVecBase3f(x, y, z));
00653 }
00654 
00655 ////////////////////////////////////////////////////////////////////
00656 //     Function: GeomVertexWriter::add_data3f
00657 //       Access: Published
00658 //  Description: Sets the write row to a particular 3-component
00659 //               value, and advances the write row.
00660 //
00661 //               If the write row advances past the end of data,
00662 //               implicitly adds a new row to the data.
00663 ////////////////////////////////////////////////////////////////////
00664 INLINE void GeomVertexWriter::
00665 add_data3f(const LVecBase3f &data) {
00666   nassertv(has_column());
00667   _packer->set_data3f(inc_add_pointer(), data);
00668 }
00669 
00670 ////////////////////////////////////////////////////////////////////
00671 //     Function: GeomVertexWriter::add_data4f
00672 //       Access: Published
00673 //  Description: Sets the write row to a particular 4-component
00674 //               value, and advances the write row.
00675 //
00676 //               If the write row advances past the end of data,
00677 //               implicitly adds a new row to the data.
00678 ////////////////////////////////////////////////////////////////////
00679 INLINE void GeomVertexWriter::
00680 add_data4f(float x, float y, float z, float w) {
00681   add_data4f(LVecBase4f(x, y, z, w));
00682 }
00683 
00684 ////////////////////////////////////////////////////////////////////
00685 //     Function: GeomVertexWriter::add_data4f
00686 //       Access: Published
00687 //  Description: Sets the write row to a particular 4-component
00688 //               value, and advances the write row.
00689 //
00690 //               If the write row advances past the end of data,
00691 //               implicitly adds a new row to the data.
00692 ////////////////////////////////////////////////////////////////////
00693 INLINE void GeomVertexWriter::
00694 add_data4f(const LVecBase4f &data) {
00695   nassertv(has_column());
00696   _packer->set_data4f(inc_add_pointer(), data);
00697 }
00698 
00699 ////////////////////////////////////////////////////////////////////
00700 //     Function: GeomVertexWriter::add_data1i
00701 //       Access: Published
00702 //  Description: Sets the write row to a particular 1-component
00703 //               value, and advances the write row.
00704 //
00705 //               If the write row advances past the end of data,
00706 //               implicitly adds a new row to the data.
00707 ////////////////////////////////////////////////////////////////////
00708 INLINE void GeomVertexWriter::
00709 add_data1i(int data) {
00710   nassertv(has_column());
00711   _packer->set_data1i(inc_add_pointer(), data);
00712 }
00713 
00714 ////////////////////////////////////////////////////////////////////
00715 //     Function: GeomVertexWriter::add_data2i
00716 //       Access: Published
00717 //  Description: Sets the write row to a particular 2-component
00718 //               value, and advances the write row.
00719 //
00720 //               If the write row advances past the end of data,
00721 //               implicitly adds a new row to the data.
00722 ////////////////////////////////////////////////////////////////////
00723 INLINE void GeomVertexWriter::
00724 add_data2i(int a, int b) {
00725   nassertv(has_column());
00726   _packer->set_data2i(inc_add_pointer(), a, b);
00727 }
00728 
00729 ////////////////////////////////////////////////////////////////////
00730 //     Function: GeomVertexWriter::add_data2i
00731 //       Access: Published
00732 //  Description: Sets the write row to a particular 2-component
00733 //               value, and advances the write row.
00734 //
00735 //               If the write row advances past the end of data,
00736 //               implicitly adds a new row to the data.
00737 ////////////////////////////////////////////////////////////////////
00738 INLINE void GeomVertexWriter::
00739 add_data2i(const int data[2]) {
00740   add_data2i(data[0], data[1]);
00741 }
00742 
00743 ////////////////////////////////////////////////////////////////////
00744 //     Function: GeomVertexWriter::add_data3i
00745 //       Access: Published
00746 //  Description: Sets the write row to a particular 3-component
00747 //               value, and advances the write row.
00748 //
00749 //               If the write row advances past the end of data,
00750 //               implicitly adds a new row to the data.
00751 ////////////////////////////////////////////////////////////////////
00752 INLINE void GeomVertexWriter::
00753 add_data3i(int a, int b, int c) {
00754   nassertv(has_column());
00755   _packer->set_data3i(inc_add_pointer(), a, b, c);
00756 }
00757 
00758 ////////////////////////////////////////////////////////////////////
00759 //     Function: GeomVertexWriter::add_data3i
00760 //       Access: Published
00761 //  Description: Sets the write row to a particular 3-component
00762 //               value, and advances the write row.
00763 //
00764 //               If the write row advances past the end of data,
00765 //               implicitly adds a new row to the data.
00766 ////////////////////////////////////////////////////////////////////
00767 INLINE void GeomVertexWriter::
00768 add_data3i(const int data[3]) {
00769   add_data3i(data[0], data[1], data[2]);
00770 }
00771 
00772 ////////////////////////////////////////////////////////////////////
00773 //     Function: GeomVertexWriter::add_data4i
00774 //       Access: Published
00775 //  Description: Sets the write row to a particular 4-component
00776 //               value, and advances the write row.
00777 //
00778 //               If the write row advances past the end of data,
00779 //               implicitly adds a new row to the data.
00780 ////////////////////////////////////////////////////////////////////
00781 INLINE void GeomVertexWriter::
00782 add_data4i(int a, int b, int c, int d) {
00783   nassertv(has_column());
00784   _packer->set_data4i(inc_add_pointer(), a, b, c, d);
00785 }
00786 
00787 ////////////////////////////////////////////////////////////////////
00788 //     Function: GeomVertexWriter::add_data4i
00789 //       Access: Published
00790 //  Description: Sets the write row to a particular 4-component
00791 //               value, and advances the write row.
00792 //
00793 //               If the write row advances past the end of data,
00794 //               implicitly adds a new row to the data.
00795 ////////////////////////////////////////////////////////////////////
00796 INLINE void GeomVertexWriter::
00797 add_data4i(const int data[4]) {
00798   add_data4i(data[0], data[1], data[2], data[3]);
00799 }
00800 
00801 ////////////////////////////////////////////////////////////////////
00802 //     Function: GeomVertexWriter::get_packer
00803 //       Access: Protected
00804 //  Description: Returns the writer's Packer object.
00805 ////////////////////////////////////////////////////////////////////
00806 INLINE GeomVertexColumn::Packer *GeomVertexWriter::
00807 get_packer() const {
00808   return _packer;
00809 }
00810 
00811 ////////////////////////////////////////////////////////////////////
00812 //     Function: GeomVertexWriter::set_pointer
00813 //       Access: Private
00814 //  Description: Sets up the array pointers freshly from the source
00815 //               object (in case they have been reallocated recently),
00816 //               and sets the internal pointer to the indicated row.
00817 ////////////////////////////////////////////////////////////////////
00818 INLINE void GeomVertexWriter::
00819 set_pointer(int row) {
00820   _pointer_begin = _handle->get_write_pointer();
00821   _pointer_end = _pointer_begin + _handle->get_data_size_bytes();
00822   quick_set_pointer(row);
00823 }
00824 
00825 ////////////////////////////////////////////////////////////////////
00826 //     Function: GeomVertexWriter::quick_set_pointer
00827 //       Access: Private
00828 //  Description: Sets up the internal pointer to the indicated row,
00829 //               without first verifying that arrays haven't been
00830 //               reallocated.
00831 ////////////////////////////////////////////////////////////////////
00832 INLINE void GeomVertexWriter::
00833 quick_set_pointer(int row) {
00834   nassertv(has_column());
00835 
00836 #if defined(_DEBUG)
00837   // Make sure we still have the same pointer as stored in the array.
00838   nassertv(_pointer_begin == _handle->get_write_pointer());
00839 #endif
00840 
00841   _pointer = _pointer_begin + _packer->_column->get_start() + _stride * row;
00842 
00843 #if defined(_DEBUG)
00844   nassertv(_pointer_begin == _pointer_end || _pointer <= _pointer_end);
00845 #endif
00846 }
00847 
00848 ////////////////////////////////////////////////////////////////////
00849 //     Function: GeomVertexWriter::inc_pointer
00850 //       Access: Private
00851 //  Description: Increments to the next row, and returns the data
00852 //               pointer as it was before incrementing.
00853 ////////////////////////////////////////////////////////////////////
00854 INLINE unsigned char *GeomVertexWriter::
00855 inc_pointer() {
00856 #if defined(_DEBUG)
00857   nassertr(_pointer < _pointer_end, empty_buffer);
00858   // Make sure we still have the same pointer as stored in the array.
00859   nassertr(_pointer_begin == _handle->get_write_pointer(), empty_buffer);
00860   nassertr(_pointer < _pointer_begin + _handle->get_data_size_bytes(), empty_buffer);
00861 #endif
00862 
00863   unsigned char *orig_pointer = _pointer;
00864   _pointer += _stride;
00865   return orig_pointer;
00866 }
00867 
00868 ////////////////////////////////////////////////////////////////////
00869 //     Function: GeomVertexWriter::inc_add_pointer
00870 //       Access: Private
00871 //  Description: Increments to the next row, and returns the data
00872 //               pointer as it was before incrementing.  If we are at
00873 //               or past the end of data, implicitly adds more
00874 //               rows first.
00875 ////////////////////////////////////////////////////////////////////
00876 INLINE unsigned char *GeomVertexWriter::
00877 inc_add_pointer() {
00878   if (_pointer >= _pointer_end) {
00879     // Reset the data pointer.
00880     int write_row = get_write_row();
00881 
00882     if (_vertex_data != (GeomVertexData *)NULL) {
00883       // If we have a whole GeomVertexData, we must set the length of
00884       // all its arrays at once.
00885       GeomVertexDataPipelineWriter writer(_vertex_data, true, _current_thread);
00886       writer.check_array_writers();
00887       writer.set_num_rows(max(write_row + 1, writer.get_num_rows()));
00888       _handle = writer.get_array_writer(_array);
00889 
00890     } else {
00891       // Otherwise, we can get away with modifying only the one array
00892       // we're using.
00893       _handle->set_num_rows(max(write_row + 1, _handle->get_num_rows()));
00894     }
00895 
00896     set_pointer(write_row);
00897   }
00898   return inc_pointer();
00899 }
00900 
 All Classes Functions Variables Enumerations