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

Revision 13041, 2.9 kB (checked in by robert, 3 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/Texture3D"
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 Texture3D_readLocalData(Object& obj, Input& fr);
14bool Texture3D_writeLocalData(const Object& obj, Output& fw);
15
16bool Texture3D_matchWrapStr(const char* str,Texture3D::WrapMode& wrap);
17const char* Texture3D_getWrapStr(Texture3D::WrapMode wrap);
18bool Texture3D_matchFilterStr(const char* str,Texture3D::FilterMode& filter);
19const char* Texture3D_getFilterStr(Texture3D::FilterMode filter);
20bool Texture3D_matchInternalFormatModeStr(const char* str,Texture3D::InternalFormatMode& mode);
21const char* Texture3D_getInternalFormatModeStr(Texture3D::InternalFormatMode mode);
22bool Texture3D_matchInternalFormatStr(const char* str,int& value);
23const char* Texture3D_getInternalFormatStr(int value);
24
25// register the read and write functions with the osgDB::Registry.
26REGISTER_DOTOSGWRAPPER(Texture3D)
27(
28    new osg::Texture3D,
29    "Texture3D",
30    "Object StateAttribute Texture3D TextureBase",
31    &Texture3D_readLocalData,
32    &Texture3D_writeLocalData
33);
34
35bool Texture3D_readLocalData(Object& obj, Input& fr)
36{
37    bool iteratorAdvanced = false;
38
39    Texture3D& texture = static_cast<Texture3D&>(obj);
40
41    if (fr[0].matchWord("file") && fr[1].isString())
42    {
43        std::string filename = fr[1].getStr();
44        Image* image = fr.readImage(filename.c_str());
45        if (image)
46        {
47            // name will have already been set by the image plugin,
48            // but it will have absolute path, so will override it
49            // here to keep the original name intact.
50            //image->setFileName(filename);
51            texture.setImage(image);
52        }
53
54        fr += 2;
55        iteratorAdvanced = true;
56    }
57
58    if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image"))
59    {
60        osg::Image* image = fr.readImage();
61        if (image) texture.setImage(image);
62    }
63
64    return iteratorAdvanced;
65}
66
67bool Texture3D_writeLocalData(const Object& obj, Output& fw)
68{
69    const Texture3D& texture = static_cast<const Texture3D&>(obj);
70
71    if (texture.getImage())
72    {
73        const osg::ImageSequence* is = dynamic_cast<const osg::ImageSequence*>(texture.getImage());
74        if (is)
75        {
76            fw.writeObject(*is);
77        }
78        else
79        {
80            std::string fileName = texture.getImage()->getFileName();
81            if (fw.getOutputTextureFiles())
82            {
83                if (fileName.empty())
84                {
85                    fileName = fw.getTextureFileNameForOutput();
86                }
87                osgDB::writeImageFile(*texture.getImage(), fileName);
88            }
89
90            if (!fileName.empty())
91            {
92                fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl;
93            }
94        }
95    }
96
97    return true;
98}
Note: See TracBrowser for help on using the browser.