Panda3D
Loading...
Searching...
No Matches
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 */
47class EXPCL_PANDA_GOBJ GeomVertexReader : public GeomEnums {
48PUBLISHED:
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,
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
61public:
62 INLINE GeomVertexReader(const GeomVertexDataPipelineReader *data_reader,
63 const InternalName *name,
64 bool force = true);
65
66PUBLISHED:
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
124protected:
125 INLINE GeomVertexColumn::Packer *get_packer() const;
126
127private:
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
165INLINE std::ostream &
166operator << (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...
This class exists just to provide scoping for the various enumerated types used by Geom,...
Definition geomEnums.h:24
This data object is returned by GeomVertexArrayData::get_handle() or modify_handle().
This is the data for one array of a GeomVertexData structure.
This defines how a single column is interleaved within a vertex array stored within a Geom.
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
bool set_column(int column)
Sets up the reader to use the nth data type of the GeomVertexFormat, numbering from 0.
bool is_at_end() const
Returns true if the reader is currently at the end of the list of vertices, false otherwise.
double get_data1d()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...
const LVecBase4d & get_data4d()
Returns the data associated with the read row, expressed as a 4-component value, and advances the rea...
const LVecBase4f & get_data4f()
Returns the data associated with the read row, expressed as a 4-component value, and advances the rea...
const LVecBase4i & get_data4i()
Returns the data associated with the read row, expressed as a 4-component value, and advances the rea...
const LVecBase3f & get_data3f()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
const LVecBase3i & get_data3i()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
LMatrix3 get_matrix3()
Returns the 3-by-3 matrix associated with the read row and advances the read row.
int get_array() const
Returns the array index containing the data type that the reader is working on.
LMatrix3d get_matrix3d()
Returns the 3-by-3 matrix associated with the read row and advances the read row.
void clear()
Resets the GeomVertexReader to the initial state.
const LVecBase2f & get_data2f()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
void set_force(bool force)
Sets the value of the force flag.
LMatrix4 get_matrix4()
Returns the 4-by-4 matrix associated with the read row and advances the read row.
const GeomVertexColumn * get_column() const
Returns the description of the data type that the reader is working on.
LMatrix4d get_matrix4d()
Returns the 4-by-4 matrix associated with the read row and advances the read row.
void set_row_unsafe(int row)
Sets the start row to the indicated value, without internal checks.
LMatrix3f get_matrix3f()
Returns the 3-by-3 matrix associated with the read row and advances the read row.
const LVecBase4 & get_data4()
Returns the data associated with the read row, expressed as a 4-component value, and advances the rea...
PN_stdfloat get_data1()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
int get_data1i()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
LMatrix4f get_matrix4f()
Returns the 4-by-4 matrix associated with the read row and advances the read row.
const GeomVertexData * get_vertex_data() const
Returns the vertex data object that the reader is processing.
const LVecBase2 & get_data2()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
bool has_column() const
Returns true if a valid data type has been successfully set, or false if the data type does not exist...
const LVecBase2i & get_data2i()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
bool get_force() const
Returns the value of the force flag.
int get_start_row() const
Returns the row index at which the reader started.
void set_row(int row)
Sets the start row to the indicated value.
int get_read_row() const
Returns the row index from which the data will be retrieved by the next call to get_data*().
float get_data1f()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
const GeomVertexArrayDataHandle * get_array_handle() const
Returns the read handle to the array object that the read is currently processing.
const LVecBase3d & get_data3d()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
size_t get_stride() const
Returns the per-row stride (bytes between consecutive rows) of the underlying vertex array.
const LVecBase2d & get_data2d()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
const LVecBase3 & get_data3()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
const GeomVertexArrayData * get_array_data() const
Returns the particular array object that the reader is currently processing.
GeomVertexReader(Thread *current_thread=Thread::get_current_thread())
Constructs an invalid GeomVertexReader.
Encodes a string name in a hash table, mapping it to a pointer.
A thread; that is, a lightweight process.
Definition thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
STL class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.