]> git.tdb.fi Git - libs/gl.git/blob - source/tests.cpp
Setting depth mask off in Framebuffer is not required
[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 void alpha_func(Predicate func, float ref)
39 {
40         glAlphaFunc(func, ref);
41 }
42
43
44 DepthTest::DepthTest():
45         write(true),
46         pred(LESS)
47 { }
48
49 DepthTest::DepthTest(Predicate p, bool w):
50         write(w),
51         pred(p)
52 { }
53
54 void DepthTest::bind() const
55 {
56         if(set_current(this))
57         {
58                 glEnable(GL_DEPTH_TEST);
59                 glDepthFunc(pred);
60                 glDepthMask(write);
61         }
62 }
63
64 const DepthTest &DepthTest::lequal()
65 {
66         static DepthTest test(LEQUAL);
67         return test;
68 }
69
70 void DepthTest::unbind()
71 {
72         if(set_current(0))
73         {
74                 glDisable(GL_DEPTH_TEST);
75                 // Allow glClear(GL_DEPTH_BUFFER_BIT) to work
76                 glDepthMask(true);
77         }
78 }
79
80 void depth_func(Predicate func)
81 {
82         glDepthFunc(func);
83 }
84
85
86 ScissorTest::ScissorTest():
87         left(0),
88         bottom(0),
89         width(1),
90         height(1)
91 { }
92
93 ScissorTest::ScissorTest(int l, int b, unsigned w, unsigned h):
94         left(l),
95         bottom(b),
96         width(w),
97         height(h)
98 { }
99
100 void ScissorTest::bind() const
101 {
102         if(set_current(this))
103         {
104                 glEnable(GL_SCISSOR_TEST);
105                 glScissor(left, bottom, width, height);
106         }
107 }
108
109 void ScissorTest::unbind()
110 {
111         if(set_current(0))
112                 glDisable(GL_SCISSOR_TEST);
113 }
114
115 void scissor(int left, int bottom, unsigned width, unsigned height)
116 {
117         glScissor(left, bottom, width, height);
118 }
119
120 } // namespace GL
121 } // namespace Msp