X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fblend.cpp;fp=source%2Fcore%2Fblend.cpp;h=8ceb23829a76894e978dfad03a1531c3421c215e;hb=bae374a3cda6a1b59f36016624ef518bf2676355;hp=324440d32e9362ad39c33c3e7afafeb878aed37b;hpb=e6077f9f25b794c174e1017c2c0763e77a6fddda;p=libs%2Fgl.git diff --git a/source/core/blend.cpp b/source/core/blend.cpp index 324440d3..8ceb2382 100644 --- a/source/core/blend.cpp +++ b/source/core/blend.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "blend.h" using namespace std; @@ -13,7 +14,8 @@ Blend::Blend(): equation(ADD), src_factor(ONE), dst_factor(ZERO), - constant(0.0f, 0.0f, 0.0f, 0.0f) + constant(0.0f, 0.0f, 0.0f, 0.0f), + write_mask(WRITE_ALL) { } Blend::Blend(BlendFactor sf, BlendFactor df): @@ -21,7 +23,8 @@ Blend::Blend(BlendFactor sf, BlendFactor df): equation(ADD), src_factor(sf), dst_factor(df), - constant(0.0f, 0.0f, 0.0f, 0.0f) + constant(0.0f, 0.0f, 0.0f, 0.0f), + write_mask(WRITE_ALL) { } Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df): @@ -29,7 +32,8 @@ Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df): equation(e), src_factor(sf), dst_factor(df), - constant(0.0f, 0.0f, 0.0f, 0.0f) + constant(0.0f, 0.0f, 0.0f, 0.0f), + write_mask(WRITE_ALL) { } @@ -182,5 +186,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