]> git.tdb.fi Git - libs/gl.git/blobdiff - source/blend.cpp
Refresh lighting and culling uniforms if the camera changes in pop_state
[libs/gl.git] / source / blend.cpp
index 854b2032d4e26ea31168beaf141790d6ffdb536f..184d5ad534f1aca6bcf441726b54e8c80af94a1b 100644 (file)
@@ -1,26 +1,54 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2008  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
+#include <msp/gl/extensions/ext_blend_minmax.h>
+#include <msp/gl/extensions/ext_blend_subtract.h>
 #include "blend.h"
-#include "extension.h"
-#include "version_1_2.h"
 
 namespace Msp {
 namespace GL {
 
-void blend_equation(BlendEquation eq)
+Blend::Blend():
+       eq(ADD),
+       src_factor(ONE),
+       dst_factor(ZERO)
+{ }
+
+Blend::Blend(BlendFactor sf, BlendFactor df):
+       eq(ADD),
+       src_factor(sf),
+       dst_factor(df)
+{ }
+
+Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df):
+       eq(e),
+       src_factor(sf),
+       dst_factor(df)
+{
+       if(eq==MIN || eq==MAX)
+               static Require _req(EXT_blend_minmax);
+       else if(eq==SUBTRACT || eq==REVERSE_SUBTRACT)
+               static Require _req(EXT_blend_subtract);
+}
+
+void Blend::bind() const
+{
+       if(set_current(this))
+       {
+               glEnable(GL_BLEND);
+               if(EXT_blend_minmax)
+                       glBlendEquation(eq);
+               glBlendFunc(src_factor, dst_factor);
+       }
+}
+
+void Blend::unbind()
 {
-       static RequireVersion _ver(1, 2);
-       glBlendEquation(eq);
+       if(set_current(0))
+               glDisable(GL_BLEND);
 }
 
-void blend_func(BlendFactor src, BlendFactor dst)
+const Blend &Blend::alpha()
 {
-       glBlendFunc(src, dst);
+       static Blend blend(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
+       return blend;
 }
 
 } // namespace GL