Fix color write mask on GL backend.

Set the color mask even if blending is disabled.
This commit is contained in:
Stephen White 2018-03-01 15:41:48 -05:00 committed by Corentin Wallez
parent 10a659ad91
commit a5aacc9cad
2 changed files with 30 additions and 4 deletions

View File

@ -85,13 +85,13 @@ namespace backend { namespace opengl {
GLBlendFactor(info.colorBlend.dstFactor, false),
GLBlendFactor(info.alphaBlend.srcFactor, true),
GLBlendFactor(info.alphaBlend.dstFactor, true));
glColorMaski(attachment, info.colorWriteMask & nxt::ColorWriteMask::Red,
info.colorWriteMask & nxt::ColorWriteMask::Green,
info.colorWriteMask & nxt::ColorWriteMask::Blue,
info.colorWriteMask & nxt::ColorWriteMask::Alpha);
} else {
glDisablei(GL_BLEND, attachment);
}
glColorMaski(attachment, info.colorWriteMask & nxt::ColorWriteMask::Red,
info.colorWriteMask & nxt::ColorWriteMask::Green,
info.colorWriteMask & nxt::ColorWriteMask::Blue,
info.colorWriteMask & nxt::ColorWriteMask::Alpha);
}
}} // namespace backend::opengl

View File

@ -667,6 +667,32 @@ TEST_P(BlendStateTest, ColorWriteMask) {
}
}
// Check that the color write mask works when blending is disabled
TEST_P(BlendStateTest, ColorWriteMaskBlendingDisabled) {
{
nxt::BlendState blendState = device.CreateBlendStateBuilder()
.SetBlendEnabled(false)
.SetColorWriteMask(nxt::ColorWriteMask::Red)
.GetResult();
SetupSingleSourcePipelines(blendState);
RGBA8 base(32, 64, 128, 192);
RGBA8 expected(32, 0, 0, 0);
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.BeginRenderPass(fb.renderPass, fb.framebuffer)
.BeginRenderSubpass()
.SetRenderPipeline(testPipeline)
.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({ { base } })))
.DrawArrays(3, 1, 0, 0)
.EndRenderSubpass()
.EndRenderPass()
.GetResult();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(expected, fb.color, kRTSize / 2, kRTSize / 2);
}
}
// Test that independent blend states on render targets works
TEST_P(BlendStateTest, IndependentBlendState) {