]> git.tdb.fi Git - libs/gl.git/blob - source/tests.cpp
Write correct specularity parameters for materials
[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                 glDisable(GL_DEPTH_TEST);
74 }
75
76 void depth_func(Predicate func)
77 {
78         glDepthFunc(func);
79 }
80
81
82 ScissorTest::ScissorTest():
83         left(0),
84         bottom(0),
85         width(1),
86         height(1)
87 { }
88
89 ScissorTest::ScissorTest(int l, int b, unsigned w, unsigned h):
90         left(l),
91         bottom(b),
92         width(w),
93         height(h)
94 { }
95
96 void ScissorTest::bind() const
97 {
98         if(set_current(this))
99         {
100                 glEnable(GL_SCISSOR_TEST);
101                 glScissor(left, bottom, width, height);
102         }
103 }
104
105 void ScissorTest::unbind()
106 {
107         if(set_current(0))
108                 glDisable(GL_SCISSOR_TEST);
109 }
110
111 void scissor(int left, int bottom, unsigned width, unsigned height)
112 {
113         glScissor(left, bottom, width, height);
114 }
115
116 } // namespace GL
117 } // namespace Msp