Panda3D
geomVertexReader.cxx
1 // Filename: geomVertexReader.cxx
2 // Created by: drose (25Mar05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "geomVertexReader.h"
16 
17 
18 #ifndef NDEBUG
19  // This is defined just for the benefit of having something non-NULL
20  // to return from a nassertr() call.
21 const unsigned char GeomVertexReader::empty_buffer[100] = { 0 };
22 #endif
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: GeomVertexReader::set_column
26 // Access: Published
27 // Description: Sets up the reader to use the indicated column
28 // description on the given array.
29 //
30 // This also resets the current read row number to the
31 // start row (the same value passed to a previous call
32 // to set_row(), or 0 if set_row() was never called.)
33 //
34 // The return value is true if the data type is valid,
35 // false otherwise.
36 ////////////////////////////////////////////////////////////////////
38 set_column(int array, const GeomVertexColumn *column) {
39  if (column == (const GeomVertexColumn *)NULL) {
40  // Clear the data type.
41  _array = -1;
42  _packer = NULL;
43  _stride = 0;
44  _pointer = NULL;
45  _pointer_end = NULL;
46 
47  return false;
48  }
49 
50  if (_vertex_data != (const GeomVertexData *)NULL) {
51  GeomVertexDataPipelineReader reader(_vertex_data, _current_thread);
52  reader.check_array_readers();
53  return set_vertex_column(array, column, &reader);
54  }
55  if (_array_data != (const GeomVertexArrayData *)NULL) {
56  return set_array_column(column);
57  }
58 
59  // No data is associated with the Reader.
60  return false;
61 }
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: GeomVertexReader::output
65 // Access: Published
66 // Description:
67 ////////////////////////////////////////////////////////////////////
68 void GeomVertexReader::
69 output(ostream &out) const {
70  const GeomVertexColumn *column = get_column();
71  if (column == (GeomVertexColumn *)NULL) {
72  out << "GeomVertexReader()";
73 
74  } else {
75  out << "GeomVertexReader, array = " << get_array_data()
76  << ", column = " << column->get_name()
77  << " (" << get_packer()->get_name()
78  << "), read row " << get_read_row();
79  }
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: GeomVertexReader::initialize
84 // Access: Private
85 // Description: Called only by the constructor.
86 ////////////////////////////////////////////////////////////////////
87 void GeomVertexReader::
88 initialize() {
89  _array = 0;
90  _packer = NULL;
91  _pointer_begin = NULL;
92  _pointer_end = NULL;
93  _pointer = NULL;
94  _start_row = 0;
95  _force = true;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: GeomVertexReader::set_vertex_column
100 // Access: Private
101 // Description: Internal method to set the column to column from the
102 // indicated array, assuming we have a GeomVertexData
103 ////////////////////////////////////////////////////////////////////
104 bool GeomVertexReader::
105 set_vertex_column(int array, const GeomVertexColumn *column,
106  const GeomVertexDataPipelineReader *data_reader) {
107  if (column == (const GeomVertexColumn *)NULL) {
108  return set_column(0, NULL);
109  }
110 
111  nassertr(_vertex_data != (const GeomVertexData *)NULL, false);
112 
113 #ifndef NDEBUG
114  _array = -1;
115  _packer = NULL;
116  nassertr(array >= 0 && array < _vertex_data->get_num_arrays(), false);
117 #endif
118 
119  _array = array;
120  _handle = data_reader->get_array_reader(_array);
121  _stride = _handle->get_array_format()->get_stride();
122 
123  _packer = column->_packer;
124  return set_pointer(_start_row);
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: GeomVertexReader::set_array_column
129 // Access: Private
130 // Description: Internal method to set the column to column from the
131 // indicated array, assuming we have a
132 // GeomVertexArrayData.
133 ////////////////////////////////////////////////////////////////////
134 bool GeomVertexReader::
135 set_array_column(const GeomVertexColumn *column) {
136  if (column == (const GeomVertexColumn *)NULL) {
137  return set_column(0, NULL);
138  }
139 
140  nassertr(_array_data != (const GeomVertexArrayData *)NULL, false);
141 
142  _handle = _array_data->get_handle();
143  _stride = _handle->get_array_format()->get_stride();
144 
145  _packer = column->_packer;
146  return set_pointer(_start_row);
147 }
const GeomVertexArrayData * get_array_data() const
Returns the particular array object that the reader is currently processing.
bool set_column(int column)
Sets up the reader to use the nth data type of the GeomVertexFormat, numbering from 0...
const GeomVertexColumn * get_column() const
Returns the description of the data type that the reader is working on.
This defines how a single column is interleaved within a vertex array stored within a Geom...
int get_read_row() const
Returns the row index from which the data will be retrieved by the next call to get_data*().
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
const InternalName * get_name() const
Returns the name of this particular data field, e.g.
This is the data for one array of a GeomVertexData structure.