mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-28 22:13:21 +00:00
Add helper method for texture type recovery
This commit is contained in:
parent
84f4ba4ca1
commit
908f3891fb
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
#include <components/files/conversion.hpp>
|
#include <components/files/conversion.hpp>
|
||||||
#include <components/misc/strings/conversion.hpp>
|
#include <components/misc/strings/conversion.hpp>
|
||||||
#include <components/sceneutil/texturetype.hpp>
|
#include <components/sceneutil/util.hpp>
|
||||||
#include <components/vfs/manager.hpp>
|
#include <components/vfs/manager.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
@ -107,12 +107,7 @@ namespace
|
|||||||
std::string fileName;
|
std::string fileName;
|
||||||
if (image)
|
if (image)
|
||||||
fileName = image->getFileName();
|
fileName = image->getFileName();
|
||||||
const osg::StateAttribute* type
|
mTextures.emplace_back(SceneUtil::getTextureType(*stateset, *texture, i), fileName);
|
||||||
= 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,4 +408,12 @@ namespace SceneUtil
|
|||||||
return osg::Image::computePixelFormat(format);
|
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
|
// Compute the unsized format equivalent to the given pixel format
|
||||||
// Unlike osg::Image::computePixelFormat, this also covers compressed formats
|
// Unlike osg::Image::computePixelFormat, this also covers compressed formats
|
||||||
GLenum computeUnsizedPixelFormat(GLenum format);
|
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
|
#endif
|
||||||
|
@ -330,14 +330,7 @@ namespace Shader
|
|||||||
const osg::Texture* texture = attr->asTexture();
|
const osg::Texture* texture = attr->asTexture();
|
||||||
if (texture)
|
if (texture)
|
||||||
{
|
{
|
||||||
std::string texName;
|
std::string texName = SceneUtil::getTextureType(*stateset, *texture, unit);
|
||||||
const osg::StateAttribute* type
|
|
||||||
= stateset->getTextureAttribute(unit, SceneUtil::TextureType::AttributeType);
|
|
||||||
if (type)
|
|
||||||
texName = static_cast<const SceneUtil::TextureType*>(type)->getName();
|
|
||||||
else
|
|
||||||
texName = texture->getName();
|
|
||||||
|
|
||||||
if ((texName.empty() || !isTextureNameRecognized(texName)) && unit == 0)
|
if ((texName.empty() || !isTextureNameRecognized(texName)) && unit == 0)
|
||||||
texName = "diffuseMap";
|
texName = "diffuseMap";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user