]> git.tdb.fi Git - libs/gl.git/blob - source/core/stenciltest.cpp
2e8bbb4db865d5052885facfd96d25341ba1f906
[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 void operator>>(const LexicalConverter &conv, StencilOp &op)
44 {
45         const string &str = conv.get();
46         if(str=="KEEP")
47                 op = KEEP;
48         else if(str=="SET_ZERO")
49                 op = SET_ZERO;
50         else if(str=="REPLACE")
51                 op = REPLACE;
52         else if(str=="INCR")
53                 op = INCR;
54         else if(str=="DECR")
55                 op = DECR;
56         else if(str=="INVERT")
57                 op = INVERT;
58         else if(str=="INCR_WRAP")
59                 op = INCR_WRAP;
60         else if(str=="DECR_WRAP")
61                 op = DECR_WRAP;
62         else
63                 throw lexical_error(format("conversion of '%s' to StencilOp", str));
64 }
65
66 void operator<<(LexicalConverter &conv, StencilOp op)
67 {
68         switch(op)
69         {
70         case KEEP: conv.result("KEEP"); break;
71         case SET_ZERO: conv.result("SET_ZERO"); break;
72         case REPLACE: conv.result("REPLACE"); break;
73         case INCR: conv.result("INCR"); break;
74         case DECR: conv.result("DECR"); break;
75         case INVERT: conv.result("INVERT"); break;
76         case INCR_WRAP: conv.result("INCR_WRAP"); break;
77         case DECR_WRAP: conv.result("DECR_WRAP"); break;
78         default: conv.result(format("StencilOp(%#x)", static_cast<int>(op)));
79         }
80 }
81
82 } // namespace GL
83 } // namespace Msp