X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fblend.cpp;h=b2f59e17c5cb57250f20aba14ca158e81c818285;hb=9a9d3517dcfdba5206d9c73ce211feac8e402bc2;hp=854b2032d4e26ea31168beaf141790d6ffdb536f;hpb=dc1d1159a61f378bda11e5989ad694a86b9a3c77;p=libs%2Fgl.git diff --git a/source/blend.cpp b/source/blend.cpp index 854b2032..b2f59e17 100644 --- a/source/blend.cpp +++ b/source/blend.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgl -Copyright © 2008 Mikko Rasa, Mikkosoft Productions +Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -12,15 +12,48 @@ Distributed under the LGPL 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!=ADD) + static RequireVersion _ver(1, 2); +} + +void Blend::bind() const +{ + if(set_current(this)) + { + glEnable(GL_BLEND); + if(glBlendEquation) + 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