]> git.tdb.fi Git - libs/gl.git/commitdiff
Remove non-OO access to blending
authorMikko Rasa <tdb@tdb.fi>
Wed, 15 Sep 2010 19:06:58 +0000 (19:06 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 15 Sep 2010 19:06:58 +0000 (19:06 +0000)
Make Bind constructible from a reference again
Use RAII binding for texture in Font

source/bindable.h
source/blend.cpp
source/blend.h
source/font.cpp

index d85ec78daac037710390a7949c1deb164c3dbb51..000234515aeeea4a5b38effe0bf27173251b8896 100644 (file)
@@ -98,11 +98,21 @@ private:
        Base *binder;
 
 public:
+       template<typename T>
+       Bind(const T &o, bool r = false):
+               binder(r ? create(&o, T::current()) : create(&o))
+       { }
+
        template<typename T>
        Bind(const T *o, bool r = false):
                binder(r ? create(o, T::current()) : create(o))
        { }
 
+       template<typename T>
+       Bind(T *o, bool r = false):
+               binder(r ? create(o, T::current()) : create(o))
+       { }
+
 private:
        Bind(const Bind &);
        Bind &operator=(const Bind &);
index 8b82772fded1e7fc6acc755c312964ac867a0b3b..b2f59e17c5cb57250f20aba14ca158e81c818285 100644 (file)
@@ -38,34 +38,22 @@ void Blend::bind() const
        if(set_current(this))
        {
                glEnable(GL_BLEND);
-               // XXX Don't try to set equation if version < 1.2
-               glBlendEquation(eq);
+               if(glBlendEquation)
+                       glBlendEquation(eq);
                glBlendFunc(src_factor, dst_factor);
        }
 }
 
-const Blend &Blend::alpha()
-{
-       static Blend blend(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
-       return blend;
-}
-
 void Blend::unbind()
 {
        if(set_current(0))
                glDisable(GL_BLEND);
 }
 
-
-void blend_equation(BlendEquation eq)
-{
-       static RequireVersion _ver(1, 2);
-       glBlendEquation(eq);
-}
-
-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
index c4c78d7d51e516fe9e7278c0983dad6446cf6f12..3d7368bb8bfeda7c27c92aaa07172f5ae10111d9 100644 (file)
@@ -14,11 +14,6 @@ Distributed under the LGPL
 namespace Msp {
 namespace GL {
 
-enum
-{
-       BLEND = GL_BLEND
-};
-
 enum BlendEquation
 {
        ADD              = GL_FUNC_ADD,
@@ -63,12 +58,10 @@ public:
 
        void bind() const;
 
-       static const Blend &alpha();
        static void unbind();
-};
 
-void blend_equation(BlendEquation eq);
-void blend_func(BlendFactor src, BlendFactor dst);
+       static const Blend &alpha();
+};
 
 } // namespace GL
 } // namespace Msp
index 44e3d241154b0e4acd8ccdd8e747091ea776f9ef..bbbc40edb1062ceb1f69b0d8e1898ff40fff2a7e 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the LGPL
 */
 
 #include <msp/datafile/collection.h>
+#include "bindable.h"
 #include "gl.h"
 #include "font.h"
 #include "immediate.h"
@@ -84,7 +85,7 @@ void Font::draw_string(const string &str, Codecs::Decoder &dec, PrimitiveBuilder
        if(!tex)
                throw InvalidState("No texture");
 
-       tex->bind();
+       Bind bind_tex(tex, true);
 
        float x = 0;
        unsigned count = 0;