From 3b62e203f754717c49ea256c425642801d251759 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 11 Mar 2016 14:25:21 -0800 Subject: [PATCH] Cache NetworkGeometry::_hasTransparentTextures --- .../model-networking/src/model-networking/ModelCache.cpp | 6 +++++- .../model-networking/src/model-networking/ModelCache.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 29c517594a..af9fe97e93 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -135,6 +135,8 @@ bool NetworkGeometry::isLoadedWithTextures() const { } if (!_isLoadedWithTextures) { + _hasTransparentTextures = false; + for (auto&& material : _materials) { if ((material->albedoTexture && !material->albedoTexture->isLoaded()) || (material->normalTexture && !material->normalTexture->isLoaded()) || @@ -148,7 +150,9 @@ bool NetworkGeometry::isLoadedWithTextures() const { if (material->albedoTexture) { // Reset the materialKey transparentTexture key only, as it is albedoTexture-dependent const auto& usage = material->albedoTexture->getGPUTexture()->getUsage(); - material->_material->setTransparentTexture(usage.isAlpha() && !usage.isAlphaMask()); + bool isTransparentTexture = usage.isAlpha() && !usage.isAlphaMask(); + material->_material->setTransparentTexture(isTransparentTexture); + _hasTransparentTextures = _hasTransparentTextures || isTransparentTexture; } } diff --git a/libraries/model-networking/src/model-networking/ModelCache.h b/libraries/model-networking/src/model-networking/ModelCache.h index 60f185f691..7f01bdafaa 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.h +++ b/libraries/model-networking/src/model-networking/ModelCache.h @@ -75,6 +75,10 @@ public: // true when the requested geometry and its textures are loaded. bool isLoadedWithTextures() const; + // true if the albedo texture has a non-masking alpha channel. + // This can only be known after isLoadedWithTextures(). + bool hasTransparentTextures() const { return _hasTransparentTextures; } + // WARNING: only valid when isLoaded returns true. const FBXGeometry& getFBXGeometry() const { return *_geometry; } const std::vector>& getMeshes() const { return _meshes; } @@ -151,6 +155,7 @@ protected: // cache for isLoadedWithTextures() mutable bool _isLoadedWithTextures = false; + mutable bool _hasTransparentTextures = false; }; /// Reads geometry in a worker thread.