]> git.tdb.fi Git - libs/gl.git/blob - source/blend.cpp
Remove non-OO access to 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                 if(glBlendEquation)
42                         glBlendEquation(eq);
43                 glBlendFunc(src_factor, dst_factor);
44         }
45 }
46
47 void Blend::unbind()
48 {
49         if(set_current(0))
50                 glDisable(GL_BLEND);
51 }
52
53 const Blend &Blend::alpha()
54 {
55         static Blend blend(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
56         return blend;
57 }
58
59 } // namespace GL
60 } // namespace Msp