1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // ColorMaskTest.cpp: Test GLES functionality related to color masks, particularly an AMD D3D9
8 // driver bug.
9
10 #include "test_utils/ANGLETest.h"
11
12 namespace angle
13 {
14 class ColorMaskTest : public ANGLETest<>
15 {
16 protected:
ColorMaskTest()17 ColorMaskTest() : mProgram(0)
18 {
19 setWindowWidth(128);
20 setWindowHeight(128);
21 setConfigRedBits(8);
22 setConfigGreenBits(8);
23 setConfigBlueBits(8);
24 setConfigAlphaBits(8);
25 setConfigDepthBits(24);
26 }
27
testSetUp()28 void testSetUp() override
29 {
30 mProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
31 ASSERT_NE(0u, mProgram) << "shader compilation failed.";
32
33 mColorUniform = glGetUniformLocation(mProgram, essl1_shaders::ColorUniform());
34 }
35
testTearDown()36 void testTearDown() override { glDeleteProgram(mProgram); }
37
38 GLuint mProgram = 0;
39 GLint mColorUniform = -1;
40 };
41
42 // Some ATI cards have a bug where a draw with a zero color write mask can cause later draws to have
43 // incorrect results. Test to make sure this bug is not exposed.
TEST_P(ColorMaskTest,AMDZeroColorMaskBug)44 TEST_P(ColorMaskTest, AMDZeroColorMaskBug)
45 {
46 int x = getWindowWidth() / 2;
47 int y = getWindowHeight() / 2;
48
49 // Clear to blue
50 glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
51 glClear(GL_COLOR_BUFFER_BIT);
52 EXPECT_PIXEL_EQ(x, y, 0, 0, 255, 255);
53
54 // Draw a quad with all colors masked and blending disabled, should remain blue
55 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
56 glDisable(GL_BLEND);
57 glUseProgram(mProgram);
58 glUniform4f(mColorUniform, 1.0f, 0.0f, 0.0f, 0.0f);
59 EXPECT_GL_NO_ERROR();
60 drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
61 EXPECT_PIXEL_EQ(x, y, 0, 0, 255, 255);
62
63 // Re-enable the color mask, should be red (with blend disabled, the red should overwrite
64 // everything)
65 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
66 glUseProgram(mProgram);
67 glUniform4f(mColorUniform, 1.0f, 0.0f, 0.0f, 0.0f);
68 EXPECT_GL_NO_ERROR();
69 drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
70 EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 0);
71 }
72
73 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
74 // tests should be run against. D3D11 Feature Level 9_3 uses different D3D formats for vertex
75 // attribs compared to Feature Levels 10_0+, so we should test them separately.
76 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(ColorMaskTest);
77
78 } // namespace angle
79