root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osg/Depth.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/Depth"
2
3#include "osgDB/Registry"
4#include "osgDB/Input"
5#include "osgDB/Output"
6
7#include <string.h>
8
9#include <string.h>
10
11using namespace osg;
12using namespace osgDB;
13
14// forward declare functions to use later.
15bool Depth_readLocalData(Object& obj, Input& fr);
16bool Depth_writeLocalData(const Object& obj, Output& fw);
17
18bool Depth_matchFuncStr(const char* str,Depth::Function& func);
19const char* Depth_getFuncStr(Depth::Function func);
20
21
22// register the read and write functions with the osgDB::Registry.
23REGISTER_DOTOSGWRAPPER(Depth)
24(
25    new osg::Depth,
26    "Depth",
27    "Object StateAttribute Depth",
28    &Depth_readLocalData,
29    &Depth_writeLocalData
30);
31
32
33bool Depth_readLocalData(Object& obj, Input& fr)
34{
35    bool iteratorAdvanced = false;
36
37    Depth& depth = static_cast<Depth&>(obj);
38
39    Depth::Function func;
40    if (fr[0].matchWord("function") && Depth_matchFuncStr(fr[1].getStr(),func))
41    {
42        depth.setFunction(func);
43        fr+=2;
44        iteratorAdvanced = true;
45    }
46
47    if (fr[0].matchWord("writeMask"))
48    {
49        if (fr[1].matchWord("TRUE") || fr[1].matchWord("ON"))
50        {
51            depth.setWriteMask(true);
52            fr+=2;
53            iteratorAdvanced = true;
54        }
55        else if (fr[1].matchWord("FALSE") || fr[1].matchWord("OFF"))
56        {
57            depth.setWriteMask(false);
58            fr+=2;
59            iteratorAdvanced = true;
60        }
61    }
62
63    double znear,zfar;
64    if (fr[0].matchWord("range") && fr[1].getFloat(znear) && fr[2].getFloat(zfar))
65    {
66        depth.setRange(znear,zfar);
67        fr+=2;
68        iteratorAdvanced = true;
69    }
70
71    return iteratorAdvanced;
72}
73
74
75bool Depth_writeLocalData(const Object& obj,Output& fw)
76{
77    const Depth& depth = static_cast<const Depth&>(obj);
78
79    fw.indent() << "function " << Depth_getFuncStr(depth.getFunction()) << std::endl;
80
81    fw.indent() << "writeMask ";
82    if (depth.getWriteMask()) fw << "TRUE" << std::endl;
83    else fw << "FALSE" << std::endl;
84
85    fw.indent() << "range " << depth.getZNear() << " " << depth.getZFar() << std::endl;
86
87    return true;
88}
89
90
91bool Depth_matchFuncStr(const char* str,Depth::Function& func)
92{
93    if (strcmp(str,"NEVER")==0) func = Depth::NEVER;
94    else if (strcmp(str,"LESS")==0) func = Depth::LESS;
95    else if (strcmp(str,"EQUAL")==0) func = Depth::EQUAL;
96    else if (strcmp(str,"LEQUAL")==0) func = Depth::LEQUAL;
97    else if (strcmp(str,"GREATER")==0) func = Depth::GREATER;
98    else if (strcmp(str,"NOTEQUAL")==0) func = Depth::NOTEQUAL;
99    else if (strcmp(str,"GEQUAL")==0) func = Depth::GEQUAL;
100    else if (strcmp(str,"ALWAYS")==0) func = Depth::ALWAYS;
101    else return false;
102    return true;
103}
104
105
106const char* Depth_getFuncStr(Depth::Function func)
107{
108    switch(func)
109    {
110        case(Depth::NEVER): return "NEVER";
111        case(Depth::LESS): return "LESS";
112        case(Depth::EQUAL): return "EQUAL";
113        case(Depth::LEQUAL): return "LEQUAL";
114        case(Depth::GREATER): return "GREATER";
115        case(Depth::NOTEQUAL): return "NOTEQUAL";
116        case(Depth::GEQUAL): return "GEQUAL";
117        case(Depth::ALWAYS): return "ALWAYS";
118    }
119    return "";
120}
Note: See TracBrowser for help on using the browser.