From: Mikko Rasa Date: Wed, 15 Sep 2010 19:06:58 +0000 (+0000) Subject: Remove non-OO access to blending X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c473f9193d3e5088772b6e5ebf53b710e2976a92;p=libs%2Fgl.git Remove non-OO access to blending Make Bind constructible from a reference again Use RAII binding for texture in Font --- diff --git a/source/bindable.h b/source/bindable.h index d85ec78d..00023451 100644 --- a/source/bindable.h +++ b/source/bindable.h @@ -98,11 +98,21 @@ private: Base *binder; public: + template + Bind(const T &o, bool r = false): + binder(r ? create(&o, T::current()) : create(&o)) + { } + template Bind(const T *o, bool r = false): binder(r ? create(o, T::current()) : create(o)) { } + template + Bind(T *o, bool r = false): + binder(r ? create(o, T::current()) : create(o)) + { } + private: Bind(const Bind &); Bind &operator=(const Bind &); diff --git a/source/blend.cpp b/source/blend.cpp index 8b82772f..b2f59e17 100644 --- a/source/blend.cpp +++ b/source/blend.cpp @@ -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 diff --git a/source/blend.h b/source/blend.h index c4c78d7d..3d7368bb 100644 --- a/source/blend.h +++ b/source/blend.h @@ -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 diff --git a/source/font.cpp b/source/font.cpp index 44e3d241..bbbc40ed 100644 --- a/source/font.cpp +++ b/source/font.cpp @@ -6,6 +6,7 @@ Distributed under the LGPL */ #include +#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;