Panda3D

geomMunger.I

00001 // Filename: geomMunger.I
00002 // Created by:  drose (10Mar05)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: GeomMunger::get_gsg
00018 //       Access: Public
00019 //  Description: Returns a pointer to the GSG that created this
00020 //               munger.
00021 ////////////////////////////////////////////////////////////////////
00022 INLINE GraphicsStateGuardianBase *GeomMunger::
00023 get_gsg() const {
00024   return _gsg;
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: GeomMunger::is_registered
00029 //       Access: Public
00030 //  Description: Returns true if this munger has been registered,
00031 //               false if it has not.  It may not be used for a Geom
00032 //               until it has been registered, but once registered, it
00033 //               may no longer be modified.
00034 ////////////////////////////////////////////////////////////////////
00035 INLINE bool GeomMunger::
00036 is_registered() const {
00037   return _is_registered;
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: GeomMunger::register_munger
00042 //       Access: Public, Static
00043 //  Description: Adds the indicated munger to the registry, if there
00044 //               is not an equivalent munger already there; in either
00045 //               case, returns the pointer to the equivalent munger
00046 //               now in the registry.
00047 //
00048 //               This must be called before a munger may be used in a
00049 //               Geom.  After this call, you should discard the
00050 //               original pointer you passed in (which may or may not
00051 //               now be invalid) and let its reference count decrement
00052 //               normally; you should use only the returned value from
00053 //               this point on.
00054 ////////////////////////////////////////////////////////////////////
00055 INLINE PT(GeomMunger) GeomMunger::
00056 register_munger(GeomMunger *munger, Thread *current_thread) {
00057   return get_registry()->register_munger(munger, current_thread);
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: GeomMunger::unregister_mungers_for_gsg
00062 //       Access: Public, Static
00063 //  Description: Removes all the mungers from the registry that are
00064 //               associated with the indicated GSG.
00065 ////////////////////////////////////////////////////////////////////
00066 INLINE void GeomMunger::
00067 unregister_mungers_for_gsg(GraphicsStateGuardianBase *gsg) {
00068   get_registry()->unregister_mungers_for_gsg(gsg);
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: GeomMunger::munge_format
00073 //       Access: Public
00074 //  Description: Given a source GeomVertexFormat, converts it if
00075 //               necessary to the appropriate format for rendering.
00076 //
00077 //               If the GeomVertexAnimationSpec so indicates, then the
00078 //               format will be chosen to convert CPU-based animation
00079 //               tables to HW-based animation tables, reserving space
00080 //               for the specified number of transforms per vertex.
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE CPT(GeomVertexFormat) GeomMunger::
00083 munge_format(const GeomVertexFormat *format,
00084              const GeomVertexAnimationSpec &animation) const {
00085   // We cast away the const pointer, because do_munge_format() needs
00086   // to update caches and stuff, but we trust it not to change any
00087   // user-definable parameters.
00088   return ((GeomMunger *)this)->do_munge_format(format, animation);
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: GeomMunger::munge_data
00093 //       Access: Public
00094 //  Description: Given a source GeomVertexData, converts it if
00095 //               necessary to the appropriate data for rendering.
00096 ////////////////////////////////////////////////////////////////////
00097 INLINE CPT(GeomVertexData) GeomMunger::
00098 munge_data(const GeomVertexData *data) const {
00099   // We cast away the const pointer, because do_munge_data() needs to
00100   // update caches and stuff, but we trust it not to change any
00101   // user-definable parameters.
00102   return ((GeomMunger *)this)->munge_data_impl(data);
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: GeomMunger::premunge_format
00107 //       Access: Public
00108 //  Description: This is similar to munge_format(), but it is done at
00109 //               load time, to optimize a model for eventual rendering
00110 //               on a particular GSG.  At this point, we do not
00111 //               necessarily know the final render state that will be
00112 //               applied, so we cannot make any destructive changes to
00113 //               the geom, its data, or its format.
00114 ////////////////////////////////////////////////////////////////////
00115 INLINE CPT(GeomVertexFormat) GeomMunger::
00116 premunge_format(const GeomVertexFormat *format) const {
00117   return ((GeomMunger *)this)->do_premunge_format(format);
00118 }
00119 
00120 ////////////////////////////////////////////////////////////////////
00121 //     Function: GeomMunger::premunge_data
00122 //       Access: Public
00123 //  Description: This is similar to munge_data(), but it is done at
00124 //               load time, to optimize a model for eventual rendering
00125 //               on a particular GSG.  At this point, we do not
00126 //               necessarily know the final render state that will be
00127 //               applied, so we cannot make any destructive changes to
00128 //               the geom, its data, or its format.
00129 ////////////////////////////////////////////////////////////////////
00130 INLINE CPT(GeomVertexData) GeomMunger::
00131 premunge_data(const GeomVertexData *data) const {
00132   return ((GeomMunger *)this)->premunge_data_impl(data);
00133 }
00134 
00135 ////////////////////////////////////////////////////////////////////
00136 //     Function: GeomMunger::premunge_geom
00137 //       Access: Public
00138 //  Description: This is similar to munge_geom(), but it is done at
00139 //               load time, to optimize a model for eventual rendering
00140 //               on a particular GSG.  At this point, we do not
00141 //               necessarily know the final render state that will be
00142 //               applied, so we cannot make any destructive changes to
00143 //               the geom, its data, or its format.
00144 //
00145 //               Unlike munge_geom(), this result is not cached, since
00146 //               the assumption is that this operation is performed at
00147 //               load time once for each model.
00148 ////////////////////////////////////////////////////////////////////
00149 INLINE void GeomMunger::
00150 premunge_geom(CPT(Geom) &geom, CPT(GeomVertexData) &data) const {
00151   ((GeomMunger *)this)->premunge_geom_impl(geom, data);
00152 }
00153 
00154 ////////////////////////////////////////////////////////////////////
00155 //     Function: GeomMunger::compare_to
00156 //       Access: Public
00157 //  Description: Provides an arbitrary ordering among all unique
00158 //               GeomMungers, so we can store the essentially
00159 //               different ones in a big set and throw away the rest.
00160 ////////////////////////////////////////////////////////////////////
00161 INLINE int GeomMunger::
00162 compare_to(const GeomMunger &other) const {
00163   // First, we compare the types; if they are of different types then
00164   // they sort differently.
00165   TypeHandle type = get_type();
00166   TypeHandle other_type = other.get_type();
00167   if (type != other_type) {
00168     return type.get_index() - other_type.get_index();
00169   }
00170 
00171   // We only call compare_to_impl() if they have the same type.
00172   return compare_to_impl(&other);
00173 }
00174 
00175 ////////////////////////////////////////////////////////////////////
00176 //     Function: GeomMunger::geom_compare_to
00177 //       Access: Public
00178 //  Description: Compares two GeomMungers, considering only whether
00179 //               they would produce a different answer to
00180 //               munge_format(), munge_data(), or munge_geom().  (They
00181 //               still might be different in other ways, but if they
00182 //               would produce the same answer, this function consider
00183 //               them to be the same.)
00184 ////////////////////////////////////////////////////////////////////
00185 INLINE int GeomMunger::
00186 geom_compare_to(const GeomMunger &other) const {
00187   // First, we compare the types; if they are of different types then
00188   // they sort differently.
00189   TypeHandle type = get_type();
00190   TypeHandle other_type = other.get_type();
00191   if (type != other_type) {
00192     return type.get_index() - other_type.get_index();
00193   }
00194 
00195   // We only call compare_to_impl() if they have the same type.
00196   return geom_compare_to_impl(&other);
00197 }
00198 
00199 ////////////////////////////////////////////////////////////////////
00200 //     Function: GeomMunger::unregister_myself
00201 //       Access: Protected
00202 //  Description: Unregisters the GeomMunger, for instance when it is
00203 //               being destructed, or whenever it has become invalid
00204 //               for some reason.  This removes it from the registry
00205 //               so that it will no longer be available to be returned
00206 //               by register_munger().
00207 //
00208 //               It is not an error to call this if the munger has
00209 //               already been unregistered.
00210 ////////////////////////////////////////////////////////////////////
00211 INLINE void GeomMunger::
00212 unregister_myself() {
00213   if (is_registered()) {
00214     get_registry()->unregister_munger(this);
00215   }
00216 }
00217 
00218 ////////////////////////////////////////////////////////////////////
00219 //     Function: GeomMunger::get_registry
00220 //       Access: Private
00221 //  Description: Returns the global registry object.
00222 ////////////////////////////////////////////////////////////////////
00223 INLINE GeomMunger::Registry *GeomMunger::
00224 get_registry() {
00225   if (_registry == (Registry *)NULL) {
00226     make_registry();
00227   }
00228   return _registry;
00229 }
 All Classes Functions Variables Enumerations