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