summaryrefslogtreecommitdiff
path: root/video.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'video.cpp')
-rw-r--r--video.cpp80
1 files changed, 65 insertions, 15 deletions
diff --git a/video.cpp b/video.cpp
index 1d71034..586a78e 100644
--- a/video.cpp
+++ b/video.cpp
@@ -277,6 +277,35 @@ static VkFormat get_vk_format(Texture_Format fmt) {
return VK_FORMAT_UNDEFINED;
}
+static VkBlendFactor get_vk_blend_factor(Blend_Factor mode) {
+ switch (mode) {
+ case Blend_Factor::zero: return VK_BLEND_FACTOR_ZERO;
+ case Blend_Factor::one: return VK_BLEND_FACTOR_ONE;
+ case Blend_Factor::src_colour: return VK_BLEND_FACTOR_SRC_COLOR;
+ case Blend_Factor::inv_src_colour: return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
+ case Blend_Factor::dst_colour: return VK_BLEND_FACTOR_DST_COLOR;
+ case Blend_Factor::inv_dst_colour: return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
+ case Blend_Factor::src_alpha: return VK_BLEND_FACTOR_SRC_ALPHA;
+ case Blend_Factor::inv_src_alpha: return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+ case Blend_Factor::dst_alpha: return VK_BLEND_FACTOR_DST_ALPHA;
+ case Blend_Factor::inv_dst_alpha: return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
+ }
+ assert(0);
+ return VK_BLEND_FACTOR_ONE;
+}
+
+static VkBlendOp get_vk_blend_op(Blend_Mode mode) {
+ switch (mode) {
+ case Blend_Mode::add: return VK_BLEND_OP_ADD;
+ case Blend_Mode::subtract: return VK_BLEND_OP_SUBTRACT;
+ case Blend_Mode::reverse_subtract: return VK_BLEND_OP_SUBTRACT;
+ case Blend_Mode::min: return VK_BLEND_OP_MIN;
+ case Blend_Mode::max: return VK_BLEND_OP_MAX;
+ }
+ assert(0);
+ return VK_BLEND_OP_ADD;
+}
+
static VkImageUsageFlags get_texture_usage(int flags) {
VkImageUsageFlags f = 0;
if (flags & Texture_Flags::sampleable)
@@ -734,6 +763,7 @@ struct Pipeline_Vk {
Arena& scope,
Device_Vk* dev,
VkGraphicsPipelineCreateInfo& info,
+ const Render_Pass& rp,
const Pipeline& desc
);
void init_layout(
@@ -2621,6 +2651,7 @@ void Pipeline_Vk::init_blending(
Arena& scope,
Device_Vk* dev,
VkGraphicsPipelineCreateInfo& info,
+ const Render_Pass& rp,
const Pipeline& desc
) {
VkPipelineColorBlendStateCreateInfo& bi =
@@ -2628,26 +2659,45 @@ void Pipeline_Vk::init_blending(
&scope,
sizeof bi
);
- VkPipelineColorBlendAttachmentState& abs =
- *(VkPipelineColorBlendAttachmentState*)arena_alloc(
- &scope,
- sizeof abs
- );
+ VkPipelineColorBlendAttachmentState* abs;
(void)dev;
(void)desc;
zero(&bi, sizeof bi);
- zero(&abs, sizeof abs);
- abs.colorWriteMask =
- VK_COLOR_COMPONENT_R_BIT |
- VK_COLOR_COMPONENT_G_BIT |
- VK_COLOR_COMPONENT_B_BIT |
- VK_COLOR_COMPONENT_A_BIT;
- abs.blendEnable = VK_FALSE;
+ if (rp.colour_count) {
+ int i, c = rp.colour_count;
+ abs =
+ (VkPipelineColorBlendAttachmentState*)arena_alloc(
+ &scope,
+ sizeof abs * c
+ );
+ zero(abs, sizeof *abs);
+ for (i = 0; i < c; i++) {
+ auto& ab = abs[i];
+ ab.colorWriteMask =
+ VK_COLOR_COMPONENT_R_BIT |
+ VK_COLOR_COMPONENT_G_BIT |
+ VK_COLOR_COMPONENT_B_BIT |
+ VK_COLOR_COMPONENT_A_BIT;
+ ab.blendEnable = desc.blend_enable;
+ if (desc.blend_enable) {
+ ab.srcColorBlendFactor =
+ get_vk_blend_factor(desc.blend_src);
+ ab.dstColorBlendFactor =
+ get_vk_blend_factor(desc.blend_dst);
+ ab.srcAlphaBlendFactor =
+ get_vk_blend_factor(desc.blend_src_alpha);
+ ab.dstAlphaBlendFactor =
+ get_vk_blend_factor(desc.blend_dst_alpha);
+ ab.colorBlendOp = get_vk_blend_op(desc.blend_mode);
+ ab.alphaBlendOp = get_vk_blend_op(desc.blend_mode_alpha);
+ }
+ }
+ }
bi.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
bi.flags = 0;
bi.logicOpEnable = VK_FALSE;
- bi.attachmentCount = 1;
- bi.pAttachments = &abs;
+ bi.attachmentCount = rp.colour_count;
+ bi.pAttachments = abs;
info.pColorBlendState = &bi;
}
@@ -2764,7 +2814,7 @@ void Pipeline_Vk::init(Device_Vk* dev, const Pso_Key& key) {
init_rasterisation(scope, dev, info, desc);
init_msaa(scope, dev, info, desc);
init_depthstencil(scope, dev, info, desc);
- init_blending(scope, dev, info, desc);
+ init_blending(scope, dev, info, key.rpo.rpo, desc);
info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
info.flags = 0;
info.renderPass = dev->get_rpo(key.rpo).rpo;