From a72d85803483fda21972d6671b101c6c8e351dc7 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Mon, 27 Feb 2012 21:27:27 +0000 Subject: [PATCH] More robust checking of file extensions courtesy of the SGPath. Thanks to Mathias FROHLICH. --- simgear/scene/material/mat.cxx | 37 +++++++++++++++------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 9c8f208b..defab591 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -128,14 +128,6 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, tname = "unknown.rgb"; } - if ((tname.rfind(".dds") == (tname.length() - 4)) || - (tname.rfind(".DDS") == (tname.length() - 4)) ) - { - dds.push_back(true); - } else { - dds.push_back(false); - } - SGPath tpath("Textures.high"); tpath.append(tname); string fullTexPath = SGModelLib::findDataFile(tpath.str(), options); @@ -145,6 +137,12 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, fullTexPath = SGModelLib::findDataFile(tpath.str(), options); } + if (tpath.lower_extension() == "dds") { + dds.push_back(true); + } else { + dds.push_back(false); + } + if (!fullTexPath.empty() ) { _internal_state st( NULL, fullTexPath, false, options ); _status.push_back( st ); @@ -162,17 +160,7 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, if (tname.empty()) { tname = "unknown.rgb"; } - - if (j == 0) { - if ((tname.rfind(".dds") == (tname.length() - 4)) || - (tname.rfind(".DDS") == (tname.length() - 4)) ) - { - dds.push_back(true); - } else { - dds.push_back(false); - } - } - + SGPath tpath("Textures.high"); tpath.append(tname); string fullTexPath = SGModelLib::findDataFile(tpath.str(), options); @@ -182,6 +170,14 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, fullTexPath = SGModelLib::findDataFile(tpath.str(), options); } + if (j == 0) { + if (tpath.lower_extension() == "dds") { + dds.push_back(true); + } else { + dds.push_back(false); + } + } + st.add_texture(fullTexPath, textures[j]->getIndex()); } @@ -219,8 +215,7 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, { osg::Texture2D* object_mask = new osg::Texture2D; - bool dds_mask = ((omname.rfind(".dds") == (omname.length() - 4)) || - (omname.rfind(".DDS") == (omname.length() - 4)) ); + bool dds_mask = (ompath.lower_extension() == "dds"); if (dds[i] != dds_mask) { // Texture format does not match mask format. This is relevant for -- 2.39.5