]> git.tdb.fi Git - libs/gl.git/blob - source/blend.cpp
Add object-oriented interfaces for the various tests and blending
[libs/gl.git] / source / blend.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2008, 2010  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "blend.h"
9 #include "extension.h"
10 #include "version_1_2.h"
11
12 namespace Msp {
13 namespace GL {
14
15 Blend::Blend():
16         eq(ADD),
17         src_factor(ONE),
18         dst_factor(ZERO)
19 { }
20
21 Blend::Blend(BlendFactor sf, BlendFactor df):
22         eq(ADD),
23         src_factor(sf),
24         dst_factor(df)
25 { }
26
27 Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df):
28         eq(e),
29         src_factor(sf),
30         dst_factor(df)
31 {
32         if(eq!=ADD)
33                 static RequireVersion _ver(1, 2);
34 }
35
36 void Blend::bind() const
37 {
38         if(set_current(this))
39         {
40                 glEnable(GL_BLEND);
41                 // XXX Don't try to set equation if version < 1.2
42                 glBlendEquation(eq);
43                 glBlendFunc(src_factor, dst_factor);
44         }
45 }
46
47 const Blend &Blend::alpha()
48 {
49         static Blend blend(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
50         return blend;
51 }
52
53 void Blend::unbind()
54 {
55         if(set_current(0))
56                 glDisable(GL_BLEND);
57 }
58
59
60 void blend_equation(BlendEquation eq)
61 {
62         static RequireVersion _ver(1, 2);
63         glBlendEquation(eq);
64 }
65
66 void blend_func(BlendFactor src, BlendFactor dst)
67 {
68         glBlendFunc(src, dst);
69 }
70
71 } // namespace GL
72 } // namespace Msp