Panda3D
|
00001 // Filename: geomVertexWriter.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 "geomVertexWriter.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 unsigned char GeomVertexWriter::empty_buffer[100] = { 0 }; 00022 #endif 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function: GeomVertexWriter::set_column 00026 // Access: Published 00027 // Description: Sets up the writer to use the indicated column 00028 // description on the given array. 00029 // 00030 // This also resets the current write 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 GeomVertexWriter:: 00038 set_column(int array, const GeomVertexColumn *column) { 00039 if (_vertex_data == (GeomVertexData *)NULL && 00040 _array_data == (GeomVertexArrayData *)NULL) { 00041 return false; 00042 } 00043 00044 if (column == (const GeomVertexColumn *)NULL) { 00045 // Clear the data type. 00046 _array = -1; 00047 _packer = NULL; 00048 _stride = 0; 00049 _pointer = NULL; 00050 _pointer_end = NULL; 00051 00052 return false; 00053 } 00054 00055 if (_vertex_data != (GeomVertexData *)NULL) { 00056 GeomVertexDataPipelineWriter writer(_vertex_data, true, _current_thread); 00057 writer.check_array_writers(); 00058 return set_vertex_column(array, column, &writer); 00059 } 00060 if (_array_data != (GeomVertexArrayData *)NULL) { 00061 return set_array_column(column); 00062 } 00063 00064 // No data is associated with the Writer. 00065 return false; 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: GeomVertexWriter::output 00070 // Access: Published 00071 // Description: 00072 //////////////////////////////////////////////////////////////////// 00073 void GeomVertexWriter:: 00074 output(ostream &out) const { 00075 const GeomVertexColumn *column = get_column(); 00076 if (column == (GeomVertexColumn *)NULL) { 00077 out << "GeomVertexWriter()"; 00078 00079 } else { 00080 out << "GeomVertexWriter, array = " << get_array_data() 00081 << ", column = " << column->get_name() 00082 << " (" << get_packer()->get_name() 00083 << "), write row " << get_write_row(); 00084 } 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: GeomVertexWriter::initialize 00089 // Access: Private 00090 // Description: Called only by the constructor. 00091 //////////////////////////////////////////////////////////////////// 00092 void GeomVertexWriter:: 00093 initialize() { 00094 _array = 0; 00095 _packer = NULL; 00096 _pointer_begin = NULL; 00097 _pointer_end = NULL; 00098 _pointer = NULL; 00099 _start_row = 0; 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: GeomVertexWriter::set_vertex_column 00104 // Access: Private 00105 // Description: Internal method to set the column to column from the 00106 // indicated array, assuming we have a GeomVertexData 00107 //////////////////////////////////////////////////////////////////// 00108 bool GeomVertexWriter:: 00109 set_vertex_column(int array, const GeomVertexColumn *column, 00110 GeomVertexDataPipelineWriter *data_writer) { 00111 if (column == (const GeomVertexColumn *)NULL) { 00112 return set_column(0, NULL); 00113 } 00114 00115 nassertr(_vertex_data != (GeomVertexData *)NULL, false); 00116 00117 #ifndef NDEBUG 00118 _array = -1; 00119 _packer = NULL; 00120 nassertr(array >= 0 && array < _vertex_data->get_num_arrays(), false); 00121 #endif 00122 00123 _array = array; 00124 _handle = data_writer->get_array_writer(_array); 00125 _stride = _handle->get_array_format()->get_stride(); 00126 00127 _packer = column->_packer; 00128 set_pointer(_start_row); 00129 00130 return true; 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: GeomVertexWriter::set_array_column 00135 // Access: Private 00136 // Description: Internal method to set the column to column from the 00137 // indicated array, assuming we have a 00138 // GeomVertexArrayData. 00139 //////////////////////////////////////////////////////////////////// 00140 bool GeomVertexWriter:: 00141 set_array_column(const GeomVertexColumn *column) { 00142 if (column == (const GeomVertexColumn *)NULL) { 00143 return set_column(0, NULL); 00144 } 00145 00146 nassertr(_array_data != (GeomVertexArrayData *)NULL, false); 00147 00148 _handle = _array_data->modify_handle(); 00149 _stride = _handle->get_array_format()->get_stride(); 00150 00151 _packer = column->_packer; 00152 set_pointer(_start_row); 00153 00154 return true; 00155 }