00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "dxGeomMunger8.h"
00016 #include "geomVertexReader.h"
00017 #include "geomVertexWriter.h"
00018 #include "config_dxgsg8.h"
00019
00020 GeomMunger *DXGeomMunger8::_deleted_chain = NULL;
00021 TypeHandle DXGeomMunger8::_type_handle;
00022
00023
00024
00025
00026
00027
00028 DXGeomMunger8::
00029 ~DXGeomMunger8() {
00030 if (_reffed_filtered_texture) {
00031 unref_delete(_filtered_texture);
00032 _reffed_filtered_texture = false;
00033 }
00034 }
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 void DXGeomMunger8::
00045 wp_callback(void *) {
00046 unregister_myself();
00047
00048 if (_reffed_filtered_texture) {
00049 unref_delete(_filtered_texture);
00050 _reffed_filtered_texture = false;
00051 }
00052 }
00053
00054
00055
00056
00057
00058
00059
00060 CPT(GeomVertexFormat) DXGeomMunger8::
00061 munge_format_impl(const GeomVertexFormat *orig,
00062 const GeomVertexAnimationSpec &animation) {
00063 if (dxgsg8_cat.is_debug()) {
00064 if (animation.get_animation_type() != AT_none) {
00065 dxgsg8_cat.debug()
00066 << "preparing animation type " << animation << " for " << *orig
00067 << "\n";
00068 }
00069 }
00070
00071
00072
00073 PT(GeomVertexFormat) new_format = new GeomVertexFormat(*orig);
00074 new_format->set_animation(animation);
00075 PT(GeomVertexArrayFormat) new_array_format = new GeomVertexArrayFormat;
00076
00077 const GeomVertexColumn *vertex_type = orig->get_vertex_column();
00078 const GeomVertexColumn *normal_type = orig->get_normal_column();
00079 const GeomVertexColumn *color_type = orig->get_color_column();
00080
00081 if (vertex_type != (const GeomVertexColumn *)NULL) {
00082 new_array_format->add_column
00083 (InternalName::get_vertex(), 3, NT_float32,
00084 vertex_type->get_contents());
00085 new_format->remove_column(vertex_type->get_name());
00086
00087 } else {
00088
00089 return orig;
00090 }
00091
00092 if (animation.get_animation_type() == AT_hardware &&
00093 animation.get_num_transforms() > 0) {
00094 if (animation.get_num_transforms() > 1) {
00095
00096
00097 new_array_format->add_column
00098 (InternalName::get_transform_weight(), animation.get_num_transforms() - 1,
00099 NT_float32, C_other);
00100 }
00101
00102 if (animation.get_indexed_transforms()) {
00103
00104
00105 new_array_format->add_column
00106 (InternalName::get_transform_index(), 1,
00107 NT_packed_dcba, C_index);
00108 }
00109
00110
00111
00112 new_format->remove_column(InternalName::get_transform_weight());
00113 new_format->remove_column(InternalName::get_transform_index());
00114
00115
00116 new_format->remove_column(InternalName::get_transform_blend());
00117 }
00118
00119 if (normal_type != (const GeomVertexColumn *)NULL) {
00120 new_array_format->add_column
00121 (InternalName::get_normal(), 3, NT_float32, C_vector);
00122 new_format->remove_column(normal_type->get_name());
00123 }
00124
00125 if (color_type != (const GeomVertexColumn *)NULL) {
00126 new_array_format->add_column
00127 (InternalName::get_color(), 1, NT_packed_dabc, C_color);
00128 new_format->remove_column(color_type->get_name());
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138 if (_filtered_texture != (TextureAttrib *)NULL) {
00139 int num_stages = _filtered_texture->get_num_on_ff_stages();
00140 vector_int ff_tc_index(num_stages, 0);
00141
00142
00143
00144
00145
00146 int si, tc_index;
00147 int max_tc_index = -1;
00148 for (si = 0; si < num_stages; ++si) {
00149 int tc_index = _filtered_texture->get_ff_tc_index(si);
00150 nassertr(tc_index < num_stages, orig);
00151 ff_tc_index[tc_index] = si;
00152 max_tc_index = max(tc_index, max_tc_index);
00153 }
00154
00155
00156
00157
00158 for (tc_index = 0; tc_index <= max_tc_index; ++tc_index) {
00159 si = ff_tc_index[tc_index];
00160 TextureStage *stage = _filtered_texture->get_on_ff_stage(si);
00161 InternalName *name = stage->get_texcoord_name();
00162
00163 const GeomVertexColumn *texcoord_type = orig->get_column(name);
00164
00165 if (texcoord_type != (const GeomVertexColumn *)NULL) {
00166 new_array_format->add_column
00167 (name, texcoord_type->get_num_values(), NT_float32, C_texcoord);
00168 } else {
00169
00170
00171 new_array_format->add_column(name, 2, NT_float32, C_texcoord);
00172 }
00173 new_format->remove_column(name);
00174 }
00175 }
00176
00177
00178
00179 new_format->insert_array(0, new_array_format);
00180
00181 return GeomVertexFormat::register_format(new_format);
00182 }
00183
00184
00185
00186
00187
00188
00189
00190 CPT(GeomVertexFormat) DXGeomMunger8::
00191 premunge_format_impl(const GeomVertexFormat *orig) {
00192
00193
00194
00195 PT(GeomVertexFormat) new_format = new GeomVertexFormat(*orig);
00196 PT(GeomVertexArrayFormat) new_array_format = new GeomVertexArrayFormat;
00197
00198 const GeomVertexColumn *vertex_type = orig->get_vertex_column();
00199 const GeomVertexColumn *normal_type = orig->get_normal_column();
00200 const GeomVertexColumn *color_type = orig->get_color_column();
00201
00202 if (vertex_type != (const GeomVertexColumn *)NULL) {
00203 new_array_format->add_column
00204 (InternalName::get_vertex(), 3, NT_float32,
00205 vertex_type->get_contents());
00206 new_format->remove_column(vertex_type->get_name());
00207
00208 } else {
00209
00210 return orig;
00211 }
00212
00213 if (normal_type != (const GeomVertexColumn *)NULL) {
00214 new_array_format->add_column
00215 (InternalName::get_normal(), 3, NT_float32, C_vector);
00216 new_format->remove_column(normal_type->get_name());
00217 }
00218
00219 if (color_type != (const GeomVertexColumn *)NULL) {
00220 new_array_format->add_column
00221 (InternalName::get_color(), 1, NT_packed_dabc, C_color);
00222 new_format->remove_column(color_type->get_name());
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232 if (_filtered_texture != (TextureAttrib *)NULL) {
00233 int num_stages = _filtered_texture->get_num_on_ff_stages();
00234 vector_int ff_tc_index(num_stages, 0);
00235
00236
00237
00238
00239
00240 int si, tc_index;
00241 int max_tc_index = -1;
00242 for (si = 0; si < num_stages; ++si) {
00243 int tc_index = _filtered_texture->get_ff_tc_index(si);
00244 nassertr(tc_index < num_stages, orig);
00245 ff_tc_index[tc_index] = si;
00246 max_tc_index = max(tc_index, max_tc_index);
00247 }
00248
00249
00250
00251
00252 for (tc_index = 0; tc_index <= max_tc_index; ++tc_index) {
00253 si = ff_tc_index[tc_index];
00254 TextureStage *stage = _filtered_texture->get_on_ff_stage(si);
00255 InternalName *name = stage->get_texcoord_name();
00256
00257 const GeomVertexColumn *texcoord_type = orig->get_column(name);
00258
00259 if (texcoord_type != (const GeomVertexColumn *)NULL) {
00260 new_array_format->add_column
00261 (name, texcoord_type->get_num_values(), NT_float32, C_texcoord);
00262 } else {
00263
00264
00265 new_array_format->add_column(name, 2, NT_float32, C_texcoord);
00266 }
00267 new_format->remove_column(name);
00268 }
00269 }
00270
00271
00272
00273 new_format->insert_array(0, new_array_format);
00274
00275 return GeomVertexFormat::register_format(new_format);
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 int DXGeomMunger8::
00287 compare_to_impl(const GeomMunger *other) const {
00288 const DXGeomMunger8 *om = DCAST(DXGeomMunger8, other);
00289 if (_filtered_texture != om->_filtered_texture) {
00290 return _filtered_texture < om->_filtered_texture ? -1 : 1;
00291 }
00292 if (_tex_gen != om->_tex_gen) {
00293 return _tex_gen < om->_tex_gen ? -1 : 1;
00294 }
00295
00296 return StandardMunger::compare_to_impl(other);
00297 }
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 int DXGeomMunger8::
00308 geom_compare_to_impl(const GeomMunger *other) const {
00309
00310
00311
00312
00313 const DXGeomMunger8 *om = DCAST(DXGeomMunger8, other);
00314 if (_filtered_texture != om->_filtered_texture) {
00315 return _filtered_texture < om->_filtered_texture ? -1 : 1;
00316 }
00317 if (_tex_gen != om->_tex_gen) {
00318 return _tex_gen < om->_tex_gen ? -1 : 1;
00319 }
00320
00321 return StandardMunger::geom_compare_to_impl(other);
00322 }