Add helper method for texture type recovery

esm4-texture
Alexei Kotov 7 months ago
parent 84f4ba4ca1
commit 908f3891fb

@ -47,7 +47,7 @@
#include <components/files/conversion.hpp>
#include <components/misc/strings/conversion.hpp>
#include <components/sceneutil/texturetype.hpp>
#include <components/sceneutil/util.hpp>
#include <components/vfs/manager.hpp>
#include "../mwbase/environment.hpp"
@ -107,12 +107,7 @@ namespace
std::string fileName;
if (image)
fileName = image->getFileName();
const osg::StateAttribute* type
= stateset->getTextureAttribute(i, SceneUtil::TextureType::AttributeType);
if (type)
mTextures.emplace_back(static_cast<const SceneUtil::TextureType*>(type)->getName(), fileName);
else
mTextures.emplace_back(texture->getName(), fileName);
mTextures.emplace_back(SceneUtil::getTextureType(*stateset, *texture, i), fileName);
}
}

@ -408,4 +408,12 @@ namespace SceneUtil
return osg::Image::computePixelFormat(format);
}
const std::string& getTextureType(const osg::StateSet& stateset, const osg::Texture& texture, unsigned int texUnit)
{
const osg::StateAttribute* type = stateset.getTextureAttribute(texUnit, SceneUtil::TextureType::AttributeType);
if (type)
return static_cast<const SceneUtil::TextureType*>(type)->getName();
return texture.getName();
}
}

@ -116,6 +116,10 @@ namespace SceneUtil
// Compute the unsized format equivalent to the given pixel format
// Unlike osg::Image::computePixelFormat, this also covers compressed formats
GLenum computeUnsizedPixelFormat(GLenum format);
// Recover the presumed texture type for the given texture unit
// It may be set as a state attribute or it may come from the used texture's name
const std::string& getTextureType(const osg::StateSet& stateset, const osg::Texture& texture, unsigned int texUnit);
}
#endif

@ -330,14 +330,7 @@ namespace Shader
const osg::Texture* texture = attr->asTexture();
if (texture)
{
std::string texName;
const osg::StateAttribute* type
= stateset->getTextureAttribute(unit, SceneUtil::TextureType::AttributeType);
if (type)
texName = static_cast<const SceneUtil::TextureType*>(type)->getName();
else
texName = texture->getName();
std::string texName = SceneUtil::getTextureType(*stateset, *texture, unit);
if ((texName.empty() || !isTextureNameRecognized(texName)) && unit == 0)
texName = "diffuseMap";

Loading…
Cancel
Save