xref: /aosp_15_r20/external/angle/src/tests/gl_tests/DifferentStencilMasksTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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     glStencilMaskSeparate(GL_FRONT, 0x0001);
71     glStencilMaskSeparate(GL_BACK, 0x0002);
72 
73     glUseProgram(mProgram);
74 
75     glDrawArrays(GL_TRIANGLES, 0, 3);
76 
77     EXPECT_GL_ERROR(GL_INVALID_OPERATION);
78 }
79 
80 // Tests that effectively different front and back masks, without stencil bits, are legal.
TEST_P(DifferentStencilMasksTest,DrawWithDifferentMask_NoStencilBuffer)81 TEST_P(DifferentStencilMasksTest, DrawWithDifferentMask_NoStencilBuffer)
82 {
83     GLTexture texture;
84     glBindTexture(GL_TEXTURE_2D, texture);
85     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
86 
87     GLFramebuffer framebuffer;
88     glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
89     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
90 
91     glStencilMaskSeparate(GL_FRONT, 0x0001);
92     glStencilMaskSeparate(GL_BACK, 0x0002);
93 
94     glUseProgram(mProgram);
95 
96     glDrawArrays(GL_TRIANGLES, 0, 3);
97 
98     EXPECT_GL_NO_ERROR();
99 }
100 
101 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
102 // tests should be run against.
103 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(DifferentStencilMasksTest);
104 }  // anonymous namespace
105