00001 // Filename: geomMunger.I00002 // Created by: drose (10Mar05)00003 //00004 ////////////////////////////////////////////////////////////////////00005 //00006 // PANDA 3D SOFTWARE00007 // Copyright (c) Carnegie Mellon University. All rights reserved.00008 //00009 // All use of this software is subject to the terms of the revised BSD00010 // license. You should have received a copy of this license along00011 // with this source code in a file named "LICENSE."00012 //00013 ////////////////////////////////////////////////////////////////////00014
00015
00016 ////////////////////////////////////////////////////////////////////00017 // Function: GeomMunger::get_gsg00018 // Access: Public00019 // Description: Returns a pointer to the GSG that created this00020 // munger.00021 ////////////////////////////////////////////////////////////////////00022 INLINE GraphicsStateGuardianBase *GeomMunger::00023get_gsg() const {
00024 return _gsg;
00025 }
00026
00027 ////////////////////////////////////////////////////////////////////00028 // Function: GeomMunger::is_registered00029 // Access: Public00030 // Description: Returns true if this munger has been registered,00031 // false if it has not. It may not be used for a Geom00032 // until it has been registered, but once registered, it00033 // may no longer be modified.00034 ////////////////////////////////////////////////////////////////////00035 INLINE boolGeomMunger::00036is_registered() const {
00037 return _is_registered;
00038 }
00039
00040 ////////////////////////////////////////////////////////////////////00041 // Function: GeomMunger::register_munger00042 // Access: Public, Static00043 // Description: Adds the indicated munger to the registry, if there00044 // is not an equivalent munger already there; in either00045 // case, returns the pointer to the equivalent munger00046 // now in the registry.00047 //00048 // This must be called before a munger may be used in a00049 // Geom. After this call, you should discard the00050 // original pointer you passed in (which may or may not00051 // now be invalid) and let its reference count decrement00052 // normally; you should use only the returned value from00053 // 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_gsg00062 // Access: Public, Static00063 // Description: Removes all the mungers from the registry that are00064 // associated with the indicated GSG.00065 ////////////////////////////////////////////////////////////////////00066 INLINE voidGeomMunger::00067unregister_mungers_for_gsg(GraphicsStateGuardianBase *gsg) {
00068 get_registry()->unregister_mungers_for_gsg(gsg);
00069 }
00070
00071 ////////////////////////////////////////////////////////////////////00072 // Function: GeomMunger::munge_format00073 // Access: Public00074 // Description: Given a source GeomVertexFormat, converts it if00075 // necessary to the appropriate format for rendering.00076 //00077 // If the GeomVertexAnimationSpec so indicates, then the00078 // format will be chosen to convert CPU-based animation00079 // tables to HW-based animation tables, reserving space00080 // 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() needs00086 // to update caches and stuff, but we trust it not to change any00087 // user-definable parameters.00088 return ((GeomMunger *)this)->do_munge_format(format, animation);
00089 }
00090
00091 ////////////////////////////////////////////////////////////////////00092 // Function: GeomMunger::munge_data00093 // Access: Public00094 // Description: Given a source GeomVertexData, converts it if00095 // 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 to00100 // update caches and stuff, but we trust it not to change any00101 // user-definable parameters.00102 return ((GeomMunger *)this)->munge_data_impl(data);
00103 }
00104
00105 ////////////////////////////////////////////////////////////////////00106 // Function: GeomMunger::premunge_format00107 // Access: Public00108 // Description: This is similar to munge_format(), but it is done at00109 // load time, to optimize a model for eventual rendering00110 // on a particular GSG. At this point, we do not00111 // necessarily know the final render state that will be00112 // applied, so we cannot make any destructive changes to00113 // 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_data00122 // Access: Public00123 // Description: This is similar to munge_data(), but it is done at00124 // load time, to optimize a model for eventual rendering00125 // on a particular GSG. At this point, we do not00126 // necessarily know the final render state that will be00127 // applied, so we cannot make any destructive changes to00128 // 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_geom00137 // Access: Public00138 // Description: This is similar to munge_geom(), but it is done at00139 // load time, to optimize a model for eventual rendering00140 // on a particular GSG. At this point, we do not00141 // necessarily know the final render state that will be00142 // applied, so we cannot make any destructive changes to00143 // the geom, its data, or its format.00144 //00145 // Unlike munge_geom(), this result is not cached, since00146 // the assumption is that this operation is performed at00147 // load time once for each model.00148 ////////////////////////////////////////////////////////////////////00149 INLINE voidGeomMunger::00150premunge_geom(CPT(Geom) &geom, CPT(GeomVertexData) &data) const {
00151 ((GeomMunger *)this)->premunge_geom_impl(geom, data);
00152 }
00153
00154 ////////////////////////////////////////////////////////////////////00155 // Function: GeomMunger::compare_to00156 // Access: Public00157 // Description: Provides an arbitrary ordering among all unique00158 // GeomMungers, so we can store the essentially00159 // different ones in a big set and throw away the rest.00160 ////////////////////////////////////////////////////////////////////00161 INLINE intGeomMunger::00162compare_to(constGeomMunger &other) const {
00163 // First, we compare the types; if they are of different types then00164 // 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 returncompare_to_impl(&other);
00173 }
00174
00175 ////////////////////////////////////////////////////////////////////00176 // Function: GeomMunger::geom_compare_to00177 // Access: Public00178 // Description: Compares two GeomMungers, considering only whether00179 // they would produce a different answer to00180 // munge_format(), munge_data(), or munge_geom(). (They00181 // still might be different in other ways, but if they00182 // would produce the same answer, this function consider00183 // them to be the same.)00184 ////////////////////////////////////////////////////////////////////00185 INLINE intGeomMunger::00186geom_compare_to(constGeomMunger &other) const {
00187 // First, we compare the types; if they are of different types then00188 // 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 returngeom_compare_to_impl(&other);
00197 }
00198
00199 ////////////////////////////////////////////////////////////////////00200 // Function: GeomMunger::unregister_myself00201 // Access: Protected00202 // Description: Unregisters the GeomMunger, for instance when it is00203 // being destructed, or whenever it has become invalid00204 // for some reason. This removes it from the registry00205 // so that it will no longer be available to be returned00206 // by register_munger().00207 //00208 // It is not an error to call this if the munger has00209 // already been unregistered.00210 ////////////////////////////////////////////////////////////////////00211 INLINE voidGeomMunger::00212unregister_myself() {
00213 if (is_registered()) {
00214 get_registry()->unregister_munger(this);
00215 }
00216 }
00217
00218 ////////////////////////////////////////////////////////////////////00219 // Function: GeomMunger::get_registry00220 // Access: Private00221 // 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 }