root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osg/Texture2D.cpp @ 13041

Revision 13041, 3.1 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include "osg/Texture2D"
2#include "osg/ImageSequence"
3
4#include "osgDB/Registry"
5#include "osgDB/Input"
6#include "osgDB/Output"
7#include "osgDB/WriteFile"
8
9using namespace osg;
10using namespace osgDB;
11
12// forward declare functions to use later.
13bool Texture2D_readLocalData(Object& obj, Input& fr);
14bool Texture2D_writeLocalData(const Object& obj, Output& fw);
15
16bool Texture2D_matchWrapStr(const char* str,Texture2D::WrapMode& wrap);
17const char* Texture2D_getWrapStr(Texture2D::WrapMode wrap);
18bool Texture2D_matchFilterStr(const char* str,Texture2D::FilterMode& filter);
19const char* Texture2D_getFilterStr(Texture2D::FilterMode filter);
20bool Texture2D_matchInternalFormatModeStr(const char* str,Texture2D::InternalFormatMode& mode);
21const char* Texture2D_getInternalFormatModeStr(Texture2D::InternalFormatMode mode);
22bool Texture2D_matchInternalFormatStr(const char* str,int& value);
23const char* Texture2D_getInternalFormatStr(int value);
24
25REGISTER_DOTOSGWRAPPER(OldTexture)
26(
27    new osg::Texture2D,
28    "Texture",
29    "Object StateAttribute Texture2D TextureBase",
30    0,
31    0
32);
33
34// register the read and write functions with the osgDB::Registry.
35REGISTER_DOTOSGWRAPPER(Texture2D)
36(
37    new osg::Texture2D,
38    "Texture2D",
39    "Object StateAttribute Texture2D TextureBase",
40    &Texture2D_readLocalData,
41    &Texture2D_writeLocalData
42);
43
44bool Texture2D_readLocalData(Object& obj, Input& fr)
45{
46    bool iteratorAdvanced = false;
47
48    Texture2D& texture = static_cast<Texture2D&>(obj);
49
50    if (fr[0].matchWord("file") && fr[1].isString())
51    {
52        std::string filename = fr[1].getStr();
53        Image* image = fr.readImage(filename.c_str());
54        if (image)
55        {
56            // name will have already been set by the image plugin,
57            // but it will have absolute path, so will override it
58            // here to keep the original name intact.
59            //image->setFileName(filename);
60            texture.setImage(image);
61        }
62
63        fr += 2;
64        iteratorAdvanced = true;
65    }
66
67    if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image"))
68    {
69        osg::Image* image = fr.readImage();
70        if (image) texture.setImage(image);
71    }
72
73    return iteratorAdvanced;
74}
75
76bool Texture2D_writeLocalData(const Object& obj, Output& fw)
77{
78    const Texture2D& texture = static_cast<const Texture2D&>(obj);
79
80    if (texture.getImage())
81    {
82        const osg::ImageSequence* is = dynamic_cast<const osg::ImageSequence*>(texture.getImage());
83        if (is)
84        {
85            fw.writeObject(*is);
86        }
87        else
88        {
89            std::string fileName = texture.getImage()->getFileName();
90            if (fw.getOutputTextureFiles())
91            {
92                if (fileName.empty())
93                {
94                    fileName = fw.getTextureFileNameForOutput();
95                }
96                osgDB::writeImageFile(*texture.getImage(), fileName);
97            }
98
99            if (!fileName.empty())
100            {
101                fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl;
102            }
103        }
104    }
105
106    return true;
107}
Note: See TracBrowser for help on using the browser.