Panda3D
geomVertexReader.h
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.h
10  * @author drose
11  * @date 2005-03-25
12  */
13 
14 #ifndef GEOMVERTEXREADER_H
15 #define GEOMVERTEXREADER_H
16 
17 #include "pandabase.h"
18 #include "geomVertexData.h"
19 #include "geomVertexColumn.h"
20 #include "internalName.h"
21 #include "luse.h"
22 #include "pointerTo.h"
23 
24 /**
25  * This object provides a high-level interface for quickly reading a sequence
26  * of numeric values from a vertex table.
27  *
28  * It is particularly optimized for reading a single column of data values for
29  * a series of vertices, without changing columns between each number.
30  * Although you can also use one GeomVertexReader to read across the columns
31  * if it is convenient, by calling set_column() repeatedly at each vertex, it
32  * is faster to read down the columns, and to use a different GeomVertexReader
33  * for each column.
34  *
35  * Note that a GeomVertexReader does not keep a reference count to the actual
36  * vertex data buffer (it grabs the current data buffer from the
37  * GeomVertexData whenever set_column() is called). This means that it is
38  * important not to keep a GeomVertexReader object around over a long period
39  * of time in which the data buffer is likely to be deallocated; it is
40  * intended for making a quick pass over the data in one session.
41  *
42  * It also means that you should create any GeomVertexWriters *before*
43  * creating GeomVertexReaders on the same data, since the writer itself might
44  * cause the vertex buffer to be deallocated. Better yet, use a
45  * GeomVertexRewriter if you are going to create both of them anyway.
46  */
47 class EXPCL_PANDA_GOBJ GeomVertexReader : public GeomEnums {
48 PUBLISHED:
49  INLINE GeomVertexReader(Thread *current_thread = Thread::get_current_thread());
50  INLINE GeomVertexReader(const GeomVertexData *vertex_data,
51  Thread *current_thread = Thread::get_current_thread());
52  INLINE GeomVertexReader(const GeomVertexData *vertex_data,
53  CPT_InternalName name,
54  Thread *current_thread = Thread::get_current_thread());
55  INLINE GeomVertexReader(const GeomVertexArrayData *array_data,
56  Thread *current_thread = Thread::get_current_thread());
57  INLINE GeomVertexReader(const GeomVertexArrayData *array_data,
58  int column,
59  Thread *current_thread = Thread::get_current_thread());
60 
61 public:
62  INLINE GeomVertexReader(const GeomVertexDataPipelineReader *data_reader,
63  const InternalName *name,
64  bool force = true);
65 
66 PUBLISHED:
67  INLINE GeomVertexReader(const GeomVertexReader &copy);
68  INLINE void operator = (const GeomVertexReader &copy);
69  INLINE ~GeomVertexReader();
70 
71  INLINE const GeomVertexData *get_vertex_data() const;
72  INLINE const GeomVertexArrayData *get_array_data() const;
73  INLINE const GeomVertexArrayDataHandle *get_array_handle() const;
74  INLINE size_t get_stride() const;
75  INLINE Thread *get_current_thread() const;
76 
77  INLINE void set_force(bool force);
78  INLINE bool get_force() const;
79 
80  INLINE bool set_column(int column);
81  INLINE bool set_column(CPT_InternalName name);
82  bool set_column(int array, const GeomVertexColumn *column);
83 
84  INLINE void clear();
85  INLINE bool has_column() const;
86  INLINE int get_array() const;
87  INLINE const GeomVertexColumn *get_column() const;
88 
89  INLINE void set_row_unsafe(int row);
90  INLINE void set_row(int row);
91 
92  INLINE int get_start_row() const;
93  INLINE int get_read_row() const;
94  INLINE bool is_at_end() const;
95 
96  INLINE float get_data1f();
97  INLINE const LVecBase2f &get_data2f();
98  INLINE const LVecBase3f &get_data3f();
99  INLINE const LVecBase4f &get_data4f();
100  INLINE LMatrix3f get_matrix3f();
101  INLINE LMatrix4f get_matrix4f();
102 
103  INLINE double get_data1d();
104  INLINE const LVecBase2d &get_data2d();
105  INLINE const LVecBase3d &get_data3d();
106  INLINE const LVecBase4d &get_data4d();
107  INLINE LMatrix3d get_matrix3d();
108  INLINE LMatrix4d get_matrix4d();
109 
110  INLINE PN_stdfloat get_data1();
111  INLINE const LVecBase2 &get_data2();
112  INLINE const LVecBase3 &get_data3();
113  INLINE const LVecBase4 &get_data4();
114  INLINE LMatrix3 get_matrix3();
115  INLINE LMatrix4 get_matrix4();
116 
117  INLINE int get_data1i();
118  INLINE const LVecBase2i &get_data2i();
119  INLINE const LVecBase3i &get_data3i();
120  INLINE const LVecBase4i &get_data4i();
121 
122  void output(std::ostream &out) const;
123 
124 protected:
125  INLINE GeomVertexColumn::Packer *get_packer() const;
126 
127 private:
128  void initialize();
129 
130  INLINE bool set_pointer(int row);
131  INLINE void quick_set_pointer(int row);
132  INLINE const unsigned char *inc_pointer();
133 
134  bool set_vertex_column(int array, const GeomVertexColumn *column,
135  const GeomVertexDataPipelineReader *data_reader);
136  bool set_array_column(const GeomVertexColumn *column);
137 
138  // It is important that we only store *one* of the following two pointers.
139  // If we are storing a GeomVertexDataarray index, we must not keep a pointer
140  // to the particular ArrayData we are working on (if we do, it may result in
141  // an extra copy of the data due to holding the reference count).
142  CPT(GeomVertexData) _vertex_data;
143  int _array;
144  CPT(GeomVertexArrayData) _array_data;
145 
146  Thread *_current_thread;
147  GeomVertexColumn::Packer *_packer;
148  int _stride;
149 
150  CPT(GeomVertexArrayDataHandle) _handle;
151  const unsigned char *_pointer_begin;
152  const unsigned char *_pointer_end;
153  const unsigned char *_pointer;
154 
155  int _start_row;
156  bool _force;
157 
158 #ifndef NDEBUG
159  // This is defined just for the benefit of having something non-NULL to
160  // return from a nassertr() call.
161  static const unsigned char empty_buffer[100];
162 #endif
163 };
164 
165 INLINE std::ostream &
166 operator << (std::ostream &out, const GeomVertexReader &reader) {
167  reader.output(out);
168  return out;
169 }
170 
171 #include "geomVertexReader.I"
172 
173 #endif
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:193
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class exists just to provide scoping for the various enumerated types used by Geom,...
Definition: geomEnums.h:24
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This data object is returned by GeomVertexArrayData::get_handle() or modify_handle().
This defines how a single column is interleaved within a vertex array stored within a Geom.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
A thread; that is, a lightweight process.
Definition: thread.h:46
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the data for one array of a GeomVertexData structure.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.