Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Blend.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 *
21 * Part of this file comes from SFML, with the same license:
22 * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23 */
24#ifndef GF_BLEND_H
25#define GF_BLEND_H
26
27#include "GraphicsApi.h"
28
29namespace gf {
30#ifndef DOXYGEN_SHOULD_SKIP_THIS
31inline namespace v1 {
32#endif
33
44 enum class BlendEquation {
45 Add,
46 Substract,
48 };
49
60 enum class BlendFactor {
61 Zero,
62 One,
63 SrcColor,
65 DstColor,
67 SrcAlpha,
69 DstAlpha,
71 };
72
126 struct GF_GRAPHICS_API BlendMode {
127
133 constexpr BlendMode()
134 : colorSrcFactor(BlendFactor::One)
135 , colorDstFactor(BlendFactor::Zero)
136 , colorEquation(BlendEquation::Add)
137 , alphaSrcFactor(BlendFactor::One)
138 , alphaDstFactor(BlendFactor::Zero)
139 , alphaEquation(BlendEquation::Add)
140 {
141
142 }
143
154 constexpr BlendMode(BlendFactor sourceFactor, BlendFactor destinationFactor, BlendEquation equation = BlendEquation::Add)
155 : colorSrcFactor(sourceFactor)
156 , colorDstFactor(destinationFactor)
157 , colorEquation(equation)
158 , alphaSrcFactor(sourceFactor)
159 , alphaDstFactor(destinationFactor)
160 , alphaEquation(equation)
161 {
162
163 }
164
175 constexpr BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDestinationFactor, BlendEquation colorBlendEquation,
176 BlendFactor alphaSourceFactor, BlendFactor alphaDestinationFactor, BlendEquation alphaBlendEquation)
177 : colorSrcFactor(colorSourceFactor)
178 , colorDstFactor(colorDestinationFactor)
179 , colorEquation(colorBlendEquation)
180 , alphaSrcFactor(alphaSourceFactor)
181 , alphaDstFactor(alphaDestinationFactor)
182 , alphaEquation(alphaBlendEquation)
183 {
184
185 }
186
193 };
194
205 #ifndef DOXYGEN_SHOULD_SKIP_THIS
206 = BlendMode(
209 )
210 #endif
211 ;
212
222 #ifndef DOXYGEN_SHOULD_SKIP_THIS
223 = BlendMode(
226 )
227 #endif
228 ;
229
239 #ifndef DOXYGEN_SHOULD_SKIP_THIS
241 #endif
242 ;
243
253 #ifndef DOXYGEN_SHOULD_SKIP_THIS
255 #endif
256 ;
257
258
267 constexpr bool operator==(const BlendMode& lhs, const BlendMode& rhs) {
268 return lhs.colorSrcFactor == rhs.colorSrcFactor
269 && lhs.colorDstFactor == rhs.colorDstFactor
270 && lhs.colorEquation == rhs.colorEquation
271 && lhs.alphaSrcFactor == rhs.alphaSrcFactor
272 && lhs.alphaDstFactor == rhs.alphaDstFactor
273 && lhs.alphaEquation == rhs.alphaEquation;
274 }
275
276#ifndef DOXYGEN_SHOULD_SKIP_THIS
277}
278#endif
279}
280
281#endif // GF_BLEND_H
constexpr ZeroType Zero
Constant to represent "zero".
Definition: Types.h:93
The namespace for gf classes.
constexpr BlendMode BlendAlpha
Alpha blend mode.
Definition: Blend.h:211
BlendEquation
Enumeration of the blending equations.
Definition: Blend.h:44
@ Substract
Pixel = Src * SrcFactor - Dst * DstFactor.
@ Add
Pixel = Src * SrcFactor + Dst * DstFactor.
@ ReverseSubstract
Pixel = Dst * DstFactor - Src * SrcFactor.
constexpr BlendMode BlendNone
No blend mode.
Definition: Blend.h:256
constexpr BlendMode BlendMultiply
Multiplicative blend mode.
Definition: Blend.h:242
constexpr BlendMode BlendAdd
Additive blend mode.
Definition: Blend.h:228
BlendFactor
Enumeration of the blending factors.
Definition: Blend.h:60
@ One
(1, 1, 1, 1)
@ OneMinusSrcColor
(1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
@ OneMinusDstColor
(1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
@ SrcColor
(src.r, src.g, src.b, src.a)
@ OneMinusDstAlpha
(1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
@ OneMinusSrcAlpha
(1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
@ SrcAlpha
(src.a, src.a, src.a, src.a)
@ Zero
(0, 0, 0, 0)
@ DstAlpha
(dst.a, dst.a, dst.a, dst.a)
@ DstColor
(dst.r, dst.g, dst.b, dst.a)
Blending modes for drawing.
Definition: Blend.h:126
BlendEquation alphaEquation
Blending equation for the alpha channel.
Definition: Blend.h:192
constexpr bool operator==(const BlendMode &lhs, const BlendMode &rhs)
Equality operator.
Definition: Blend.h:267
constexpr BlendMode()
Default constructor.
Definition: Blend.h:133
BlendFactor colorSrcFactor
Source blending factor for the color channels.
Definition: Blend.h:187
BlendFactor alphaSrcFactor
Source blending factor for the alpha channel.
Definition: Blend.h:190
BlendEquation colorEquation
Blending equation for the color channels.
Definition: Blend.h:189
constexpr BlendMode(BlendFactor sourceFactor, BlendFactor destinationFactor, BlendEquation equation=BlendEquation::Add)
Construct the blend mode given the factors and equation.
Definition: Blend.h:154
BlendFactor alphaDstFactor
Destination blending factor for the alpha channel.
Definition: Blend.h:191
BlendFactor colorDstFactor
Destination blending factor for the color channels.
Definition: Blend.h:188
constexpr BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDestinationFactor, BlendEquation colorBlendEquation, BlendFactor alphaSourceFactor, BlendFactor alphaDestinationFactor, BlendEquation alphaBlendEquation)
Construct the blend mode given the factors and equation.
Definition: Blend.h:175