]> git.tdb.fi Git - libs/gl.git/blob - source/core/predicate.cpp
Decouple the Predicate enum from OpenGL constants
[libs/gl.git] / source / core / predicate.cpp
1 #include <msp/strings/format.h>
2 #include "predicate.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GL {
8
9 GLenum get_gl_predicate(Predicate pred)
10 {
11         switch(pred)
12         {
13         case NEVER: return GL_NEVER;
14         case ALWAYS: return GL_ALWAYS;
15         case LESS: return GL_LESS;
16         case LEQUAL: return GL_LEQUAL;
17         case EQUAL: return GL_EQUAL;
18         case GREATER: return GL_GREATER;
19         case GEQUAL: return GL_GEQUAL;
20         case NOTEQUAL: return GL_NOTEQUAL;
21         default: throw invalid_argument("get_gl_predicate");
22         }
23 }
24
25 void operator>>(const LexicalConverter &conv, Predicate &pred)
26 {
27         const string &str = conv.get();
28         if(str=="NEVER")
29                 pred = NEVER;
30         else if(str=="ALWAYS")
31                 pred = ALWAYS;
32         else if(str=="LESS")
33                 pred = LESS;
34         else if(str=="LEQUAL")
35                 pred = LEQUAL;
36         else if(str=="EQUAL")
37                 pred = EQUAL;
38         else if(str=="GREATER")
39                 pred = GREATER;
40         else if(str=="GEQUAL")
41                 pred = GEQUAL;
42         else if(str=="NOTEQUAL")
43                 pred = NOTEQUAL;
44         else
45                 throw lexical_error(format("conversion of '%s' to Predicate", str));
46 }
47
48 void operator<<(LexicalConverter &conv, Predicate pred)
49 {
50         switch(pred)
51         {
52         case NEVER: conv.result("NEVER"); break;
53         case ALWAYS: conv.result("ALWAYS"); break;
54         case LESS: conv.result("LESS"); break;
55         case LEQUAL: conv.result("LEQUAL"); break;
56         case EQUAL: conv.result("EQUAL"); break;
57         case GREATER: conv.result("GREATER"); break;
58         case GEQUAL: conv.result("GEQUAL"); break;
59         case NOTEQUAL: conv.result("NOTEQUAL"); break;
60         default: conv.result(format("Predicate(%#x)", static_cast<int>(pred))); break;
61         }
62 }
63
64 } // namespace GL
65 } // namespace Msp