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