Gamedev Framework (gf)  0.7.0
A C++14 framework for 2D games
Blend.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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 
132  struct GF_API BlendMode {
133 
139  constexpr BlendMode()
140  : colorSrcFactor(BlendFactor::One)
141  , colorDstFactor(BlendFactor::Zero)
142  , colorEquation(BlendEquation::Add)
143  , alphaSrcFactor(BlendFactor::One)
144  , alphaDstFactor(BlendFactor::Zero)
145  , alphaEquation(BlendEquation::Add)
146  {
147 
148  }
149 
160  constexpr BlendMode(BlendFactor sourceFactor, BlendFactor destinationFactor, BlendEquation equation = BlendEquation::Add)
161  : colorSrcFactor(sourceFactor)
162  , colorDstFactor(destinationFactor)
163  , colorEquation(equation)
164  , alphaSrcFactor(sourceFactor)
165  , alphaDstFactor(destinationFactor)
166  , alphaEquation(equation)
167  {
168 
169  }
170 
181  constexpr BlendMode(BlendFactor colorSourceFactor, BlendFactor colorDestinationFactor, BlendEquation colorBlendEquation,
182  BlendFactor alphaSourceFactor, BlendFactor alphaDestinationFactor, BlendEquation alphaBlendEquation)
183  : colorSrcFactor(colorSourceFactor)
184  , colorDstFactor(colorDestinationFactor)
185  , colorEquation(colorBlendEquation)
186  , alphaSrcFactor(alphaSourceFactor)
187  , alphaDstFactor(alphaDestinationFactor)
188  , alphaEquation(alphaBlendEquation)
189  {
190 
191  }
192 
199  };
200 
210  constexpr BlendMode BlendAlpha
211  #ifndef DOXYGEN_SHOULD_SKIP_THIS
212  = BlendMode(
215  )
216  #endif
217  ;
218 
227  constexpr BlendMode BlendAdd
228  #ifndef DOXYGEN_SHOULD_SKIP_THIS
229  = BlendMode(
232  )
233  #endif
234  ;
235 
244  constexpr BlendMode BlendMultiply
245  #ifndef DOXYGEN_SHOULD_SKIP_THIS
247  #endif
248  ;
249 
258  constexpr BlendMode BlendNone
259  #ifndef DOXYGEN_SHOULD_SKIP_THIS
261  #endif
262  ;
263 
264 
273  constexpr bool operator==(const BlendMode& lhs, const BlendMode& rhs) {
274  return lhs.colorSrcFactor == rhs.colorSrcFactor
275  && lhs.colorDstFactor == rhs.colorDstFactor
276  && lhs.colorEquation == rhs.colorEquation
277  && lhs.alphaSrcFactor == rhs.alphaSrcFactor
278  && lhs.alphaDstFactor == rhs.alphaDstFactor
279  && lhs.alphaEquation == rhs.alphaEquation;
280  }
281 
282 #ifndef DOXYGEN_SHOULD_SKIP_THIS
283 }
284 #endif
285 }
286 
287 #endif // GF_BLEND_H
Pixel = Dst * DstFactor - Src * SrcFactor.
BlendEquation alphaEquation
Blending equation for the alpha channel.
Definition: Blend.h:198
(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:193
constexpr BlendMode BlendAlpha
Alpha blend mode.
Definition: Blend.h:217
constexpr BlendMode BlendNone
No blend mode.
Definition: Blend.h:262
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:194
BlendFactor alphaDstFactor
Destination blending factor for the alpha channel.
Definition: Blend.h:197
BlendEquation colorEquation
Blending equation for the color channels.
Definition: Blend.h:195
(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:181
The namespace for gf classes.
Definition: Action.h:34
BlendFactor alphaSrcFactor
Source blending factor for the alpha channel.
Definition: Blend.h:196
constexpr BlendMode BlendMultiply
Multiplicative blend mode.
Definition: Blend.h:248
Pixel = Src * SrcFactor + Dst * DstFactor.
Blending modes for drawing.
Definition: Blend.h:132
(src.a, src.a, src.a, src.a)
constexpr BlendMode BlendAdd
Additive blend mode.
Definition: Blend.h:234
(1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
constexpr BlendMode()
Default constructor.
Definition: Blend.h:139
constexpr bool operator==(const BlendMode &lhs, const BlendMode &rhs)
Equality operator.
Definition: Blend.h:273
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:160
(dst.a, dst.a, dst.a, dst.a)