X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fblend.cpp;h=df4043e29fcfc228a557a7a5f54238d1f302f5e2;hb=e69287d99126a20326d713c9a44360f15c94d137;hp=c9407c2130fe3e7bb9d0770ee194ded9bd8d2649;hpb=1bff68e595a66f3755743a7ee0f974eb876f3520;p=libs%2Fgl.git diff --git a/source/blend.cpp b/source/blend.cpp index c9407c21..df4043e2 100644 --- a/source/blend.cpp +++ b/source/blend.cpp @@ -1,24 +1,66 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#define GL_GLEXT_PROTOTYPES +#include +#include #include "blend.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() +{ + if(set_current(0)) + glDisable(GL_BLEND); +} + +const Blend &Blend::alpha() +{ + static Blend blend(SRC_ALPHA, ONE_MINUS_SRC_ALPHA); + return blend; +} + +const Blend &Blend::additive() { - glBlendEquation(eq); + static Blend blend(ONE, ONE); + return blend; } -void blend_func(BlendFactor src, BlendFactor dst) +const Blend &Blend::additive_alpha() { - glBlendFunc(src, dst); + static Blend blend(SRC_ALPHA, ONE); + return blend; } } // namespace GL