From 951b774c704d2c9d51c0a1e2caa41423d35e6e21 Mon Sep 17 00:00:00 2001 From: Thomas Galvin Date: Mon, 20 Jan 2014 20:52:45 -0500 Subject: [PATCH 1/7] Implemented a more flexible blending system (fixes #298) --- include/SFML/Graphics/BlendMode.hpp | 151 ++++++++++++++++++++++++++-- src/SFML/Graphics/BlendMode.cpp | 93 +++++++++++++++++ src/SFML/Graphics/CMakeLists.txt | 7 +- src/SFML/Graphics/RenderTarget.cpp | 84 ++++++++++------ 4 files changed, 293 insertions(+), 42 deletions(-) create mode 100644 src/SFML/Graphics/BlendMode.cpp diff --git a/include/SFML/Graphics/BlendMode.hpp b/include/SFML/Graphics/BlendMode.hpp index 4b12e117e..1a93a7111 100644 --- a/include/SFML/Graphics/BlendMode.hpp +++ b/include/SFML/Graphics/BlendMode.hpp @@ -25,22 +25,161 @@ #ifndef SFML_BLENDMODE_HPP #define SFML_BLENDMODE_HPP +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + namespace sf { + //////////////////////////////////////////////////////////// /// \ingroup graphics -/// \brief Available blending modes for drawing +/// \brief Blending modes for drawing /// //////////////////////////////////////////////////////////// -enum BlendMode +struct SFML_GRAPHICS_API BlendMode { - BlendAlpha, ///< Pixel = Source * Source.a + Dest * (1 - Source.a) - BlendAdd, ///< Pixel = Source + Dest - BlendMultiply, ///< Pixel = Source * Dest - BlendNone ///< Pixel = Source + //////////////////////////////////////////////////////// + /// \ingroup graphics + /// \brief Enumeration of the blending factors + /// + //////////////////////////////////////////////////////// + enum BlendFactor + { + Zero, ///< (0,0,0,0) + One, ///< (1,1,1,1) + SrcColor, ///< (src.r,src.g,src.b,src.a) + OneMinusSrcColor, ///< (1,1,1,1) - (src.r,src.g,src.b,src.a) + DstColor, ///< (dst.r,dst.g,dst.b,dst.a) + OneMinusDstColor, ///< (1,1,1,1) - (dst.r,dst.g,dst.b,dst.a) + SrcAlpha, ///< (src.a,src.a,src.a,src.a) + OneMinusSrcAlpha, ///< (1,1,1,1) - (src.a,src.a,src.a,src.a) + DstAlpha, ///< (dst.a,dst.a,dst.a,dst.a) + OneMinusDstAlpha, ///< (1,1,1,1) - (dst.a,dst.a,dst.a,dst.a) + }; + + //////////////////////////////////////////////////////// + /// \ingroup graphics + /// \brief Enumeration of the blending equations + /// + //////////////////////////////////////////////////////// + enum BlendEquation + { + Add, ///< Pixel = Source * SourceFactor + Dst * DstFactor + Subtract, ///< Pixel = Source * SourceFactor - Dst * DstFactor + }; + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// Constructs a blending mode that does alpha blending. + /// + //////////////////////////////////////////////////////////// + BlendMode(); + + //////////////////////////////////////////////////////////// + /// \brief Construct the blend mode given the factors and equation. + /// + /// \param colorSourceFactor Specifies how to compute the source factor for the color channels. + /// \param colorDstFactor Specifies how to compute the destination factor for the color channels. + /// \param colorBlendEquation Specifies how to combine the source and destination colors. + /// \param alphaSourceFactor Specifies how to compute the source factor. + /// \param alphaDstFactor Specifies how to compute the destination factor. + /// \param alphaBlendEquation Specifies how to combine the source and destination alphas. + /// + /// + //////////////////////////////////////////////////////////// + BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDstFactor, + BlendEquation colorBlendEquation, BlendFactor alphaSourceFactor, + BlendFactor alphaDstFactor, BlendEquation alphaBlendEquation); + + //////////////////////////////////////////////////////////// + // Member Data + //////////////////////////////////////////////////////////// + BlendFactor colorSrcFactor; ///< Source blending factor for the color channels + BlendFactor colorDstFactor; ///< Destination blending factor for the color channels + BlendEquation colorEquation; ///< Blending equation for the color channels + BlendFactor alphaSrcFactor; ///< Source blending factor for the alpha channel + BlendFactor alphaDstFactor; ///< Destination blending factor for the alpha channel + BlendEquation alphaEquation; ///< Blending equation for the alpha channel }; +//////////////////////////////////////////////////////////// +/// \relates BlendMode +/// \brief Overload of the == operator +/// +/// This operator compares two blending modes and checks if they are equal. +/// +/// \param left Left operand +/// \param right Right operand +/// +/// \return True if blending modes are equal, false if they are different +/// +//////////////////////////////////////////////////////////// +SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right); + +//////////////////////////////////////////////////////////// +/// \relates BlendMode +/// \brief Overload of the != operator +/// +/// This operator compares two blending modes and checks if they are different. +/// +/// \param left Left operand +/// \param right Right operand +/// +/// \return True if blending modes are different, false if they are equal +/// +//////////////////////////////////////////////////////////// +SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right); + + +//////////////////////////////////////////////////////////// +// Commonly used blending modes +//////////////////////////////////////////////////////////// +SFML_GRAPHICS_API extern const BlendMode BlendAlpha; +SFML_GRAPHICS_API extern const BlendMode BlendAdd; +SFML_GRAPHICS_API extern const BlendMode BlendMultiply; +SFML_GRAPHICS_API extern const BlendMode BlendNone; + } // namespace sf #endif // SFML_BLENDMODE_HPP + + +//////////////////////////////////////////////////////////// +/// \class sf::BlendMode +/// \ingroup graphics +/// +/// sf::BlendMode is a class that represents a blend mode. A +/// blend mode is composed of 6 components: +/// \li %Color Source Factor (colorSrcFactor) +/// \li %Color Destination Factor (colorDstFactor) +/// \li %Color Blend Equation (colorEquation) +/// \li Alpha Source Factor (alphaSrcFactor) +/// \li Alpha Destination Factor (alphaDstFactor) +/// \li Alpha Blend Equation (alphaEquation) +/// +/// Each component has its own setter function. These make +/// modifying a blending mode rather easy: +/// +/// \code +/// sf::BlendMode blendMode; // Standard alpha blending +/// blendMode.colorSrcFactor = sf::BlendMode::One; // Pre-multiplied alpha blending +/// blendMode.colorEquation = sf::BlendMode::Subtract; // An exotic subtraction blending mode +/// \endcode +/// +/// The most common blending modes are defined as const +/// variables for convenience and compatibility with older +/// code: +/// +/// \code +/// sf::BlendMode alphaBlending = sf::BlendAlpha; +/// sf::BlendMode additiveBlending = sf::BlendAdd; +/// sf::BlendMode multiplicativeBlending = sf::BlendMultipy; +/// sf::BlendMode noBlending = sf::BlendNone; +/// \endcode +/// +//////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/BlendMode.cpp b/src/SFML/Graphics/BlendMode.cpp new file mode 100644 index 000000000..4145a228d --- /dev/null +++ b/src/SFML/Graphics/BlendMode.cpp @@ -0,0 +1,93 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +// Commonly used blending modes +//////////////////////////////////////////////////////////// +const BlendMode BlendAlpha(BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, BlendMode::Add, + BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add); +const BlendMode BlendAdd(BlendMode::SrcAlpha, BlendMode::One, BlendMode::Add, + BlendMode::One, BlendMode::One, BlendMode::Add); +const BlendMode BlendMultiply(BlendMode::DstColor, BlendMode::Zero, BlendMode::Add, + BlendMode::DstColor, BlendMode::Zero, BlendMode::Add); +const BlendMode BlendNone(BlendMode::One, BlendMode::Zero, BlendMode::Add, + BlendMode::One, BlendMode::Zero, BlendMode::Add); + + +//////////////////////////////////////////////////////////// +BlendMode::BlendMode() : +colorSrcFactor(BlendMode::SrcAlpha), +colorDstFactor(BlendMode::OneMinusSrcAlpha), +colorEquation (BlendMode::Add), +alphaSrcFactor(BlendMode::One), +alphaDstFactor(BlendMode::OneMinusSrcAlpha), +alphaEquation (BlendMode::Add) +{ + +} + + +//////////////////////////////////////////////////////////// +BlendMode::BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDstFactor, + BlendEquation colorBlendEquation, BlendFactor alphaSourceFactor, + BlendFactor alphaDstFactor, BlendEquation alphaBlendEquation) : +colorSrcFactor(colorSourceFactor), +colorDstFactor(colorDstFactor), +colorEquation (colorBlendEquation), +alphaSrcFactor(alphaSourceFactor), +alphaDstFactor(alphaDstFactor), +alphaEquation (alphaBlendEquation) +{ + +} + + +//////////////////////////////////////////////////////////// +bool operator ==(const BlendMode& left, const BlendMode& right) +{ + return (left.colorSrcFactor == right.colorSrcFactor) && + (left.colorDstFactor == right.colorDstFactor) && + (left.colorEquation == right.colorEquation) && + (left.alphaSrcFactor == right.alphaSrcFactor) && + (left.alphaDstFactor == right.alphaDstFactor) && + (left.alphaEquation == right.alphaEquation); +} + + +//////////////////////////////////////////////////////////// +bool operator !=(const BlendMode& left, const BlendMode& right) +{ + return !(left == right); +} + +} // namespace sf diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index ca11e1b09..999483af3 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -4,6 +4,7 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/src/SFML/Graphics) # all source files set(SRC + ${SRCROOT}/BlendMode.cpp ${INCROOT}/BlendMode.hpp ${SRCROOT}/Color.cpp ${INCROOT}/Color.hpp @@ -86,15 +87,15 @@ source_group("stb_image" FILES ${STB_SRC}) # let CMake know about our additional graphics libraries paths (on Windows and OSX) if(SFML_OS_WINDOWS OR SFML_OS_MACOSX) set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/jpeg") -endif() - +endif() + if(SFML_OS_WINDOWS) set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/windows") set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/windows/freetype") elseif(SFML_OS_MACOSX) set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/osx") set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/osx/freetype2") - set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-osx/Frameworks") + set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-osx/Frameworks") endif() # find external libraries diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 9c94bebbd..e5a62ec52 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -35,6 +35,41 @@ #include +namespace +{ + // Convert an sf::BlendMode::BlendFactor constant to the corresponding OpenGL constant. + sf::Uint32 factorToGlConstant(sf::BlendMode::BlendFactor blendFactor) + { + switch (blendFactor) + { + default: + case sf::BlendMode::Zero: return GL_ZERO; + case sf::BlendMode::One: return GL_ONE; + case sf::BlendMode::SrcColor: return GL_SRC_COLOR; + case sf::BlendMode::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR; + case sf::BlendMode::DstColor: return GL_DST_COLOR; + case sf::BlendMode::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR; + case sf::BlendMode::SrcAlpha: return GL_SRC_ALPHA; + case sf::BlendMode::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA; + case sf::BlendMode::DstAlpha: return GL_DST_ALPHA; + case sf::BlendMode::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA; + } + } + + + // Convert an sf::BlendMode::BlendEquation constant to the corresponding OpenGL constant. + sf::Uint32 equationToGlConstant(sf::BlendMode::BlendEquation blendEquation) + { + switch (blendEquation) + { + default: + case sf::BlendMode::Add: return GL_FUNC_ADD; + case sf::BlendMode::Subtract: return GL_FUNC_SUBTRACT; + } + } +} + + namespace sf { //////////////////////////////////////////////////////////// @@ -355,38 +390,20 @@ void RenderTarget::applyCurrentView() //////////////////////////////////////////////////////////// void RenderTarget::applyBlendMode(BlendMode mode) { - switch (mode) - { - // glBlendFuncSeparateEXT is used when available to avoid an incorrect alpha value when the target - // is a RenderTexture -- in this case the alpha value must be written directly to the target buffer + // Apply the blend mode, falling back to the non-separate versions if necessary + if (GLEW_EXT_blend_func_separate) + glCheck(glBlendFuncSeparateEXT(factorToGlConstant(mode.colorSrcFactor), + factorToGlConstant(mode.colorDstFactor), factorToGlConstant(mode.alphaSrcFactor), + factorToGlConstant(mode.alphaDstFactor))); + else + glCheck(glBlendFunc(factorToGlConstant(mode.colorSrcFactor), + factorToGlConstant(mode.colorDstFactor))); - // Alpha blending - default : - case BlendAlpha : - if (GLEW_EXT_blend_func_separate) - glCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); - else - glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - break; - - // Additive blending - case BlendAdd : - if (GLEW_EXT_blend_func_separate) - glCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE)); - else - glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE)); - break; - - // Multiplicative blending - case BlendMultiply : - glCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO)); - break; - - // No blending - case BlendNone : - glCheck(glBlendFunc(GL_ONE, GL_ZERO)); - break; - } + if (GLEW_EXT_blend_equation_separate) + glCheck(glBlendEquationSeparateEXT(equationToGlConstant(mode.colorEquation), + equationToGlConstant(mode.alphaEquation))); + else + glCheck(glBlendEquation(equationToGlConstant(mode.colorEquation))); m_cache.lastBlendMode = mode; } @@ -436,8 +453,9 @@ void RenderTarget::applyShader(const Shader* shader) // to render them. // // * Blending mode -// It's a simple integral value, so we can easily check -// whether the value to apply is the same as before or not. +// Since it overloads the == operator, we can easily check +// whether any of the 6 blending components changed and, +// thus, whether we need to update the blend mode. // // * Texture // Storing the pointer or OpenGL ID of the last used texture From 05d196d86dcf4bc5d462a3a766b9eed0ff9d22cd Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Wed, 12 Mar 2014 12:08:24 +0100 Subject: [PATCH 2/7] Fixed compile error (trailing enum comma) and other minor things --- include/SFML/Graphics/BlendMode.hpp | 35 +++++++++++--------------- include/SFML/Graphics/RenderTarget.hpp | 2 +- src/SFML/Graphics/BlendMode.cpp | 11 ++++---- src/SFML/Graphics/RenderTarget.cpp | 22 +++++++++++----- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/include/SFML/Graphics/BlendMode.hpp b/include/SFML/Graphics/BlendMode.hpp index f5deca84c..4e4a167ed 100644 --- a/include/SFML/Graphics/BlendMode.hpp +++ b/include/SFML/Graphics/BlendMode.hpp @@ -57,7 +57,7 @@ struct SFML_GRAPHICS_API BlendMode SrcAlpha, ///< (src.a,src.a,src.a,src.a) OneMinusSrcAlpha, ///< (1,1,1,1) - (src.a,src.a,src.a,src.a) DstAlpha, ///< (dst.a,dst.a,dst.a,dst.a) - OneMinusDstAlpha, ///< (1,1,1,1) - (dst.a,dst.a,dst.a,dst.a) + OneMinusDstAlpha ///< (1,1,1,1) - (dst.a,dst.a,dst.a,dst.a) }; //////////////////////////////////////////////////////// @@ -67,8 +67,8 @@ struct SFML_GRAPHICS_API BlendMode //////////////////////////////////////////////////////// enum BlendEquation { - Add, ///< Pixel = Source * SourceFactor + Dst * DstFactor - Subtract, ///< Pixel = Source * SourceFactor - Dst * DstFactor + Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor + Subtract ///< Pixel = Src * SrcFactor - Dst * DstFactor }; //////////////////////////////////////////////////////////// @@ -82,18 +82,17 @@ struct SFML_GRAPHICS_API BlendMode //////////////////////////////////////////////////////////// /// \brief Construct the blend mode given the factors and equation. /// - /// \param colorSourceFactor Specifies how to compute the source factor for the color channels. - /// \param colorDstFactor Specifies how to compute the destination factor for the color channels. - /// \param colorBlendEquation Specifies how to combine the source and destination colors. - /// \param alphaSourceFactor Specifies how to compute the source factor. - /// \param alphaDstFactor Specifies how to compute the destination factor. - /// \param alphaBlendEquation Specifies how to combine the source and destination alphas. - /// + /// \param colorSourceFactor Specifies how to compute the source factor for the color channels. + /// \param colorDestinationFactor Specifies how to compute the destination factor for the color channels. + /// \param colorBlendEquation Specifies how to combine the source and destination colors. + /// \param alphaSourceFactor Specifies how to compute the source factor. + /// \param alphaDestinationFactor Specifies how to compute the destination factor. + /// \param alphaBlendEquation Specifies how to combine the source and destination alphas. /// //////////////////////////////////////////////////////////// - BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDstFactor, + BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDestinationFactor, BlendEquation colorBlendEquation, BlendFactor alphaSourceFactor, - BlendFactor alphaDstFactor, BlendEquation alphaBlendEquation); + BlendFactor alphaDestinationFactor, BlendEquation alphaBlendEquation); //////////////////////////////////////////////////////////// // Member Data @@ -110,8 +109,6 @@ struct SFML_GRAPHICS_API BlendMode /// \relates BlendMode /// \brief Overload of the == operator /// -/// This operator compares two blending modes and checks if they are equal. -/// /// \param left Left operand /// \param right Right operand /// @@ -124,8 +121,6 @@ SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right /// \relates BlendMode /// \brief Overload of the != operator /// -/// This operator compares two blending modes and checks if they are different. -/// /// \param left Left operand /// \param right Right operand /// @@ -162,7 +157,7 @@ SFML_GRAPHICS_API extern const BlendMode BlendNone; /// \li Alpha Destination Factor (alphaDstFactor) /// \li Alpha Blend Equation (alphaEquation) /// -/// Each component has its own setter function. These make +/// Each component has its own public member variable. These make /// modifying a blending mode rather easy: /// /// \code @@ -171,9 +166,9 @@ SFML_GRAPHICS_API extern const BlendMode BlendNone; /// blendMode.colorEquation = sf::BlendMode::Subtract; // An exotic subtraction blending mode /// \endcode /// -/// The most common blending modes are defined as const -/// variables for convenience and compatibility with older -/// code: +/// The most common blending modes are defined as constants +/// in the sf namespace, for convenience and compatibility with +/// older code: /// /// \code /// sf::BlendMode alphaBlending = sf::BlendAlpha; diff --git a/include/SFML/Graphics/RenderTarget.hpp b/include/SFML/Graphics/RenderTarget.hpp index 8995d12c5..033e2c78c 100644 --- a/include/SFML/Graphics/RenderTarget.hpp +++ b/include/SFML/Graphics/RenderTarget.hpp @@ -354,7 +354,7 @@ private: /// \param mode Blending mode to apply /// //////////////////////////////////////////////////////////// - void applyBlendMode(BlendMode mode); + void applyBlendMode(const BlendMode& mode); //////////////////////////////////////////////////////////// /// \brief Apply a new transform diff --git a/src/SFML/Graphics/BlendMode.cpp b/src/SFML/Graphics/BlendMode.cpp index 4145a228d..9a7ab2279 100644 --- a/src/SFML/Graphics/BlendMode.cpp +++ b/src/SFML/Graphics/BlendMode.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -26,7 +26,6 @@ // Headers //////////////////////////////////////////////////////////// #include -#include namespace sf @@ -58,14 +57,14 @@ alphaEquation (BlendMode::Add) //////////////////////////////////////////////////////////// -BlendMode::BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDstFactor, +BlendMode::BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDestinationFactor, BlendEquation colorBlendEquation, BlendFactor alphaSourceFactor, - BlendFactor alphaDstFactor, BlendEquation alphaBlendEquation) : + BlendFactor alphaDestinationFactor, BlendEquation alphaBlendEquation) : colorSrcFactor(colorSourceFactor), -colorDstFactor(colorDstFactor), +colorDstFactor(colorDestinationFactor), colorEquation (colorBlendEquation), alphaSrcFactor(alphaSourceFactor), -alphaDstFactor(alphaDstFactor), +alphaDstFactor(alphaDestinationFactor), alphaEquation (alphaBlendEquation) { diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 3e756c8cf..4209ce7be 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -388,22 +388,32 @@ void RenderTarget::applyCurrentView() //////////////////////////////////////////////////////////// -void RenderTarget::applyBlendMode(BlendMode mode) +void RenderTarget::applyBlendMode(const BlendMode& mode) { // Apply the blend mode, falling back to the non-separate versions if necessary if (GLEW_EXT_blend_func_separate) - glCheck(glBlendFuncSeparateEXT(factorToGlConstant(mode.colorSrcFactor), - factorToGlConstant(mode.colorDstFactor), factorToGlConstant(mode.alphaSrcFactor), - factorToGlConstant(mode.alphaDstFactor))); + { + glCheck(glBlendFuncSeparateEXT( + factorToGlConstant(mode.colorSrcFactor), factorToGlConstant(mode.colorDstFactor), + factorToGlConstant(mode.alphaSrcFactor), factorToGlConstant(mode.alphaDstFactor))); + } else - glCheck(glBlendFunc(factorToGlConstant(mode.colorSrcFactor), + { + glCheck(glBlendFunc( + factorToGlConstant(mode.colorSrcFactor), factorToGlConstant(mode.colorDstFactor))); + } if (GLEW_EXT_blend_equation_separate) - glCheck(glBlendEquationSeparateEXT(equationToGlConstant(mode.colorEquation), + { + glCheck(glBlendEquationSeparateEXT( + equationToGlConstant(mode.colorEquation), equationToGlConstant(mode.alphaEquation))); + } else + { glCheck(glBlendEquation(equationToGlConstant(mode.colorEquation))); + } m_cache.lastBlendMode = mode; } From 75784dbb9a6695941a62c7401e2c211b17a27585 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Wed, 12 Mar 2014 12:22:47 +0100 Subject: [PATCH 3/7] Omitted "Blend" prefix for nested BlendMode enums BlendMode::Factor instead of BlendMode::BlendFactor BlendMode::Equation instead of BlendMode::BlendEquation --- include/SFML/Graphics/BlendMode.hpp | 22 +++++++++++----------- src/SFML/Graphics/BlendMode.cpp | 6 +++--- src/SFML/Graphics/RenderTarget.cpp | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/SFML/Graphics/BlendMode.hpp b/include/SFML/Graphics/BlendMode.hpp index 4e4a167ed..a59be8132 100644 --- a/include/SFML/Graphics/BlendMode.hpp +++ b/include/SFML/Graphics/BlendMode.hpp @@ -46,7 +46,7 @@ struct SFML_GRAPHICS_API BlendMode /// \brief Enumeration of the blending factors /// //////////////////////////////////////////////////////// - enum BlendFactor + enum Factor { Zero, ///< (0,0,0,0) One, ///< (1,1,1,1) @@ -65,7 +65,7 @@ struct SFML_GRAPHICS_API BlendMode /// \brief Enumeration of the blending equations /// //////////////////////////////////////////////////////// - enum BlendEquation + enum Equation { Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor Subtract ///< Pixel = Src * SrcFactor - Dst * DstFactor @@ -90,19 +90,19 @@ struct SFML_GRAPHICS_API BlendMode /// \param alphaBlendEquation Specifies how to combine the source and destination alphas. /// //////////////////////////////////////////////////////////// - BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDestinationFactor, - BlendEquation colorBlendEquation, BlendFactor alphaSourceFactor, - BlendFactor alphaDestinationFactor, BlendEquation alphaBlendEquation); + BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor, + Equation colorBlendEquation, Factor alphaSourceFactor, + Factor alphaDestinationFactor, Equation alphaBlendEquation); //////////////////////////////////////////////////////////// // Member Data //////////////////////////////////////////////////////////// - BlendFactor colorSrcFactor; ///< Source blending factor for the color channels - BlendFactor colorDstFactor; ///< Destination blending factor for the color channels - BlendEquation colorEquation; ///< Blending equation for the color channels - BlendFactor alphaSrcFactor; ///< Source blending factor for the alpha channel - BlendFactor alphaDstFactor; ///< Destination blending factor for the alpha channel - BlendEquation alphaEquation; ///< Blending equation for the alpha channel + Factor colorSrcFactor; ///< Source blending factor for the color channels + Factor colorDstFactor; ///< Destination blending factor for the color channels + Equation colorEquation; ///< Blending equation for the color channels + Factor alphaSrcFactor; ///< Source blending factor for the alpha channel + Factor alphaDstFactor; ///< Destination blending factor for the alpha channel + Equation alphaEquation; ///< Blending equation for the alpha channel }; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/BlendMode.cpp b/src/SFML/Graphics/BlendMode.cpp index 9a7ab2279..15b2ca5cc 100644 --- a/src/SFML/Graphics/BlendMode.cpp +++ b/src/SFML/Graphics/BlendMode.cpp @@ -57,9 +57,9 @@ alphaEquation (BlendMode::Add) //////////////////////////////////////////////////////////// -BlendMode::BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDestinationFactor, - BlendEquation colorBlendEquation, BlendFactor alphaSourceFactor, - BlendFactor alphaDestinationFactor, BlendEquation alphaBlendEquation) : +BlendMode::BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor, + Equation colorBlendEquation, Factor alphaSourceFactor, + Factor alphaDestinationFactor, Equation alphaBlendEquation) : colorSrcFactor(colorSourceFactor), colorDstFactor(colorDestinationFactor), colorEquation (colorBlendEquation), diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 4209ce7be..61dfb67a6 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -37,8 +37,8 @@ namespace { - // Convert an sf::BlendMode::BlendFactor constant to the corresponding OpenGL constant. - sf::Uint32 factorToGlConstant(sf::BlendMode::BlendFactor blendFactor) + // Convert an sf::BlendMode::Factor constant to the corresponding OpenGL constant. + sf::Uint32 factorToGlConstant(sf::BlendMode::Factor blendFactor) { switch (blendFactor) { @@ -58,7 +58,7 @@ namespace // Convert an sf::BlendMode::BlendEquation constant to the corresponding OpenGL constant. - sf::Uint32 equationToGlConstant(sf::BlendMode::BlendEquation blendEquation) + sf::Uint32 equationToGlConstant(sf::BlendMode::Equation blendEquation) { switch (blendEquation) { From fab46cdfd73cf17200ba992d6a560596b2d3b0ae Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sun, 16 Mar 2014 10:50:27 +0100 Subject: [PATCH 4/7] Improved formatting --- include/SFML/Graphics/BlendMode.hpp | 40 ++++++++++++++--------------- src/SFML/Graphics/BlendMode.cpp | 12 ++++----- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/SFML/Graphics/BlendMode.hpp b/include/SFML/Graphics/BlendMode.hpp index a59be8132..c091b41ef 100644 --- a/include/SFML/Graphics/BlendMode.hpp +++ b/include/SFML/Graphics/BlendMode.hpp @@ -48,16 +48,16 @@ struct SFML_GRAPHICS_API BlendMode //////////////////////////////////////////////////////// enum Factor { - Zero, ///< (0,0,0,0) - One, ///< (1,1,1,1) - SrcColor, ///< (src.r,src.g,src.b,src.a) - OneMinusSrcColor, ///< (1,1,1,1) - (src.r,src.g,src.b,src.a) - DstColor, ///< (dst.r,dst.g,dst.b,dst.a) - OneMinusDstColor, ///< (1,1,1,1) - (dst.r,dst.g,dst.b,dst.a) - SrcAlpha, ///< (src.a,src.a,src.a,src.a) - OneMinusSrcAlpha, ///< (1,1,1,1) - (src.a,src.a,src.a,src.a) - DstAlpha, ///< (dst.a,dst.a,dst.a,dst.a) - OneMinusDstAlpha ///< (1,1,1,1) - (dst.a,dst.a,dst.a,dst.a) + Zero, ///< (0, 0, 0, 0) + One, ///< (1, 1, 1, 1) + SrcColor, ///< (src.r, src.g, src.b, src.a) + OneMinusSrcColor, ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a) + DstColor, ///< (dst.r, dst.g, dst.b, dst.a) + OneMinusDstColor, ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a) + SrcAlpha, ///< (src.a, src.a, src.a, src.a) + OneMinusSrcAlpha, ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a) + DstAlpha, ///< (dst.a, dst.a, dst.a, dst.a) + OneMinusDstAlpha ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a) }; //////////////////////////////////////////////////////// @@ -67,8 +67,8 @@ struct SFML_GRAPHICS_API BlendMode //////////////////////////////////////////////////////// enum Equation { - Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor - Subtract ///< Pixel = Src * SrcFactor - Dst * DstFactor + Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor + Subtract ///< Pixel = Src * SrcFactor - Dst * DstFactor }; //////////////////////////////////////////////////////////// @@ -91,18 +91,18 @@ struct SFML_GRAPHICS_API BlendMode /// //////////////////////////////////////////////////////////// BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor, - Equation colorBlendEquation, Factor alphaSourceFactor, - Factor alphaDestinationFactor, Equation alphaBlendEquation); + Equation colorBlendEquation, Factor alphaSourceFactor, + Factor alphaDestinationFactor, Equation alphaBlendEquation); //////////////////////////////////////////////////////////// // Member Data //////////////////////////////////////////////////////////// - Factor colorSrcFactor; ///< Source blending factor for the color channels - Factor colorDstFactor; ///< Destination blending factor for the color channels - Equation colorEquation; ///< Blending equation for the color channels - Factor alphaSrcFactor; ///< Source blending factor for the alpha channel - Factor alphaDstFactor; ///< Destination blending factor for the alpha channel - Equation alphaEquation; ///< Blending equation for the alpha channel + Factor colorSrcFactor; ///< Source blending factor for the color channels + Factor colorDstFactor; ///< Destination blending factor for the color channels + Equation colorEquation; ///< Blending equation for the color channels + Factor alphaSrcFactor; ///< Source blending factor for the alpha channel + Factor alphaDstFactor; ///< Destination blending factor for the alpha channel + Equation alphaEquation; ///< Blending equation for the alpha channel }; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/BlendMode.cpp b/src/SFML/Graphics/BlendMode.cpp index 15b2ca5cc..e7ffd4901 100644 --- a/src/SFML/Graphics/BlendMode.cpp +++ b/src/SFML/Graphics/BlendMode.cpp @@ -34,13 +34,13 @@ namespace sf // Commonly used blending modes //////////////////////////////////////////////////////////// const BlendMode BlendAlpha(BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, BlendMode::Add, - BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add); + BlendMode::One, BlendMode::OneMinusSrcAlpha, 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, BlendMode::Add, - BlendMode::DstColor, BlendMode::Zero, BlendMode::Add); + BlendMode::DstColor, BlendMode::Zero, BlendMode::Add); const BlendMode BlendNone(BlendMode::One, BlendMode::Zero, BlendMode::Add, - BlendMode::One, BlendMode::Zero, BlendMode::Add); + BlendMode::One, BlendMode::Zero, BlendMode::Add); //////////////////////////////////////////////////////////// @@ -58,8 +58,8 @@ alphaEquation (BlendMode::Add) //////////////////////////////////////////////////////////// BlendMode::BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor, - Equation colorBlendEquation, Factor alphaSourceFactor, - Factor alphaDestinationFactor, Equation alphaBlendEquation) : + Equation colorBlendEquation, Factor alphaSourceFactor, + Factor alphaDestinationFactor, Equation alphaBlendEquation) : colorSrcFactor(colorSourceFactor), colorDstFactor(colorDestinationFactor), colorEquation (colorBlendEquation), From 330db58bc1cdc500ee02c68492d6295dd191b879 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sun, 16 Mar 2014 11:47:34 +0100 Subject: [PATCH 5/7] Improved documentation --- include/SFML/Graphics/BlendMode.hpp | 55 +++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/include/SFML/Graphics/BlendMode.hpp b/include/SFML/Graphics/BlendMode.hpp index c091b41ef..6017426df 100644 --- a/include/SFML/Graphics/BlendMode.hpp +++ b/include/SFML/Graphics/BlendMode.hpp @@ -45,6 +45,8 @@ struct SFML_GRAPHICS_API BlendMode /// \ingroup graphics /// \brief Enumeration of the blending factors /// + /// The factors are mapped directly to their OpenGL equivalents, + /// specified by glBlendFunc() or glBlendFuncSeparate(). //////////////////////////////////////////////////////// enum Factor { @@ -64,6 +66,8 @@ struct SFML_GRAPHICS_API BlendMode /// \ingroup graphics /// \brief Enumeration of the blending equations /// + /// The equations are mapped directly to their OpenGL equivalents, + /// specified by glBlendEquation() or glBlendEquationSeparate(). //////////////////////////////////////////////////////// enum Equation { @@ -148,27 +152,42 @@ SFML_GRAPHICS_API extern const BlendMode BlendNone; /// \class sf::BlendMode /// \ingroup graphics /// -/// sf::BlendMode is a class that represents a blend mode. A -/// blend mode is composed of 6 components: -/// \li %Color Source Factor (colorSrcFactor) -/// \li %Color Destination Factor (colorDstFactor) -/// \li %Color Blend Equation (colorEquation) -/// \li Alpha Source Factor (alphaSrcFactor) -/// \li Alpha Destination Factor (alphaDstFactor) -/// \li Alpha Blend Equation (alphaEquation) +/// sf::BlendMode is a class that represents a blend mode. A blend +/// mode determines how the colors of an object you draw are +/// mixed with the colors that are already in the buffer. +/// +/// The class is composed of 6 components, each of which has its +/// own public member variable: +/// \li %Color Source Factor (@ref colorSrcFactor) +/// \li %Color Destination Factor (@ref colorDstFactor) +/// \li %Color Blend Equation (@ref colorEquation) +/// \li Alpha Source Factor (@ref alphaSrcFactor) +/// \li Alpha Destination Factor (@ref alphaDstFactor) +/// \li Alpha Blend Equation (@ref alphaEquation) +/// +/// The source factor specifies how the pixel you are drawing contributes +/// to the final color. The destination factor specifies how the pixel +/// already drawn in the buffer contributes to the final color. /// -/// Each component has its own public member variable. These make -/// modifying a blending mode rather easy: +/// The color channels RGB (red, green, blue; simply referred to as +/// color) and A (alpha; the transparency) can be treated separately. This +/// separation can be useful for specific blend modes, but most often you +/// won't need it and will simply treat the color as a single unit. /// +/// The blend factors and equations correspond to their OpenGL equivalents. +/// In general, the color of the resulting pixel is calculated according +/// to the following formula (\a src is the color of the source pixel, \a dst +/// the color of the destination pixel, the other variables correspond to the +/// public members, with the equations being + or - operators): /// \code -/// sf::BlendMode blendMode; // Standard alpha blending -/// blendMode.colorSrcFactor = sf::BlendMode::One; // Pre-multiplied alpha blending -/// blendMode.colorEquation = sf::BlendMode::Subtract; // An exotic subtraction blending mode +/// dst.rgb = colorSrcFactor * src.rgb (colorEquation) colorDstFactor * dst.rgb +/// dst.a = alphaSrcFactor * src.a (alphaEquation) alphaDstFactor * dst.a /// \endcode +/// All factors and colors are represented as floating point numbers between +/// 0 and 1. Where necessary, the result is clamped to fit in that range. /// /// The most common blending modes are defined as constants -/// in the sf namespace, for convenience and compatibility with -/// older code: +/// in the sf namespace: /// /// \code /// sf::BlendMode alphaBlending = sf::BlendAlpha; @@ -177,4 +196,10 @@ SFML_GRAPHICS_API extern const BlendMode BlendNone; /// sf::BlendMode noBlending = sf::BlendNone; /// \endcode /// +/// In SFML, a blend mode can be specified every time you draw a sf::Drawable +/// object to a render target. It is part of the sf::RenderStates compound +/// that is passed to the member function sf::RenderTarget::draw(). +/// +/// \see sf::RenderStates, sf::RenderTarget +/// //////////////////////////////////////////////////////////// From ec494babbef305c69e24d79311ad07984a1b2463 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sun, 16 Mar 2014 11:58:45 +0100 Subject: [PATCH 6/7] Passed BlendMode objects by const-reference --- include/SFML/Graphics/RenderStates.hpp | 4 ++-- src/SFML/Graphics/RenderStates.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/SFML/Graphics/RenderStates.hpp b/include/SFML/Graphics/RenderStates.hpp index bae862978..986554b8e 100644 --- a/include/SFML/Graphics/RenderStates.hpp +++ b/include/SFML/Graphics/RenderStates.hpp @@ -66,7 +66,7 @@ public : /// \param theBlendMode Blend mode to use /// //////////////////////////////////////////////////////////// - RenderStates(BlendMode theBlendMode); + RenderStates(const BlendMode& theBlendMode); //////////////////////////////////////////////////////////// /// \brief Construct a default set of render states with a custom transform @@ -101,7 +101,7 @@ public : /// \param theShader Shader to use /// //////////////////////////////////////////////////////////// - RenderStates(BlendMode theBlendMode, const Transform& theTransform, + RenderStates(const BlendMode& theBlendMode, const Transform& theTransform, const Texture* theTexture, const Shader* theShader); //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/RenderStates.cpp b/src/SFML/Graphics/RenderStates.cpp index d66ec42a1..2ec3fb895 100644 --- a/src/SFML/Graphics/RenderStates.cpp +++ b/src/SFML/Graphics/RenderStates.cpp @@ -56,7 +56,7 @@ shader (NULL) //////////////////////////////////////////////////////////// -RenderStates::RenderStates(BlendMode theBlendMode) : +RenderStates::RenderStates(const BlendMode& theBlendMode) : blendMode(theBlendMode), transform(), texture (NULL), @@ -86,7 +86,7 @@ shader (theShader) //////////////////////////////////////////////////////////// -RenderStates::RenderStates(BlendMode theBlendMode, const Transform& theTransform, +RenderStates::RenderStates(const BlendMode& theBlendMode, const Transform& theTransform, const Texture* theTexture, const Shader* theShader) : blendMode(theBlendMode), transform(theTransform), From f99bbfc534c0402d140b61def91614bae43781ef Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Tue, 22 Apr 2014 21:37:39 +0200 Subject: [PATCH 7/7] Reviewed the sf::BlendMode class (added a constructor, made minor modifications in comments) --- include/SFML/Graphics/BlendMode.hpp | 25 +++++++++++++++++-------- src/SFML/Graphics/BlendMode.cpp | 19 +++++++++++++++---- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/SFML/Graphics/BlendMode.hpp b/include/SFML/Graphics/BlendMode.hpp index 6017426df..412286d06 100644 --- a/include/SFML/Graphics/BlendMode.hpp +++ b/include/SFML/Graphics/BlendMode.hpp @@ -35,14 +35,12 @@ namespace sf { //////////////////////////////////////////////////////////// -/// \ingroup graphics /// \brief Blending modes for drawing /// //////////////////////////////////////////////////////////// struct SFML_GRAPHICS_API BlendMode { //////////////////////////////////////////////////////// - /// \ingroup graphics /// \brief Enumeration of the blending factors /// /// The factors are mapped directly to their OpenGL equivalents, @@ -63,7 +61,6 @@ struct SFML_GRAPHICS_API BlendMode }; //////////////////////////////////////////////////////// - /// \ingroup graphics /// \brief Enumeration of the blending equations /// /// The equations are mapped directly to their OpenGL equivalents, @@ -83,6 +80,19 @@ struct SFML_GRAPHICS_API BlendMode //////////////////////////////////////////////////////////// BlendMode(); + //////////////////////////////////////////////////////////// + /// \brief Construct the blend mode given the factors and equation. + /// + /// This constructor uses the same factors and equation for both + /// color and alpha components. It also defaults to the Add equation. + /// + /// \param sourceFactor Specifies how to compute the source factor for the color and alpha channels. + /// \param destinationFactor Specifies how to compute the destination factor for the color and alpha channels. + /// \param blendEquation Specifies how to combine the source and destination colors and alpha. + /// + //////////////////////////////////////////////////////////// + BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Add); + //////////////////////////////////////////////////////////// /// \brief Construct the blend mode given the factors and equation. /// @@ -133,14 +143,13 @@ SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right //////////////////////////////////////////////////////////// SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right); - //////////////////////////////////////////////////////////// // Commonly used blending modes //////////////////////////////////////////////////////////// -SFML_GRAPHICS_API extern const BlendMode BlendAlpha; -SFML_GRAPHICS_API extern const BlendMode BlendAdd; -SFML_GRAPHICS_API extern const BlendMode BlendMultiply; -SFML_GRAPHICS_API extern const BlendMode BlendNone; +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 BlendMultiply; ///< Multiply source and dest +SFML_GRAPHICS_API extern const BlendMode BlendNone; ///< Overwrite dest with source } // namespace sf diff --git a/src/SFML/Graphics/BlendMode.cpp b/src/SFML/Graphics/BlendMode.cpp index e7ffd4901..3d392f441 100644 --- a/src/SFML/Graphics/BlendMode.cpp +++ b/src/SFML/Graphics/BlendMode.cpp @@ -37,10 +37,8 @@ const BlendMode BlendAlpha(BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, Ble BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add); const BlendMode BlendAdd(BlendMode::SrcAlpha, BlendMode::One, BlendMode::Add, BlendMode::One, BlendMode::One, BlendMode::Add); -const BlendMode BlendMultiply(BlendMode::DstColor, BlendMode::Zero, BlendMode::Add, - BlendMode::DstColor, BlendMode::Zero, BlendMode::Add); -const BlendMode BlendNone(BlendMode::One, BlendMode::Zero, BlendMode::Add, - BlendMode::One, BlendMode::Zero, BlendMode::Add); +const BlendMode BlendMultiply(BlendMode::DstColor, BlendMode::Zero); +const BlendMode BlendNone(BlendMode::One, BlendMode::Zero); //////////////////////////////////////////////////////////// @@ -56,6 +54,19 @@ alphaEquation (BlendMode::Add) } +//////////////////////////////////////////////////////////// +BlendMode::BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation) : +colorSrcFactor(sourceFactor), +colorDstFactor(destinationFactor), +colorEquation (blendEquation), +alphaSrcFactor(sourceFactor), +alphaDstFactor(destinationFactor), +alphaEquation (blendEquation) +{ + +} + + //////////////////////////////////////////////////////////// BlendMode::BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor, Equation colorBlendEquation, Factor alphaSourceFactor,