FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_blendMode.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_VULKAN_C_BLENDMODE_HPP_INCLUDED
18#define _FGE_VULKAN_C_BLENDMODE_HPP_INCLUDED
19
20#include "volk.h"
21
22namespace fge::vulkan
23{
24
37{
38 constexpr BlendMode() noexcept = default;
39 constexpr BlendMode(VkBlendFactor srcBlendFactor,
40 VkBlendFactor dstBlendFactor,
41 VkBlendOp blendOp = VK_BLEND_OP_ADD) noexcept :
42 _srcColorBlendFactor(srcBlendFactor),
43 _dstColorBlendFactor(dstBlendFactor),
44 _colorBlendOp(blendOp),
45 _srcAlphaBlendFactor(srcBlendFactor),
46 _dstAlphaBlendFactor(dstBlendFactor),
47 _alphaBlendOp(blendOp)
48 {}
49 constexpr BlendMode(VkBlendFactor srcColorBlendFactor,
50 VkBlendFactor dstColorBlendFactor,
51 VkBlendOp colorBlendOp,
52 VkBlendFactor srcAlphaBlendFactor,
53 VkBlendFactor dstAlphaBlendFactor,
54 VkBlendOp alphaBlendOp) noexcept :
55 _srcColorBlendFactor(srcColorBlendFactor),
56 _dstColorBlendFactor(dstColorBlendFactor),
57 _colorBlendOp(colorBlendOp),
58 _srcAlphaBlendFactor(srcAlphaBlendFactor),
59 _dstAlphaBlendFactor(dstAlphaBlendFactor),
60 _alphaBlendOp(alphaBlendOp)
61 {}
62
63 [[nodiscard]] constexpr bool operator==(BlendMode const& right) const
64 {
65 return this->_srcColorBlendFactor == right._srcColorBlendFactor &&
66 this->_dstColorBlendFactor == right._dstColorBlendFactor && this->_colorBlendOp == right._colorBlendOp &&
67 this->_srcAlphaBlendFactor == right._srcAlphaBlendFactor &&
68 this->_dstAlphaBlendFactor == right._dstAlphaBlendFactor && this->_alphaBlendOp == right._alphaBlendOp;
69 }
70 [[nodiscard]] constexpr bool operator!=(BlendMode const& right) const { return !this->operator==(right); }
71
72 VkBlendFactor _srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
73 VkBlendFactor _dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
74 VkBlendOp _colorBlendOp = VK_BLEND_OP_ADD;
75 VkBlendFactor _srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
76 VkBlendFactor _dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
77 VkBlendOp _alphaBlendOp = VK_BLEND_OP_ADD;
78};
79
80inline constexpr BlendMode BlendAlpha(VK_BLEND_FACTOR_SRC_ALPHA,
81 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
82 VK_BLEND_OP_ADD,
83 VK_BLEND_FACTOR_ONE,
84 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
85 VK_BLEND_OP_ADD);
86inline constexpr BlendMode BlendAdd(VK_BLEND_FACTOR_SRC_ALPHA,
87 VK_BLEND_FACTOR_ONE,
88 VK_BLEND_OP_ADD,
89 VK_BLEND_FACTOR_ONE,
90 VK_BLEND_FACTOR_ONE,
91 VK_BLEND_OP_ADD);
92inline constexpr BlendMode
93 BlendMultiply(VK_BLEND_FACTOR_DST_COLOR, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD);
94inline constexpr BlendMode
95 BlendMin(VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE, VK_BLEND_OP_MIN);
96inline constexpr BlendMode
97 BlendMax(VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE, VK_BLEND_OP_MAX);
98inline constexpr BlendMode
99 BlendNone(VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD);
100
105} // namespace fge::vulkan
106
107#endif //_FGE_VULKAN_C_BLENDMODE_HPP_INCLUDED
constexpr BlendMode BlendAdd(VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE, VK_BLEND_OP_ADD, VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE, VK_BLEND_OP_ADD)
Add source to dest.
constexpr BlendMode BlendMax(VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE, VK_BLEND_OP_MAX)
Take maximum between source and dest.
constexpr BlendMode BlendNone(VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD)
Overwrite dest with source.
constexpr BlendMode BlendMultiply(VK_BLEND_FACTOR_DST_COLOR, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_ADD)
Multiply source and dest.
constexpr BlendMode BlendMin(VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE, VK_BLEND_OP_MIN)
Take minimum between source and dest.
constexpr BlendMode BlendAlpha(VK_BLEND_FACTOR_SRC_ALPHA, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, VK_BLEND_OP_ADD, VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, VK_BLEND_OP_ADD)
Blend source and dest according to dest alpha.
This is a simple abstraction class for VkBlendFactor, VkBlendOp.
Definition C_blendMode.hpp:37