Panda3D
geomVertexColumn.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 geomVertexColumn.h
10  * @author drose
11  * @date 2005-03-06
12  */
13 
14 #ifndef GEOMVERTEXCOLUMN_H
15 #define GEOMVERTEXCOLUMN_H
16 
17 #include "pandabase.h"
18 #include "geomEnums.h"
19 #include "internalName.h"
20 #include "pointerTo.h"
21 #include "luse.h"
22 
23 class TypedWritable;
24 class BamWriter;
25 class BamReader;
26 class Datagram;
27 class DatagramIterator;
28 
29 class GeomVertexReader;
30 class GeomVertexWriter;
31 
32 /**
33  * This defines how a single column is interleaved within a vertex array
34  * stored within a Geom. The GeomVertexArrayFormat class maintains a list of
35  * these to completely define a particular array structure.
36  */
37 class EXPCL_PANDA_GOBJ GeomVertexColumn : public GeomEnums {
38 private:
39  INLINE GeomVertexColumn();
40 PUBLISHED:
41  INLINE explicit GeomVertexColumn(CPT_InternalName name, int num_components,
42  NumericType numeric_type, Contents contents,
43  int start, int column_alignment = 0,
44  int num_elements = 0, int element_stride = 0);
45  INLINE GeomVertexColumn(const GeomVertexColumn &copy);
46  void operator = (const GeomVertexColumn &copy);
47  INLINE ~GeomVertexColumn();
48 
49  INLINE const InternalName *get_name() const;
50  INLINE int get_num_components() const;
51  INLINE int get_num_values() const;
52  INLINE int get_num_elements() const;
53  INLINE NumericType get_numeric_type() const;
54  INLINE Contents get_contents() const;
55  INLINE int get_start() const;
56  INLINE int get_column_alignment() const;
57  INLINE int get_element_stride() const;
58  INLINE int get_component_bytes() const;
59  INLINE int get_total_bytes() const;
60  INLINE bool has_homogeneous_coord() const;
61 
62  INLINE bool overlaps_with(int start_byte, int num_bytes) const;
63  INLINE bool is_bytewise_equivalent(const GeomVertexColumn &other) const;
64 
65  void set_name(InternalName *name);
66  void set_num_components(int num_components);
67  void set_numeric_type(NumericType numeric_type);
68  void set_contents(Contents contents);
69  void set_start(int start);
70  void set_column_alignment(int column_alignment);
71 
72  void output(std::ostream &out) const;
73 
74 public:
75  INLINE bool is_packed_argb() const;
76  INLINE bool is_uint8_rgba() const;
77 
78  INLINE int compare_to(const GeomVertexColumn &other) const;
79  INLINE bool operator == (const GeomVertexColumn &other) const;
80  INLINE bool operator != (const GeomVertexColumn &other) const;
81  INLINE bool operator < (const GeomVertexColumn &other) const;
82 
83 private:
84  class Packer;
85 
86  void setup();
87  Packer *make_packer() const;
88 
89 public:
90  void write_datagram(BamWriter *manager, Datagram &dg);
91  int complete_pointers(TypedWritable **plist, BamReader *manager);
92  void fillin(DatagramIterator &scan, BamReader *manager);
93 
94 private:
95  CPT_InternalName _name;
96  int _num_components;
97  int _num_values;
98  int _num_elements;
99  NumericType _numeric_type;
100  Contents _contents;
101  int _start;
102  int _column_alignment;
103  int _element_stride;
104  int _component_bytes;
105  int _total_bytes;
106  Packer *_packer;
107 
108  // This nested class provides the implementation for packing and unpacking
109  // data in a very general way, but also provides the hooks for implementing
110  // the common, very direct code paths (for instance, 3-component float32 to
111  // LVecBase3f) as quickly as possible.
112  class Packer : public MemoryBase {
113  public:
114  virtual ~Packer();
115 
116  virtual float get_data1f(const unsigned char *pointer);
117  virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
118  virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
119  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
120 
121  virtual double get_data1d(const unsigned char *pointer);
122  virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
123  virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
124  virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
125 
126  virtual int get_data1i(const unsigned char *pointer);
127  virtual const LVecBase2i &get_data2i(const unsigned char *pointer);
128  virtual const LVecBase3i &get_data3i(const unsigned char *pointer);
129  virtual const LVecBase4i &get_data4i(const unsigned char *pointer);
130 
131  virtual void set_data1f(unsigned char *pointer, float data);
132  virtual void set_data2f(unsigned char *pointer, const LVecBase2f &data);
133  virtual void set_data3f(unsigned char *pointer, const LVecBase3f &data);
134  virtual void set_data4f(unsigned char *pointer, const LVecBase4f &data);
135 
136  virtual void set_data1d(unsigned char *pointer, double data);
137  virtual void set_data2d(unsigned char *pointer, const LVecBase2d &data);
138  virtual void set_data3d(unsigned char *pointer, const LVecBase3d &data);
139  virtual void set_data4d(unsigned char *pointer, const LVecBase4d &data);
140 
141  virtual void set_data1i(unsigned char *pointer, int data);
142  virtual void set_data2i(unsigned char *pointer, const LVecBase2i &data);
143  virtual void set_data3i(unsigned char *pointer, const LVecBase3i &data);
144  virtual void set_data4i(unsigned char *pointer, const LVecBase4i &data);
145 
146  virtual const char *get_name() const {
147  return "Packer";
148  }
149 
150  const GeomVertexColumn *_column;
151  LVecBase2f _v2;
152  LVecBase3f _v3;
153  LVecBase4f _v4;
154  LVecBase2d _v2d;
155  LVecBase3d _v3d;
156  LVecBase4d _v4d;
157  LVecBase2i _v2i;
158  LVecBase3i _v3i;
159  LVecBase4i _v4i;
160  unsigned int _a, _b, _c, _d;
161  };
162 
163 
164  // This is a specialization on the generic Packer that handles points, which
165  // are special because the fourth component, if not present in the data, is
166  // implicitly 1.0; and if it is present, then any three-component or smaller
167  // return is implicitly divided by the fourth component.
168  class Packer_point : public Packer {
169  public:
170  virtual float get_data1f(const unsigned char *pointer);
171  virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
172  virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
173  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
174 
175  virtual double get_data1d(const unsigned char *pointer);
176  virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
177  virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
178  virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
179 
180  virtual void set_data1f(unsigned char *pointer, float data);
181  virtual void set_data2f(unsigned char *pointer, const LVecBase2f &data);
182  virtual void set_data3f(unsigned char *pointer, const LVecBase3f &data);
183  virtual void set_data4f(unsigned char *pointer, const LVecBase4f &data);
184 
185  virtual void set_data1d(unsigned char *pointer, double data);
186  virtual void set_data2d(unsigned char *pointer, const LVecBase2d &data);
187  virtual void set_data3d(unsigned char *pointer, const LVecBase3d &data);
188  virtual void set_data4d(unsigned char *pointer, const LVecBase4d &data);
189 
190  virtual const char *get_name() const {
191  return "Packer_point";
192  }
193  };
194 
195  // This is similar to Packer_point, in that the fourth component is
196  // implicitly 1.0 if it is not present in the data, but we never divide by
197  // alpha. It also transforms integer colors to the 0-1 range.
198  class Packer_color : public Packer {
199  public:
200  virtual float get_data1f(const unsigned char *pointer);
201  virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
202  virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
203  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
204 
205  virtual double get_data1d(const unsigned char *pointer);
206  virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
207  virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
208  virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
209 
210  virtual void set_data1f(unsigned char *pointer, float data);
211  virtual void set_data2f(unsigned char *pointer, const LVecBase2f &data);
212  virtual void set_data3f(unsigned char *pointer, const LVecBase3f &data);
213  virtual void set_data4f(unsigned char *pointer, const LVecBase4f &data);
214 
215  virtual void set_data1d(unsigned char *pointer, double data);
216  virtual void set_data2d(unsigned char *pointer, const LVecBase2d &data);
217  virtual void set_data3d(unsigned char *pointer, const LVecBase3d &data);
218  virtual void set_data4d(unsigned char *pointer, const LVecBase4d &data);
219 
220  virtual const char *get_name() const {
221  return "Packer_color";
222  }
223  };
224 
225 
226  // These are the specializations on the generic Packer that handle the
227  // direct code paths.
228 
229  class Packer_float32_3 : public Packer {
230  public:
231  virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
232  virtual void set_data3f(unsigned char *pointer, const LVecBase3f &value);
233 
234  virtual const char *get_name() const {
235  return "Packer_float32_3";
236  }
237  };
238 
239  class Packer_point_float32_2 : public Packer_point {
240  public:
241  virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
242  virtual void set_data2f(unsigned char *pointer, const LVecBase2f &value);
243 
244  virtual const char *get_name() const {
245  return "Packer_point_float32_2";
246  }
247  };
248 
249  class Packer_point_float32_3 : public Packer_point {
250  public:
251  virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
252  virtual void set_data3f(unsigned char *pointer, const LVecBase3f &value);
253 
254  virtual const char *get_name() const {
255  return "Packer_point_float32_3";
256  }
257  };
258 
259  class Packer_point_float32_4 : public Packer_point {
260  public:
261  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
262  virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value);
263 
264  virtual const char *get_name() const {
265  return "Packer_point_float32_4";
266  }
267  };
268 
269  class Packer_nativefloat_3 : public Packer_float32_3 {
270  public:
271  virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
272 
273  virtual const char *get_name() const {
274  return "Packer_nativefloat_3";
275  }
276  };
277 
278  class Packer_point_nativefloat_2 : public Packer_point_float32_2 {
279  public:
280  virtual const LVecBase2f &get_data2f(const unsigned char *pointer);
281 
282  virtual const char *get_name() const {
283  return "Packer_nativefloat_2";
284  }
285  };
286 
287  class Packer_point_nativefloat_3 : public Packer_point_float32_3 {
288  public:
289  virtual const LVecBase3f &get_data3f(const unsigned char *pointer);
290 
291  virtual const char *get_name() const {
292  return "Packer_point_nativefloat_3";
293  }
294  };
295 
296  class Packer_point_nativefloat_4 : public Packer_point_float32_4 {
297  public:
298  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
299 
300  virtual const char *get_name() const {
301  return "Packer_point_nativefloat_4";
302  }
303  };
304 
305  class Packer_float64_3 : public Packer {
306  public:
307  virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
308  virtual void set_data3d(unsigned char *pointer, const LVecBase3d &value);
309 
310  virtual const char *get_name() const {
311  return "Packer_float64_3";
312  }
313  };
314 
315  class Packer_point_float64_2 : public Packer_point {
316  public:
317  virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
318  virtual void set_data2d(unsigned char *pointer, const LVecBase2d &value);
319 
320  virtual const char *get_name() const {
321  return "Packer_point_float64_2";
322  }
323  };
324 
325  class Packer_point_float64_3 : public Packer_point {
326  public:
327  virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
328  virtual void set_data3d(unsigned char *pointer, const LVecBase3d &value);
329 
330  virtual const char *get_name() const {
331  return "Packer_point_float64_3";
332  }
333  };
334 
335  class Packer_point_float64_4 : public Packer_point {
336  public:
337  virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
338  virtual void set_data4d(unsigned char *pointer, const LVecBase4d &value);
339 
340  virtual const char *get_name() const {
341  return "Packer_point_float64_4";
342  }
343  };
344 
345  class Packer_nativedouble_3 final : public Packer_float64_3 {
346  public:
347  virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
348 
349  virtual const char *get_name() const {
350  return "Packer_nativedouble_3";
351  }
352  };
353 
354  class Packer_point_nativedouble_2 final : public Packer_point_float64_2 {
355  public:
356  virtual const LVecBase2d &get_data2d(const unsigned char *pointer);
357 
358  virtual const char *get_name() const {
359  return "Packer_nativedouble_2";
360  }
361  };
362 
363  class Packer_point_nativedouble_3 final : public Packer_point_float64_3 {
364  public:
365  virtual const LVecBase3d &get_data3d(const unsigned char *pointer);
366 
367  virtual const char *get_name() const {
368  return "Packer_point_nativedouble_3";
369  }
370  };
371 
372  class Packer_point_nativedouble_4 : public Packer_point_float64_4 {
373  public:
374  virtual const LVecBase4d &get_data4d(const unsigned char *pointer);
375 
376  virtual const char *get_name() const {
377  return "Packer_point_nativedouble_4";
378  }
379  };
380 
381  class Packer_argb_packed final : public Packer_color {
382  public:
383  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
384  virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value);
385 
386  virtual const char *get_name() const {
387  return "Packer_argb_packed";
388  }
389  };
390 
391  class Packer_rgba_uint8_4 final : public Packer_color {
392  public:
393  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
394  virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value);
395 
396  virtual const char *get_name() const {
397  return "Packer_rgba_uint8_4";
398  }
399  };
400 
401  class Packer_rgba_float32_4 : public Packer_color {
402  public:
403  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
404  virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value);
405 
406  virtual const char *get_name() const {
407  return "Packer_rgba_float32_4";
408  }
409  };
410 
411  class Packer_rgba_nativefloat_4 final : public Packer_rgba_float32_4 {
412  public:
413  virtual const LVecBase4f &get_data4f(const unsigned char *pointer);
414 
415  virtual const char *get_name() const {
416  return "Packer_rgba_nativefloat_4";
417  }
418  };
419 
420  class Packer_uint16_1 final : public Packer {
421  public:
422  virtual int get_data1i(const unsigned char *pointer);
423  virtual void set_data1i(unsigned char *pointer, int value);
424 
425  virtual const char *get_name() const {
426  return "Packer_uint16_1";
427  }
428  };
429 
430  friend class GeomVertexArrayFormat;
431  friend class GeomVertexData;
432  friend class GeomVertexReader;
433  friend class GeomVertexWriter;
434 };
435 
436 INLINE std::ostream &operator << (std::ostream &out, const GeomVertexColumn &obj);
437 
438 #include "geomVertexColumn.I"
439 
440 #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
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
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
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
This defines how a single column is interleaved within a vertex array stored within a Geom.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class is intended to be the base class of all objects in Panda that might be allocated and delet...
Definition: memoryBase.h:69
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
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:73
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
This describes the structure of a single array within a Geom data.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.