]> git.tdb.fi Git - libs/gl.git/blob - source/windingtest.cpp
Fix an incorrect extension name
[libs/gl.git] / source / windingtest.cpp
1 #include <msp/strings/format.h>
2 #include "windingtest.h"
3
4 namespace Msp {
5 namespace GL {
6
7 void operator>>(const LexicalConverter &conv, FaceWinding &winding)
8 {
9         if(conv.get()=="CLOCKWISE")
10                 winding = CLOCKWISE;
11         else if(conv.get()=="COUNTERCLOCKWISE")
12                 winding = COUNTERCLOCKWISE;
13         else
14                 throw lexical_error(format("conversion of '%s' to FaceWinding", conv.get()));
15 }
16
17 WindingTest::WindingTest():
18         test(false),
19         winding(COUNTERCLOCKWISE)
20 { }
21
22 WindingTest::WindingTest(FaceWinding w):
23         test(true),
24         winding(w)
25 { }
26
27 void WindingTest::bind() const
28 {
29         if(set_current(this))
30         {
31                 if(test)
32                 {
33                         glEnable(GL_CULL_FACE);
34                         glFrontFace(winding);
35                 }
36                 else
37                         glDisable(GL_CULL_FACE);
38         }
39 }
40
41 void WindingTest::unbind()
42 {
43         if(set_current(0))
44                 glDisable(GL_CULL_FACE);
45 }
46
47 WindingTest &WindingTest::clockwise()
48 {
49         static WindingTest test(CLOCKWISE);
50         return test;
51 }
52
53 WindingTest &WindingTest::counterclockwise()
54 {
55         static WindingTest test(COUNTERCLOCKWISE);
56         return test;
57 }
58
59 } // namespace GL
60 } // namespace Msp