root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgTerrain/Layer.cpp @ 13041

Revision 13041, 3.8 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include <osgTerrain/Layer>
2
3#include <iostream>
4#include <string>
5
6#include <osg/Vec3>
7#include <osg/Vec4>
8#include <osg/io_utils>
9
10#include <osgDB/ReadFile>
11#include <osgDB/Registry>
12#include <osgDB/Input>
13#include <osgDB/Output>
14#include <osgDB/ParameterOutput>
15
16#include <string.h>
17
18bool Layer_readLocalData(osg::Object &obj, osgDB::Input &fr);
19bool Layer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
20bool Layer_matchFilterStr(const char* str, osg::Texture::FilterMode& filter);
21const char* Layer_getFilterStr(osg::Texture::FilterMode filter);
22
23REGISTER_DOTOSGWRAPPER(Layer_Proxy)
24(
25    new osgTerrain::Layer,
26    "Layer",
27    "Object Layer",
28    Layer_readLocalData,
29    Layer_writeLocalData
30);
31
32bool Layer_readLocalData(osg::Object& obj, osgDB::Input &fr)
33{
34    osgTerrain::Layer& layer = static_cast<osgTerrain::Layer&>(obj);
35
36    bool itrAdvanced = false;
37
38    osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgTerrain::Locator>());
39    osgTerrain::Locator* locator = dynamic_cast<osgTerrain::Locator*>(readObject.get());
40    if (locator) layer.setLocator(locator);
41
42    osg::Texture::FilterMode filter;
43    if (fr[0].matchWord("MinFilter") && Layer_matchFilterStr(fr[1].getStr(),filter))
44    {
45        layer.setMinFilter(filter);
46        fr+=2;
47        itrAdvanced = true;
48    }
49
50    if ((fr[0].matchWord("Filter") || fr[0].matchWord("MagFilter")) &&
51        Layer_matchFilterStr(fr[1].getStr(),filter))
52    {
53        layer.setMagFilter(filter);
54        fr+=2;
55        itrAdvanced = true;
56    }
57
58
59    unsigned int minLevel=0;
60    if (fr.read("MinLevel",minLevel))
61    {
62        itrAdvanced = true;
63        layer.setMinLevel(minLevel);
64    }
65
66    unsigned int maxLevel = MAXIMUM_NUMBER_OF_LEVELS;
67    if (fr.read("MaxLevel",maxLevel))
68    {
69        itrAdvanced = true;
70        layer.setMaxLevel(maxLevel);
71    }
72
73    return itrAdvanced;
74}
75
76bool Layer_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
77{
78    const osgTerrain::Layer& layer = static_cast<const osgTerrain::Layer&>(obj);
79
80    if (layer.getLocator() && !(layer.getLocator()->getDefinedInFile()))
81    {
82        fw.writeObject(*layer.getLocator());
83    }
84
85    fw.indent()<<"MinFilter "<<Layer_getFilterStr(layer.getMinFilter())<<std::endl;
86    fw.indent()<<"MagFilter "<<Layer_getFilterStr(layer.getMagFilter())<<std::endl;
87
88    if (layer.getMinLevel()!=0)
89    {
90        fw.indent()<<"MinLevel "<<layer.getMinLevel()<<std::endl;
91    }
92
93    if (layer.getMaxLevel()!=MAXIMUM_NUMBER_OF_LEVELS)
94    {
95        fw.indent()<<"MaxLevel "<<layer.getMaxLevel()<<std::endl;
96    }
97
98    return true;
99}
100
101bool Layer_matchFilterStr(const char* str, osg::Texture::FilterMode& filter)
102{
103    if (strcmp(str,"NEAREST")==0) filter = osg::Texture::NEAREST;
104    else if (strcmp(str,"LINEAR")==0) filter = osg::Texture::LINEAR;
105    else if (strcmp(str,"NEAREST_MIPMAP_NEAREST")==0) filter = osg::Texture::NEAREST_MIPMAP_NEAREST;
106    else if (strcmp(str,"LINEAR_MIPMAP_NEAREST")==0) filter = osg::Texture::LINEAR_MIPMAP_NEAREST;
107    else if (strcmp(str,"NEAREST_MIPMAP_LINEAR")==0) filter = osg::Texture::NEAREST_MIPMAP_LINEAR;
108    else if (strcmp(str,"LINEAR_MIPMAP_LINEAR")==0) filter = osg::Texture::LINEAR_MIPMAP_LINEAR;
109    else if (strcmp(str,"ANISOTROPIC")==0) filter = osg::Texture::LINEAR;
110    else return false;
111    return true;
112}
113
114
115const char* Layer_getFilterStr(osg::Texture::FilterMode filter)
116{
117    switch(filter)
118    {
119        case(osg::Texture::NEAREST): return "NEAREST";
120        case(osg::Texture::LINEAR): return "LINEAR";
121        case(osg::Texture::NEAREST_MIPMAP_NEAREST): return "NEAREST_MIPMAP_NEAREST";
122        case(osg::Texture::LINEAR_MIPMAP_NEAREST): return "LINEAR_MIPMAP_NEAREST";
123        case(osg::Texture::NEAREST_MIPMAP_LINEAR): return "NEAREST_MIPMAP_LINEAR";
124        case(osg::Texture::LINEAR_MIPMAP_LINEAR): return "LINEAR_MIPMAP_LINEAR";
125    }
126    return "";
127}
Note: See TracBrowser for help on using the browser.