X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fblend.cpp;h=8b82772fded1e7fc6acc755c312964ac867a0b3b;hb=020811d96d5c823686e5c2b0a392b95d1a321f05;hp=899ccf599c255e8141fb14c2e3046af6fceaddbc;hpb=d23880571efc16dff1cfeeb92f35fe54c8f64c3d;p=libs%2Fgl.git diff --git a/source/blend.cpp b/source/blend.cpp index 899ccf59..8b82772f 100644 --- a/source/blend.cpp +++ b/source/blend.cpp @@ -1,11 +1,10 @@ /* $Id$ This file is part of libmspgl -Copyright © 2008 Mikko Rasa, Mikkosoft Productions +Copyright © 2008, 2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#define GL_GLEXT_PROTOTYPES #include "blend.h" #include "extension.h" #include "version_1_2.h" @@ -13,9 +12,54 @@ Distributed under the LGPL namespace Msp { namespace GL { +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); + // XXX Don't try to set equation if version < 1.2 + 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) { - require_version(1, 2); + static RequireVersion _ver(1, 2); glBlendEquation(eq); }