]> git.tdb.fi Git - libs/gl.git/blob - source/core/stenciltest.cpp
Use default member initializers for simple types
[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::Loader::Loader(StencilTest &st):
12         ObjectLoader<StencilTest>(st)
13 {
14         add("compare", &Loader::compare);
15         add("actions", &Loader::actions);
16         add("reference", &StencilTest::reference);
17 }
18
19 void StencilTest::Loader::compare(Predicate c)
20 {
21         obj.enabled = true;
22         obj.compare = c;
23 }
24
25 void StencilTest::Loader::actions(StencilOp sf, StencilOp df, StencilOp dp)
26 {
27         obj.stencil_fail_op = sf;
28         obj.depth_fail_op = df;
29         obj.depth_pass_op = dp;
30 }
31
32
33 void operator>>(const LexicalConverter &conv, StencilOp &op)
34 {
35         const string &str = conv.get();
36         if(str=="KEEP")
37                 op = KEEP;
38         else if(str=="SET_ZERO")
39                 op = SET_ZERO;
40         else if(str=="REPLACE")
41                 op = REPLACE;
42         else if(str=="INCR")
43                 op = INCR;
44         else if(str=="DECR")
45                 op = DECR;
46         else if(str=="INVERT")
47                 op = INVERT;
48         else if(str=="INCR_WRAP")
49                 op = INCR_WRAP;
50         else if(str=="DECR_WRAP")
51                 op = DECR_WRAP;
52         else
53                 throw lexical_error(format("conversion of '%s' to StencilOp", str));
54 }
55
56 void operator<<(LexicalConverter &conv, StencilOp op)
57 {
58         switch(op)
59         {
60         case KEEP: conv.result("KEEP"); break;
61         case SET_ZERO: conv.result("SET_ZERO"); break;
62         case REPLACE: conv.result("REPLACE"); break;
63         case INCR: conv.result("INCR"); break;
64         case DECR: conv.result("DECR"); break;
65         case INVERT: conv.result("INVERT"); break;
66         case INCR_WRAP: conv.result("INCR_WRAP"); break;
67         case DECR_WRAP: conv.result("DECR_WRAP"); break;
68         default: conv.result(format("StencilOp(%#x)", static_cast<int>(op)));
69         }
70 }
71
72 } // namespace GL
73 } // namespace Msp