]> git.tdb.fi Git - libs/gl.git/blob - source/core/stenciltest.cpp
Completely hide OpenGL from the public headers
[libs/gl.git] / source / core / stenciltest.cpp
1 #include <stdexcept>
2 #include <msp/strings/format.h>
3 #include "gl.h"
4 #include "stenciltest.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 StencilTest::StencilTest():
12         enabled(false),
13         compare(ALWAYS),
14         stencil_fail_op(KEEP),
15         depth_fail_op(KEEP),
16         depth_pass_op(KEEP),
17         reference(0)
18 { }
19
20
21 StencilTest::Loader::Loader(StencilTest &st):
22         ObjectLoader<StencilTest>(st)
23 {
24         add("compare", &Loader::compare);
25         add("actions", &Loader::actions);
26         add("reference", &StencilTest::reference);
27 }
28
29 void StencilTest::Loader::compare(Predicate c)
30 {
31         obj.enabled = true;
32         obj.compare = c;
33 }
34
35 void StencilTest::Loader::actions(StencilOp sf, StencilOp df, StencilOp dp)
36 {
37         obj.stencil_fail_op = sf;
38         obj.depth_fail_op = df;
39         obj.depth_pass_op = dp;
40 }
41
42
43 unsigned get_gl_stencil_op(StencilOp op)
44 {
45         switch(op)
46         {
47         case KEEP: return GL_KEEP;
48         case SET_ZERO: return GL_ZERO;
49         case REPLACE: return GL_REPLACE;
50         case INCR: return GL_INCR;
51         case DECR: return GL_DECR;
52         case INVERT: return GL_INVERT;
53         case INCR_WRAP: return GL_INCR_WRAP;
54         case DECR_WRAP: return GL_DECR_WRAP;
55         default: throw invalid_argument("get_gl_stencil_op");
56         }
57 }
58
59 void operator>>(const LexicalConverter &conv, StencilOp &op)
60 {
61         const string &str = conv.get();
62         if(str=="KEEP")
63                 op = KEEP;
64         else if(str=="SET_ZERO")
65                 op = SET_ZERO;
66         else if(str=="REPLACE")
67                 op = REPLACE;
68         else if(str=="INCR")
69                 op = INCR;
70         else if(str=="DECR")
71                 op = DECR;
72         else if(str=="INVERT")
73                 op = INVERT;
74         else if(str=="INCR_WRAP")
75                 op = INCR_WRAP;
76         else if(str=="DECR_WRAP")
77                 op = DECR_WRAP;
78         else
79                 throw lexical_error(format("conversion of '%s' to StencilOp", str));
80 }
81
82 void operator<<(LexicalConverter &conv, StencilOp op)
83 {
84         switch(op)
85         {
86         case KEEP: conv.result("KEEP"); break;
87         case SET_ZERO: conv.result("SET_ZERO"); break;
88         case REPLACE: conv.result("REPLACE"); break;
89         case INCR: conv.result("INCR"); break;
90         case DECR: conv.result("DECR"); break;
91         case INVERT: conv.result("INVERT"); break;
92         case INCR_WRAP: conv.result("INCR_WRAP"); break;
93         case DECR_WRAP: conv.result("DECR_WRAP"); break;
94         default: conv.result(format("StencilOp(%#x)", static_cast<int>(op)));
95         }
96 }
97
98 } // namespace GL
99 } // namespace Msp