Panda3D

geomMunger.I
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 geomMunger.I
10 * @author drose
11 * @date 2005-03-10
12 */
13
14 /**
15 * Returns a pointer to the GSG that created this munger.
16 */
17 INLINE GraphicsStateGuardianBase *GeomMunger::
18 get_gsg() const {
19 return _gsg;
20 }
21
22 /**
23 * Returns true if this munger has been registered, false if it has not. It
24 * may not be used for a Geom until it has been registered, but once
25 * registered, it may no longer be modified.
26 */
27 INLINE bool GeomMunger::
28 is_registered() const {
29 return _is_registered;
30 }
31
32 /**
33 * Adds the indicated munger to the registry, if there is not an equivalent
34 * munger already there; in either case, returns the pointer to the equivalent
35 * munger now in the registry.
36 *
37 * This must be called before a munger may be used in a Geom. After this
38 * call, you should discard the original pointer you passed in (which may or
39 * may not now be invalid) and let its reference count decrement normally; you
40 * should use only the returned value from this point on.
41 */
42 INLINE PT(GeomMunger) GeomMunger::
43 register_munger(GeomMunger *munger, Thread *current_thread) {
44 return get_registry()->register_munger(munger, current_thread);
45 }
46
47 /**
48 * Removes all the mungers from the registry that are associated with the
49 * indicated GSG.
50 */
51 INLINE void GeomMunger::
52 unregister_mungers_for_gsg(GraphicsStateGuardianBase *gsg) {
53 get_registry()->unregister_mungers_for_gsg(gsg);
54 }
55
56 /**
57 * Given a source GeomVertexFormat, converts it if necessary to the
58 * appropriate format for rendering.
59 *
60 * If the GeomVertexAnimationSpec so indicates, then the format will be chosen
61 * to convert CPU-based animation tables to HW-based animation tables,
62 * reserving space for the specified number of transforms per vertex.
63 */
64 INLINE CPT(GeomVertexFormat) GeomMunger::
65 munge_format(const GeomVertexFormat *format,
66 const GeomVertexAnimationSpec &animation) const {
67 // We cast away the const pointer, because do_munge_format() needs to update
68 // caches and stuff, but we trust it not to change any user-definable
69 // parameters.
70 return ((GeomMunger *)this)->do_munge_format(format, animation);
71 }
72
73 /**
74 * Given a source GeomVertexData, converts it if necessary to the appropriate
75 * data for rendering.
76 */
77 INLINE CPT(GeomVertexData) GeomMunger::
78 munge_data(const GeomVertexData *data) const {
79 // We cast away the const pointer, because do_munge_data() needs to update
80 // caches and stuff, but we trust it not to change any user-definable
81 // parameters.
82 return ((GeomMunger *)this)->munge_data_impl(data);
83 }
84
85 /**
86 * This is similar to munge_format(), but it is done at load time, to optimize
87 * a model for eventual rendering on a particular GSG. At this point, we do
88 * not necessarily know the final render state that will be applied, so we
89 * cannot make any destructive changes to the geom, its data, or its format.
90 */
91 INLINE CPT(GeomVertexFormat) GeomMunger::
92 premunge_format(const GeomVertexFormat *format) const {
93 return ((GeomMunger *)this)->do_premunge_format(format);
94 }
95
96 /**
97 * This is similar to munge_data(), but it is done at load time, to optimize a
98 * model for eventual rendering on a particular GSG. At this point, we do not
99 * necessarily know the final render state that will be applied, so we cannot
100 * make any destructive changes to the geom, its data, or its format.
101 */
102 INLINE CPT(GeomVertexData) GeomMunger::
103 premunge_data(const GeomVertexData *data) const {
104 return ((GeomMunger *)this)->premunge_data_impl(data);
105 }
106
107 /**
108 * This is similar to munge_geom(), but it is done at load time, to optimize a
109 * model for eventual rendering on a particular GSG. At this point, we do not
110 * necessarily know the final render state that will be applied, so we cannot
111 * make any destructive changes to the geom, its data, or its format.
112 *
113 * Unlike munge_geom(), this result is not cached, since the assumption is
114 * that this operation is performed at load time once for each model.
115 */
116 INLINE void GeomMunger::
117 premunge_geom(CPT(Geom) &geom, CPT(GeomVertexData) &data) const {
118 ((GeomMunger *)this)->premunge_geom_impl(geom, data);
119 }
120
121 /**
122 * Provides an arbitrary ordering among all unique GeomMungers, so we can
123 * store the essentially different ones in a big set and throw away the rest.
124 */
125 INLINE int GeomMunger::
126 compare_to(const GeomMunger &other) const {
127 // First, we compare the types; if they are of different types then they
128 // sort differently.
129 TypeHandle type = get_type();
130 TypeHandle other_type = other.get_type();
131 if (type != other_type) {
132 return type.get_index() - other_type.get_index();
133 }
134
135 // We only call compare_to_impl() if they have the same type.
136 return compare_to_impl(&other);
137 }
138
139 /**
140 * Compares two GeomMungers, considering only whether they would produce a
141 * different answer to munge_format(), munge_data(), or munge_geom(). (They
142 * still might be different in other ways, but if they would produce the same
143 * answer, this function consider them to be the same.)
144 */
145 INLINE int GeomMunger::
146 geom_compare_to(const GeomMunger &other) const {
147 // First, we compare the types; if they are of different types then they
148 // sort differently.
149 TypeHandle type = get_type();
150 TypeHandle other_type = other.get_type();
151 if (type != other_type) {
152 return type.get_index() - other_type.get_index();
153 }
154
155 // We only call compare_to_impl() if they have the same type.
156 return geom_compare_to_impl(&other);
157 }
158
159 /**
160 * Unregisters the GeomMunger, for instance when it is being destructed, or
161 * whenever it has become invalid for some reason. This removes it from the
162 * registry so that it will no longer be available to be returned by
163 * register_munger().
164 *
165 * It is not an error to call this if the munger has already been
166 * unregistered.
167 */
168 INLINE void GeomMunger::
169 unregister_myself() {
170 if (is_registered()) {
171 get_registry()->unregister_munger(this);
172 }
173 }
174
175 /**
176 * Returns the global registry object.
177 */
178 INLINE GeomMunger::Registry *GeomMunger::
179 get_registry() {
180 if (_registry == nullptr) {
181 make_registry();
182 }
183 return _registry;
184 }
GeomMunger
Objects of this class are used to convert vertex data from a Geom into a format suitable for passing ...
Definition: geomMunger.h:50
GeomMunger::get_gsg
GraphicsStateGuardianBase * get_gsg() const
Returns a pointer to the GSG that created this munger.
Definition: geomMunger.I:18
GeomMunger::unregister_mungers_for_gsg
static void unregister_mungers_for_gsg(GraphicsStateGuardianBase *gsg)
Removes all the mungers from the registry that are associated with the indicated GSG.
Definition: geomMunger.I:52
GeomMunger::is_registered
bool is_registered() const
Returns true if this munger has been registered, false if it has not.
Definition: geomMunger.I:28
GeomVertexAnimationSpec
This object describes how the vertex animation, if any, represented in a GeomVertexData is encoded.
Definition: geomVertexAnimationSpec.h:38
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
Geom
A container for geometry primitives.
Definition: geom.h:54
GraphicsStateGuardianBase
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Definition: graphicsStateGuardianBase.h:110
Thread
A thread; that is, a lightweight process.
Definition: thread.h:46
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypeHandle::get_index
get_index
Returns the integer index associated with this TypeHandle.
Definition: typeHandle.h:135
CPT
CPT(GeomVertexFormat) GeomMunger
Given a source GeomVertexFormat, converts it if necessary to the appropriate format for rendering.
Definition: geomMunger.I:64
PT
PT(GeomMunger) GeomMunger
Adds the indicated munger to the registry, if there is not an equivalent munger already there; in eit...
Definition: geomMunger.I:42