File: texturemanager.cpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (60 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "texturemanager.hpp"

#include <osg/Texture2D>

#include <components/resource/imagemanager.hpp>
#include <components/resource/objectcache.hpp>
#include <components/resource/scenemanager.hpp>

namespace Terrain
{

    TextureManager::TextureManager(Resource::SceneManager* sceneMgr, double expiryDelay)
        : ResourceManager(sceneMgr->getVFS(), expiryDelay)
        , mSceneManager(sceneMgr)
    {
    }

    struct UpdateTextureFilteringFunctor
    {
        UpdateTextureFilteringFunctor(Resource::SceneManager* sceneMgr)
            : mSceneManager(sceneMgr)
        {
        }
        Resource::SceneManager* mSceneManager;

        void operator()(std::string, osg::Object* obj)
        {
            mSceneManager->applyFilterSettings(static_cast<osg::Texture2D*>(obj));
        }
    };

    void TextureManager::updateTextureFiltering()
    {
        UpdateTextureFilteringFunctor f(mSceneManager);
        mCache->call(f);
    }

    osg::ref_ptr<osg::Texture2D> TextureManager::getTexture(VFS::Path::NormalizedView name)
    {
        // don't bother with case folding, since there is only one way of referring to terrain textures we can assume
        // the case is always the same
        osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(name);

        if (obj != nullptr)
            return static_cast<osg::Texture2D*>(obj.get());

        osg::ref_ptr<osg::Texture2D> texture(new osg::Texture2D(mSceneManager->getImageManager()->getImage(name)));
        texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
        texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
        mSceneManager->applyFilterSettings(texture);
        mCache->addEntryToObjectCache(name.value(), texture.get());
        return texture;
    }

    void TextureManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const
    {
        Resource::reportStats("Terrain Texture", frameNumber, mCache->getStats(), *stats);
    }

}