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"
18#include "typedWritableReferenceCount.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
26 class GeomVertexFormat;
27 class GeomVertexData;
28 class GeomVertexArrayData;
29 class InternalName;
30 class FactoryParams;
31 class BamWriter;
32 class 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 */
47 class EXPCL_PANDA_GOBJ GeomVertexArrayFormat final : public TypedWritableReferenceCount, public GeomEnums {
48PUBLISHED:
49 GeomVertexArrayFormat();
50 GeomVertexArrayFormat(const GeomVertexArrayFormat &copy);
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);
72 ~GeomVertexArrayFormat();
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
123 public:
124 int compare_to(const GeomVertexArrayFormat &other) const;
125
126 private:
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
143 typedef pvector<GeomVertexColumn *> Columns;
144 Columns _columns;
145 bool _columns_unsorted;
146
147 typedef pmap<const InternalName *, GeomVertexColumn *> ColumnsByName;
148 ColumnsByName _columns_by_name;
149
150 // This is the global registry of all currently-in-use array formats.
151 typedef pset<GeomVertexArrayFormat *, IndirectCompareTo<GeomVertexArrayFormat> > ArrayFormats;
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
164 public:
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
171 protected:
172 static TypedWritable *make_from_bam(const FactoryParams &params);
173 void fillin(DatagramIterator &scan, BamReader *manager);
174
175 public:
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
189 private:
190 static TypeHandle _type_handle;
191
192 friend class GeomVertexFormat;
193};
194
195INLINE std::ostream &operator << (std::ostream &out, const GeomVertexArrayFormat &obj);
196
197#include "geomVertexArrayFormat.I"
198
199#endif
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
CPT_InternalName
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition internalName.h:193
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
GeomEnums
This class exists just to provide scoping for the various enumerated types used by Geom,...
Definition geomEnums.h:24
GeomVertexArrayData
This is the data for one array of a GeomVertexData structure.
Definition geomVertexArrayData.h:58
GeomVertexArrayFormat
This describes the structure of a single array within a Geom data.
Definition geomVertexArrayFormat.h:47
GeomVertexArrayFormat::remove_column
void remove_column(const InternalName *name)
Removes the column with the indicated name, if any.
Definition geomVertexArrayFormat.cxx:279
GeomVertexArrayFormat::get_column
get_column
Returns the specification with the indicated name, or NULL if the name is not used.
Definition geomVertexArrayFormat.h:106
GeomVertexArrayFormat::align_columns_for_animation
void align_columns_for_animation()
Reprocesses the columns in the format to align the C_point and C_vector columns to 16-byte boundaries...
Definition geomVertexArrayFormat.cxx:350
GeomVertexArrayFormat::has_column
bool has_column(const InternalName *name) const
Returns true if the array has the named column, false otherwise.
Definition geomVertexArrayFormat.I:141
GeomVertexArrayFormat::get_num_columns
get_num_columns
Returns the number of different columns in the array.
Definition geomVertexArrayFormat.h:106
GeomVertexArrayFormat::set_stride
set_stride
Changes the total number of bytes reserved in the array for each vertex.
Definition geomVertexArrayFormat.h:82
GeomVertexArrayFormat::get_total_bytes
get_total_bytes
Returns the total number of bytes used by the data types within the format, including gaps between el...
Definition geomVertexArrayFormat.h:93
GeomVertexArrayFormat::set_pad_to
set_pad_to
Explicitly sets the byte divisor to which the data record must be padded to meet hardware limitations...
Definition geomVertexArrayFormat.h:86
GeomVertexArrayFormat::get_stride
get_stride
Returns the total number of bytes reserved in the array for each vertex.
Definition geomVertexArrayFormat.h:82
GeomVertexArrayFormat::get_pad_to
get_pad_to
Returns the byte divisor to which the data record must be padded to meet hardware limitations.
Definition geomVertexArrayFormat.h:86
GeomVertexArrayFormat::is_registered
is_registered
Returns true if this format has been registered, false if it has not.
Definition geomVertexArrayFormat.h:78
GeomVertexArrayFormat::get_divisor
get_divisor
Returns the divisor attribute for the data in this array.
Definition geomVertexArrayFormat.h:90
GeomVertexArrayFormat::count_unused_space
int count_unused_space() const
Returns the number of bytes per row that are not assigned to any column.
Definition geomVertexArrayFormat.cxx:440
GeomVertexArrayFormat::get_format_string
std::string get_format_string(bool pad=true) const
Returns a string with format codes representing the exact memory layout of the columns in memory,...
Definition geomVertexArrayFormat.cxx:543
GeomVertexArrayFormat::clear_columns
void clear_columns()
Removes all columns previously added, sets the stride to zero, and prepares to start over.
Definition geomVertexArrayFormat.cxx:311
GeomVertexArrayFormat::pack_columns
void pack_columns()
Removes wasted space between columns.
Definition geomVertexArrayFormat.cxx:326
GeomVertexArrayFormat::add_column
int add_column(CPT_InternalName name, int num_components, NumericType numeric_type, Contents contents, int start=-1, int column_alignment=0)
Adds a new column to the specification.
Definition geomVertexArrayFormat.cxx:217
GeomVertexArrayFormat::set_divisor
set_divisor
Set this to 0 to indicate that this array contains per-vertex data, or to 1 to indicate that it conta...
Definition geomVertexArrayFormat.h:90
GeomVertexArrayFormat::is_data_subset_of
bool is_data_subset_of(const GeomVertexArrayFormat &other) const
Returns true if all of the fields in this array format are also present and equivalent in the other a...
Definition geomVertexArrayFormat.cxx:415
GeomVertexColumn
This defines how a single column is interleaved within a vertex array stored within a Geom.
Definition geomVertexColumn.h:37
GeomVertexData
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
Definition geomVertexData.h:68
GeomVertexFormat
This class defines the physical layout of the vertex data stored within a Geom.
Definition geomVertexFormat.h:55
InternalName
Encodes a string name in a hash table, mapping it to a pointer.
Definition internalName.h:38
LightMutex
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41
ReferenceCount::unref
virtual bool unref() const
Explicitly decrements the reference count.
Definition referenceCount.I:179
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition typedWritable.h:35
TypedWritable::finalize
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
Definition typedWritable.cxx:113
TypedWritable::fillin
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...
Definition typedWritable.cxx:103
TypedWritable::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition typedWritable.cxx:54
TypedWritable::complete_pointers
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().
Definition typedWritable.cxx:81
plist
This is our own Panda specialization on the default STL list.
Definition plist.h:35
geomEnums.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
geomVertexArrayFormat.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
geomVertexColumn.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indirectCompareTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lightMutex.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22
typedWritableReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.