X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fblend.cpp;h=99ffcd075c933a4441a8535dfed14b735a09acb4;hp=a5e8f44d2917ffc8c7fc2e48cb784b28b3ec01fd;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=2b2676392aff2eb6b38c3e463cc67f4d67a4ef8b diff --git a/source/core/blend.cpp b/source/core/blend.cpp index a5e8f44d..99ffcd07 100644 --- a/source/core/blend.cpp +++ b/source/core/blend.cpp @@ -1,6 +1,5 @@ -#include -#include #include +#include #include "blend.h" using namespace std; @@ -8,28 +7,17 @@ using namespace std; namespace Msp { namespace GL { -Blend::Blend(): - enabled(false), - equation(ADD), - src_factor(ONE), - dst_factor(ZERO), - constant(0.0f, 0.0f, 0.0f, 0.0f) -{ } - Blend::Blend(BlendFactor sf, BlendFactor df): enabled(true), - equation(ADD), src_factor(sf), - dst_factor(df), - constant(0.0f, 0.0f, 0.0f, 0.0f) + dst_factor(df) { } Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df): enabled(true), equation(e), src_factor(sf), - dst_factor(df), - constant(0.0f, 0.0f, 0.0f, 0.0f) + dst_factor(df) { } @@ -60,41 +48,6 @@ void Blend::Loader::factors(BlendFactor sf, BlendFactor df) } -GLenum get_gl_blend_equation(BlendEquation eq) -{ - switch(eq) - { - case ADD: return GL_FUNC_ADD; - case SUBTRACT: return GL_FUNC_SUBTRACT; - case REVERSE_SUBTRACT: return GL_FUNC_REVERSE_SUBTRACT; - case MIN: return GL_MIN; - case MAX: return GL_MAX; - default: throw invalid_argument("get_gl_blend_equation"); - } -} - -GLenum get_gl_blend_factor(BlendFactor factor) -{ - switch(factor) - { - case ZERO: return GL_ZERO; - case ONE: return GL_ONE; - case SRC_COLOR: return GL_SRC_COLOR; - case ONE_MINUS_SRC_COLOR: return GL_ONE_MINUS_SRC_COLOR; - case SRC_ALPHA: return GL_SRC_ALPHA; - case ONE_MINUS_SRC_ALPHA: return GL_ONE_MINUS_SRC_ALPHA; - case DST_COLOR: return GL_DST_COLOR; - case ONE_MINUS_DST_COLOR: return GL_ONE_MINUS_DST_COLOR; - case DST_ALPHA: return GL_DST_ALPHA; - case ONE_MINUS_DST_ALPHA: return GL_ONE_MINUS_DST_ALPHA; - case CONSTANT_COLOR: return GL_CONSTANT_COLOR; - case ONE_MINUS_CONSTANT_COLOR: return GL_ONE_MINUS_CONSTANT_COLOR; - case CONSTANT_ALPHA: return GL_CONSTANT_ALPHA; - case ONE_MINUS_CONSTANT_ALPHA: return GL_ONE_MINUS_CONSTANT_ALPHA; - default: throw invalid_argument("get_gl_blend_factor"); - } -} - void operator>>(const LexicalConverter &conv, BlendEquation &eq) { const string &str = conv.get(); @@ -182,5 +135,47 @@ void operator<<(LexicalConverter &conv, BlendFactor factor) } } +void operator>>(const LexicalConverter &conv, ColorWriteMask &mask) +{ + ColorWriteMask result = WRITE_NONE; + for(const string &p: split(conv.get(), '_')) + { + if(p=="ALL") + result = result|WRITE_ALL; + else if(p=="RED") + result = result|WRITE_RED; + else if(p=="GREEN") + result = result|WRITE_GREEN; + else if(p=="BLUE") + result = result|WRITE_BLUE; + else if(p=="ALPHA") + result = result|WRITE_ALPHA; + else + throw lexical_error(format("conversion of '%s' to ColorWriteMask", conv.get())); + } + mask = result; +} + +void operator<<(LexicalConverter &conv, ColorWriteMask mask) +{ + if(mask==WRITE_ALL) + conv.result("ALL"); + else if(mask&~WRITE_ALL) + conv.result(format("ColorWriteMask(%#x)", static_cast(mask))); + else + { + string result; + if(mask&WRITE_RED) + result = "RED"; + if(mask&WRITE_GREEN) + append(result, "_", "GREEN"); + if(mask&WRITE_BLUE) + append(result, "_", "BLUE"); + if(mask&WRITE_ALPHA) + append(result, "_", "ALPHA"); + conv.result(result); + } +} + } // namespace GL } // namespace Msp