Panda3D
Loading...
Searching...
No Matches
geomVertexArrayFormat.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 geomVertexArrayFormat.h
10 * @author drose
11 * @date 2005-03-06
12 */
13
14#ifndef GEOMVERTEXARRAYFORMAT_H
15#define GEOMVERTEXARRAYFORMAT_H
16
17#include "pandabase.h"
19#include "geomVertexColumn.h"
20#include "geomEnums.h"
21#include "indirectCompareTo.h"
22#include "pvector.h"
23#include "pmap.h"
24#include "lightMutex.h"
25
27class GeomVertexData;
29class InternalName;
30class FactoryParams;
31class BamWriter;
32class BamReader;
33
34/**
35 * This describes the structure of a single array within a Geom data. See
36 * GeomVertexFormat for the parent class which collects together all of the
37 * individual GeomVertexArrayFormat objects.
38 *
39 * A particular array may include any number of standard or user-defined
40 * columns. All columns consist of a sequence of one or more numeric values,
41 * packed in any of a variety of formats; the semantic meaning of each column
42 * is defined in general with its contents member, and in particular by its
43 * name. The standard array types used most often are named "vertex",
44 * "normal", "texcoord", and "color"; other kinds of data may be piggybacked
45 * into the data record simply by choosing a unique name.
46 */
47class EXPCL_PANDA_GOBJ GeomVertexArrayFormat final : public TypedWritableReferenceCount, public GeomEnums {
48PUBLISHED:
51 GeomVertexArrayFormat(CPT_InternalName name0, int num_components0,
52 NumericType numeric_type0, Contents contents0);
53 GeomVertexArrayFormat(CPT_InternalName name0, int num_components0,
54 NumericType numeric_type0, Contents contents0,
55 CPT_InternalName name1, int num_components1,
56 NumericType numeric_type1, Contents contents1);
57 GeomVertexArrayFormat(CPT_InternalName name0, int num_components0,
58 NumericType numeric_type0, Contents contents0,
59 CPT_InternalName name1, int num_components1,
60 NumericType numeric_type1, Contents contents1,
61 CPT_InternalName name2, int num_components2,
62 NumericType numeric_type2, Contents contents2);
63 GeomVertexArrayFormat(CPT_InternalName name0, int num_components0,
64 NumericType numeric_type0, Contents contents0,
65 CPT_InternalName name1, int num_components1,
66 NumericType numeric_type1, Contents contents1,
67 CPT_InternalName name2, int num_components2,
68 NumericType numeric_type2, Contents contents2,
69 CPT_InternalName name3, int num_components3,
70 NumericType numeric_type3, Contents contents3);
71 void operator = (const GeomVertexArrayFormat &copy);
73
74 virtual bool unref() const;
75
76 INLINE bool is_registered() const;
77 INLINE static CPT(GeomVertexArrayFormat) register_format(const GeomVertexArrayFormat *format);
78 MAKE_PROPERTY(registered, is_registered);
79
80 INLINE int get_stride() const;
81 INLINE void set_stride(int stride);
82 MAKE_PROPERTY(stride, get_stride, set_stride);
83
84 INLINE int get_pad_to() const;
85 INLINE void set_pad_to(int pad_to);
86 MAKE_PROPERTY(pad_to, get_pad_to, set_pad_to);
87
88 INLINE int get_divisor() const;
89 INLINE void set_divisor(int divisor);
90 MAKE_PROPERTY(divisor, get_divisor, set_divisor);
91
92 INLINE int get_total_bytes() const;
93 MAKE_PROPERTY(total_bytes, get_total_bytes);
94
95 int add_column(CPT_InternalName name, int num_components,
96 NumericType numeric_type, Contents contents,
97 int start = -1, int column_alignment = 0);
98 int add_column(const GeomVertexColumn &column);
99 void remove_column(const InternalName *name);
100 void clear_columns();
101 void pack_columns();
102 void align_columns_for_animation();
103
104 INLINE int get_num_columns() const;
105 INLINE const GeomVertexColumn *get_column(int i) const;
106 MAKE_SEQ(get_columns, get_num_columns, get_column);
107 MAKE_SEQ_PROPERTY(columns, get_num_columns, get_column);
108
109 const GeomVertexColumn *get_column(const InternalName *name) const;
110 const GeomVertexColumn *get_column(int start_byte, int num_bytes) const;
111 INLINE bool has_column(const InternalName *name) const;
112
113 bool is_data_subset_of(const GeomVertexArrayFormat &other) const;
114 int count_unused_space() const;
115
116 void output(std::ostream &out) const;
117 void write(std::ostream &out, int indent_level = 0) const;
118 void write_with_data(std::ostream &out, int indent_level,
119 const GeomVertexArrayData *array_data) const;
120
121 std::string get_format_string(bool pad = true) const;
122
123public:
124 int compare_to(const GeomVertexArrayFormat &other) const;
125
126private:
127 class Registry;
128 INLINE static Registry *get_registry();
129 static void make_registry();
130
131 void do_register();
132 void do_unregister();
133
134 INLINE void consider_sort_columns() const;
135 void sort_columns();
136
137 bool _is_registered;
138 int _stride;
139 int _total_bytes;
140 int _pad_to;
141 int _divisor;
142
144 Columns _columns;
145 bool _columns_unsorted;
146
148 ColumnsByName _columns_by_name;
149
150 // This is the global registry of all currently-in-use array formats.
152 class EXPCL_PANDA_GOBJ Registry {
153 public:
154 Registry();
155 CPT(GeomVertexArrayFormat) register_format(GeomVertexArrayFormat *format);
156 void unregister_format(GeomVertexArrayFormat *format);
157
158 ArrayFormats _formats;
159 LightMutex _lock;
160 };
161
162 static Registry *_registry;
163
164public:
165 static void register_with_read_factory();
166 virtual void write_datagram(BamWriter *manager, Datagram &dg);
167 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
168
169 virtual void finalize(BamReader *manager);
170
171protected:
172 static TypedWritable *make_from_bam(const FactoryParams &params);
173 void fillin(DatagramIterator &scan, BamReader *manager);
174
175public:
176 static TypeHandle get_class_type() {
177 return _type_handle;
178 }
179 static void init_type() {
180 TypedWritableReferenceCount::init_type();
181 register_type(_type_handle, "GeomVertexArrayFormat",
182 TypedWritableReferenceCount::get_class_type());
183 }
184 virtual TypeHandle get_type() const {
185 return get_class_type();
186 }
187 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
188
189private:
190 static TypeHandle _type_handle;
191
192 friend class GeomVertexFormat;
193};
194
195INLINE std::ostream &operator << (std::ostream &out, const GeomVertexArrayFormat &obj);
196
198
199#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
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
An instance of this class is passed to the Factory when requesting it to do its business and construc...
This class exists just to provide scoping for the various enumerated types used by Geom,...
Definition geomEnums.h:24
This is the data for one array of a GeomVertexData structure.
This describes the structure of a single array within a Geom data.
This defines how a single column is interleaved within a vertex array stored within a Geom.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This class defines the physical layout of the vertex data stored within a Geom.
Encodes a string name in a hash table, mapping it to a pointer.
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41
virtual bool unref() const
Explicitly decrements the reference count.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
Base class for objects that can be written to and read from Bam files.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
An STL function object class, this is intended to be used on any ordered collection of class objects ...
This is our own Panda specialization on the default STL list.
Definition plist.h:35
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL set.
Definition pset.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.