X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fblend.h;h=3edebc8c7f4bdde90e8d7aa14c2ab87cc300ff04;hb=e1be82a4dfce8d90358c506f65be09da4dc9d5ec;hp=986844c0e6a7e1f2caa15249a8c7d8531bd4bf09;hpb=2b2676392aff2eb6b38c3e463cc67f4d67a4ef8b;p=libs%2Fgl.git diff --git a/source/core/blend.h b/source/core/blend.h index 986844c0..3edebc8c 100644 --- a/source/core/blend.h +++ b/source/core/blend.h @@ -4,12 +4,11 @@ #include #include #include "color.h" -#include "gl.h" namespace Msp { namespace GL { -enum BlendEquation +enum BlendEquation: std::uint8_t { ADD, SUBTRACT, @@ -18,7 +17,7 @@ enum BlendEquation MAX }; -enum BlendFactor +enum BlendFactor: std::uint8_t { ZERO, ONE, @@ -36,8 +35,18 @@ enum BlendFactor ONE_MINUS_CONSTANT_ALPHA }; +enum ColorWriteMask: std::uint8_t +{ + WRITE_NONE = 0, + WRITE_RED = 1, + WRITE_GREEN = 2, + WRITE_BLUE = 4, + WRITE_ALPHA = 8, + WRITE_ALL = 15 +}; + /** -Blends incoming fragments with those already in the framebuffer. +Blends incoming fragment color values with those already in the framebuffer. */ struct Blend { @@ -52,19 +61,30 @@ struct Blend void factors(BlendFactor, BlendFactor); }; - bool enabled; - BlendEquation equation; - BlendFactor src_factor; - BlendFactor dst_factor; - Color constant; + bool enabled = false; + BlendEquation equation = ADD; + BlendFactor src_factor = ONE; + BlendFactor dst_factor = ZERO; + Color constant = { 0.0f, 0.0f, 0.0f, 0.0f }; + ColorWriteMask write_mask = WRITE_ALL; - Blend(); + Blend() = default; Blend(BlendFactor, BlendFactor); Blend(BlendEquation, BlendFactor, BlendFactor); + + bool operator==(const Blend &) const; + bool operator!=(const Blend &b) const { return !operator==(b); } }; -GLenum get_gl_blend_equation(BlendEquation); -GLenum get_gl_blend_factor(BlendFactor); +inline bool Blend::operator==(const Blend &other) const +{ + return enabled==other.enabled && equation==other.equation && src_factor==other.src_factor && + dst_factor==other.dst_factor && constant==other.constant && write_mask==other.write_mask; +} + + +inline ColorWriteMask operator|(ColorWriteMask m1, ColorWriteMask m2) +{ return static_cast(static_cast(m1)|static_cast(m2)); } void operator>>(const LexicalConverter &, BlendEquation &); void operator<<(LexicalConverter &, BlendEquation); @@ -72,7 +92,12 @@ void operator<<(LexicalConverter &, BlendEquation); void operator>>(const LexicalConverter &, BlendFactor &); void operator<<(LexicalConverter &, BlendFactor); +void operator>>(const LexicalConverter &, ColorWriteMask &); +void operator<<(LexicalConverter &, ColorWriteMask); + } // namespace GL } // namespace Msp +#include "blend_backend.h" + #endif