mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
6ef848b7c5
Instead use getImage and let the caller create the Texture. Sharing of textures is then handled in post by the SharedStateManager. This is closer to what the OSG serializer does. Streamlines the TextureManager and will make it easier to multithread.
34 lines
1.1 KiB
C++
34 lines
1.1 KiB
C++
#include "util.hpp"
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <components/resource/resourcesystem.hpp>
|
|
#include <components/resource/texturemanager.hpp>
|
|
#include <components/misc/resourcehelpers.hpp>
|
|
|
|
namespace MWRender
|
|
{
|
|
|
|
void overrideTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node)
|
|
{
|
|
if (texture.empty())
|
|
return;
|
|
std::string correctedTexture = Misc::ResourceHelpers::correctTexturePath(texture, resourceSystem->getVFS());
|
|
// Not sure if wrap settings should be pulled from the overridden texture?
|
|
osg::ref_ptr<osg::Texture2D> tex = new osg::Texture2D(resourceSystem->getTextureManager()->getImage(correctedTexture));
|
|
tex->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
tex->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
osg::ref_ptr<osg::StateSet> stateset;
|
|
if (node->getStateSet())
|
|
stateset = static_cast<osg::StateSet*>(node->getStateSet()->clone(osg::CopyOp::SHALLOW_COPY));
|
|
else
|
|
stateset = new osg::StateSet;
|
|
|
|
stateset->setTextureAttribute(0, tex, osg::StateAttribute::OVERRIDE);
|
|
|
|
node->setStateSet(stateset);
|
|
}
|
|
|
|
}
|