]> git.tdb.fi Git - libs/gl.git/blob - source/tests.h
Add object-oriented interfaces for the various tests and blending
[libs/gl.git] / source / tests.h
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 #ifndef MSP_GL_TESTS_H_
9 #define MSP_GL_TESTS_H_
10
11 #include "bindable.h"
12 #include "gl.h"
13 #include "predicate.h"
14
15 namespace Msp {
16 namespace GL {
17
18 enum
19 {
20         SCISSOR_TEST = GL_SCISSOR_TEST,
21         ALPHA_TEST   = GL_ALPHA_TEST,
22         DEPTH_TEST   = GL_DEPTH_TEST
23 };
24
25 /**
26 Tests incoming fragment alpha values against a reference.  If the test fails,
27 the fragment is discarded.
28 */
29 class AlphaTest: public Bindable<AlphaTest>
30 {
31 private:
32         Predicate pred;
33         float ref;
34
35 public:
36         AlphaTest();
37         AlphaTest(Predicate, float);
38
39         void bind() const;
40
41         static void unbind();
42 };
43
44 void alpha_func(Predicate func, float ref);
45
46
47 /**
48 Tests incoming fragment depth values against the depth buffer.  If the test
49 fails, the fragment is discarded.
50 */
51 class DepthTest: public Bindable<DepthTest>
52 {
53 private:
54         bool write;
55         Predicate pred;
56
57         static const DepthTest *current; 
58
59 public:
60         DepthTest();
61         DepthTest(Predicate, bool = true);
62
63         void bind() const;
64
65         static const DepthTest &lequal();
66         static void unbind();
67 };
68
69 void depth_func(Predicate func);
70
71
72 /**
73 Tests fragment coordinates against a rectangle.  Any fragments outside the
74 rectangle are discarded.
75 */
76 class ScissorTest: public Bindable<ScissorTest>
77 {
78 private:
79         int left;
80         int bottom;
81         unsigned width;
82         unsigned height;
83
84 public:
85         ScissorTest();
86         ScissorTest(int, int, unsigned, unsigned);
87
88         void bind() const;
89
90         static void unbind();
91 };
92
93 void scissor(int left, int bottom, unsigned width, unsigned height);
94
95 } // namespace GL
96 } // namespace Msp
97
98 #endif