1 //
2 // Copyright 2015 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 // DifferentStencilMasksTest:
7 // Tests the equality between stencilWriteMask and stencilBackWriteMask.
8 //
9
10 #include "test_utils/ANGLETest.h"
11 #include "test_utils/gl_raii.h"
12
13 using namespace angle;
14
15 namespace
16 {
17 class DifferentStencilMasksTest : public ANGLETest
18 {
19 protected:
DifferentStencilMasksTest()20 DifferentStencilMasksTest() : mProgram(0)
21 {
22 setWindowWidth(128);
23 setWindowHeight(128);
24 setConfigRedBits(8);
25 setConfigGreenBits(8);
26 setConfigBlueBits(8);
27 setConfigAlphaBits(8);
28 setConfigDepthBits(24);
29 setConfigStencilBits(8);
30
31 setWebGLCompatibilityEnabled(true);
32 }
33
testSetUp()34 void testSetUp() override
35 {
36 mProgram = CompileProgram(essl1_shaders::vs::Zero(), essl1_shaders::fs::Blue());
37 ASSERT_NE(0u, mProgram);
38
39 glEnable(GL_STENCIL_TEST);
40 ASSERT_GL_NO_ERROR();
41 }
42
testTearDown()43 void testTearDown() override
44 {
45 glDisable(GL_STENCIL_TEST);
46 if (mProgram != 0)
47 glDeleteProgram(mProgram);
48 }
49
50 GLuint mProgram;
51 };
52
53 // Tests that effectively same front and back masks are legal.
TEST_P(DifferentStencilMasksTest,DrawWithSameEffectiveMask)54 TEST_P(DifferentStencilMasksTest, DrawWithSameEffectiveMask)
55 {
56 // 0x00ff and 0x01ff are effectively 0x00ff by being masked by the current stencil bits, 8.
57 glStencilMaskSeparate(GL_FRONT, 0x00ff);
58 glStencilMaskSeparate(GL_BACK, 0x01ff);
59
60 glUseProgram(mProgram);
61
62 glDrawArrays(GL_TRIANGLES, 0, 3);
63
64 EXPECT_GL_NO_ERROR();
65 }
66
67 // Tests that effectively different front and back masks are illegal.
TEST_P(DifferentStencilMasksTest,DrawWithDifferentMask)68 TEST_P(DifferentStencilMasksTest, DrawWithDifferentMask)
69 {
70 // TODO(hqle): Make this test work for Metal. http://anglebug.com/4134
71 ANGLE_SKIP_TEST_IF(IsMetal());
72
73 glStencilMaskSeparate(GL_FRONT, 0x0001);
74 glStencilMaskSeparate(GL_BACK, 0x0002);
75
76 glUseProgram(mProgram);
77
78 glDrawArrays(GL_TRIANGLES, 0, 3);
79
80 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
81 }
82
83 // Tests that effectively different front and back masks, without stencil bits, are legal.
TEST_P(DifferentStencilMasksTest,DrawWithDifferentMask_NoStencilBuffer)84 TEST_P(DifferentStencilMasksTest, DrawWithDifferentMask_NoStencilBuffer)
85 {
86 GLTexture texture;
87 glBindTexture(GL_TEXTURE_2D, texture.get());
88 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
89
90 GLFramebuffer framebuffer;
91 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
92 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
93
94 glStencilMaskSeparate(GL_FRONT, 0x0001);
95 glStencilMaskSeparate(GL_BACK, 0x0002);
96
97 glUseProgram(mProgram);
98
99 glDrawArrays(GL_TRIANGLES, 0, 3);
100
101 EXPECT_GL_NO_ERROR();
102 }
103
104 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
105 // tests should be run against.
106 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(DifferentStencilMasksTest);
107 } // anonymous namespace
108