1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // DepthStencilTest:
7*8975f5c5SAndroid Build Coastguard Worker // Tests covering depth- or stencil-only rendering to make sure the other non-existing aspect is
8*8975f5c5SAndroid Build Coastguard Worker // not affecting the results (since the format may be emulated with one that has both aspects).
9*8975f5c5SAndroid Build Coastguard Worker //
10*8975f5c5SAndroid Build Coastguard Worker
11*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/ANGLETest.h"
12*8975f5c5SAndroid Build Coastguard Worker
13*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/gl_raii.h"
14*8975f5c5SAndroid Build Coastguard Worker
15*8975f5c5SAndroid Build Coastguard Worker using namespace angle;
16*8975f5c5SAndroid Build Coastguard Worker
17*8975f5c5SAndroid Build Coastguard Worker namespace
18*8975f5c5SAndroid Build Coastguard Worker {
19*8975f5c5SAndroid Build Coastguard Worker
20*8975f5c5SAndroid Build Coastguard Worker class DepthStencilTest : public ANGLETest<>
21*8975f5c5SAndroid Build Coastguard Worker {
22*8975f5c5SAndroid Build Coastguard Worker protected:
DepthStencilTest()23*8975f5c5SAndroid Build Coastguard Worker DepthStencilTest()
24*8975f5c5SAndroid Build Coastguard Worker {
25*8975f5c5SAndroid Build Coastguard Worker setWindowWidth(128);
26*8975f5c5SAndroid Build Coastguard Worker setWindowHeight(128);
27*8975f5c5SAndroid Build Coastguard Worker setConfigRedBits(8);
28*8975f5c5SAndroid Build Coastguard Worker setConfigGreenBits(8);
29*8975f5c5SAndroid Build Coastguard Worker setConfigBlueBits(8);
30*8975f5c5SAndroid Build Coastguard Worker setConfigAlphaBits(8);
31*8975f5c5SAndroid Build Coastguard Worker setConfigDepthBits(24);
32*8975f5c5SAndroid Build Coastguard Worker setConfigStencilBits(8);
33*8975f5c5SAndroid Build Coastguard Worker }
34*8975f5c5SAndroid Build Coastguard Worker
testSetUp()35*8975f5c5SAndroid Build Coastguard Worker void testSetUp() override
36*8975f5c5SAndroid Build Coastguard Worker {
37*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, mColorTexture);
38*8975f5c5SAndroid Build Coastguard Worker glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
39*8975f5c5SAndroid Build Coastguard Worker GL_UNSIGNED_BYTE, nullptr);
40*8975f5c5SAndroid Build Coastguard Worker
41*8975f5c5SAndroid Build Coastguard Worker // Setup Color/Stencil FBO with a stencil format that's emulated with packed depth/stencil.
42*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, mColorStencilFBO);
43*8975f5c5SAndroid Build Coastguard Worker
44*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorTexture,
45*8975f5c5SAndroid Build Coastguard Worker 0);
46*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, mStencilTexture);
47*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWindowWidth(),
48*8975f5c5SAndroid Build Coastguard Worker getWindowHeight());
49*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
50*8975f5c5SAndroid Build Coastguard Worker mStencilTexture);
51*8975f5c5SAndroid Build Coastguard Worker
52*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
53*8975f5c5SAndroid Build Coastguard Worker
54*8975f5c5SAndroid Build Coastguard Worker // Note: GL_DEPTH_COMPONENT24 is allowed in GLES2 with GL_OES_depth24 extension.
55*8975f5c5SAndroid Build Coastguard Worker if (getClientMajorVersion() >= 3 || IsGLExtensionEnabled("GL_OES_depth24"))
56*8975f5c5SAndroid Build Coastguard Worker {
57*8975f5c5SAndroid Build Coastguard Worker // Setup Color/Depth FBO with a depth format that's emulated with packed depth/stencil.
58*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, mColorDepthFBO);
59*8975f5c5SAndroid Build Coastguard Worker
60*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
61*8975f5c5SAndroid Build Coastguard Worker mColorTexture, 0);
62*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, mDepthTexture);
63*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, getWindowWidth(),
64*8975f5c5SAndroid Build Coastguard Worker getWindowHeight());
65*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
66*8975f5c5SAndroid Build Coastguard Worker mDepthTexture);
67*8975f5c5SAndroid Build Coastguard Worker }
68*8975f5c5SAndroid Build Coastguard Worker
69*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
70*8975f5c5SAndroid Build Coastguard Worker }
71*8975f5c5SAndroid Build Coastguard Worker
bindColorStencilFBO()72*8975f5c5SAndroid Build Coastguard Worker void bindColorStencilFBO()
73*8975f5c5SAndroid Build Coastguard Worker {
74*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, mColorStencilFBO);
75*8975f5c5SAndroid Build Coastguard Worker mHasDepth = false;
76*8975f5c5SAndroid Build Coastguard Worker }
77*8975f5c5SAndroid Build Coastguard Worker
bindColorDepthFBO()78*8975f5c5SAndroid Build Coastguard Worker void bindColorDepthFBO()
79*8975f5c5SAndroid Build Coastguard Worker {
80*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, mColorDepthFBO);
81*8975f5c5SAndroid Build Coastguard Worker mHasStencil = false;
82*8975f5c5SAndroid Build Coastguard Worker }
83*8975f5c5SAndroid Build Coastguard Worker
84*8975f5c5SAndroid Build Coastguard Worker void prepareSingleEmulatedWithPacked();
85*8975f5c5SAndroid Build Coastguard Worker void ensureColor(GLColor color);
86*8975f5c5SAndroid Build Coastguard Worker void ensureDepthUnaffected();
87*8975f5c5SAndroid Build Coastguard Worker void ensureStencilUnaffected();
88*8975f5c5SAndroid Build Coastguard Worker
89*8975f5c5SAndroid Build Coastguard Worker private:
90*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer mColorStencilFBO;
91*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer mColorDepthFBO;
92*8975f5c5SAndroid Build Coastguard Worker GLTexture mColorTexture;
93*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer mDepthTexture;
94*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer mStencilTexture;
95*8975f5c5SAndroid Build Coastguard Worker
96*8975f5c5SAndroid Build Coastguard Worker bool mHasDepth = true;
97*8975f5c5SAndroid Build Coastguard Worker bool mHasStencil = true;
98*8975f5c5SAndroid Build Coastguard Worker };
99*8975f5c5SAndroid Build Coastguard Worker
100*8975f5c5SAndroid Build Coastguard Worker class DepthStencilTestES3 : public DepthStencilTest
101*8975f5c5SAndroid Build Coastguard Worker {
102*8975f5c5SAndroid Build Coastguard Worker protected:
103*8975f5c5SAndroid Build Coastguard Worker void compareDepth(uint32_t expected);
104*8975f5c5SAndroid Build Coastguard Worker void clearAndCompareDepth(GLfloat depth, uint32_t expected);
105*8975f5c5SAndroid Build Coastguard Worker void drawAndCompareDepth(GLProgram &program, GLfloat depth, uint32_t expected);
106*8975f5c5SAndroid Build Coastguard Worker };
107*8975f5c5SAndroid Build Coastguard Worker
ensureColor(GLColor color)108*8975f5c5SAndroid Build Coastguard Worker void DepthStencilTest::ensureColor(GLColor color)
109*8975f5c5SAndroid Build Coastguard Worker {
110*8975f5c5SAndroid Build Coastguard Worker const int width = getWindowWidth();
111*8975f5c5SAndroid Build Coastguard Worker const int height = getWindowHeight();
112*8975f5c5SAndroid Build Coastguard Worker
113*8975f5c5SAndroid Build Coastguard Worker std::vector<GLColor> pixelData(width * height);
114*8975f5c5SAndroid Build Coastguard Worker glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
115*8975f5c5SAndroid Build Coastguard Worker
116*8975f5c5SAndroid Build Coastguard Worker for (int i = 0; i < width * height; i += 16)
117*8975f5c5SAndroid Build Coastguard Worker {
118*8975f5c5SAndroid Build Coastguard Worker GLColor actualColor = pixelData[i];
119*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(color.R, actualColor.R, 1);
120*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(color.G, actualColor.G, 1);
121*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(color.B, actualColor.B, 1);
122*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(color.A, actualColor.A, 1);
123*8975f5c5SAndroid Build Coastguard Worker
124*8975f5c5SAndroid Build Coastguard Worker if (i % width == 0)
125*8975f5c5SAndroid Build Coastguard Worker i += 16 * width;
126*8975f5c5SAndroid Build Coastguard Worker }
127*8975f5c5SAndroid Build Coastguard Worker }
128*8975f5c5SAndroid Build Coastguard Worker
ensureDepthUnaffected()129*8975f5c5SAndroid Build Coastguard Worker void DepthStencilTest::ensureDepthUnaffected()
130*8975f5c5SAndroid Build Coastguard Worker {
131*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(depthTestProgram, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Blue());
132*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_DEPTH_TEST);
133*8975f5c5SAndroid Build Coastguard Worker glDepthFunc(GL_EQUAL);
134*8975f5c5SAndroid Build Coastguard Worker drawQuad(depthTestProgram, essl1_shaders::PositionAttrib(), 0.123f);
135*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_DEPTH_TEST);
136*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
137*8975f5c5SAndroid Build Coastguard Worker
138*8975f5c5SAndroid Build Coastguard Worker // Since depth shouldn't exist, the drawQuad above should succeed in turning the whole image
139*8975f5c5SAndroid Build Coastguard Worker // blue.
140*8975f5c5SAndroid Build Coastguard Worker ensureColor(GLColor::blue);
141*8975f5c5SAndroid Build Coastguard Worker }
142*8975f5c5SAndroid Build Coastguard Worker
ensureStencilUnaffected()143*8975f5c5SAndroid Build Coastguard Worker void DepthStencilTest::ensureStencilUnaffected()
144*8975f5c5SAndroid Build Coastguard Worker {
145*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(stencilTestProgram, essl1_shaders::vs::Passthrough(),
146*8975f5c5SAndroid Build Coastguard Worker essl1_shaders::fs::Green());
147*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
148*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_EQUAL, 0x1B, 0xFF);
149*8975f5c5SAndroid Build Coastguard Worker drawQuad(stencilTestProgram, essl1_shaders::PositionAttrib(), 0.0f);
150*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_STENCIL_TEST);
151*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
152*8975f5c5SAndroid Build Coastguard Worker
153*8975f5c5SAndroid Build Coastguard Worker // Since stencil shouldn't exist, the drawQuad above should succeed in turning the whole image
154*8975f5c5SAndroid Build Coastguard Worker // green.
155*8975f5c5SAndroid Build Coastguard Worker ensureColor(GLColor::green);
156*8975f5c5SAndroid Build Coastguard Worker }
157*8975f5c5SAndroid Build Coastguard Worker
prepareSingleEmulatedWithPacked()158*8975f5c5SAndroid Build Coastguard Worker void DepthStencilTest::prepareSingleEmulatedWithPacked()
159*8975f5c5SAndroid Build Coastguard Worker {
160*8975f5c5SAndroid Build Coastguard Worker const int w = getWindowWidth();
161*8975f5c5SAndroid Build Coastguard Worker const int h = getWindowHeight();
162*8975f5c5SAndroid Build Coastguard Worker const int whalf = w >> 1;
163*8975f5c5SAndroid Build Coastguard Worker const int hhalf = h >> 1;
164*8975f5c5SAndroid Build Coastguard Worker
165*8975f5c5SAndroid Build Coastguard Worker // Clear to a random color, 0.75 depth and 0x36 stencil
166*8975f5c5SAndroid Build Coastguard Worker Vector4 color1(0.1f, 0.2f, 0.3f, 0.4f);
167*8975f5c5SAndroid Build Coastguard Worker GLColor color1RGB(color1);
168*8975f5c5SAndroid Build Coastguard Worker
169*8975f5c5SAndroid Build Coastguard Worker glClearColor(color1[0], color1[1], color1[2], color1[3]);
170*8975f5c5SAndroid Build Coastguard Worker glClearDepthf(0.75f);
171*8975f5c5SAndroid Build Coastguard Worker glClearStencil(0x36);
172*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
173*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
174*8975f5c5SAndroid Build Coastguard Worker
175*8975f5c5SAndroid Build Coastguard Worker // Verify color was cleared correctly.
176*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, 0, color1RGB, 1);
177*8975f5c5SAndroid Build Coastguard Worker
178*8975f5c5SAndroid Build Coastguard Worker // Use masked color to clear two channels of the image to a second color, 0.25 depth and 0x59
179*8975f5c5SAndroid Build Coastguard Worker // stencil.
180*8975f5c5SAndroid Build Coastguard Worker Vector4 color2(0.2f, 0.4f, 0.6f, 0.8f);
181*8975f5c5SAndroid Build Coastguard Worker glClearColor(color2[0], color2[1], color2[2], color2[3]);
182*8975f5c5SAndroid Build Coastguard Worker glClearDepthf(0.25f);
183*8975f5c5SAndroid Build Coastguard Worker glClearStencil(0x59);
184*8975f5c5SAndroid Build Coastguard Worker glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_FALSE);
185*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
186*8975f5c5SAndroid Build Coastguard Worker glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
187*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
188*8975f5c5SAndroid Build Coastguard Worker
189*8975f5c5SAndroid Build Coastguard Worker GLColor color2RGB(Vector4(color2[0], color1[1], color2[2], color1[3]));
190*8975f5c5SAndroid Build Coastguard Worker
191*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(whalf, hhalf, color2RGB, 1);
192*8975f5c5SAndroid Build Coastguard Worker
193*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, 0, color2RGB, 1);
194*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(w - 1, 0, color2RGB, 1);
195*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, h - 1, color2RGB, 1);
196*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(w - 1, h - 1, color2RGB, 1);
197*8975f5c5SAndroid Build Coastguard Worker
198*8975f5c5SAndroid Build Coastguard Worker // Use scissor to clear the center to a third color, 0.5 depth and 0xA9 stencil.
199*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_SCISSOR_TEST);
200*8975f5c5SAndroid Build Coastguard Worker glScissor(whalf / 2, hhalf / 2, whalf, hhalf);
201*8975f5c5SAndroid Build Coastguard Worker
202*8975f5c5SAndroid Build Coastguard Worker Vector4 color3(0.3f, 0.5f, 0.7f, 0.9f);
203*8975f5c5SAndroid Build Coastguard Worker GLColor color3RGB(color3);
204*8975f5c5SAndroid Build Coastguard Worker glClearColor(color3[0], color3[1], color3[2], color3[3]);
205*8975f5c5SAndroid Build Coastguard Worker glClearDepthf(0.5f);
206*8975f5c5SAndroid Build Coastguard Worker glClearStencil(0xA9);
207*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
208*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_SCISSOR_TEST);
209*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
210*8975f5c5SAndroid Build Coastguard Worker
211*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(whalf, hhalf, color3RGB, 1);
212*8975f5c5SAndroid Build Coastguard Worker
213*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, 0, color2RGB, 1);
214*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(w - 1, 0, color2RGB, 1);
215*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(0, h - 1, color2RGB, 1);
216*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_NEAR(w - 1, h - 1, color2RGB, 1);
217*8975f5c5SAndroid Build Coastguard Worker
218*8975f5c5SAndroid Build Coastguard Worker // Use scissor to draw to the right half of the image with a fourth color, 0.6 depth and 0x84
219*8975f5c5SAndroid Build Coastguard Worker // stencil.
220*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_SCISSOR_TEST);
221*8975f5c5SAndroid Build Coastguard Worker glScissor(whalf, 0, whalf, h);
222*8975f5c5SAndroid Build Coastguard Worker
223*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(redProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
224*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
225*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 0x84, 0xFF);
226*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
227*8975f5c5SAndroid Build Coastguard Worker glStencilMask(0xFF);
228*8975f5c5SAndroid Build Coastguard Worker drawQuad(redProgram, essl1_shaders::PositionAttrib(), 0.2f);
229*8975f5c5SAndroid Build Coastguard Worker
230*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_STENCIL_TEST);
231*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_SCISSOR_TEST);
232*8975f5c5SAndroid Build Coastguard Worker }
233*8975f5c5SAndroid Build Coastguard Worker
234*8975f5c5SAndroid Build Coastguard Worker // Tests that clearing or rendering into a depth-only format doesn't affect stencil.
TEST_P(DepthStencilTest,DepthOnlyEmulatedWithPacked)235*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTest, DepthOnlyEmulatedWithPacked)
236*8975f5c5SAndroid Build Coastguard Worker {
237*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !IsGLExtensionEnabled("GL_OES_depth24"));
238*8975f5c5SAndroid Build Coastguard Worker
239*8975f5c5SAndroid Build Coastguard Worker bindColorDepthFBO();
240*8975f5c5SAndroid Build Coastguard Worker prepareSingleEmulatedWithPacked();
241*8975f5c5SAndroid Build Coastguard Worker ensureStencilUnaffected();
242*8975f5c5SAndroid Build Coastguard Worker }
243*8975f5c5SAndroid Build Coastguard Worker
244*8975f5c5SAndroid Build Coastguard Worker // Tests that clearing or rendering into a stencil-only format doesn't affect depth.
TEST_P(DepthStencilTest,StencilOnlyEmulatedWithPacked)245*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTest, StencilOnlyEmulatedWithPacked)
246*8975f5c5SAndroid Build Coastguard Worker {
247*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/40096654
248*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D9());
249*8975f5c5SAndroid Build Coastguard Worker bindColorStencilFBO();
250*8975f5c5SAndroid Build Coastguard Worker prepareSingleEmulatedWithPacked();
251*8975f5c5SAndroid Build Coastguard Worker ensureDepthUnaffected();
252*8975f5c5SAndroid Build Coastguard Worker }
253*8975f5c5SAndroid Build Coastguard Worker
254*8975f5c5SAndroid Build Coastguard Worker // Tests that drawing into stencil buffer along multiple render passes works.
TEST_P(DepthStencilTest,StencilOnlyDrawThenCopyThenDraw)255*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTest, StencilOnlyDrawThenCopyThenDraw)
256*8975f5c5SAndroid Build Coastguard Worker {
257*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
258*8975f5c5SAndroid Build Coastguard Worker glUseProgram(drawColor);
259*8975f5c5SAndroid Build Coastguard Worker GLint colorUniformLocation =
260*8975f5c5SAndroid Build Coastguard Worker glGetUniformLocation(drawColor, angle::essl1_shaders::ColorUniform());
261*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(colorUniformLocation, -1);
262*8975f5c5SAndroid Build Coastguard Worker
263*8975f5c5SAndroid Build Coastguard Worker bindColorStencilFBO();
264*8975f5c5SAndroid Build Coastguard Worker
265*8975f5c5SAndroid Build Coastguard Worker // Draw red once
266*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
267*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 0x55, 0xFF);
268*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
269*8975f5c5SAndroid Build Coastguard Worker glStencilMask(0xFF);
270*8975f5c5SAndroid Build Coastguard Worker
271*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorUniformLocation, 1.0f, 0.0f, 0.0f, 1.0f);
272*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawColor, essl1_shaders::PositionAttrib(), 1.0f);
273*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
274*8975f5c5SAndroid Build Coastguard Worker
275*8975f5c5SAndroid Build Coastguard Worker // Create a texture and copy color into it, this breaks the render pass.
276*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
277*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
278*8975f5c5SAndroid Build Coastguard Worker glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, getWindowWidth(), getWindowHeight(), 0);
279*8975f5c5SAndroid Build Coastguard Worker
280*8975f5c5SAndroid Build Coastguard Worker // Draw green, expecting correct stencil.
281*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_EQUAL, 0x55, 0xFF);
282*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
283*8975f5c5SAndroid Build Coastguard Worker
284*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorUniformLocation, 0.0f, 1.0f, 0.0f, 1.0f);
285*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawColor, essl1_shaders::PositionAttrib(), 1.0f);
286*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
287*8975f5c5SAndroid Build Coastguard Worker
288*8975f5c5SAndroid Build Coastguard Worker // Verify that the texture is now green
289*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
290*8975f5c5SAndroid Build Coastguard Worker
291*8975f5c5SAndroid Build Coastguard Worker // For completeness, also verify that the copy texture is red
292*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
293*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, fbo);
294*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
295*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
296*8975f5c5SAndroid Build Coastguard Worker
297*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
298*8975f5c5SAndroid Build Coastguard Worker }
299*8975f5c5SAndroid Build Coastguard Worker
300*8975f5c5SAndroid Build Coastguard Worker // Tests that clearing depth/stencil followed by draw works when the depth/stencil attachment is a
301*8975f5c5SAndroid Build Coastguard Worker // texture.
TEST_P(DepthStencilTestES3,ClearThenDraw)302*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTestES3, ClearThenDraw)
303*8975f5c5SAndroid Build Coastguard Worker {
304*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer FBO;
305*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, FBO);
306*8975f5c5SAndroid Build Coastguard Worker
307*8975f5c5SAndroid Build Coastguard Worker constexpr GLsizei kSize = 6;
308*8975f5c5SAndroid Build Coastguard Worker
309*8975f5c5SAndroid Build Coastguard Worker // Create framebuffer to draw into, with both color and depth attachments.
310*8975f5c5SAndroid Build Coastguard Worker GLTexture color;
311*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, color);
312*8975f5c5SAndroid Build Coastguard Worker glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
313*8975f5c5SAndroid Build Coastguard Worker
314*8975f5c5SAndroid Build Coastguard Worker GLTexture depth;
315*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, depth);
316*8975f5c5SAndroid Build Coastguard Worker glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, kSize, kSize, 0, GL_DEPTH_STENCIL,
317*8975f5c5SAndroid Build Coastguard Worker GL_UNSIGNED_INT_24_8_OES, nullptr);
318*8975f5c5SAndroid Build Coastguard Worker
319*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
320*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, fbo);
321*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
322*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depth, 0);
323*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
324*8975f5c5SAndroid Build Coastguard Worker
325*8975f5c5SAndroid Build Coastguard Worker // Set viewport and clear depth/stencil
326*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, kSize, kSize);
327*8975f5c5SAndroid Build Coastguard Worker glClearDepthf(1);
328*8975f5c5SAndroid Build Coastguard Worker glClearStencil(0x55);
329*8975f5c5SAndroid Build Coastguard Worker glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
330*8975f5c5SAndroid Build Coastguard Worker
331*8975f5c5SAndroid Build Coastguard Worker // If depth is not cleared to 1, rendering would fail.
332*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_DEPTH_TEST);
333*8975f5c5SAndroid Build Coastguard Worker glDepthFunc(GL_LESS);
334*8975f5c5SAndroid Build Coastguard Worker
335*8975f5c5SAndroid Build Coastguard Worker // If stencil is not clear to 0x55, rendering would fail.
336*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
337*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_EQUAL, 0x55, 0xFF);
338*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
339*8975f5c5SAndroid Build Coastguard Worker glStencilMask(0xFF);
340*8975f5c5SAndroid Build Coastguard Worker
341*8975f5c5SAndroid Build Coastguard Worker // Set up program
342*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawRed, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
343*8975f5c5SAndroid Build Coastguard Worker
344*8975f5c5SAndroid Build Coastguard Worker // Draw red
345*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawRed, essl1_shaders::PositionAttrib(), 0.0f);
346*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
347*8975f5c5SAndroid Build Coastguard Worker
348*8975f5c5SAndroid Build Coastguard Worker // Verify.
349*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
350*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::red);
351*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::red);
352*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::red);
353*8975f5c5SAndroid Build Coastguard Worker }
354*8975f5c5SAndroid Build Coastguard Worker
355*8975f5c5SAndroid Build Coastguard Worker // Test that VK_EXT_load_op_none is working properly when
356*8975f5c5SAndroid Build Coastguard Worker // one of the depth / stencil load op is none.
357*8975f5c5SAndroid Build Coastguard Worker // This reproduces a deqp failure on ARM: angleproject:7370
TEST_P(DepthStencilTestES3,LoadStoreOpNoneExtension)358*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTestES3, LoadStoreOpNoneExtension)
359*8975f5c5SAndroid Build Coastguard Worker {
360*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
361*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, fbo);
362*8975f5c5SAndroid Build Coastguard Worker
363*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorRbo;
364*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
365*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, getWindowWidth(), getWindowHeight());
366*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
367*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
368*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
369*8975f5c5SAndroid Build Coastguard Worker
370*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer depthStencilBuffer;
371*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, depthStencilBuffer);
372*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, getWindowWidth(),
373*8975f5c5SAndroid Build Coastguard Worker getWindowHeight());
374*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
375*8975f5c5SAndroid Build Coastguard Worker depthStencilBuffer);
376*8975f5c5SAndroid Build Coastguard Worker
377*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
378*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
379*8975f5c5SAndroid Build Coastguard Worker
380*8975f5c5SAndroid Build Coastguard Worker glClearDepthf(1.0f);
381*8975f5c5SAndroid Build Coastguard Worker glClear(GL_DEPTH_BUFFER_BIT);
382*8975f5c5SAndroid Build Coastguard Worker glClearStencil(0.0f);
383*8975f5c5SAndroid Build Coastguard Worker glClear(GL_STENCIL_BUFFER_BIT);
384*8975f5c5SAndroid Build Coastguard Worker
385*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
386*8975f5c5SAndroid Build Coastguard Worker
387*8975f5c5SAndroid Build Coastguard Worker // Draw a red quad, stencil enabled, depth disabled
388*8975f5c5SAndroid Build Coastguard Worker // Depth Load Op: None. Depth Store Op: None.
389*8975f5c5SAndroid Build Coastguard Worker // Stencil Load Op: Load. Stencil Store Op: Store.
390*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
391*8975f5c5SAndroid Build Coastguard Worker GLint colorLocation = glGetUniformLocation(program, angle::essl1_shaders::ColorUniform());
392*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, colorLocation);
393*8975f5c5SAndroid Build Coastguard Worker
394*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_BLEND);
395*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
396*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_LEQUAL, 0, ~0u);
397*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
398*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_DITHER);
399*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_DEPTH_TEST);
400*8975f5c5SAndroid Build Coastguard Worker
401*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
402*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorLocation, 1.0f, 0.0f, 0.0f, 1.0f);
403*8975f5c5SAndroid Build Coastguard Worker drawQuad(program, "a_position", 0.5f);
404*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
405*8975f5c5SAndroid Build Coastguard Worker
406*8975f5c5SAndroid Build Coastguard Worker // Draw a green quad, stencil enabled, depth enabled.
407*8975f5c5SAndroid Build Coastguard Worker // Depth Load Op: Load. Depth Store Op: Store.
408*8975f5c5SAndroid Build Coastguard Worker // Stencil Load Op: Load. Stencil Store Op: Store.
409*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorLocation, 0.0f, 1.0f, 0.0f, 1.0f);
410*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_DEPTH_TEST);
411*8975f5c5SAndroid Build Coastguard Worker drawQuad(program, "a_position", 0.5f);
412*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
413*8975f5c5SAndroid Build Coastguard Worker }
414*8975f5c5SAndroid Build Coastguard Worker
compareDepth(uint32_t expected)415*8975f5c5SAndroid Build Coastguard Worker void DepthStencilTestES3::compareDepth(uint32_t expected)
416*8975f5c5SAndroid Build Coastguard Worker {
417*8975f5c5SAndroid Build Coastguard Worker uint32_t pixel;
418*8975f5c5SAndroid Build Coastguard Worker glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &pixel);
419*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
420*8975f5c5SAndroid Build Coastguard Worker
421*8975f5c5SAndroid Build Coastguard Worker // Right shift by 8 bits to only compare 24 depth bits
422*8975f5c5SAndroid Build Coastguard Worker // and ignore 8 undefined bits.
423*8975f5c5SAndroid Build Coastguard Worker pixel = pixel >> 8;
424*8975f5c5SAndroid Build Coastguard Worker
425*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(pixel, expected, 1);
426*8975f5c5SAndroid Build Coastguard Worker }
427*8975f5c5SAndroid Build Coastguard Worker
clearAndCompareDepth(GLfloat depth,uint32_t expected)428*8975f5c5SAndroid Build Coastguard Worker void DepthStencilTestES3::clearAndCompareDepth(GLfloat depth, uint32_t expected)
429*8975f5c5SAndroid Build Coastguard Worker {
430*8975f5c5SAndroid Build Coastguard Worker glClearDepthf(depth);
431*8975f5c5SAndroid Build Coastguard Worker glClear(GL_DEPTH_BUFFER_BIT);
432*8975f5c5SAndroid Build Coastguard Worker compareDepth(expected);
433*8975f5c5SAndroid Build Coastguard Worker }
434*8975f5c5SAndroid Build Coastguard Worker
drawAndCompareDepth(GLProgram & program,GLfloat positionZ,uint32_t expected)435*8975f5c5SAndroid Build Coastguard Worker void DepthStencilTestES3::drawAndCompareDepth(GLProgram &program,
436*8975f5c5SAndroid Build Coastguard Worker GLfloat positionZ,
437*8975f5c5SAndroid Build Coastguard Worker uint32_t expected)
438*8975f5c5SAndroid Build Coastguard Worker {
439*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_DEPTH_TEST);
440*8975f5c5SAndroid Build Coastguard Worker glDepthFunc(GL_ALWAYS);
441*8975f5c5SAndroid Build Coastguard Worker drawQuad(program, essl3_shaders::PositionAttrib(), positionZ, 1.0f);
442*8975f5c5SAndroid Build Coastguard Worker glDisable(GL_DEPTH_TEST);
443*8975f5c5SAndroid Build Coastguard Worker compareDepth(expected);
444*8975f5c5SAndroid Build Coastguard Worker }
445*8975f5c5SAndroid Build Coastguard Worker
TEST_P(DepthStencilTestES3,ReadPixelsDepth24)446*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTestES3, ReadPixelsDepth24)
447*8975f5c5SAndroid Build Coastguard Worker {
448*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_depth24") ||
449*8975f5c5SAndroid Build Coastguard Worker !IsGLExtensionEnabled("GL_NV_read_depth"));
450*8975f5c5SAndroid Build Coastguard Worker
451*8975f5c5SAndroid Build Coastguard Worker // The test fails on native GLES on Android in glReadPixels
452*8975f5c5SAndroid Build Coastguard Worker // with GL_INVALID_OPERATION due to the format/type combination
453*8975f5c5SAndroid Build Coastguard Worker // not being supported.
454*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES());
455*8975f5c5SAndroid Build Coastguard Worker
456*8975f5c5SAndroid Build Coastguard Worker // Create GL_DEPTH_COMPONENT24 texture
457*8975f5c5SAndroid Build Coastguard Worker GLTexture depthTexture;
458*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, depthTexture);
459*8975f5c5SAndroid Build Coastguard Worker glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, getWindowWidth(), getWindowHeight(), 0,
460*8975f5c5SAndroid Build Coastguard Worker GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
461*8975f5c5SAndroid Build Coastguard Worker
462*8975f5c5SAndroid Build Coastguard Worker // Set up framebuffer
463*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer depthFBO;
464*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer depthRenderbuffer;
465*8975f5c5SAndroid Build Coastguard Worker
466*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, depthFBO);
467*8975f5c5SAndroid Build Coastguard Worker
468*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0);
469*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
470*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, getWindowWidth(),
471*8975f5c5SAndroid Build Coastguard Worker getWindowHeight());
472*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
473*8975f5c5SAndroid Build Coastguard Worker depthRenderbuffer);
474*8975f5c5SAndroid Build Coastguard Worker
475*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
476*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
477*8975f5c5SAndroid Build Coastguard Worker
478*8975f5c5SAndroid Build Coastguard Worker // Test clear
479*8975f5c5SAndroid Build Coastguard Worker clearAndCompareDepth(0.0f, 0x0);
480*8975f5c5SAndroid Build Coastguard Worker clearAndCompareDepth(0.125f, 0x200000);
481*8975f5c5SAndroid Build Coastguard Worker clearAndCompareDepth(0.5f, 0x800000);
482*8975f5c5SAndroid Build Coastguard Worker clearAndCompareDepth(1.0f, 0xffffff);
483*8975f5c5SAndroid Build Coastguard Worker
484*8975f5c5SAndroid Build Coastguard Worker // Test draw
485*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(depthTestProgram, essl3_shaders::vs::Simple(), essl3_shaders::fs::Green());
486*8975f5c5SAndroid Build Coastguard Worker drawAndCompareDepth(depthTestProgram, 0.0f, 0x800000);
487*8975f5c5SAndroid Build Coastguard Worker drawAndCompareDepth(depthTestProgram, 0.125f, 0x8fffff);
488*8975f5c5SAndroid Build Coastguard Worker drawAndCompareDepth(depthTestProgram, 0.5f, 0xbfffff);
489*8975f5c5SAndroid Build Coastguard Worker drawAndCompareDepth(depthTestProgram, 1.0f, 0xffffff);
490*8975f5c5SAndroid Build Coastguard Worker
491*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
492*8975f5c5SAndroid Build Coastguard Worker }
493*8975f5c5SAndroid Build Coastguard Worker
494*8975f5c5SAndroid Build Coastguard Worker // Tests that the stencil test is correctly handled when a framebuffer is cleared before that
495*8975f5c5SAndroid Build Coastguard Worker // framebuffer's stencil attachment has been configured.
TEST_P(DepthStencilTestES3,FramebufferClearThenStencilAttachedThenStencilTestState)496*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTestES3, FramebufferClearThenStencilAttachedThenStencilTestState)
497*8975f5c5SAndroid Build Coastguard Worker {
498*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_NV_read_stencil"));
499*8975f5c5SAndroid Build Coastguard Worker
500*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
501*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, fbo);
502*8975f5c5SAndroid Build Coastguard Worker
503*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorRbo;
504*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
505*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, getWindowWidth(), getWindowHeight());
506*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
507*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.f, 0.f, 0.f, 0.f);
508*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
509*8975f5c5SAndroid Build Coastguard Worker
510*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer stencilRbo;
511*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, stencilRbo);
512*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWindowWidth(), getWindowHeight());
513*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRbo);
514*8975f5c5SAndroid Build Coastguard Worker glClearStencil(2);
515*8975f5c5SAndroid Build Coastguard Worker glClear(GL_STENCIL_BUFFER_BIT);
516*8975f5c5SAndroid Build Coastguard Worker
517*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
518*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
519*8975f5c5SAndroid Build Coastguard Worker
520*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::transparentBlack);
521*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_STENCIL_EQ(0, 0, 2);
522*8975f5c5SAndroid Build Coastguard Worker
523*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
524*8975f5c5SAndroid Build Coastguard Worker
525*8975f5c5SAndroid Build Coastguard Worker GLint colorLocation = glGetUniformLocation(program, angle::essl1_shaders::ColorUniform());
526*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, colorLocation);
527*8975f5c5SAndroid Build Coastguard Worker
528*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
529*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorLocation, 1.0f, 0.0f, 0.0f, 1.0f);
530*8975f5c5SAndroid Build Coastguard Worker
531*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
532*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 0, 0xFF);
533*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
534*8975f5c5SAndroid Build Coastguard Worker drawQuad(program, "a_position", 0.5f);
535*8975f5c5SAndroid Build Coastguard Worker
536*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
537*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_STENCIL_EQ(0, 0, 3);
538*8975f5c5SAndroid Build Coastguard Worker }
539*8975f5c5SAndroid Build Coastguard Worker
540*8975f5c5SAndroid Build Coastguard Worker // Tests that the stencil test is correctly handled when both the stencil test state is configured
541*8975f5c5SAndroid Build Coastguard Worker // and a framebuffer is cleared before that framebuffer's stencil attachment has been configured.
TEST_P(DepthStencilTestES3,StencilTestStateThenFramebufferClearThenStencilAttached)542*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTestES3, StencilTestStateThenFramebufferClearThenStencilAttached)
543*8975f5c5SAndroid Build Coastguard Worker {
544*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_NV_read_stencil"));
545*8975f5c5SAndroid Build Coastguard Worker
546*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
547*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 0, 0xFF);
548*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
549*8975f5c5SAndroid Build Coastguard Worker
550*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
551*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, fbo);
552*8975f5c5SAndroid Build Coastguard Worker
553*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorRbo;
554*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
555*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, getWindowWidth(), getWindowHeight());
556*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
557*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.f, 0.f, 0.f, 0.f);
558*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
559*8975f5c5SAndroid Build Coastguard Worker
560*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer stencilRbo;
561*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, stencilRbo);
562*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWindowWidth(), getWindowHeight());
563*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRbo);
564*8975f5c5SAndroid Build Coastguard Worker glClearStencil(2);
565*8975f5c5SAndroid Build Coastguard Worker glClear(GL_STENCIL_BUFFER_BIT);
566*8975f5c5SAndroid Build Coastguard Worker
567*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
568*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
569*8975f5c5SAndroid Build Coastguard Worker
570*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::transparentBlack);
571*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_STENCIL_EQ(0, 0, 2);
572*8975f5c5SAndroid Build Coastguard Worker
573*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
574*8975f5c5SAndroid Build Coastguard Worker
575*8975f5c5SAndroid Build Coastguard Worker GLint colorLocation = glGetUniformLocation(program, angle::essl1_shaders::ColorUniform());
576*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, colorLocation);
577*8975f5c5SAndroid Build Coastguard Worker
578*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
579*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorLocation, 1.0f, 0.0f, 0.0f, 1.0f);
580*8975f5c5SAndroid Build Coastguard Worker
581*8975f5c5SAndroid Build Coastguard Worker drawQuad(program, "a_position", 0.5f);
582*8975f5c5SAndroid Build Coastguard Worker
583*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
584*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_STENCIL_EQ(0, 0, 3);
585*8975f5c5SAndroid Build Coastguard Worker }
586*8975f5c5SAndroid Build Coastguard Worker
587*8975f5c5SAndroid Build Coastguard Worker // Tests that the stencil test is correctly handled when a framebuffer is cleared before that
588*8975f5c5SAndroid Build Coastguard Worker // framebuffer's stencil attachment has been configured and the stencil test state is configured
589*8975f5c5SAndroid Build Coastguard Worker // during framebuffer setup.
TEST_P(DepthStencilTestES3,FramebufferClearThenStencilTestStateThenStencilAttached)590*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTestES3, FramebufferClearThenStencilTestStateThenStencilAttached)
591*8975f5c5SAndroid Build Coastguard Worker {
592*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_NV_read_stencil"));
593*8975f5c5SAndroid Build Coastguard Worker
594*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer fbo;
595*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, fbo);
596*8975f5c5SAndroid Build Coastguard Worker
597*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer colorRbo;
598*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, colorRbo);
599*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, getWindowWidth(), getWindowHeight());
600*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo);
601*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.f, 0.f, 0.f, 0.f);
602*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
603*8975f5c5SAndroid Build Coastguard Worker
604*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
605*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 0, 0xFF);
606*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
607*8975f5c5SAndroid Build Coastguard Worker
608*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer stencilRbo;
609*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, stencilRbo);
610*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWindowWidth(), getWindowHeight());
611*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilRbo);
612*8975f5c5SAndroid Build Coastguard Worker glClearStencil(2);
613*8975f5c5SAndroid Build Coastguard Worker glClear(GL_STENCIL_BUFFER_BIT);
614*8975f5c5SAndroid Build Coastguard Worker
615*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
616*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
617*8975f5c5SAndroid Build Coastguard Worker
618*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::transparentBlack);
619*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_STENCIL_EQ(0, 0, 2);
620*8975f5c5SAndroid Build Coastguard Worker
621*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
622*8975f5c5SAndroid Build Coastguard Worker
623*8975f5c5SAndroid Build Coastguard Worker GLint colorLocation = glGetUniformLocation(program, angle::essl1_shaders::ColorUniform());
624*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(-1, colorLocation);
625*8975f5c5SAndroid Build Coastguard Worker
626*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
627*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorLocation, 1.0f, 0.0f, 0.0f, 1.0f);
628*8975f5c5SAndroid Build Coastguard Worker
629*8975f5c5SAndroid Build Coastguard Worker drawQuad(program, "a_position", 0.5f);
630*8975f5c5SAndroid Build Coastguard Worker
631*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
632*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_STENCIL_EQ(0, 0, 3);
633*8975f5c5SAndroid Build Coastguard Worker }
634*8975f5c5SAndroid Build Coastguard Worker
635*8975f5c5SAndroid Build Coastguard Worker // Tests that drawing with read-only depth/stencil followed by depth/stencil output (in two render
636*8975f5c5SAndroid Build Coastguard Worker // passes) works. Regression test for a synchronization bug in the Vulkan backend, caught by
637*8975f5c5SAndroid Build Coastguard Worker // syncval VVL.
TEST_P(DepthStencilTestES3,ReadOnlyDepthStencilThenOutputDepthStencil)638*8975f5c5SAndroid Build Coastguard Worker TEST_P(DepthStencilTestES3, ReadOnlyDepthStencilThenOutputDepthStencil)
639*8975f5c5SAndroid Build Coastguard Worker {
640*8975f5c5SAndroid Build Coastguard Worker constexpr GLsizei kSize = 64;
641*8975f5c5SAndroid Build Coastguard Worker
642*8975f5c5SAndroid Build Coastguard Worker // Create FBO with color, depth and stencil
643*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
644*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
645*8975f5c5SAndroid Build Coastguard Worker glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
646*8975f5c5SAndroid Build Coastguard Worker
647*8975f5c5SAndroid Build Coastguard Worker GLRenderbuffer renderbuffer;
648*8975f5c5SAndroid Build Coastguard Worker glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
649*8975f5c5SAndroid Build Coastguard Worker glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
650*8975f5c5SAndroid Build Coastguard Worker
651*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
652*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
653*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
654*8975f5c5SAndroid Build Coastguard Worker glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
655*8975f5c5SAndroid Build Coastguard Worker renderbuffer);
656*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
657*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
658*8975f5c5SAndroid Build Coastguard Worker
659*8975f5c5SAndroid Build Coastguard Worker // Initialize depth/stencil
660*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_DEPTH_TEST);
661*8975f5c5SAndroid Build Coastguard Worker glDepthFunc(GL_ALWAYS);
662*8975f5c5SAndroid Build Coastguard Worker
663*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_STENCIL_TEST);
664*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_ALWAYS, 0xAA, 0xFF);
665*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
666*8975f5c5SAndroid Build Coastguard Worker glStencilMask(0xFF);
667*8975f5c5SAndroid Build Coastguard Worker
668*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
669*8975f5c5SAndroid Build Coastguard Worker glUseProgram(drawColor);
670*8975f5c5SAndroid Build Coastguard Worker GLint colorUniformLocation =
671*8975f5c5SAndroid Build Coastguard Worker glGetUniformLocation(drawColor, angle::essl1_shaders::ColorUniform());
672*8975f5c5SAndroid Build Coastguard Worker ASSERT_NE(colorUniformLocation, -1);
673*8975f5c5SAndroid Build Coastguard Worker
674*8975f5c5SAndroid Build Coastguard Worker // Draw red with depth = 1 and stencil = 0xAA
675*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorUniformLocation, 1.0f, 0.0f, 0.0f, 1.0f);
676*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawColor, essl1_shaders::PositionAttrib(), 1);
677*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
678*8975f5c5SAndroid Build Coastguard Worker
679*8975f5c5SAndroid Build Coastguard Worker // Break the render pass by making a copy of the color texture.
680*8975f5c5SAndroid Build Coastguard Worker GLTexture copyTex;
681*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, copyTex);
682*8975f5c5SAndroid Build Coastguard Worker glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
683*8975f5c5SAndroid Build Coastguard Worker glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, kSize / 2, kSize / 2);
684*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
685*8975f5c5SAndroid Build Coastguard Worker
686*8975f5c5SAndroid Build Coastguard Worker // Disable depth/stencil output and issue a draw call that's expected to pass depth/stencil.
687*8975f5c5SAndroid Build Coastguard Worker glDepthFunc(GL_LESS);
688*8975f5c5SAndroid Build Coastguard Worker glDepthMask(GL_FALSE);
689*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_EQUAL, 0xAA, 0xFF);
690*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
691*8975f5c5SAndroid Build Coastguard Worker
692*8975f5c5SAndroid Build Coastguard Worker // Draw green
693*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorUniformLocation, 0.0f, 1.0f, 0.0f, 1.0f);
694*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.95);
695*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
696*8975f5c5SAndroid Build Coastguard Worker
697*8975f5c5SAndroid Build Coastguard Worker // Break the render pass
698*8975f5c5SAndroid Build Coastguard Worker glCopyTexSubImage2D(GL_TEXTURE_2D, 0, kSize / 2, 0, 0, 0, kSize / 2, kSize / 2);
699*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
700*8975f5c5SAndroid Build Coastguard Worker
701*8975f5c5SAndroid Build Coastguard Worker // Draw again to start another render pass still with depth/stencil read-only
702*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorUniformLocation, 0.0f, 0.0f, 1.0f, 1.0f);
703*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.95);
704*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
705*8975f5c5SAndroid Build Coastguard Worker
706*8975f5c5SAndroid Build Coastguard Worker // Break the render pass
707*8975f5c5SAndroid Build Coastguard Worker glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, kSize / 2, 0, 0, kSize / 2, kSize / 2);
708*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
709*8975f5c5SAndroid Build Coastguard Worker
710*8975f5c5SAndroid Build Coastguard Worker // Re-enable depth/stencil output and issue a draw call that's expected to pass depth/stencil.
711*8975f5c5SAndroid Build Coastguard Worker glDepthMask(GL_TRUE);
712*8975f5c5SAndroid Build Coastguard Worker glStencilFunc(GL_EQUAL, 0xAB, 0xF0);
713*8975f5c5SAndroid Build Coastguard Worker glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
714*8975f5c5SAndroid Build Coastguard Worker
715*8975f5c5SAndroid Build Coastguard Worker // Draw yellow
716*8975f5c5SAndroid Build Coastguard Worker glUniform4f(colorUniformLocation, 1.0f, 1.0f, 0.0f, 1.0f);
717*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.95);
718*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
719*8975f5c5SAndroid Build Coastguard Worker
720*8975f5c5SAndroid Build Coastguard Worker // Break the render pass
721*8975f5c5SAndroid Build Coastguard Worker glCopyTexSubImage2D(GL_TEXTURE_2D, 0, kSize / 2, kSize / 2, 0, 0, kSize / 2, kSize / 2);
722*8975f5c5SAndroid Build Coastguard Worker ASSERT_GL_NO_ERROR();
723*8975f5c5SAndroid Build Coastguard Worker
724*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer readFramebuffer;
725*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_READ_FRAMEBUFFER, readFramebuffer);
726*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, copyTex, 0);
727*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
728*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(kSize / 2, 0, GLColor::green);
729*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(0, kSize / 2, GLColor::blue);
730*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, GLColor::yellow);
731*8975f5c5SAndroid Build Coastguard Worker }
732*8975f5c5SAndroid Build Coastguard Worker
733*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND(
734*8975f5c5SAndroid Build Coastguard Worker DepthStencilTest,
735*8975f5c5SAndroid Build Coastguard Worker ES2_VULKAN().enable(Feature::ForceFallbackFormat),
736*8975f5c5SAndroid Build Coastguard Worker ES2_VULKAN_SWIFTSHADER().enable(Feature::ForceFallbackFormat),
737*8975f5c5SAndroid Build Coastguard Worker ES3_VULKAN().enable(Feature::ForceFallbackFormat),
738*8975f5c5SAndroid Build Coastguard Worker ES3_VULKAN_SWIFTSHADER().enable(Feature::ForceFallbackFormat));
739*8975f5c5SAndroid Build Coastguard Worker
740*8975f5c5SAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DepthStencilTestES3);
741*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_ES3_AND(
742*8975f5c5SAndroid Build Coastguard Worker DepthStencilTestES3,
743*8975f5c5SAndroid Build Coastguard Worker ES3_VULKAN().enable(Feature::ForceFallbackFormat),
744*8975f5c5SAndroid Build Coastguard Worker ES3_VULKAN().enable(Feature::DisallowMixedDepthStencilLoadOpNoneAndLoad),
745*8975f5c5SAndroid Build Coastguard Worker ES3_VULKAN_SWIFTSHADER().enable(Feature::ForceFallbackFormat));
746*8975f5c5SAndroid Build Coastguard Worker
747*8975f5c5SAndroid Build Coastguard Worker } // anonymous namespace
748