Panda3D
geomVertexReader.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file geomVertexReader.cxx
10  * @author drose
11  * @date 2005-03-25
12  */
13 
14 #include "geomVertexReader.h"
15 
16 #ifndef NDEBUG
17  // This is defined just for the benefit of having something non-NULL to
18  // return from a nassertr() call.
19 const unsigned char GeomVertexReader::empty_buffer[100] = { 0 };
20 #endif
21 
22 /**
23  * Sets up the reader to use the indicated column description on the given
24  * array.
25  *
26  * This also resets the current read row number to the start row (the same
27  * value passed to a previous call to set_row(), or 0 if set_row() was never
28  * called.)
29  *
30  * The return value is true if the data type is valid, false otherwise.
31  */
33 set_column(int array, const GeomVertexColumn *column) {
34  if (column == nullptr) {
35  // Clear the data type.
36  _array = -1;
37  _packer = nullptr;
38  _stride = 0;
39  _pointer = nullptr;
40  _pointer_end = nullptr;
41 
42  return false;
43  }
44 
45  if (_vertex_data != nullptr) {
46  GeomVertexDataPipelineReader reader(_vertex_data, _current_thread);
47  reader.check_array_readers();
48  return set_vertex_column(array, column, &reader);
49  }
50  if (_array_data != nullptr) {
51  return set_array_column(column);
52  }
53 
54  // No data is associated with the Reader.
55  return false;
56 }
57 
58 /**
59  *
60  */
61 void GeomVertexReader::
62 output(std::ostream &out) const {
63  const GeomVertexColumn *column = get_column();
64  if (column == nullptr) {
65  out << "GeomVertexReader()";
66 
67  } else {
68  out << "GeomVertexReader, array = " << get_array_data()
69  << ", column = " << column->get_name()
70  << " (" << get_packer()->get_name()
71  << "), read row " << get_read_row();
72  }
73 }
74 
75 /**
76  * Called only by the constructor.
77  */
78 void GeomVertexReader::
79 initialize() {
80  _array = 0;
81  _packer = nullptr;
82  _pointer_begin = nullptr;
83  _pointer_end = nullptr;
84  _pointer = nullptr;
85  _start_row = 0;
86  _force = true;
87 }
88 
89 /**
90  * Internal method to set the column to column from the indicated array,
91  * assuming we have a GeomVertexData
92  */
93 bool GeomVertexReader::
94 set_vertex_column(int array, const GeomVertexColumn *column,
95  const GeomVertexDataPipelineReader *data_reader) {
96  if (column == nullptr) {
97  return set_column(0, nullptr);
98  }
99 
100  nassertr(_vertex_data != nullptr, false);
101 
102 #ifndef NDEBUG
103  _array = -1;
104  _packer = nullptr;
105  nassertr(array >= 0 && (size_t)array < _vertex_data->get_num_arrays(), false);
106 #endif
107 
108  _array = array;
109  _handle = data_reader->get_array_reader(_array);
110  _stride = _handle->get_array_format()->get_stride();
111 
112  _packer = column->_packer;
113  return set_pointer(_start_row);
114 }
115 
116 /**
117  * Internal method to set the column to column from the indicated array,
118  * assuming we have a GeomVertexArrayData.
119  */
120 bool GeomVertexReader::
121 set_array_column(const GeomVertexColumn *column) {
122  if (column == nullptr) {
123  return set_column(0, nullptr);
124  }
125 
126  nassertr(_array_data != nullptr, false);
127 
128  _handle = _array_data->get_handle();
129  _stride = _handle->get_array_format()->get_stride();
130 
131  _packer = column->_packer;
132  return set_pointer(_start_row);
133 }
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*().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.