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