vulkan: implement setColorMask

This commit is contained in:
niki
2022-07-13 16:50:28 +02:00
parent a591b2b99e
commit c6d79ae87e
4 changed files with 36 additions and 4 deletions
+12 -1
View File
@@ -265,7 +265,15 @@ namespace love {
cleanup();
}
void Graphics::setColorMask(ColorChannelMask mask) {
flushBatchedDraws();
states.back().colorMask = mask;
}
void Graphics::setBlendState(const BlendState& blend) {
flushBatchedDraws();
states.back().blend = blend;
}
@@ -1325,7 +1333,7 @@ namespace love {
multisampling.alphaToOneEnable = VK_FALSE; // Optional
VkPipelineColorBlendAttachmentState colorBlendAttachment{};
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
colorBlendAttachment.colorWriteMask = Vulkan::getColorMask(configuration.colorChannelMask);
colorBlendAttachment.blendEnable = Vulkan::getBool(configuration.blendState.enable);
colorBlendAttachment.srcColorBlendFactor = Vulkan::getBlendFactor(configuration.blendState.srcFactorRGB);
colorBlendAttachment.dstColorBlendFactor = Vulkan::getBlendFactor(configuration.blendState.dstFactorRGB);
@@ -1490,6 +1498,9 @@ namespace love {
}
bool operator==(const GraphicsPipelineConfiguration& first, const GraphicsPipelineConfiguration& other) {
if (first.colorChannelMask != other.colorChannelMask) {
return false;
}
if (!(first.blendState == other.blendState)) { // not sure why != doesn't work
return false;
}
+2 -1
View File
@@ -26,6 +26,7 @@ namespace love {
PrimitiveType primitiveType = PRIMITIVE_MAX_ENUM;
VkPolygonMode polygonMode = VK_POLYGON_MODE_FILL;
BlendState blendState;
ColorChannelMask colorChannelMask;
friend static bool operator==(const GraphicsPipelineConfiguration& first, const GraphicsPipelineConfiguration& other);
};
@@ -99,7 +100,7 @@ namespace love {
void setStencilMode(StencilAction action, CompareMode compare, int value, love::uint32 readmask, love::uint32 writemask) override { std::cout << "setStencilMode "; }
void setDepthMode(CompareMode compare, bool write) override { std::cout << "setDepthMode "; }
void setFrontFaceWinding(Winding winding) override { std::cout << "setFrontFaceWinding "; }
void setColorMask(ColorChannelMask mask) override { std::cout << "setColorMask "; }
void setColorMask(ColorChannelMask mask) override;
void setBlendState(const BlendState& blend) override;
void setPointSize(float size) override;
void setWireframe(bool enable) override;
+21 -2
View File
@@ -326,7 +326,7 @@ namespace love {
return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
case BLENDFACTOR_SRC_ALPHA_SATURATED:
return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE;
case BLENDFACTOR_MAX_ENUM:
default:
throw love::Exception("unknown blend factor");
}
}
@@ -343,7 +343,7 @@ namespace love {
return VK_BLEND_OP_SUBTRACT;
case BLENDOP_REVERSE_SUBTRACT:
return VK_BLEND_OP_REVERSE_SUBTRACT;
case BLENDOP_MAX_ENUM:
default:
throw love::Exception("unknown blend operation");
}
}
@@ -355,6 +355,25 @@ namespace love {
return VK_FALSE;
}
}
VkColorComponentFlags Vulkan::getColorMask(ColorChannelMask mask) {
VkColorComponentFlags flags = 0;
if (mask.r) {
flags |= VK_COLOR_COMPONENT_R_BIT;
}
if (mask.g) {
flags |= VK_COLOR_COMPONENT_G_BIT;
}
if (mask.b) {
flags |= VK_COLOR_COMPONENT_B_BIT;
}
if (mask.a) {
flags |= VK_COLOR_COMPONENT_A_BIT;
}
return flags;
}
}
}
}
+1
View File
@@ -26,6 +26,7 @@ namespace love {
static VkBlendFactor getBlendFactor(BlendFactor);
static VkBlendOp getBlendOp(BlendOperation);
static VkBool32 getBool(bool);
static VkColorComponentFlags getColorMask(ColorChannelMask);
};
}
}