From 65542e7521a2832dab0423b2c5bfee97490140cf Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Mon, 3 Jan 2022 17:17:17 +0000 Subject: [PATCH] WS30: Disable texture cache for material atlas The texture cache interacts badly with the code creating the WS30 texture atlas, resulting in a bad atlas. This change adds a new SGReaderWriterOptions::LoadOriginHint::ORIGIN_MATERIAL_ATLAS which causes the material cache not to cache the texture. --- simgear/scene/material/matlib.cxx | 9 ++++++--- simgear/scene/model/ModelRegistry.cxx | 2 +- simgear/scene/util/SGReaderWriterOptions.hxx | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index 05f27692..6065f1f4 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -327,9 +327,9 @@ SGMaterial *SGMaterialCache::find(int lc) const } // Generate a texture atlas for this location -SGMaterialCache::Atlas SGMaterialLib::getMaterialTextureAtlas(SGVec2f center, const simgear::SGReaderWriterOptions* options) +SGMaterialCache::Atlas SGMaterialLib::getMaterialTextureAtlas(SGVec2f center, const simgear::SGReaderWriterOptions* const_options) { - SGMaterialCache::Atlas atlas; + SGMaterialCache::Atlas atlas; // Non-VPB does not use the Atlas, so save some effort and return if (! SGSceneFeatures::instance()->getVPBActive()) return atlas; @@ -349,10 +349,13 @@ SGMaterialCache::Atlas SGMaterialLib::getMaterialTextureAtlas(SGVec2f center, co if (atlas_iter != _atlasCache.end()) return atlas_iter->second; // Cache lookup failure - generate a new atlas, but only if we have a chance of reading any textures - if (options == 0) { + if (const_options == 0) { return atlas; } + osg::ref_ptr options = SGReaderWriterOptions::copyOrCreate(const_options); + options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_MATERIAL_ATLAS); + atlas.image = new osg::Texture2DArray(); SG_LOG(SG_TERRAIN, SG_DEBUG, "Generating atlas of size " << landclasslib.size()); diff --git a/simgear/scene/model/ModelRegistry.cxx b/simgear/scene/model/ModelRegistry.cxx index f48b8710..ffac1b46 100644 --- a/simgear/scene/model/ModelRegistry.cxx +++ b/simgear/scene/model/ModelRegistry.cxx @@ -299,7 +299,7 @@ ModelRegistry::readImage(const string& fileName, ec.addFromMap(sgoptC->getModelData()->getErrorContext()); } - if (cache_active && (!sgoptC || sgoptC->getLoadOriginHint() != SGReaderWriterOptions::LoadOriginHint::ORIGIN_SPLASH_SCREEN)) { + if (cache_active && (!sgoptC || (sgoptC->getLoadOriginHint() != SGReaderWriterOptions::LoadOriginHint::ORIGIN_SPLASH_SCREEN && sgoptC->getLoadOriginHint() != SGReaderWriterOptions::LoadOriginHint::ORIGIN_MATERIAL_ATLAS))) { if (fileExtension != "dds" && fileExtension != "gz") { std::string root = getPathRoot(absFileName); diff --git a/simgear/scene/util/SGReaderWriterOptions.hxx b/simgear/scene/util/SGReaderWriterOptions.hxx index 9122c83a..d484df0f 100644 --- a/simgear/scene/util/SGReaderWriterOptions.hxx +++ b/simgear/scene/util/SGReaderWriterOptions.hxx @@ -47,6 +47,7 @@ public: ORIGIN_EFFECTS_NORMALIZED, ORIGIN_SPLASH_SCREEN, ORIGIN_CANVAS, + ORIGIN_MATERIAL_ATLAS }; //SGReaderWriterOptions* cloneOptions(const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) const { return static_cast(clone(copyop)); }