Panda3D
 All Classes Functions Variables Enumerations
geomVertexWriter.h
1 // Filename: geomVertexWriter.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 GEOMVERTEXWRITER_H
16 #define GEOMVERTEXWRITER_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 : GeomVertexWriter
27 // Description : This object provides a high-level interface for
28 // quickly writing a sequence of numeric values from a
29 // vertex table.
30 //
31 // This object can be used both to replace existing
32 // vertices in the table, or to extend the table with
33 // new vertices. The set_data*() family of methods can
34 // only be used to replace existing data; it is an error
35 // to allow these to run past the end of the data. The
36 // add_data*() family of methods, on the other hand, can
37 // be used to replace existing data or add new data; if
38 // you call set_row() into the middle of existing
39 // data the add_data*() methods will behave like the
40 // corresponding set_data*(), but if they run past the
41 // end of existing data they will quietly add new
42 // vertices.
43 //
44 // Like GeomVertexReader, the writer is particularly
45 // optimized for writing a single column of data values
46 // for a series of vertices, without changing columns
47 // between each number. Although you can also use one
48 // GeomVertexWriter to write across the columns if it is
49 // convenient, by calling set_column() repeatedly at
50 // each vertex, it is faster to write down the columns,
51 // and to use a different GeomVertexWriter for each
52 // column.
53 //
54 // Note that, like a GeomVertexReader, a
55 // GeomVertexWriter does not keep a reference count to
56 // the actual vertex data buffer. This means that it is
57 // important not to keep a GeomVertexWriter object
58 // around over a long period of time in which the data
59 // buffer is likely to be deallocated; it is intended
60 // for making a quick pass over the data in one session.
61 //
62 // It also means that you should create any
63 // GeomVertexWriters *before* creating GeomVertexReaders
64 // on the same data, since the writer itself might cause
65 // the vertex buffer to be deallocated. Better yet, use
66 // a GeomVertexRewriter if you are going to create both
67 // of them anyway.
68 ////////////////////////////////////////////////////////////////////
69 class EXPCL_PANDA_GOBJ GeomVertexWriter : public GeomEnums {
70 PUBLISHED:
71  INLINE GeomVertexWriter(Thread *current_thread = Thread::get_current_thread());
72  INLINE GeomVertexWriter(GeomVertexData *vertex_data,
73  Thread *current_thread = Thread::get_current_thread());
74  INLINE GeomVertexWriter(GeomVertexData *vertex_data,
75  CPT_InternalName name,
76  Thread *current_thread = Thread::get_current_thread());
77  INLINE GeomVertexWriter(GeomVertexArrayData *array_data,
78  Thread *current_thread = Thread::get_current_thread());
79  INLINE GeomVertexWriter(GeomVertexArrayData *array_data,
80  int column,
81  Thread *current_thread = Thread::get_current_thread());
82 
83 public:
84  INLINE GeomVertexWriter(GeomVertexDataPipelineWriter *data_writer,
85  const InternalName *name);
86 
87 PUBLISHED:
88  INLINE GeomVertexWriter(const GeomVertexWriter &copy);
89  INLINE void operator = (const GeomVertexWriter &copy);
90  INLINE ~GeomVertexWriter();
91 
92  INLINE GeomVertexData *get_vertex_data() const;
93  INLINE GeomVertexArrayData *get_array_data() const;
94  INLINE GeomVertexArrayDataHandle *get_array_handle() const;
95  INLINE size_t get_stride() const;
96  INLINE Thread *get_current_thread() const;
97 
98  INLINE bool set_column(int column);
99  INLINE bool set_column(CPT_InternalName name);
100  bool set_column(int array, const GeomVertexColumn *column);
101  INLINE void clear();
102  bool reserve_num_rows(int num_rows);
103 
104  INLINE bool has_column() const;
105  INLINE int get_array() const;
106  INLINE const GeomVertexColumn *get_column() const;
107 
108  INLINE void set_row_unsafe(int row);
109  INLINE void set_row(int row);
110 
111  INLINE int get_start_row() const;
112  INLINE int get_write_row() const;
113  INLINE bool is_at_end() const;
114 
115  INLINE void set_data1f(float data);
116  INLINE void set_data2f(float x, float y);
117  INLINE void set_data2f(const LVecBase2f &data);
118  INLINE void set_data3f(float x, float y, float z);
119  INLINE void set_data3f(const LVecBase3f &data);
120  INLINE void set_data4f(float x, float y, float z, float w);
121  INLINE void set_data4f(const LVecBase4f &data);
122  INLINE void set_matrix3f(const LMatrix3f &mat);
123  INLINE void set_matrix4f(const LMatrix4f &mat);
124 
125  INLINE void set_data1d(double data);
126  INLINE void set_data2d(double x, double y);
127  INLINE void set_data2d(const LVecBase2d &data);
128  INLINE void set_data3d(double x, double y, double z);
129  INLINE void set_data3d(const LVecBase3d &data);
130  INLINE void set_data4d(double x, double y, double z, double w);
131  INLINE void set_data4d(const LVecBase4d &data);
132  INLINE void set_matrix3d(const LMatrix3d &mat);
133  INLINE void set_matrix4d(const LMatrix4d &mat);
134 
135  INLINE void set_data1(PN_stdfloat data);
136  INLINE void set_data2(PN_stdfloat x, PN_stdfloat y);
137  INLINE void set_data2(const LVecBase2 &data);
138  INLINE void set_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
139  INLINE void set_data3(const LVecBase3 &data);
140  INLINE void set_data4(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat w);
141  INLINE void set_data4(const LVecBase4 &data);
142  INLINE void set_matrix3(const LMatrix3 &mat);
143  INLINE void set_matrix4(const LMatrix4 &mat);
144 
145  INLINE void set_data1i(int data);
146  INLINE void set_data2i(int a, int b);
147  INLINE void set_data2i(const int data[2]);
148  INLINE void set_data2i(const LVecBase2i &data);
149  INLINE void set_data3i(int a, int b, int c);
150  INLINE void set_data3i(const int data[3]);
151  INLINE void set_data3i(const LVecBase3i &data);
152  INLINE void set_data4i(int a, int b, int c, int d);
153  INLINE void set_data4i(const int data[4]);
154  INLINE void set_data4i(const LVecBase4i &data);
155 
156  INLINE void add_data1f(float data);
157  INLINE void add_data2f(float x, float y);
158  INLINE void add_data2f(const LVecBase2f &data);
159  INLINE void add_data3f(float x, float y, float z);
160  INLINE void add_data3f(const LVecBase3f &data);
161  INLINE void add_data4f(float x, float y, float z, float w);
162  INLINE void add_data4f(const LVecBase4f &data);
163  INLINE void add_matrix3f(const LMatrix3f &mat);
164  INLINE void add_matrix4f(const LMatrix4f &mat);
165 
166  INLINE void add_data1d(double data);
167  INLINE void add_data2d(double x, double y);
168  INLINE void add_data2d(const LVecBase2d &data);
169  INLINE void add_data3d(double x, double y, double z);
170  INLINE void add_data3d(const LVecBase3d &data);
171  INLINE void add_data4d(double x, double y, double z, double w);
172  INLINE void add_data4d(const LVecBase4d &data);
173  INLINE void add_matrix3d(const LMatrix3d &mat);
174  INLINE void add_matrix4d(const LMatrix4d &mat);
175 
176  INLINE void add_data1(PN_stdfloat data);
177  INLINE void add_data2(PN_stdfloat x, PN_stdfloat y);
178  INLINE void add_data2(const LVecBase2 &data);
179  INLINE void add_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
180  INLINE void add_data3(const LVecBase3 &data);
181  INLINE void add_data4(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat w);
182  INLINE void add_data4(const LVecBase4 &data);
183  INLINE void add_matrix3(const LMatrix3 &mat);
184  INLINE void add_matrix4(const LMatrix4 &mat);
185 
186  INLINE void add_data1i(int data);
187  INLINE void add_data2i(int a, int b);
188  INLINE void add_data2i(const int data[2]);
189  INLINE void add_data2i(const LVecBase2i &data);
190  INLINE void add_data3i(int a, int b, int c);
191  INLINE void add_data3i(const int data[3]);
192  INLINE void add_data3i(const LVecBase3i &data);
193  INLINE void add_data4i(int a, int b, int c, int d);
194  INLINE void add_data4i(const int data[4]);
195  INLINE void add_data4i(const LVecBase4i &data);
196 
197  void output(ostream &out) const;
198 
199 protected:
200  INLINE GeomVertexColumn::Packer *get_packer() const;
201 
202 private:
203  class Writer;
204 
205  void initialize();
206 
207  INLINE void set_pointer(int row);
208  INLINE void quick_set_pointer(int row);
209  INLINE unsigned char *inc_pointer();
210  INLINE unsigned char *inc_add_pointer();
211 
212  bool set_vertex_column(int array, const GeomVertexColumn *column,
213  GeomVertexDataPipelineWriter *data_writer);
214  bool set_array_column(const GeomVertexColumn *column);
215 
216  // It is important that we only store *one* of the following two
217  // pointers. If we are storing a GeomVertexData/array index, we
218  // must not keep a pointer to the particular ArrayData we are
219  // working on (if we do, it may result in an extra copy of the data
220  // due to holding the reference count).
221  PT(GeomVertexData) _vertex_data;
222  int _array;
223  PT(GeomVertexArrayData) _array_data;
224 
225  Thread *_current_thread;
226  GeomVertexColumn::Packer *_packer;
227  int _stride;
228 
229  PT(GeomVertexArrayDataHandle) _handle;
230  unsigned char *_pointer_begin;
231  unsigned char *_pointer_end;
232  unsigned char *_pointer;
233 
234  int _start_row;
235 
236 #ifndef NDEBUG
237  // This is defined just for the benefit of having something non-NULL
238  // to return from a nassertr() call.
239  static unsigned char empty_buffer[100];
240 #endif
241 };
242 
243 INLINE ostream &
244 operator << (ostream &out, const GeomVertexWriter &writer) {
245  writer.output(out);
246  return out;
247 }
248 
249 #include "geomVertexWriter.I"
250 
251 #endif
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
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
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
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 is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
This is the data for one array of a GeomVertexData structure.