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