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