]> git.tdb.fi Git - libs/gl.git/blob - source/windingtest.cpp
Have Object provide an identity matrix from get_matrix
[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         winding(COUNTERCLOCKWISE)
19 { }
20
21 WindingTest::WindingTest(FaceWinding w):
22         winding(w)
23 { }
24
25 void WindingTest::bind() const
26 {
27         if(set_current(this))
28         {
29                 glEnable(GL_CULL_FACE);
30                 glFrontFace(winding);
31         }
32 }
33
34 void WindingTest::unbind()
35 {
36         if(set_current(0))
37                 glDisable(GL_CULL_FACE);
38 }
39
40 const WindingTest &WindingTest::get_reverse() const
41 {
42         if(winding==CLOCKWISE)
43                 return counterclockwise();
44         else
45                 return clockwise();
46 }
47
48 const WindingTest &WindingTest::clockwise()
49 {
50         static WindingTest test(CLOCKWISE);
51         return test;
52 }
53
54 const WindingTest &WindingTest::counterclockwise()
55 {
56         static WindingTest test(COUNTERCLOCKWISE);
57         return test;
58 }
59
60 } // namespace GL
61 } // namespace Msp