X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fblend.cpp;h=cecd562dc1019f389e151049b94d4c01e55b2623;hb=6afbace895a7bbcf216ab8e48280ea0303ab5892;hp=899ccf599c255e8141fb14c2e3046af6fceaddbc;hpb=d23880571efc16dff1cfeeb92f35fe54c8f64c3d;p=libs%2Fgl.git diff --git a/source/blend.cpp b/source/blend.cpp index 899ccf59..cecd562d 100644 --- a/source/blend.cpp +++ b/source/blend.cpp @@ -1,27 +1,54 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#define GL_GLEXT_PROTOTYPES #include "blend.h" -#include "extension.h" -#include "version_1_2.h" +#include "ext_blend_minmax.h" +#include "ext_blend_subtract.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(glBlendEquation) + glBlendEquation(eq); + glBlendFunc(src_factor, dst_factor); + } +} + +void Blend::unbind() { - require_version(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