From a5aacc9cad5d49690b4f83b94b179d865205df6a Mon Sep 17 00:00:00 2001 From: Stephen White Date: Thu, 1 Mar 2018 15:41:48 -0500 Subject: [PATCH] Fix color write mask on GL backend. Set the color mask even if blending is disabled. --- src/backend/opengl/BlendStateGL.cpp | 8 ++++---- src/tests/end2end/BlendStateTests.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/backend/opengl/BlendStateGL.cpp b/src/backend/opengl/BlendStateGL.cpp index d1ead39f25..42d981e905 100644 --- a/src/backend/opengl/BlendStateGL.cpp +++ b/src/backend/opengl/BlendStateGL.cpp @@ -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 diff --git a/src/tests/end2end/BlendStateTests.cpp b/src/tests/end2end/BlendStateTests.cpp index dc65297d1d..56a780cc6c 100644 --- a/src/tests/end2end/BlendStateTests.cpp +++ b/src/tests/end2end/BlendStateTests.cpp @@ -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({ { 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) {