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