]> git.tdb.fi Git - libs/gl.git/blob - source/tests.cpp
08580d4d80a0234758569dd62446d4d3b288a732
[libs/gl.git] / source / tests.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007, 2010  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "tests.h"
9
10 namespace Msp {
11 namespace GL {
12
13 AlphaTest::AlphaTest():
14         pred(ALWAYS),
15         ref(0)
16 { }
17
18 AlphaTest::AlphaTest(Predicate p, float r):
19         pred(p),
20         ref(r)
21 { }
22
23 void AlphaTest::bind() const
24 {
25         if(set_current(this))
26         {
27                 glEnable(GL_ALPHA_TEST);
28                 glAlphaFunc(pred, ref);
29         }
30 }
31
32 void AlphaTest::unbind()
33 {
34         if(set_current(0))
35                 glDisable(GL_ALPHA_TEST);
36 }
37
38
39 DepthTest::DepthTest():
40         write(true),
41         pred(LESS)
42 { }
43
44 DepthTest::DepthTest(Predicate p, bool w):
45         write(w),
46         pred(p)
47 { }
48
49 void DepthTest::bind() const
50 {
51         if(set_current(this))
52         {
53                 glEnable(GL_DEPTH_TEST);
54                 glDepthFunc(pred);
55                 glDepthMask(write);
56         }
57 }
58
59 const DepthTest &DepthTest::lequal()
60 {
61         static DepthTest test(LEQUAL);
62         return test;
63 }
64
65 void DepthTest::unbind()
66 {
67         if(set_current(0))
68         {
69                 glDisable(GL_DEPTH_TEST);
70                 // Allow glClear(GL_DEPTH_BUFFER_BIT) to work
71                 glDepthMask(true);
72         }
73 }
74
75
76 ScissorTest::ScissorTest():
77         left(0),
78         bottom(0),
79         width(1),
80         height(1)
81 { }
82
83 ScissorTest::ScissorTest(int l, int b, unsigned w, unsigned h):
84         left(l),
85         bottom(b),
86         width(w),
87         height(h)
88 { }
89
90 void ScissorTest::bind() const
91 {
92         if(set_current(this))
93         {
94                 glEnable(GL_SCISSOR_TEST);
95                 glScissor(left, bottom, width, height);
96         }
97 }
98
99 void ScissorTest::unbind()
100 {
101         if(set_current(0))
102                 glDisable(GL_SCISSOR_TEST);
103 }
104
105 } // namespace GL
106 } // namespace Msp