X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fblend.h;h=3edebc8c7f4bdde90e8d7aa14c2ab87cc300ff04;hp=e7b291e617dab5c2044e787c99ee7a09a7dfcac5;hb=HEAD;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266 diff --git a/source/core/blend.h b/source/core/blend.h index e7b291e6..874230c6 100644 --- a/source/core/blend.h +++ b/source/core/blend.h @@ -1,69 +1,105 @@ #ifndef MSP_GL_BLEND_H_ #define MSP_GL_BLEND_H_ +#include #include -#include "bindable.h" -#include "gl.h" -#include +#include "color.h" namespace Msp { namespace GL { -enum BlendEquation +enum BlendEquation: std::uint8_t { - ADD = GL_FUNC_ADD, - SUBTRACT = GL_FUNC_SUBTRACT, - REVERSE_SUBTRACT = GL_FUNC_REVERSE_SUBTRACT, - MIN = GL_MIN, - MAX = GL_MAX + ADD, + SUBTRACT, + REVERSE_SUBTRACT, + MIN, + MAX }; -enum BlendFactor +enum BlendFactor: std::uint8_t { - ZERO = GL_ZERO, - ONE = GL_ONE, - SRC_COLOR = GL_SRC_COLOR, - ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR, - SRC_ALPHA = GL_SRC_ALPHA, - ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA, - DST_COLOR = GL_DST_COLOR, - ONE_MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR, - DST_ALPHA = GL_DST_ALPHA, - ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA, - CONSTANT_COLOR = GL_CONSTANT_COLOR, - ONE_MINUS_CONSTANT_COLOR = GL_ONE_MINUS_CONSTANT_COLOR, - CONSTANT_ALPHA = GL_CONSTANT_ALPHA, - ONE_MINUS_CONSTANT_ALPHA = GL_ONE_MINUS_CONSTANT_ALPHA + ZERO, + ONE, + SRC_COLOR, + ONE_MINUS_SRC_COLOR, + SRC_ALPHA, + ONE_MINUS_SRC_ALPHA, + DST_COLOR, + ONE_MINUS_DST_COLOR, + DST_ALPHA, + ONE_MINUS_DST_ALPHA, + CONSTANT_COLOR, + ONE_MINUS_CONSTANT_COLOR, + CONSTANT_ALPHA, + 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. */ -class Blend: public Bindable +struct Blend { -private: - BlendEquation eq; - BlendFactor src_factor; - BlendFactor dst_factor; + class Loader: public DataFile::ObjectLoader + { + public: + Loader(Blend &); -public: - Blend(); + private: + void constant(float, float, float, float); + void equation(BlendEquation); + void factors(BlendFactor, BlendFactor); + }; + + 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; + bool alpha_to_coverage = false; + + Blend() = default; Blend(BlendFactor, BlendFactor); Blend(BlendEquation, BlendFactor, BlendFactor); - void bind() const; + bool operator==(const Blend &) const; + bool operator!=(const Blend &b) const { return !operator==(b); } +}; + +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 && + alpha_to_coverage==other.alpha_to_coverage; +} - static void unbind(); - static const Blend &alpha(); - static const Blend &additive(); - static const Blend &additive_alpha(); -}; +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); 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