From 8dbabc8b434c3a99743c91055402aa9d5c5d02ba Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 7 Apr 2020 12:12:52 +0100 Subject: [PATCH] Texture-compression fixes Rename a highly confusing method, and disable the older texture- compression code since it interacts badly with the new texture-cache. --- simgear/scene/material/TextureBuilder.cxx | 4 ++-- simgear/scene/model/ModelRegistry.cxx | 13 ++++++++++--- simgear/scene/model/model.cxx | 4 ++-- simgear/scene/util/SGSceneFeatures.cxx | 8 +++++++- simgear/scene/util/SGSceneFeatures.hxx | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index 6fff6348..dd228fd4 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -292,9 +292,9 @@ bool setAttrs(const TexTuple& attrs, Texture* tex, int s = image->s(); int t = image->t(); if (s <= t && 32 <= s) { - SGSceneFeatures::instance()->setTextureCompression(tex); + SGSceneFeatures::instance()->applyTextureCompression(tex); } else if (t < s && 32 <= t) { - SGSceneFeatures::instance()->setTextureCompression(tex); + SGSceneFeatures::instance()->applyTextureCompression(tex); } tex->setMaxAnisotropy(SGSceneFeatures::instance()->getTextureFilter()); } else { diff --git a/simgear/scene/model/ModelRegistry.cxx b/simgear/scene/model/ModelRegistry.cxx index 3178d206..5e2bcdf4 100644 --- a/simgear/scene/model/ModelRegistry.cxx +++ b/simgear/scene/model/ModelRegistry.cxx @@ -117,7 +117,9 @@ protected: } }; - +// disabling old-syle texture compression in favour of the +// texture-cache +#if 0 class SGTexCompressionVisitor : public SGTextureStateAttributeVisitor { public: virtual void apply(int, StateSet::RefAttributePair& refAttr) @@ -142,12 +144,13 @@ public: int t = image->t(); if (s <= t && 32 <= s) { - SGSceneFeatures::instance()->setTextureCompression(texture); + SGSceneFeatures::instance()->applyTextureCompression(texture); } else if (t < s && 32 <= t) { - SGSceneFeatures::instance()->setTextureCompression(texture); + SGSceneFeatures::instance()->applyTextureCompression(texture); } } }; +#endif class SGTexDataVarianceVisitor : public SGTextureStateAttributeVisitor { public: @@ -645,8 +648,12 @@ osg::Node* OptimizeModelPolicy::optimize(osg::Node* node, SGTexDataVarianceVisitor dataVarianceVisitor; node->accept(dataVarianceVisitor); +// disabling old-syle texture compression in favour of the +// texture-cache +#if 0 SGTexCompressionVisitor texComp; node->accept(texComp); +#endif return node; } diff --git a/simgear/scene/model/model.cxx b/simgear/scene/model/model.cxx index 3eea102f..008fdeb5 100644 --- a/simgear/scene/model/model.cxx +++ b/simgear/scene/model/model.cxx @@ -75,9 +75,9 @@ SGLoadTexture2D(bool staticTexture, const std::string& path, int t = image->t(); if (s <= t && 32 <= s) { - SGSceneFeatures::instance()->setTextureCompression(texture.get()); + SGSceneFeatures::instance()->applyTextureCompression(texture.get()); } else if (t < s && 32 <= t) { - SGSceneFeatures::instance()->setTextureCompression(texture.get()); + SGSceneFeatures::instance()->applyTextureCompression(texture.get()); } } diff --git a/simgear/scene/util/SGSceneFeatures.cxx b/simgear/scene/util/SGSceneFeatures.cxx index f17b52ac..f04ff858 100644 --- a/simgear/scene/util/SGSceneFeatures.cxx +++ b/simgear/scene/util/SGSceneFeatures.cxx @@ -67,8 +67,13 @@ SGSceneFeatures::instance() } void -SGSceneFeatures::setTextureCompression(osg::Texture* texture) const +SGSceneFeatures::applyTextureCompression(osg::Texture* texture) const { + // disable older texture-compression, since it interacts confusingly + // with the the runtime texture-cache. We always want to use + // 'USE_IMAGE_DATA_FORMAT' when the texture-cache is active, since we + // decided whether to compress (or not) prior to this point. +#if 0 switch (_textureCompression) { case UseARBCompression: texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION); @@ -86,6 +91,7 @@ SGSceneFeatures::setTextureCompression(osg::Texture* texture) const texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT); break; } +#endif } bool diff --git a/simgear/scene/util/SGSceneFeatures.hxx b/simgear/scene/util/SGSceneFeatures.hxx index cb9453d5..9be4e99a 100644 --- a/simgear/scene/util/SGSceneFeatures.hxx +++ b/simgear/scene/util/SGSceneFeatures.hxx @@ -58,7 +58,7 @@ public: TextureCompression getTextureCompression() const { return _textureCompression; } // modify the texture compression on the texture parameter - void setTextureCompression(osg::Texture* texture) const; + void applyTextureCompression(osg::Texture* texture) const; void setEnablePointSpriteLights(bool enable) {