Panda3D

geomVertexRewriter.I

00001 // Filename: geomVertexRewriter.I
00002 // Created by:  drose (28Mar05)
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: GeomVertexRewriter::Default Constructor
00018 //       Access: Published
00019 //  Description: Constructs an invalid GeomVertexRewriter.  You must use
00020 //               the assignment operator to assign a valid
00021 //               GeomVertexRewriter to this object before you can use
00022 //               it.
00023 ////////////////////////////////////////////////////////////////////
00024 INLINE GeomVertexRewriter::
00025 GeomVertexRewriter(Thread *current_thread) :
00026   GeomVertexWriter(current_thread),
00027   GeomVertexReader(current_thread)
00028 {
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: GeomVertexRewriter::Constructor
00033 //       Access: Published
00034 //  Description: Constructs a new rewriter to process the vertices of
00035 //               the indicated data object.
00036 ////////////////////////////////////////////////////////////////////
00037 INLINE GeomVertexRewriter::
00038 GeomVertexRewriter(GeomVertexData *vertex_data, Thread *current_thread) :
00039   GeomVertexWriter(vertex_data, current_thread),
00040   GeomVertexReader(vertex_data, current_thread)
00041 {
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: GeomVertexRewriter::Constructor
00046 //       Access: Published
00047 //  Description: Constructs a new rewriter to process the vertices of
00048 //               the indicated data object.  This flavor creates the
00049 //               rewriter specifically to process the named data type.
00050 ////////////////////////////////////////////////////////////////////
00051 INLINE GeomVertexRewriter::
00052 GeomVertexRewriter(GeomVertexData *vertex_data, const string &name,
00053                    Thread *current_thread) :
00054   GeomVertexWriter(vertex_data, current_thread),
00055   GeomVertexReader(vertex_data, current_thread)
00056 {
00057   set_column(name);
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: GeomVertexRewriter::Constructor
00062 //       Access: Published
00063 //  Description: Constructs a new rewriter to process the vertices of
00064 //               the indicated data object.  This flavor creates the
00065 //               rewriter specifically to process the named data type.
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE GeomVertexRewriter::
00068 GeomVertexRewriter(GeomVertexData *vertex_data, const InternalName *name,
00069                    Thread *current_thread) :
00070   GeomVertexWriter(vertex_data, current_thread),
00071   GeomVertexReader(vertex_data, current_thread)
00072 {
00073   set_column(name);
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: GeomVertexRewriter::Constructor
00078 //       Access: Published
00079 //  Description: Constructs a new rewriter to process the vertices of
00080 //               the indicated array only.
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE GeomVertexRewriter::
00083 GeomVertexRewriter(GeomVertexArrayData *array_data, Thread *current_thread) :
00084   GeomVertexWriter(array_data, current_thread),
00085   GeomVertexReader(array_data, current_thread)
00086 {
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: GeomVertexRewriter::Constructor
00091 //       Access: Published
00092 //  Description: Constructs a new rewriter to process the vertices of
00093 //               the indicated array only.
00094 ////////////////////////////////////////////////////////////////////
00095 INLINE GeomVertexRewriter::
00096 GeomVertexRewriter(GeomVertexArrayData *array_data, int column,
00097                    Thread *current_thread) :
00098   GeomVertexWriter(array_data, current_thread),
00099   GeomVertexReader(array_data, current_thread)
00100 {
00101   set_column(column);
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //     Function: GeomVertexRewriter::Copy Constructor
00106 //       Access: Published
00107 //  Description: 
00108 ////////////////////////////////////////////////////////////////////
00109 INLINE GeomVertexRewriter::
00110 GeomVertexRewriter(const GeomVertexRewriter &copy) :
00111   GeomVertexWriter(copy),
00112   GeomVertexReader(copy)
00113 {
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: GeomVertexRewriter::Copy Assignment Operator
00118 //       Access: Published
00119 //  Description: 
00120 ////////////////////////////////////////////////////////////////////
00121 INLINE void GeomVertexRewriter::
00122 operator = (const GeomVertexRewriter &copy) {
00123   GeomVertexWriter::operator = (copy);
00124   GeomVertexReader::operator = (copy);
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: GeomVertexRewriter::Destructor
00129 //       Access: Published
00130 //  Description: 
00131 ////////////////////////////////////////////////////////////////////
00132 INLINE GeomVertexRewriter::
00133 ~GeomVertexRewriter() {
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: GeomVertexRewriter::get_vertex_data
00138 //       Access: Published
00139 //  Description: Returns the vertex data object that the
00140 //               rewriter is processing.
00141 ////////////////////////////////////////////////////////////////////
00142 INLINE GeomVertexData *GeomVertexRewriter::
00143 get_vertex_data() const {
00144   nassertr(GeomVertexWriter::get_vertex_data() == 
00145            GeomVertexReader::get_vertex_data(), NULL);
00146   return GeomVertexWriter::get_vertex_data();
00147 }
00148 
00149 ////////////////////////////////////////////////////////////////////
00150 //     Function: GeomVertexRewriter::get_array_data
00151 //       Access: Published
00152 //  Description: Returns the particular array object that the
00153 //               rewriter is currently processing.
00154 ////////////////////////////////////////////////////////////////////
00155 INLINE GeomVertexArrayData *GeomVertexRewriter::
00156 get_array_data() const {
00157   nassertr(GeomVertexWriter::get_array_data() == 
00158            GeomVertexReader::get_array_data(), NULL);
00159   return GeomVertexWriter::get_array_data();
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: GeomVertexRewriter::get_array_handle
00164 //       Access: Published
00165 //  Description: Returns the write handle to the array object that the
00166 //               rewriter is currently processing.  This low-level call
00167 //               should be used with caution; be careful with
00168 //               modifying the data in the handle out from under the
00169 //               GeomVertexRewriter.
00170 ////////////////////////////////////////////////////////////////////
00171 INLINE GeomVertexArrayDataHandle *GeomVertexRewriter::
00172 get_array_handle() const {
00173   return GeomVertexWriter::get_array_handle();
00174 }
00175 
00176 ////////////////////////////////////////////////////////////////////
00177 //     Function: GeomVertexRewriter::get_stride
00178 //       Access: Published
00179 //  Description: Returns the per-row stride (bytes between consecutive
00180 //               rows) of the underlying vertex array.  This low-level
00181 //               information is normally not needed to use the
00182 //               GeomVertexRewriter directly.
00183 ////////////////////////////////////////////////////////////////////
00184 INLINE size_t GeomVertexRewriter::
00185 get_stride() const {
00186   nassertr(GeomVertexWriter::get_stride() == GeomVertexReader::get_stride(), 0);
00187   return GeomVertexWriter::get_stride();
00188 }
00189 
00190 ////////////////////////////////////////////////////////////////////
00191 //     Function: GeomVertexRewriter::get_current_thread
00192 //       Access: Published
00193 //  Description: Returns the Thread pointer of the currently-executing
00194 //               thread, as passed to the constructor of this object.
00195 ////////////////////////////////////////////////////////////////////
00196 INLINE Thread *GeomVertexRewriter::
00197 get_current_thread() const {
00198   nassertr(GeomVertexWriter::get_current_thread() == 
00199            GeomVertexReader::get_current_thread(), NULL);
00200   return GeomVertexWriter::get_current_thread();
00201 }
00202 
00203 ////////////////////////////////////////////////////////////////////
00204 //     Function: GeomVertexRewriter::set_column
00205 //       Access: Published
00206 //  Description: Sets up the rewriter to use the nth data type of the
00207 //               GeomVertexFormat, numbering from 0.
00208 //
00209 //               This also resets both the read and write row
00210 //               numbers to the start row (the same value passed to
00211 //               a previous call to set_row(), or 0 if set_row()
00212 //               was never called.)
00213 //
00214 //               The return value is true if the data type is valid,
00215 //               false otherwise.
00216 ////////////////////////////////////////////////////////////////////
00217 INLINE bool GeomVertexRewriter::
00218 set_column(int column) {
00219   // It's important to invoke the writer first, then the reader.  See
00220   // set_row().
00221   GeomVertexWriter::set_column(column);
00222   return GeomVertexReader::set_column(column);
00223 }
00224 
00225 ////////////////////////////////////////////////////////////////////
00226 //     Function: GeomVertexRewriter::set_column
00227 //       Access: Published
00228 //  Description: Sets up the rewriter to use the data type with the
00229 //               indicated name.
00230 //
00231 //               This also resets both the read and write row
00232 //               numbers to the start row (the same value passed to
00233 //               a previous call to set_row(), or 0 if set_row()
00234 //               was never called.)
00235 //
00236 //               The return value is true if the data type is valid,
00237 //               false otherwise.
00238 ////////////////////////////////////////////////////////////////////
00239 INLINE bool GeomVertexRewriter::
00240 set_column(const string &name) {
00241   return set_column(InternalName::make(name));
00242 }
00243 
00244 ////////////////////////////////////////////////////////////////////
00245 //     Function: GeomVertexRewriter::set_column
00246 //       Access: Published
00247 //  Description: Sets up the rewriter to use the data type with the
00248 //               indicated name.
00249 //
00250 //               This also resets both the read and write row
00251 //               numbers to the start row (the same value passed to
00252 //               a previous call to set_row(), or 0 if set_row()
00253 //               was never called.)
00254 //
00255 //               The return value is true if the data type is valid,
00256 //               false otherwise.
00257 ////////////////////////////////////////////////////////////////////
00258 INLINE bool GeomVertexRewriter::
00259 set_column(const InternalName *name) {
00260   // It's important to invoke the writer first, then the reader.  See
00261   // set_row().
00262   GeomVertexWriter::set_column(name);
00263   return GeomVertexReader::set_column(name);
00264 }
00265 
00266 ////////////////////////////////////////////////////////////////////
00267 //     Function: GeomVertexRewriter::set_column
00268 //       Access: Published
00269 //  Description: Sets up the rewriter to use the indicated column
00270 //               description on the given array.
00271 //
00272 //               This also resets both the read and write row
00273 //               numbers to the start row (the same value passed to
00274 //               a previous call to set_row(), or 0 if set_row()
00275 //               was never called.)
00276 //
00277 //               The return value is true if the data type is valid,
00278 //               false otherwise.
00279 ////////////////////////////////////////////////////////////////////
00280 INLINE bool GeomVertexRewriter::
00281 set_column(int array, const GeomVertexColumn *column) {
00282   // It's important to invoke the writer first, then the reader.  See
00283   // set_row().
00284   GeomVertexWriter::set_column(array, column);
00285   return GeomVertexReader::set_column(array, column);
00286 }
00287 
00288 ////////////////////////////////////////////////////////////////////
00289 //     Function: GeomVertexRewriter::clear
00290 //       Access: Published
00291 //  Description: Resets the GeomVertexRewriter to the initial state.
00292 ////////////////////////////////////////////////////////////////////
00293 INLINE void GeomVertexRewriter::
00294 clear() {
00295   GeomVertexWriter::clear();
00296   GeomVertexReader::clear();
00297 }
00298 
00299 ////////////////////////////////////////////////////////////////////
00300 //     Function: GeomVertexRewriter::has_column
00301 //       Access: Published
00302 //  Description: Returns true if a valid data type has been
00303 //               successfully set, or false if the data type does not
00304 //               exist.
00305 ////////////////////////////////////////////////////////////////////
00306 INLINE bool GeomVertexRewriter::
00307 has_column() const {
00308   nassertr(GeomVertexWriter::get_column() == 
00309            GeomVertexReader::get_column(), false);
00310   return GeomVertexWriter::has_column();
00311 }
00312 
00313 ////////////////////////////////////////////////////////////////////
00314 //     Function: GeomVertexRewriter::get_array
00315 //       Access: Published
00316 //  Description: Returns the array index containing the data type that
00317 //               the rewriter is working on.
00318 ////////////////////////////////////////////////////////////////////
00319 INLINE int GeomVertexRewriter::
00320 get_array() const {
00321   nassertr(GeomVertexWriter::get_array() == 
00322            GeomVertexReader::get_array(), -1);
00323   return GeomVertexWriter::get_array();
00324 }
00325 
00326 ////////////////////////////////////////////////////////////////////
00327 //     Function: GeomVertexRewriter::get_column
00328 //       Access: Published
00329 //  Description: Returns the description of the data type that the
00330 //               rewriter is working on.
00331 ////////////////////////////////////////////////////////////////////
00332 INLINE const GeomVertexColumn *GeomVertexRewriter::
00333 get_column() const {
00334   nassertr(GeomVertexWriter::get_column() == 
00335            GeomVertexReader::get_column(), NULL);
00336   return GeomVertexWriter::get_column();
00337 }
00338 
00339 ////////////////////////////////////////////////////////////////////
00340 //     Function: GeomVertexRewriter::set_row_unsafe
00341 //       Access: Published
00342 //  Description: Sets the start row to the indicated value, without
00343 //               internal checks.  This is the same as set_row(), but
00344 //               it does not check for the possibility that the array
00345 //               has been reallocated internally for some reason; use
00346 //               only when you are confident that the array is
00347 //               unchanged and you really need every bit of available
00348 //               performance.
00349 ////////////////////////////////////////////////////////////////////
00350 INLINE void GeomVertexRewriter::
00351 set_row_unsafe(int row) {
00352   // It's important to invoke the Writer first, since that might force
00353   // a recopy of the array, which might invalidate the pointer already
00354   // stored by the Reader if we invoked the Reader first.
00355   GeomVertexWriter::set_row_unsafe(row);
00356   GeomVertexReader::set_row_unsafe(row);
00357 }
00358 
00359 ////////////////////////////////////////////////////////////////////
00360 //     Function: GeomVertexRewriter::set_row
00361 //       Access: Published
00362 //  Description: Sets the start, write, and write index to the
00363 //               indicated value.  The rewriter will begin traversing
00364 //               from the given row.
00365 ////////////////////////////////////////////////////////////////////
00366 INLINE void GeomVertexRewriter::
00367 set_row(int row) {
00368   GeomVertexWriter::set_row(row);
00369   GeomVertexReader::set_row(row);
00370 }
00371 
00372 ////////////////////////////////////////////////////////////////////
00373 //     Function: GeomVertexRewriter::get_start_row
00374 //       Access: Published
00375 //  Description: Returns the row index at which the rewriter
00376 //               started.  It will return to this row if you reset
00377 //               the current column.
00378 ////////////////////////////////////////////////////////////////////
00379 INLINE int GeomVertexRewriter::
00380 get_start_row() const {
00381   nassertr(GeomVertexWriter::get_start_row() == 
00382            GeomVertexReader::get_start_row(), 0);
00383   return GeomVertexWriter::get_start_row();
00384 }
00385 
00386 ////////////////////////////////////////////////////////////////////
00387 //     Function: GeomVertexRewriter::is_at_end
00388 //       Access: Published
00389 //  Description: Returns true if the reader or writer is currently at
00390 //               the end of the list of vertices, false otherwise.
00391 ////////////////////////////////////////////////////////////////////
00392 INLINE bool GeomVertexRewriter::
00393 is_at_end() const {
00394   return GeomVertexWriter::is_at_end() || GeomVertexReader::is_at_end();
00395 }
 All Classes Functions Variables Enumerations