]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/blend_backend.cpp
Initial implementation of Vulkan backend
[libs/gl.git] / source / backends / vulkan / blend_backend.cpp
1 #include "blend.h"
2 #include "blend_backend.h"
3 #include "vulkan.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace GL {
9
10 unsigned get_vulkan_blend_equation(BlendEquation eq)
11 {
12         switch(eq)
13         {
14         case ADD: return VK_BLEND_OP_ADD;
15         case SUBTRACT: return VK_BLEND_OP_SUBTRACT;
16         case REVERSE_SUBTRACT: return VK_BLEND_OP_REVERSE_SUBTRACT;
17         case MIN: return VK_BLEND_OP_MIN;
18         case MAX: return VK_BLEND_OP_MAX;
19         default: throw invalid_argument("get_vulkan_blend_equation");
20         }
21 }
22
23 unsigned get_vulkan_blend_factor(BlendFactor factor)
24 {
25         switch(factor)
26         {
27         case ZERO: return VK_BLEND_FACTOR_ZERO;
28         case ONE: return VK_BLEND_FACTOR_ONE;
29         case SRC_COLOR: return VK_BLEND_FACTOR_SRC_COLOR;
30         case ONE_MINUS_SRC_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
31         case SRC_ALPHA: return VK_BLEND_FACTOR_SRC_ALPHA;
32         case ONE_MINUS_SRC_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
33         case DST_COLOR: return VK_BLEND_FACTOR_DST_COLOR;
34         case ONE_MINUS_DST_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
35         case DST_ALPHA: return VK_BLEND_FACTOR_DST_ALPHA;
36         case ONE_MINUS_DST_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
37         case CONSTANT_COLOR: return VK_BLEND_FACTOR_CONSTANT_COLOR;
38         case ONE_MINUS_CONSTANT_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
39         case CONSTANT_ALPHA: return VK_BLEND_FACTOR_CONSTANT_ALPHA;
40         case ONE_MINUS_CONSTANT_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA;
41         default: throw invalid_argument("get_vulkan_blend_factor");
42         }
43 }
44
45 unsigned get_vulkan_color_mask(ColorWriteMask mask)
46 {
47         unsigned result = 0;
48         if(mask&WRITE_RED)
49                 result |= VK_COLOR_COMPONENT_R_BIT;
50         if(mask&WRITE_GREEN)
51                 result |= VK_COLOR_COMPONENT_G_BIT;
52         if(mask&WRITE_BLUE)
53                 result |= VK_COLOR_COMPONENT_B_BIT;
54         if(mask&WRITE_ALPHA)
55                 result |= VK_COLOR_COMPONENT_A_BIT;
56         return result;
57 }
58
59 } // namespace GL
60 } // namespace Msp