Panda3D

geomVertexReader.cxx

00001 // Filename: geomVertexReader.cxx
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 #include "geomVertexReader.h"
00016 
00017 
00018 #ifndef NDEBUG
00019   // This is defined just for the benefit of having something non-NULL
00020   // to return from a nassertr() call.
00021 const unsigned char GeomVertexReader::empty_buffer[100] = { 0 };
00022 #endif
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: GeomVertexReader::set_column
00026 //       Access: Published
00027 //  Description: Sets up the reader to use the indicated column
00028 //               description on the given array.
00029 //
00030 //               This also resets the current read row number to the
00031 //               start row (the same value passed to a previous call
00032 //               to set_row(), or 0 if set_row() was never called.)
00033 //
00034 //               The return value is true if the data type is valid,
00035 //               false otherwise.
00036 ////////////////////////////////////////////////////////////////////
00037 bool GeomVertexReader::
00038 set_column(int array, const GeomVertexColumn *column) {
00039   if (column == (const GeomVertexColumn *)NULL) {
00040     // Clear the data type.
00041     _array = -1;
00042     _packer = NULL;
00043     _stride = 0;
00044     _pointer = NULL;
00045     _pointer_end = NULL;
00046 
00047     return false;
00048   }
00049 
00050   if (_vertex_data != (const GeomVertexData *)NULL) {
00051     GeomVertexDataPipelineReader reader(_vertex_data, _current_thread);
00052     reader.check_array_readers();
00053     return set_vertex_column(array, column, &reader);
00054   }
00055   if (_array_data != (const GeomVertexArrayData *)NULL) {
00056     return set_array_column(column);
00057   }
00058 
00059   // No data is associated with the Reader.
00060   return false;
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: GeomVertexReader::output
00065 //       Access: Published
00066 //  Description: 
00067 ////////////////////////////////////////////////////////////////////
00068 void GeomVertexReader::
00069 output(ostream &out) const {
00070   const GeomVertexColumn *column = get_column();
00071   if (column == (GeomVertexColumn *)NULL) {
00072     out << "GeomVertexReader()";
00073     
00074   } else {
00075     out << "GeomVertexReader, array = " << get_array_data()
00076         << ", column = " << column->get_name()
00077         << " (" << get_packer()->get_name()
00078         << "), read row " << get_read_row();
00079   }
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: GeomVertexReader::initialize
00084 //       Access: Private
00085 //  Description: Called only by the constructor.
00086 ////////////////////////////////////////////////////////////////////
00087 void GeomVertexReader::
00088 initialize() {
00089   _array = 0;
00090   _packer = NULL;
00091   _pointer_begin = NULL;
00092   _pointer_end = NULL;
00093   _pointer = NULL;
00094   _start_row = 0;
00095   _force = true;
00096 }
00097 
00098 ////////////////////////////////////////////////////////////////////
00099 //     Function: GeomVertexReader::set_vertex_column
00100 //       Access: Private
00101 //  Description: Internal method to set the column to column from the
00102 //               indicated array, assuming we have a GeomVertexData
00103 ////////////////////////////////////////////////////////////////////
00104 bool GeomVertexReader::
00105 set_vertex_column(int array, const GeomVertexColumn *column,
00106                   const GeomVertexDataPipelineReader *data_reader) {
00107   if (column == (const GeomVertexColumn *)NULL) {
00108     return set_column(0, NULL);
00109   }
00110 
00111   nassertr(_vertex_data != (const GeomVertexData *)NULL, false);
00112 
00113 #ifndef NDEBUG
00114   _array = -1;
00115   _packer = NULL;
00116   nassertr(array >= 0 && array < _vertex_data->get_num_arrays(), false);
00117 #endif
00118 
00119   _array = array;
00120   _handle = data_reader->get_array_reader(_array);
00121   _stride = _handle->get_array_format()->get_stride();
00122 
00123   _packer = column->_packer;
00124   return set_pointer(_start_row);
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: GeomVertexReader::set_array_column
00129 //       Access: Private
00130 //  Description: Internal method to set the column to column from the
00131 //               indicated array, assuming we have a
00132 //               GeomVertexArrayData.
00133 ////////////////////////////////////////////////////////////////////
00134 bool GeomVertexReader::
00135 set_array_column(const GeomVertexColumn *column) {
00136   if (column == (const GeomVertexColumn *)NULL) {
00137     return set_column(0, NULL);
00138   }
00139 
00140   nassertr(_array_data != (const GeomVertexArrayData *)NULL, false);
00141 
00142   _handle = _array_data->get_handle();
00143   _stride = _handle->get_array_format()->get_stride();
00144 
00145   _packer = column->_packer;
00146   return set_pointer(_start_row);
00147 }
 All Classes Functions Variables Enumerations