Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Blend.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 "Portability.h"
28 
29 namespace gf {
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 inline 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_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 
204  constexpr BlendMode BlendAlpha
205  #ifndef DOXYGEN_SHOULD_SKIP_THIS
206  = BlendMode(
209  )
210  #endif
211  ;
212 
221  constexpr BlendMode BlendAdd
222  #ifndef DOXYGEN_SHOULD_SKIP_THIS
223  = BlendMode(
226  )
227  #endif
228  ;
229 
238  constexpr BlendMode BlendMultiply
239  #ifndef DOXYGEN_SHOULD_SKIP_THIS
241  #endif
242  ;
243 
252  constexpr BlendMode BlendNone
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
Pixel = Dst * DstFactor - Src * SrcFactor.
BlendEquation alphaEquation
Blending equation for the alpha channel.
Definition: Blend.h:192
(1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
(1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
BlendFactor colorSrcFactor
Source blending factor for the color channels.
Definition: Blend.h:187
constexpr BlendMode BlendAlpha
Alpha blend mode.
Definition: Blend.h:211
constexpr BlendMode BlendNone
No blend mode.
Definition: Blend.h:256
Pixel = Src * SrcFactor - Dst * DstFactor.
(1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
BlendFactor colorDstFactor
Destination blending factor for the color channels.
Definition: Blend.h:188
BlendFactor alphaDstFactor
Destination blending factor for the alpha channel.
Definition: Blend.h:191
BlendEquation colorEquation
Blending equation for the color channels.
Definition: Blend.h:189
(dst.r, dst.g, dst.b, dst.a)
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
The namespace for gf classes.
Definition: Action.h:35
BlendFactor alphaSrcFactor
Source blending factor for the alpha channel.
Definition: Blend.h:190
constexpr BlendMode BlendMultiply
Multiplicative blend mode.
Definition: Blend.h:242
Pixel = Src * SrcFactor + Dst * DstFactor.
Blending modes for drawing.
Definition: Blend.h:126
(src.a, src.a, src.a, src.a)
constexpr BlendMode BlendAdd
Additive blend mode.
Definition: Blend.h:228
(1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
constexpr BlendMode()
Default constructor.
Definition: Blend.h:133
constexpr bool operator==(const BlendMode &lhs, const BlendMode &rhs)
Equality operator.
Definition: Blend.h:267
BlendFactor
Enumeration of the blending factors.
Definition: Blend.h:60
(src.r, src.g, src.b, src.a)
BlendEquation
Enumeration of the blending equations.
Definition: Blend.h:44
constexpr BlendMode(BlendFactor sourceFactor, BlendFactor destinationFactor, BlendEquation equation=BlendEquation::Add)
Construct the blend mode given the factors and equation.
Definition: Blend.h:154
(dst.a, dst.a, dst.a, dst.a)