]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/blend_backend.cpp
Initial implementation of Vulkan backend
[libs/gl.git] / source / backends / vulkan / blend_backend.cpp
diff --git a/source/backends/vulkan/blend_backend.cpp b/source/backends/vulkan/blend_backend.cpp
new file mode 100644 (file)
index 0000000..e96fcbf
--- /dev/null
@@ -0,0 +1,60 @@
+#include "blend.h"
+#include "blend_backend.h"
+#include "vulkan.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+unsigned get_vulkan_blend_equation(BlendEquation eq)
+{
+       switch(eq)
+       {
+       case ADD: return VK_BLEND_OP_ADD;
+       case SUBTRACT: return VK_BLEND_OP_SUBTRACT;
+       case REVERSE_SUBTRACT: return VK_BLEND_OP_REVERSE_SUBTRACT;
+       case MIN: return VK_BLEND_OP_MIN;
+       case MAX: return VK_BLEND_OP_MAX;
+       default: throw invalid_argument("get_vulkan_blend_equation");
+       }
+}
+
+unsigned get_vulkan_blend_factor(BlendFactor factor)
+{
+       switch(factor)
+       {
+       case ZERO: return VK_BLEND_FACTOR_ZERO;
+       case ONE: return VK_BLEND_FACTOR_ONE;
+       case SRC_COLOR: return VK_BLEND_FACTOR_SRC_COLOR;
+       case ONE_MINUS_SRC_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
+       case SRC_ALPHA: return VK_BLEND_FACTOR_SRC_ALPHA;
+       case ONE_MINUS_SRC_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+       case DST_COLOR: return VK_BLEND_FACTOR_DST_COLOR;
+       case ONE_MINUS_DST_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
+       case DST_ALPHA: return VK_BLEND_FACTOR_DST_ALPHA;
+       case ONE_MINUS_DST_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
+       case CONSTANT_COLOR: return VK_BLEND_FACTOR_CONSTANT_COLOR;
+       case ONE_MINUS_CONSTANT_COLOR: return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
+       case CONSTANT_ALPHA: return VK_BLEND_FACTOR_CONSTANT_ALPHA;
+       case ONE_MINUS_CONSTANT_ALPHA: return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA;
+       default: throw invalid_argument("get_vulkan_blend_factor");
+       }
+}
+
+unsigned get_vulkan_color_mask(ColorWriteMask mask)
+{
+       unsigned result = 0;
+       if(mask&WRITE_RED)
+               result |= VK_COLOR_COMPONENT_R_BIT;
+       if(mask&WRITE_GREEN)
+               result |= VK_COLOR_COMPONENT_G_BIT;
+       if(mask&WRITE_BLUE)
+               result |= VK_COLOR_COMPONENT_B_BIT;
+       if(mask&WRITE_ALPHA)
+               result |= VK_COLOR_COMPONENT_A_BIT;
+       return result;
+}
+
+} // namespace GL
+} // namespace Msp