]> git.tdb.fi Git - libs/gl.git/blob - source/windingtest.cpp
b54f71217f5b8387c054dec03eaea18380cd576c
[libs/gl.git] / source / windingtest.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2011  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "windingtest.h"
9
10 namespace Msp {
11 namespace GL {
12
13 void operator>>(const LexicalConverter &conv, FaceWinding &winding)
14 {
15         if(conv.get()=="CLOCKWISE")
16                 winding = CLOCKWISE;
17         else if(conv.get()=="COUNTERCLOCKWISE")
18                 winding = COUNTERCLOCKWISE;
19         else
20                 throw InvalidParameterValue("Invalid FaceWinding");
21 }
22
23 WindingTest::WindingTest():
24         test(false),
25         winding(COUNTERCLOCKWISE)
26 { }
27
28 WindingTest::WindingTest(FaceWinding w):
29         test(true),
30         winding(w)
31 { }
32
33 void WindingTest::bind() const
34 {
35         if(set_current(this))
36         {
37                 if(test)
38                 {
39                         glEnable(GL_CULL_FACE);
40                         glFrontFace(winding);
41                 }
42                 else
43                         glDisable(GL_CULL_FACE);
44         }
45 }
46
47 void WindingTest::unbind()
48 {
49         if(set_current(0))
50                 glDisable(GL_CULL_FACE);
51 }
52
53 WindingTest &WindingTest::clockwise()
54 {
55         static WindingTest test(CLOCKWISE);
56         return test;
57 }
58
59 WindingTest &WindingTest::counterclockwise()
60 {
61         static WindingTest test(COUNTERCLOCKWISE);
62         return test;
63 }
64
65 } // namespace GL
66 } // namespace Msp