From 39d45e9e0a8585abd25e8ddeaa77241fb4eee388 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sun, 26 Feb 2012 22:38:38 +0000 Subject: [PATCH] Handle dds object masks properly: 1) Only flip the object-mask if the texture xor the object mask is dds 2) Handle NTFS file systems where the extension may be .DDS rather than .dds. --- simgear/scene/material/mat.cxx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 5888b867..9c8f208b 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -128,7 +128,9 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, tname = "unknown.rgb"; } - if (tname.rfind(".dds") == (tname.length() - 4)) { + if ((tname.rfind(".dds") == (tname.length() - 4)) || + (tname.rfind(".DDS") == (tname.length() - 4)) ) + { dds.push_back(true); } else { dds.push_back(false); @@ -162,7 +164,9 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, } if (j == 0) { - if (tname.rfind(".dds") == (tname.length() - 4)) { + if ((tname.rfind(".dds") == (tname.length() - 4)) || + (tname.rfind(".DDS") == (tname.length() - 4)) ) + { dds.push_back(true); } else { dds.push_back(false); @@ -215,10 +219,14 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, { osg::Texture2D* object_mask = new osg::Texture2D; - if (dds[i]) { - // Texture is a DDS. This is relevant for the object mask, as DDS - // textures have an origin at the bottom left rather than top - // left, therefore we flip the object mask vertically. + bool dds_mask = ((omname.rfind(".dds") == (omname.length() - 4)) || + (omname.rfind(".DDS") == (omname.length() - 4)) ); + + if (dds[i] != dds_mask) { + // Texture format does not match mask format. This is relevant for + // the object mask, as DDS textures have an origin at the bottom + // left rather than top left, therefore we flip the object mask + // vertically. image->flipVertical(); } -- 2.39.5