From 4f99add87e1f67d8f508c5163fabeec33f64592d Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 10 Aug 2005 20:26:08 +0000 Subject: [PATCH] preserve case of texture filenames --- pandatool/src/palettizer/palettizer.cxx | 36 ++++++++++++++----- pandatool/src/palettizer/textureReference.cxx | 12 ++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/pandatool/src/palettizer/palettizer.cxx b/pandatool/src/palettizer/palettizer.cxx index 7ac2f0429f..34b3a28cf2 100644 --- a/pandatool/src/palettizer/palettizer.cxx +++ b/pandatool/src/palettizer/palettizer.cxx @@ -896,15 +896,25 @@ get_default_group() { //////////////////////////////////////////////////////////////////// TextureImage *Palettizer:: get_texture(const string &name) { + // Look first in the same-case name, just in case it happens to be + // there (from an older version of egg-palettize that did this). Textures::iterator ti = _textures.find(name); if (ti != _textures.end()) { return (*ti).second; } + // Then look in the downcase name, since we nowadays index textures + // only by their downcase names (to implement case insensitivity). + string downcase_name = downcase(name); + ti = _textures.find(downcase_name); + if (ti != _textures.end()) { + return (*ti).second; + } + TextureImage *image = new TextureImage; image->set_name(name); // image->set_filename(name); - _textures.insert(Textures::value_type(name, image)); + _textures.insert(Textures::value_type(downcase_name, image)); return image; } @@ -1120,9 +1130,9 @@ finalize(BamReader *manager) { ci != _texture_conflicts.end(); ++ci) { TextureImage *texture_b = (*ci); - string name = downcase(texture_b->get_name()); + string downcase_name = downcase(texture_b->get_name()); - Textures::iterator ti = _textures.find(name); + Textures::iterator ti = _textures.find(downcase_name); nassertv(ti != _textures.end()); TextureImage *texture_a = (*ti).second; _textures.erase(ti); @@ -1131,11 +1141,11 @@ finalize(BamReader *manager) { // If either texture is not used, there's not really a // conflict--the other one wins. if (texture_a->is_used()) { - bool inserted1 = _textures.insert(Textures::value_type(texture_a->get_name(), texture_a)).second; + bool inserted1 = _textures.insert(Textures::value_type(downcase_name, texture_a)).second; nassertd(inserted1) { } } else if (texture_b->is_used()) { - bool inserted2 = _textures.insert(Textures::value_type(texture_b->get_name(), texture_b)).second; + bool inserted2 = _textures.insert(Textures::value_type(downcase_name, texture_b)).second; nassertd(inserted2) { } } @@ -1143,9 +1153,19 @@ finalize(BamReader *manager) { // If both textures are used, there *is* a conflict. nout << "Texture name conflict: \"" << texture_a->get_name() << "\" vs. \"" << texture_b->get_name() << "\"\n"; - bool inserted1 = _textures.insert(Textures::value_type(texture_a->get_name(), texture_a)).second; - bool inserted2 = _textures.insert(Textures::value_type(texture_b->get_name(), texture_b)).second; - nassertd(inserted1 && inserted2) { } + if (texture_a->get_name() != downcase_name && + texture_b->get_name() != downcase_name) { + // Arbitrarily pick texture_a to get the right case. + bool inserted1 = _textures.insert(Textures::value_type(downcase_name, texture_a)).second; + bool inserted2 = _textures.insert(Textures::value_type(texture_b->get_name(), texture_b)).second; + nassertd(inserted1 && inserted2) { } + + } else { + // One of them is already the right case. + bool inserted1 = _textures.insert(Textures::value_type(texture_a->get_name(), texture_a)).second; + bool inserted2 = _textures.insert(Textures::value_type(texture_b->get_name(), texture_b)).second; + nassertd(inserted1 && inserted2) { } + } } } } diff --git a/pandatool/src/palettizer/textureReference.cxx b/pandatool/src/palettizer/textureReference.cxx index b7bc541cca..d41f8d4942 100644 --- a/pandatool/src/palettizer/textureReference.cxx +++ b/pandatool/src/palettizer/textureReference.cxx @@ -108,8 +108,18 @@ from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex) { _properties._magfilter = _egg_tex->get_magfilter(); _properties._anisotropic_degree = _egg_tex->get_anisotropic_degree(); - string name = downcase(filename.get_basename_wo_extension()); + string name = filename.get_basename_wo_extension(); TextureImage *texture = pal->get_texture(name); + if (texture->get_name() != name) { + nout << "Texture name conflict: \"" << name + << "\" conflicts with existing texture named \"" + << texture->get_name() << "\".\n"; + + // Make this a hard error; refuse to do anything else until the + // user fixes it. Case conflicts can be very bad, especially if + // CVS is involved on a Windows machine. + exit(1); + } _source_texture = texture->get_source(filename, alpha_filename, alpha_file_channel); _source_texture->update_properties(_properties);