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