mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Pregenerate glow texture names
To avoid strings generation and allocations every time model is added to a scene.
This commit is contained in:
parent
2fc87efa8f
commit
3ad79e3b3e
1 changed files with 23 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "util.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -17,6 +18,26 @@
|
|||
|
||||
namespace SceneUtil
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::array<std::string, 32> generateGlowTextureNames()
|
||||
{
|
||||
std::array<std::string, 32> result;
|
||||
for (std::size_t i = 0; i < result.size(); ++i)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << "textures/magicitem/caust";
|
||||
stream << std::setw(2);
|
||||
stream << std::setfill('0');
|
||||
stream << i;
|
||||
stream << ".dds";
|
||||
result[i] = std::move(stream).str();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const std::array<std::string, 32> glowTextureNames = generateGlowTextureNames();
|
||||
}
|
||||
|
||||
class FindLowestUnusedTexUnitVisitor : public osg::NodeVisitor
|
||||
{
|
||||
|
@ -197,16 +218,9 @@ namespace SceneUtil
|
|||
const osg::Vec4f& glowColor, float glowDuration)
|
||||
{
|
||||
std::vector<osg::ref_ptr<osg::Texture2D>> textures;
|
||||
for (int i = 0; i < 32; ++i)
|
||||
for (const std::string& name : glowTextureNames)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << "textures/magicitem/caust";
|
||||
stream << std::setw(2);
|
||||
stream << std::setfill('0');
|
||||
stream << i;
|
||||
stream << ".dds";
|
||||
|
||||
osg::ref_ptr<osg::Image> image = resourceSystem->getImageManager()->getImage(stream.str());
|
||||
osg::ref_ptr<osg::Image> image = resourceSystem->getImageManager()->getImage(name);
|
||||
osg::ref_ptr<osg::Texture2D> tex(new osg::Texture2D(image));
|
||||
tex->setName("envMap");
|
||||
tex->setWrap(osg::Texture::WRAP_S, osg::Texture2D::REPEAT);
|
||||
|
|
Loading…
Reference in a new issue