]> git.tdb.fi Git - libs/gl.git/blob - source/blend.cpp
Give meshes a higher priority when loading
[libs/gl.git] / source / blend.cpp
1 #include <msp/gl/extensions/ext_blend_minmax.h>
2 #include <msp/gl/extensions/ext_blend_subtract.h>
3 #include "blend.h"
4
5 namespace Msp {
6 namespace GL {
7
8 Blend::Blend():
9         eq(ADD),
10         src_factor(ONE),
11         dst_factor(ZERO)
12 { }
13
14 Blend::Blend(BlendFactor sf, BlendFactor df):
15         eq(ADD),
16         src_factor(sf),
17         dst_factor(df)
18 { }
19
20 Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df):
21         eq(e),
22         src_factor(sf),
23         dst_factor(df)
24 {
25         if(eq==MIN || eq==MAX)
26                 static Require _req(EXT_blend_minmax);
27         else if(eq==SUBTRACT || eq==REVERSE_SUBTRACT)
28                 static Require _req(EXT_blend_subtract);
29 }
30
31 void Blend::bind() const
32 {
33         if(set_current(this))
34         {
35                 glEnable(GL_BLEND);
36                 if(EXT_blend_minmax)
37                         glBlendEquation(eq);
38                 glBlendFunc(src_factor, dst_factor);
39         }
40 }
41
42 void Blend::unbind()
43 {
44         if(set_current(0))
45                 glDisable(GL_BLEND);
46 }
47
48 const Blend &Blend::alpha()
49 {
50         static Blend blend(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
51         return blend;
52 }
53
54 } // namespace GL
55 } // namespace Msp