Add Min and Max blend modes
This commit is contained in:
parent
0fe1626a1f
commit
05c83617de
@ -70,7 +70,9 @@ struct SFML_GRAPHICS_API BlendMode
|
|||||||
{
|
{
|
||||||
Add, //!< Pixel = Src * SrcFactor + Dst * DstFactor
|
Add, //!< Pixel = Src * SrcFactor + Dst * DstFactor
|
||||||
Subtract, //!< Pixel = Src * SrcFactor - Dst * DstFactor
|
Subtract, //!< Pixel = Src * SrcFactor - Dst * DstFactor
|
||||||
ReverseSubtract //!< Pixel = Dst * DstFactor - Src * SrcFactor
|
ReverseSubtract, //!< Pixel = Dst * DstFactor - Src * SrcFactor
|
||||||
|
Min, //!< Pixel = min(Dst, Src)
|
||||||
|
Max //!< Pixel = max(Dst, Src)
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -150,6 +152,8 @@ SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right
|
|||||||
SFML_GRAPHICS_API extern const BlendMode BlendAlpha; //!< Blend source and dest according to dest alpha
|
SFML_GRAPHICS_API extern const BlendMode BlendAlpha; //!< Blend source and dest according to dest alpha
|
||||||
SFML_GRAPHICS_API extern const BlendMode BlendAdd; //!< Add source to dest
|
SFML_GRAPHICS_API extern const BlendMode BlendAdd; //!< Add source to dest
|
||||||
SFML_GRAPHICS_API extern const BlendMode BlendMultiply; //!< Multiply source and dest
|
SFML_GRAPHICS_API extern const BlendMode BlendMultiply; //!< Multiply source and dest
|
||||||
|
SFML_GRAPHICS_API extern const BlendMode BlendMin; //!< Take minimum between source and dest
|
||||||
|
SFML_GRAPHICS_API extern const BlendMode BlendMax; //!< Take maximum between source and dest
|
||||||
SFML_GRAPHICS_API extern const BlendMode BlendNone; //!< Overwrite dest with source
|
SFML_GRAPHICS_API extern const BlendMode BlendNone; //!< Overwrite dest with source
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
@ -37,8 +37,10 @@ const BlendMode BlendAlpha(BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, Ble
|
|||||||
BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add);
|
BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add);
|
||||||
const BlendMode BlendAdd(BlendMode::SrcAlpha, BlendMode::One, BlendMode::Add,
|
const BlendMode BlendAdd(BlendMode::SrcAlpha, BlendMode::One, BlendMode::Add,
|
||||||
BlendMode::One, BlendMode::One, BlendMode::Add);
|
BlendMode::One, BlendMode::One, BlendMode::Add);
|
||||||
const BlendMode BlendMultiply(BlendMode::DstColor, BlendMode::Zero);
|
const BlendMode BlendMultiply(BlendMode::DstColor, BlendMode::Zero, BlendMode::Add);
|
||||||
const BlendMode BlendNone(BlendMode::One, BlendMode::Zero);
|
const BlendMode BlendMin(BlendMode::One, BlendMode::One, BlendMode::Min);
|
||||||
|
const BlendMode BlendMax(BlendMode::One, BlendMode::One, BlendMode::Max);
|
||||||
|
const BlendMode BlendNone(BlendMode::One, BlendMode::Zero, BlendMode::Add);
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
#define GLEXT_multitexture true
|
#define GLEXT_multitexture true
|
||||||
#define GLEXT_texture_edge_clamp true
|
#define GLEXT_texture_edge_clamp true
|
||||||
#define GLEXT_EXT_texture_edge_clamp true
|
#define GLEXT_EXT_texture_edge_clamp true
|
||||||
#define GLEXT_blend_minmax true
|
|
||||||
#define GLEXT_glClientActiveTexture glClientActiveTexture
|
#define GLEXT_glClientActiveTexture glClientActiveTexture
|
||||||
#define GLEXT_glActiveTexture glActiveTexture
|
#define GLEXT_glActiveTexture glActiveTexture
|
||||||
#define GLEXT_GL_TEXTURE0 GL_TEXTURE0
|
#define GLEXT_GL_TEXTURE0 GL_TEXTURE0
|
||||||
@ -140,6 +139,11 @@
|
|||||||
#define GLEXT_texture_sRGB false
|
#define GLEXT_texture_sRGB false
|
||||||
#define GLEXT_GL_SRGB8_ALPHA8 0
|
#define GLEXT_GL_SRGB8_ALPHA8 0
|
||||||
|
|
||||||
|
// Core since 3.0 - EXT_blend_minmax
|
||||||
|
#define GLEXT_blend_minmax SF_GLAD_GL_EXT_blend_minmax
|
||||||
|
#define GLEXT_GL_MIN GL_MIN_EXT
|
||||||
|
#define GLEXT_GL_MAX GL_MAX_EXT
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// SFML requires at a bare minimum OpenGL 1.1 capability
|
// SFML requires at a bare minimum OpenGL 1.1 capability
|
||||||
@ -164,6 +168,8 @@
|
|||||||
#define GLEXT_blend_minmax SF_GLAD_GL_EXT_blend_minmax
|
#define GLEXT_blend_minmax SF_GLAD_GL_EXT_blend_minmax
|
||||||
#define GLEXT_glBlendEquation glBlendEquationEXT
|
#define GLEXT_glBlendEquation glBlendEquationEXT
|
||||||
#define GLEXT_GL_FUNC_ADD GL_FUNC_ADD_EXT
|
#define GLEXT_GL_FUNC_ADD GL_FUNC_ADD_EXT
|
||||||
|
#define GLEXT_GL_MIN GL_MIN_EXT
|
||||||
|
#define GLEXT_GL_MAX GL_MAX_EXT
|
||||||
|
|
||||||
// Core since 1.2 - EXT_blend_subtract
|
// Core since 1.2 - EXT_blend_subtract
|
||||||
#define GLEXT_blend_subtract SF_GLAD_GL_EXT_blend_subtract
|
#define GLEXT_blend_subtract SF_GLAD_GL_EXT_blend_subtract
|
||||||
|
@ -110,13 +110,36 @@ namespace
|
|||||||
{
|
{
|
||||||
switch (blendEquation)
|
switch (blendEquation)
|
||||||
{
|
{
|
||||||
case sf::BlendMode::Add: return GLEXT_GL_FUNC_ADD;
|
case sf::BlendMode::Add:
|
||||||
case sf::BlendMode::Subtract: return GLEXT_GL_FUNC_SUBTRACT;
|
return GLEXT_GL_FUNC_ADD;
|
||||||
case sf::BlendMode::ReverseSubtract: return GLEXT_GL_FUNC_REVERSE_SUBTRACT;
|
case sf::BlendMode::Subtract:
|
||||||
|
if (GLEXT_blend_subtract)
|
||||||
|
return GLEXT_GL_FUNC_SUBTRACT;
|
||||||
|
break;
|
||||||
|
case sf::BlendMode::ReverseSubtract:
|
||||||
|
if (GLEXT_blend_subtract)
|
||||||
|
return GLEXT_GL_FUNC_REVERSE_SUBTRACT;
|
||||||
|
break;
|
||||||
|
case sf::BlendMode::Min:
|
||||||
|
if (GLEXT_blend_minmax)
|
||||||
|
return GLEXT_GL_MIN;
|
||||||
|
break;
|
||||||
|
case sf::BlendMode::Max:
|
||||||
|
if (GLEXT_blend_minmax)
|
||||||
|
return GLEXT_GL_MAX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool warned = false;
|
||||||
|
if (!warned)
|
||||||
|
{
|
||||||
|
sf::err() << "OpenGL extension EXT_blend_minmax or EXT_blend_subtract unavailable" << std::endl;
|
||||||
|
sf::err() << "Some blending equations will fallback to sf::BlendMode::Add" << std::endl;
|
||||||
|
sf::err() << "Ensure that hardware acceleration is enabled if available" << std::endl;
|
||||||
|
|
||||||
|
warned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::err() << "Invalid value for sf::BlendMode::Equation! Fallback to sf::BlendMode::Add." << std::endl;
|
|
||||||
assert(false);
|
|
||||||
return GLEXT_GL_FUNC_ADD;
|
return GLEXT_GL_FUNC_ADD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -591,7 +614,7 @@ void RenderTarget::applyBlendMode(const BlendMode& mode)
|
|||||||
factorToGlConstant(mode.colorDstFactor)));
|
factorToGlConstant(mode.colorDstFactor)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GLEXT_blend_minmax && GLEXT_blend_subtract)
|
if (GLEXT_blend_minmax || GLEXT_blend_subtract)
|
||||||
{
|
{
|
||||||
if (GLEXT_blend_equation_separate)
|
if (GLEXT_blend_equation_separate)
|
||||||
{
|
{
|
||||||
@ -610,7 +633,11 @@ void RenderTarget::applyBlendMode(const BlendMode& mode)
|
|||||||
|
|
||||||
if (!warned)
|
if (!warned)
|
||||||
{
|
{
|
||||||
err() << "OpenGL extension EXT_blend_minmax and/or EXT_blend_subtract unavailable" << std::endl;
|
#ifdef SFML_OPENGL_ES
|
||||||
|
err() << "OpenGL ES extension OES_blend_subtract unavailable" << std::endl;
|
||||||
|
#else
|
||||||
|
err() << "OpenGL extension EXT_blend_minmax and EXT_blend_subtract unavailable" << std::endl;
|
||||||
|
#endif
|
||||||
err() << "Selecting a blend equation not possible" << std::endl;
|
err() << "Selecting a blend equation not possible" << std::endl;
|
||||||
err() << "Ensure that hardware acceleration is enabled if available" << std::endl;
|
err() << "Ensure that hardware acceleration is enabled if available" << std::endl;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user