Cache NetworkGeometry::_hasTransparentTextures

This commit is contained in:
Zach Pomerantz 2016-03-11 14:25:21 -08:00
parent 22d41c833f
commit 3b62e203f7
2 changed files with 10 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -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<std::unique_ptr<NetworkMesh>>& 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.