xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fClipControlTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * OpenGL Conformance Test Suite
3*35238bceSAndroid Build Coastguard Worker  * -----------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright (c) 2014-2019 The Khronos Group Inc.
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  */ /*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief
22*35238bceSAndroid Build Coastguard Worker  */ /*-------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker /**
25*35238bceSAndroid Build Coastguard Worker  * \file  gl2fClipControlTests.cpp
26*35238bceSAndroid Build Coastguard Worker  * \brief Implements conformance tests for "EXT_clip_control" functionality.
27*35238bceSAndroid Build Coastguard Worker  */ /*-------------------------------------------------------------------*/
28*35238bceSAndroid Build Coastguard Worker 
29*35238bceSAndroid Build Coastguard Worker #include "es2fClipControlTests.hpp"
30*35238bceSAndroid Build Coastguard Worker 
31*35238bceSAndroid Build Coastguard Worker #include "deSharedPtr.hpp"
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "gluDrawUtil.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "gluDefs.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
38*35238bceSAndroid Build Coastguard Worker 
39*35238bceSAndroid Build Coastguard Worker #include "tcuFuzzyImageCompare.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
44*35238bceSAndroid Build Coastguard Worker 
45*35238bceSAndroid Build Coastguard Worker #include "glw.h"
46*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
47*35238bceSAndroid Build Coastguard Worker 
48*35238bceSAndroid Build Coastguard Worker #include <cmath>
49*35238bceSAndroid Build Coastguard Worker 
50*35238bceSAndroid Build Coastguard Worker namespace deqp
51*35238bceSAndroid Build Coastguard Worker {
52*35238bceSAndroid Build Coastguard Worker namespace gles2
53*35238bceSAndroid Build Coastguard Worker {
54*35238bceSAndroid Build Coastguard Worker namespace Functional
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker 
57*35238bceSAndroid Build Coastguard Worker class ClipControlApi
58*35238bceSAndroid Build Coastguard Worker {
59*35238bceSAndroid Build Coastguard Worker public:
ClipControlApi(Context & context)60*35238bceSAndroid Build Coastguard Worker     ClipControlApi(Context &context) : m_context(context)
61*35238bceSAndroid Build Coastguard Worker     {
62*35238bceSAndroid Build Coastguard Worker         if (!Supported(m_context))
63*35238bceSAndroid Build Coastguard Worker         {
64*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("Required extension EXT_clip_control is not supported");
65*35238bceSAndroid Build Coastguard Worker         }
66*35238bceSAndroid Build Coastguard Worker         clipControl = context.getRenderContext().getFunctions().clipControl;
67*35238bceSAndroid Build Coastguard Worker     }
68*35238bceSAndroid Build Coastguard Worker 
Supported(Context & context)69*35238bceSAndroid Build Coastguard Worker     static bool Supported(Context &context)
70*35238bceSAndroid Build Coastguard Worker     {
71*35238bceSAndroid Build Coastguard Worker         return context.getContextInfo().isExtensionSupported("GL_EXT_clip_control");
72*35238bceSAndroid Build Coastguard Worker     }
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker     glw::glClipControlFunc clipControl;
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker private:
77*35238bceSAndroid Build Coastguard Worker     Context &m_context;
78*35238bceSAndroid Build Coastguard Worker };
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker class ClipControlBaseTest : public TestCase
81*35238bceSAndroid Build Coastguard Worker {
82*35238bceSAndroid Build Coastguard Worker protected:
ClipControlBaseTest(Context & context,const char * name,const char * description)83*35238bceSAndroid Build Coastguard Worker     ClipControlBaseTest(Context &context, const char *name, const char *description)
84*35238bceSAndroid Build Coastguard Worker         : TestCase(context, name, description)
85*35238bceSAndroid Build Coastguard Worker     {
86*35238bceSAndroid Build Coastguard Worker     }
87*35238bceSAndroid Build Coastguard Worker 
init()88*35238bceSAndroid Build Coastguard Worker     void init() override
89*35238bceSAndroid Build Coastguard Worker     {
90*35238bceSAndroid Build Coastguard Worker         ClipControlApi api(m_context);
91*35238bceSAndroid Build Coastguard Worker     }
92*35238bceSAndroid Build Coastguard Worker 
verifyState(glw::GLenum origin,glw::GLenum depth)93*35238bceSAndroid Build Coastguard Worker     bool verifyState(glw::GLenum origin, glw::GLenum depth)
94*35238bceSAndroid Build Coastguard Worker     {
95*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
96*35238bceSAndroid Build Coastguard Worker 
97*35238bceSAndroid Build Coastguard Worker         bool ret = true;
98*35238bceSAndroid Build Coastguard Worker 
99*35238bceSAndroid Build Coastguard Worker         glw::GLint retI;
100*35238bceSAndroid Build Coastguard Worker         gl.getIntegerv(GL_CLIP_ORIGIN, &retI);
101*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_CLIP_ORIGIN");
102*35238bceSAndroid Build Coastguard Worker 
103*35238bceSAndroid Build Coastguard Worker         ret &= (static_cast<glw::GLenum>(retI) == origin);
104*35238bceSAndroid Build Coastguard Worker 
105*35238bceSAndroid Build Coastguard Worker         gl.getIntegerv(GL_CLIP_DEPTH_MODE, &retI);
106*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "get GL_CLIP_DEPTH_MODE");
107*35238bceSAndroid Build Coastguard Worker 
108*35238bceSAndroid Build Coastguard Worker         ret &= (static_cast<glw::GLenum>(retI) == depth);
109*35238bceSAndroid Build Coastguard Worker 
110*35238bceSAndroid Build Coastguard Worker         return ret;
111*35238bceSAndroid Build Coastguard Worker     }
112*35238bceSAndroid Build Coastguard Worker };
113*35238bceSAndroid Build Coastguard Worker 
114*35238bceSAndroid Build Coastguard Worker class ClipControlRenderBaseTest : public ClipControlBaseTest
115*35238bceSAndroid Build Coastguard Worker {
116*35238bceSAndroid Build Coastguard Worker protected:
ClipControlRenderBaseTest(Context & context,const char * name,const char * description)117*35238bceSAndroid Build Coastguard Worker     ClipControlRenderBaseTest(Context &context, const char *name, const char *description)
118*35238bceSAndroid Build Coastguard Worker         : ClipControlBaseTest(context, name, description)
119*35238bceSAndroid Build Coastguard Worker         , m_fbo(0)
120*35238bceSAndroid Build Coastguard Worker         , m_rboC(0)
121*35238bceSAndroid Build Coastguard Worker         , m_depthTexure(0)
122*35238bceSAndroid Build Coastguard Worker     {
123*35238bceSAndroid Build Coastguard Worker     }
124*35238bceSAndroid Build Coastguard Worker 
fsh()125*35238bceSAndroid Build Coastguard Worker     const char *fsh()
126*35238bceSAndroid Build Coastguard Worker     {
127*35238bceSAndroid Build Coastguard Worker         return "void main() {"
128*35238bceSAndroid Build Coastguard Worker                "\n"
129*35238bceSAndroid Build Coastguard Worker                "    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);"
130*35238bceSAndroid Build Coastguard Worker                "\n"
131*35238bceSAndroid Build Coastguard Worker                "}";
132*35238bceSAndroid Build Coastguard Worker     }
133*35238bceSAndroid Build Coastguard Worker 
fuzzyDepthCompare(tcu::TestLog & log,const char * imageSetName,const char * imageSetDesc,const tcu::TextureLevel & reference,const tcu::TextureLevel & result,float threshold,const tcu::TextureLevel * importanceMask=NULL)134*35238bceSAndroid Build Coastguard Worker     bool fuzzyDepthCompare(tcu::TestLog &log, const char *imageSetName, const char *imageSetDesc,
135*35238bceSAndroid Build Coastguard Worker                            const tcu::TextureLevel &reference, const tcu::TextureLevel &result, float threshold,
136*35238bceSAndroid Build Coastguard Worker                            const tcu::TextureLevel *importanceMask = NULL)
137*35238bceSAndroid Build Coastguard Worker     {
138*35238bceSAndroid Build Coastguard Worker         (void)imageSetName;
139*35238bceSAndroid Build Coastguard Worker         (void)imageSetDesc;
140*35238bceSAndroid Build Coastguard Worker         bool depthOk     = true;
141*35238bceSAndroid Build Coastguard Worker         float difference = 0.0f;
142*35238bceSAndroid Build Coastguard Worker 
143*35238bceSAndroid Build Coastguard Worker         for (int y = 0; y < result.getHeight() && depthOk; y++)
144*35238bceSAndroid Build Coastguard Worker         {
145*35238bceSAndroid Build Coastguard Worker             for (int x = 0; x < result.getWidth() && depthOk; x++)
146*35238bceSAndroid Build Coastguard Worker             {
147*35238bceSAndroid Build Coastguard Worker                 float ref  = reference.getAccess().getPixDepth(x, y);
148*35238bceSAndroid Build Coastguard Worker                 float res  = result.getAccess().getPixel(x, y).x();
149*35238bceSAndroid Build Coastguard Worker                 difference = std::abs(ref - res);
150*35238bceSAndroid Build Coastguard Worker                 if (importanceMask)
151*35238bceSAndroid Build Coastguard Worker                 {
152*35238bceSAndroid Build Coastguard Worker                     difference *= importanceMask->getAccess().getPixDepth(x, y);
153*35238bceSAndroid Build Coastguard Worker                 }
154*35238bceSAndroid Build Coastguard Worker                 depthOk &= (difference < threshold);
155*35238bceSAndroid Build Coastguard Worker             }
156*35238bceSAndroid Build Coastguard Worker         }
157*35238bceSAndroid Build Coastguard Worker 
158*35238bceSAndroid Build Coastguard Worker         if (!depthOk)
159*35238bceSAndroid Build Coastguard Worker             log << tcu::TestLog::Message << "Image comparison failed: difference = " << difference
160*35238bceSAndroid Build Coastguard Worker                 << ", threshold = " << threshold << tcu::TestLog::EndMessage;
161*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 pixelBias(0.0f, 0.0f, 0.0f, 0.0f);
162*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 pixelScale(1.0f, 1.0f, 1.0f, 1.0f);
163*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::ImageSet("Result", "Depth image comparison result")
164*35238bceSAndroid Build Coastguard Worker             << tcu::TestLog::Image("Result", "Result", result.getAccess(), pixelScale, pixelBias)
165*35238bceSAndroid Build Coastguard Worker             << tcu::TestLog::Image("Reference", "Reference", reference.getAccess(), pixelScale, pixelBias);
166*35238bceSAndroid Build Coastguard Worker         if (importanceMask)
167*35238bceSAndroid Build Coastguard Worker         {
168*35238bceSAndroid Build Coastguard Worker             log << tcu::TestLog::Image("Importance mask", "mask", importanceMask->getAccess(), pixelScale, pixelBias);
169*35238bceSAndroid Build Coastguard Worker         }
170*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::EndImageSet;
171*35238bceSAndroid Build Coastguard Worker 
172*35238bceSAndroid Build Coastguard Worker         return depthOk;
173*35238bceSAndroid Build Coastguard Worker     }
174*35238bceSAndroid Build Coastguard Worker 
init(void)175*35238bceSAndroid Build Coastguard Worker     virtual void init(void)
176*35238bceSAndroid Build Coastguard Worker     {
177*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = m_context.getRenderContext().getRenderTarget();
178*35238bceSAndroid Build Coastguard Worker         glw::GLuint viewportW                 = renderTarget.getWidth();
179*35238bceSAndroid Build Coastguard Worker         glw::GLuint viewportH                 = renderTarget.getHeight();
180*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl              = m_context.getRenderContext().getFunctions();
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker         gl.genFramebuffers(1, &m_fbo);
183*35238bceSAndroid Build Coastguard Worker         gl.genRenderbuffers(1, &m_rboC);
184*35238bceSAndroid Build Coastguard Worker         gl.genTextures(1, &m_depthTexure);
185*35238bceSAndroid Build Coastguard Worker 
186*35238bceSAndroid Build Coastguard Worker         gl.bindRenderbuffer(GL_RENDERBUFFER, m_rboC);
187*35238bceSAndroid Build Coastguard Worker         gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, viewportW, viewportH);
188*35238bceSAndroid Build Coastguard Worker 
189*35238bceSAndroid Build Coastguard Worker         gl.bindTexture(GL_TEXTURE_2D, m_depthTexure);
190*35238bceSAndroid Build Coastguard Worker         gl.texImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, viewportW, viewportH, 0, GL_DEPTH_COMPONENT,
191*35238bceSAndroid Build Coastguard Worker                       GL_UNSIGNED_SHORT, DE_NULL);
192*35238bceSAndroid Build Coastguard Worker 
193*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
194*35238bceSAndroid Build Coastguard Worker         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rboC);
195*35238bceSAndroid Build Coastguard Worker         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexure, 0);
196*35238bceSAndroid Build Coastguard Worker     }
197*35238bceSAndroid Build Coastguard Worker 
deinit(void)198*35238bceSAndroid Build Coastguard Worker     virtual void deinit(void)
199*35238bceSAndroid Build Coastguard Worker     {
200*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
201*35238bceSAndroid Build Coastguard Worker         gl.deleteFramebuffers(1, &m_fbo);
202*35238bceSAndroid Build Coastguard Worker         gl.deleteRenderbuffers(1, &m_rboC);
203*35238bceSAndroid Build Coastguard Worker         gl.deleteTextures(1, &m_depthTexure);
204*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
205*35238bceSAndroid Build Coastguard Worker     }
206*35238bceSAndroid Build Coastguard Worker 
getDepthTexture()207*35238bceSAndroid Build Coastguard Worker     GLuint getDepthTexture()
208*35238bceSAndroid Build Coastguard Worker     {
209*35238bceSAndroid Build Coastguard Worker         return m_depthTexure;
210*35238bceSAndroid Build Coastguard Worker     }
211*35238bceSAndroid Build Coastguard Worker 
212*35238bceSAndroid Build Coastguard Worker private:
213*35238bceSAndroid Build Coastguard Worker     GLuint m_fbo, m_rboC, m_depthTexure;
214*35238bceSAndroid Build Coastguard Worker };
215*35238bceSAndroid Build Coastguard Worker 
216*35238bceSAndroid Build Coastguard Worker /*
217*35238bceSAndroid Build Coastguard Worker  Verify the following state values are implemented and return a valid
218*35238bceSAndroid Build Coastguard Worker  initial value by calling GetIntegerv:
219*35238bceSAndroid Build Coastguard Worker 
220*35238bceSAndroid Build Coastguard Worker  Get Value                                 Initial Value
221*35238bceSAndroid Build Coastguard Worker  -------------------------------------------------------
222*35238bceSAndroid Build Coastguard Worker  CLIP_ORIGIN                                  LOWER_LEFT
223*35238bceSAndroid Build Coastguard Worker  CLIP_DEPTH_MODE                     NEGATIVE_ONE_TO_ONE
224*35238bceSAndroid Build Coastguard Worker 
225*35238bceSAndroid Build Coastguard Worker  Verify no GL error is generated.
226*35238bceSAndroid Build Coastguard Worker  */
227*35238bceSAndroid Build Coastguard Worker class ClipControlInitialState : public ClipControlBaseTest
228*35238bceSAndroid Build Coastguard Worker {
229*35238bceSAndroid Build Coastguard Worker public:
ClipControlInitialState(Context & context,const char * name)230*35238bceSAndroid Build Coastguard Worker     ClipControlInitialState(Context &context, const char *name)
231*35238bceSAndroid Build Coastguard Worker         : ClipControlBaseTest(context, name, "Verify initial state")
232*35238bceSAndroid Build Coastguard Worker     {
233*35238bceSAndroid Build Coastguard Worker     }
234*35238bceSAndroid Build Coastguard Worker 
iterate()235*35238bceSAndroid Build Coastguard Worker     IterateResult iterate() override
236*35238bceSAndroid Build Coastguard Worker     {
237*35238bceSAndroid Build Coastguard Worker         if (!verifyState(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE))
238*35238bceSAndroid Build Coastguard Worker         {
239*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Wrong intitial state: GL_CLIP_ORIGIN should be GL_LOWER_LEFT,"
240*35238bceSAndroid Build Coastguard Worker                      " GL_CLIP_ORIGIN should be NEGATIVE_ONE_TO_ONE");
241*35238bceSAndroid Build Coastguard Worker         }
242*35238bceSAndroid Build Coastguard Worker 
243*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, qpGetTestResultName(QP_TEST_RESULT_PASS));
244*35238bceSAndroid Build Coastguard Worker         return STOP;
245*35238bceSAndroid Build Coastguard Worker     }
246*35238bceSAndroid Build Coastguard Worker };
247*35238bceSAndroid Build Coastguard Worker 
248*35238bceSAndroid Build Coastguard Worker /*
249*35238bceSAndroid Build Coastguard Worker  Modify the state to each of the following combinations and after each
250*35238bceSAndroid Build Coastguard Worker  state change verify the state values:
251*35238bceSAndroid Build Coastguard Worker 
252*35238bceSAndroid Build Coastguard Worker  ClipControl(UPPER_LEFT, ZERO_TO_ONE)
253*35238bceSAndroid Build Coastguard Worker  ClipControl(UPPER_LEFT, NEGATIVE_ONE_TO_ONE)
254*35238bceSAndroid Build Coastguard Worker  ClipControl(LOWER_LEFT, ZERO_TO_ONE)
255*35238bceSAndroid Build Coastguard Worker  ClipControl(LOWER_LEFT, NEGATIVE_ONE_TO_ONE)
256*35238bceSAndroid Build Coastguard Worker 
257*35238bceSAndroid Build Coastguard Worker  Verify no GL error is generated.
258*35238bceSAndroid Build Coastguard Worker 
259*35238bceSAndroid Build Coastguard Worker  */
260*35238bceSAndroid Build Coastguard Worker class ClipControlModifyGetState : public ClipControlBaseTest
261*35238bceSAndroid Build Coastguard Worker {
262*35238bceSAndroid Build Coastguard Worker public:
ClipControlModifyGetState(Context & context,const char * name)263*35238bceSAndroid Build Coastguard Worker     ClipControlModifyGetState(Context &context, const char *name)
264*35238bceSAndroid Build Coastguard Worker         : ClipControlBaseTest(context, name, "Verify initial state")
265*35238bceSAndroid Build Coastguard Worker     {
266*35238bceSAndroid Build Coastguard Worker     }
267*35238bceSAndroid Build Coastguard Worker 
deinit()268*35238bceSAndroid Build Coastguard Worker     void deinit() override
269*35238bceSAndroid Build Coastguard Worker     {
270*35238bceSAndroid Build Coastguard Worker         if (ClipControlApi::Supported(m_context))
271*35238bceSAndroid Build Coastguard Worker         {
272*35238bceSAndroid Build Coastguard Worker             ClipControlApi cc(m_context);
273*35238bceSAndroid Build Coastguard Worker             cc.clipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
274*35238bceSAndroid Build Coastguard Worker         }
275*35238bceSAndroid Build Coastguard Worker     }
276*35238bceSAndroid Build Coastguard Worker 
iterate()277*35238bceSAndroid Build Coastguard Worker     IterateResult iterate() override
278*35238bceSAndroid Build Coastguard Worker     {
279*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
280*35238bceSAndroid Build Coastguard Worker         ClipControlApi cc(m_context);
281*35238bceSAndroid Build Coastguard Worker 
282*35238bceSAndroid Build Coastguard Worker         GLenum cases[4][2] = {
283*35238bceSAndroid Build Coastguard Worker             {GL_UPPER_LEFT, GL_ZERO_TO_ONE},
284*35238bceSAndroid Build Coastguard Worker             {GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE},
285*35238bceSAndroid Build Coastguard Worker             {GL_LOWER_LEFT, GL_ZERO_TO_ONE},
286*35238bceSAndroid Build Coastguard Worker             {GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE},
287*35238bceSAndroid Build Coastguard Worker         };
288*35238bceSAndroid Build Coastguard Worker 
289*35238bceSAndroid Build Coastguard Worker         for (size_t i = 0; i < DE_LENGTH_OF_ARRAY(cases); i++)
290*35238bceSAndroid Build Coastguard Worker         {
291*35238bceSAndroid Build Coastguard Worker             cc.clipControl(cases[i][0], cases[i][1]);
292*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "ClipControl()");
293*35238bceSAndroid Build Coastguard Worker             if (!verifyState(cases[i][0], cases[i][1]))
294*35238bceSAndroid Build Coastguard Worker             {
295*35238bceSAndroid Build Coastguard Worker                 TCU_FAIL("Wrong ClipControl state after ClipControl() call");
296*35238bceSAndroid Build Coastguard Worker             }
297*35238bceSAndroid Build Coastguard Worker         }
298*35238bceSAndroid Build Coastguard Worker 
299*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, qpGetTestResultName(QP_TEST_RESULT_PASS));
300*35238bceSAndroid Build Coastguard Worker         return STOP;
301*35238bceSAndroid Build Coastguard Worker     }
302*35238bceSAndroid Build Coastguard Worker };
303*35238bceSAndroid Build Coastguard Worker 
304*35238bceSAndroid Build Coastguard Worker /*
305*35238bceSAndroid Build Coastguard Worker  Check that ClipControl generate an GL_INVALID_ENUM error if origin is
306*35238bceSAndroid Build Coastguard Worker  not GL_LOWER_LEFT or GL_UPPER_LEFT.
307*35238bceSAndroid Build Coastguard Worker 
308*35238bceSAndroid Build Coastguard Worker  Check that ClipControl generate an GL_INVALID_ENUM error if depth is
309*35238bceSAndroid Build Coastguard Worker  not GL_NEGATIVE_ONE_TO_ONE or GL_ZERO_TO_ONE.
310*35238bceSAndroid Build Coastguard Worker 
311*35238bceSAndroid Build Coastguard Worker  Test is based on OpenGL 4.5 Core Profile Specification May 28th Section
312*35238bceSAndroid Build Coastguard Worker  13.5 Primitive Clipping:
313*35238bceSAndroid Build Coastguard Worker  "An INVALID_ENUM error is generated if origin is not LOWER_LEFT or
314*35238bceSAndroid Build Coastguard Worker  UPPER_LEFT.
315*35238bceSAndroid Build Coastguard Worker  An INVALID_ENUM error is generated if depth is not NEGATIVE_ONE_-
316*35238bceSAndroid Build Coastguard Worker  TO_ONE or ZERO_TO_ONE."
317*35238bceSAndroid Build Coastguard Worker  */
318*35238bceSAndroid Build Coastguard Worker class ClipControlErrors : public ClipControlBaseTest
319*35238bceSAndroid Build Coastguard Worker {
320*35238bceSAndroid Build Coastguard Worker public:
ClipControlErrors(Context & context,const char * name)321*35238bceSAndroid Build Coastguard Worker     ClipControlErrors(Context &context, const char *name)
322*35238bceSAndroid Build Coastguard Worker         : ClipControlBaseTest(context, name, "Verify that proper errors are generated when using ClipControl.")
323*35238bceSAndroid Build Coastguard Worker     {
324*35238bceSAndroid Build Coastguard Worker     }
325*35238bceSAndroid Build Coastguard Worker 
deinit()326*35238bceSAndroid Build Coastguard Worker     void deinit() override
327*35238bceSAndroid Build Coastguard Worker     {
328*35238bceSAndroid Build Coastguard Worker         if (ClipControlApi::Supported(m_context))
329*35238bceSAndroid Build Coastguard Worker         {
330*35238bceSAndroid Build Coastguard Worker             ClipControlApi cc(m_context);
331*35238bceSAndroid Build Coastguard Worker             cc.clipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
332*35238bceSAndroid Build Coastguard Worker         }
333*35238bceSAndroid Build Coastguard Worker     }
334*35238bceSAndroid Build Coastguard Worker 
iterate()335*35238bceSAndroid Build Coastguard Worker     IterateResult iterate() override
336*35238bceSAndroid Build Coastguard Worker     {
337*35238bceSAndroid Build Coastguard Worker         /* API query */
338*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log        = m_testCtx.getLog();
339*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
340*35238bceSAndroid Build Coastguard Worker         ClipControlApi cc(m_context);
341*35238bceSAndroid Build Coastguard Worker 
342*35238bceSAndroid Build Coastguard Worker         /* Finding improper value. */
343*35238bceSAndroid Build Coastguard Worker         GLenum improper_value = GL_NONE;
344*35238bceSAndroid Build Coastguard Worker 
345*35238bceSAndroid Build Coastguard Worker         while ((GL_UPPER_LEFT == improper_value) || (GL_LOWER_LEFT == improper_value) ||
346*35238bceSAndroid Build Coastguard Worker                (GL_ZERO_TO_ONE == improper_value) || (GL_NEGATIVE_ONE_TO_ONE == improper_value))
347*35238bceSAndroid Build Coastguard Worker         {
348*35238bceSAndroid Build Coastguard Worker             ++improper_value;
349*35238bceSAndroid Build Coastguard Worker         }
350*35238bceSAndroid Build Coastguard Worker 
351*35238bceSAndroid Build Coastguard Worker         /* Test setup. */
352*35238bceSAndroid Build Coastguard Worker         GLenum cases[5][2] = {{GL_UPPER_LEFT, improper_value},
353*35238bceSAndroid Build Coastguard Worker                               {GL_LOWER_LEFT, improper_value},
354*35238bceSAndroid Build Coastguard Worker                               {improper_value, GL_ZERO_TO_ONE},
355*35238bceSAndroid Build Coastguard Worker                               {improper_value, GL_NEGATIVE_ONE_TO_ONE},
356*35238bceSAndroid Build Coastguard Worker                               {improper_value, improper_value}};
357*35238bceSAndroid Build Coastguard Worker 
358*35238bceSAndroid Build Coastguard Worker         /* Test iterations. */
359*35238bceSAndroid Build Coastguard Worker         for (size_t i = 0; i < DE_LENGTH_OF_ARRAY(cases); i++)
360*35238bceSAndroid Build Coastguard Worker         {
361*35238bceSAndroid Build Coastguard Worker             cc.clipControl(cases[i][0], cases[i][1]);
362*35238bceSAndroid Build Coastguard Worker 
363*35238bceSAndroid Build Coastguard Worker             if (GL_INVALID_ENUM != gl.getError())
364*35238bceSAndroid Build Coastguard Worker             {
365*35238bceSAndroid Build Coastguard Worker                 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, qpGetTestResultName(QP_TEST_RESULT_FAIL));
366*35238bceSAndroid Build Coastguard Worker 
367*35238bceSAndroid Build Coastguard Worker                 log << tcu::TestLog::Message
368*35238bceSAndroid Build Coastguard Worker                     << "ClipControl have not generated GL_INVALID_ENUM error when called with invalid value ("
369*35238bceSAndroid Build Coastguard Worker                     << cases[i][0] << ", " << cases[i][1] << ")." << tcu::TestLog::EndMessage;
370*35238bceSAndroid Build Coastguard Worker             }
371*35238bceSAndroid Build Coastguard Worker         }
372*35238bceSAndroid Build Coastguard Worker 
373*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, qpGetTestResultName(QP_TEST_RESULT_PASS));
374*35238bceSAndroid Build Coastguard Worker         return STOP;
375*35238bceSAndroid Build Coastguard Worker     }
376*35238bceSAndroid Build Coastguard Worker };
377*35238bceSAndroid Build Coastguard Worker 
378*35238bceSAndroid Build Coastguard Worker /*
379*35238bceSAndroid Build Coastguard Worker  Clip Control Origin Test
380*35238bceSAndroid Build Coastguard Worker 
381*35238bceSAndroid Build Coastguard Worker  * Basic <origin> behavior can be tested by rendering to a viewport with
382*35238bceSAndroid Build Coastguard Worker  clip coordinates where -1.0 <= x_c <= 0.0 and -1.0 <= y_c <= 0.0.
383*35238bceSAndroid Build Coastguard Worker  When <origin> is LOWER_LEFT the "bottom left" portion of the window
384*35238bceSAndroid Build Coastguard Worker  is rendered and when UPPER_LEFT is used the "top left" portion of the
385*35238bceSAndroid Build Coastguard Worker  window is rendered. The default framebuffer should be bound. Here is the
386*35238bceSAndroid Build Coastguard Worker  basic outline of the test:
387*35238bceSAndroid Build Coastguard Worker 
388*35238bceSAndroid Build Coastguard Worker  - Clear the default framebuffer to red (1,0,0).
389*35238bceSAndroid Build Coastguard Worker  - Set ClipControl(UPPER_LEFT, NEGATIVE_ONE_TO_ONE)
390*35238bceSAndroid Build Coastguard Worker  - Render a triangle fan covering (-1.0, -1.0) to (0.0, 0.0) and
391*35238bceSAndroid Build Coastguard Worker  write a pixel value of green (0,1,0).
392*35238bceSAndroid Build Coastguard Worker  - Read back the default framebuffer with ReadPixels
393*35238bceSAndroid Build Coastguard Worker  - Verify the green pixels at the top and red at the bottom.
394*35238bceSAndroid Build Coastguard Worker 
395*35238bceSAndroid Build Coastguard Worker  Repeat the above test with LOWER_LEFT and verify green at the bottom
396*35238bceSAndroid Build Coastguard Worker  and red at the top.
397*35238bceSAndroid Build Coastguard Worker  */
398*35238bceSAndroid Build Coastguard Worker class ClipControlOriginTest : public ClipControlRenderBaseTest
399*35238bceSAndroid Build Coastguard Worker {
400*35238bceSAndroid Build Coastguard Worker public:
ClipControlOriginTest(Context & context,const char * name)401*35238bceSAndroid Build Coastguard Worker     ClipControlOriginTest(Context &context, const char *name)
402*35238bceSAndroid Build Coastguard Worker         : ClipControlRenderBaseTest(context, name, "Clip Control Origin Test")
403*35238bceSAndroid Build Coastguard Worker         , m_vao(0)
404*35238bceSAndroid Build Coastguard Worker         , m_vbo(0)
405*35238bceSAndroid Build Coastguard Worker     {
406*35238bceSAndroid Build Coastguard Worker     }
407*35238bceSAndroid Build Coastguard Worker 
deinit()408*35238bceSAndroid Build Coastguard Worker     void deinit() override
409*35238bceSAndroid Build Coastguard Worker     {
410*35238bceSAndroid Build Coastguard Worker         ClipControlRenderBaseTest::deinit();
411*35238bceSAndroid Build Coastguard Worker 
412*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
413*35238bceSAndroid Build Coastguard Worker         if (ClipControlApi::Supported(m_context))
414*35238bceSAndroid Build Coastguard Worker         {
415*35238bceSAndroid Build Coastguard Worker             ClipControlApi cc(m_context);
416*35238bceSAndroid Build Coastguard Worker             cc.clipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
417*35238bceSAndroid Build Coastguard Worker         }
418*35238bceSAndroid Build Coastguard Worker 
419*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.0, 0.0, 0.0, 0.0);
420*35238bceSAndroid Build Coastguard Worker         if (m_vao)
421*35238bceSAndroid Build Coastguard Worker         {
422*35238bceSAndroid Build Coastguard Worker             gl.deleteVertexArrays(1, &m_vao);
423*35238bceSAndroid Build Coastguard Worker         }
424*35238bceSAndroid Build Coastguard Worker         if (m_vbo)
425*35238bceSAndroid Build Coastguard Worker         {
426*35238bceSAndroid Build Coastguard Worker             gl.deleteBuffers(1, &m_vbo);
427*35238bceSAndroid Build Coastguard Worker         }
428*35238bceSAndroid Build Coastguard Worker     }
429*35238bceSAndroid Build Coastguard Worker 
iterate()430*35238bceSAndroid Build Coastguard Worker     IterateResult iterate() override
431*35238bceSAndroid Build Coastguard Worker     {
432*35238bceSAndroid Build Coastguard Worker 
433*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log        = m_testCtx.getLog();
434*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
435*35238bceSAndroid Build Coastguard Worker         ClipControlApi cc(m_context);
436*35238bceSAndroid Build Coastguard Worker 
437*35238bceSAndroid Build Coastguard Worker         //Render a triangle fan covering(-1.0, -1.0) to(1.0, 0.0) and
438*35238bceSAndroid Build Coastguard Worker         //write a pixel value of green(0, 1, 0).
439*35238bceSAndroid Build Coastguard Worker 
440*35238bceSAndroid Build Coastguard Worker         de::SharedPtr<glu::ShaderProgram> program(
441*35238bceSAndroid Build Coastguard Worker             new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vsh(), fsh())));
442*35238bceSAndroid Build Coastguard Worker 
443*35238bceSAndroid Build Coastguard Worker         log << (*program);
444*35238bceSAndroid Build Coastguard Worker         if (!program->isOk())
445*35238bceSAndroid Build Coastguard Worker         {
446*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Program compilation failed");
447*35238bceSAndroid Build Coastguard Worker         }
448*35238bceSAndroid Build Coastguard Worker 
449*35238bceSAndroid Build Coastguard Worker         gl.genVertexArrays(1, &m_vao);
450*35238bceSAndroid Build Coastguard Worker         gl.bindVertexArray(m_vao);
451*35238bceSAndroid Build Coastguard Worker 
452*35238bceSAndroid Build Coastguard Worker         gl.genBuffers(1, &m_vbo);
453*35238bceSAndroid Build Coastguard Worker 
454*35238bceSAndroid Build Coastguard Worker         const float vertex_data0[] = {-1.0, -1.0, 0.0, -1.0, -1.0, 0.0, 0.0, 0.0};
455*35238bceSAndroid Build Coastguard Worker 
456*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo);
457*35238bceSAndroid Build Coastguard Worker         gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertex_data0), vertex_data0, GL_STATIC_DRAW);
458*35238bceSAndroid Build Coastguard Worker 
459*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
460*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(0);
461*35238bceSAndroid Build Coastguard Worker 
462*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program->getProgram());
463*35238bceSAndroid Build Coastguard Worker 
464*35238bceSAndroid Build Coastguard Worker         glw::GLenum origins[] = {GL_UPPER_LEFT, GL_LOWER_LEFT};
465*35238bceSAndroid Build Coastguard Worker 
466*35238bceSAndroid Build Coastguard Worker         qpTestResult result = QP_TEST_RESULT_PASS;
467*35238bceSAndroid Build Coastguard Worker 
468*35238bceSAndroid Build Coastguard Worker         for (size_t orig = 0; orig < DE_LENGTH_OF_ARRAY(origins); orig++)
469*35238bceSAndroid Build Coastguard Worker         {
470*35238bceSAndroid Build Coastguard Worker             //Clear the default framebuffer to red(1, 0, 0).
471*35238bceSAndroid Build Coastguard Worker             gl.clearColor(1.0, 0.0, 0.0, 1.0);
472*35238bceSAndroid Build Coastguard Worker             gl.clear(GL_COLOR_BUFFER_BIT);
473*35238bceSAndroid Build Coastguard Worker 
474*35238bceSAndroid Build Coastguard Worker             //Set ClipControl(UPPER_LEFT, NEGATIVE_ONE_TO_ONE)
475*35238bceSAndroid Build Coastguard Worker             cc.clipControl(origins[orig], GL_NEGATIVE_ONE_TO_ONE);
476*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "ClipControl()");
477*35238bceSAndroid Build Coastguard Worker 
478*35238bceSAndroid Build Coastguard Worker             //test method modification: use GL_TRIANGLE_STRIP, not FAN.
479*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
480*35238bceSAndroid Build Coastguard Worker 
481*35238bceSAndroid Build Coastguard Worker             //Read back the default framebuffer with ReadPixels
482*35238bceSAndroid Build Coastguard Worker             //Verify the green pixels at the top and red at the bottom.
483*35238bceSAndroid Build Coastguard Worker             qpTestResult loopResult = ValidateFramebuffer(m_context, origins[orig]);
484*35238bceSAndroid Build Coastguard Worker             if (loopResult != QP_TEST_RESULT_PASS)
485*35238bceSAndroid Build Coastguard Worker             {
486*35238bceSAndroid Build Coastguard Worker                 result = loopResult;
487*35238bceSAndroid Build Coastguard Worker             }
488*35238bceSAndroid Build Coastguard Worker         }
489*35238bceSAndroid Build Coastguard Worker 
490*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(result, qpGetTestResultName(result));
491*35238bceSAndroid Build Coastguard Worker 
492*35238bceSAndroid Build Coastguard Worker         return STOP;
493*35238bceSAndroid Build Coastguard Worker     }
494*35238bceSAndroid Build Coastguard Worker 
vsh()495*35238bceSAndroid Build Coastguard Worker     const char *vsh()
496*35238bceSAndroid Build Coastguard Worker     {
497*35238bceSAndroid Build Coastguard Worker         return "attribute highp vec2 Position;"
498*35238bceSAndroid Build Coastguard Worker                "\n"
499*35238bceSAndroid Build Coastguard Worker                "void main() {"
500*35238bceSAndroid Build Coastguard Worker                "\n"
501*35238bceSAndroid Build Coastguard Worker                "    gl_Position = vec4(Position, 0.0, 1.0);"
502*35238bceSAndroid Build Coastguard Worker                "\n"
503*35238bceSAndroid Build Coastguard Worker                "}";
504*35238bceSAndroid Build Coastguard Worker     }
505*35238bceSAndroid Build Coastguard Worker 
ValidateFramebuffer(Context & context,glw::GLenum origin)506*35238bceSAndroid Build Coastguard Worker     qpTestResult ValidateFramebuffer(Context &context, glw::GLenum origin)
507*35238bceSAndroid Build Coastguard Worker     {
508*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = context.getRenderContext().getRenderTarget();
509*35238bceSAndroid Build Coastguard Worker         glw::GLsizei viewportW                = renderTarget.getWidth();
510*35238bceSAndroid Build Coastguard Worker         glw::GLsizei viewportH                = renderTarget.getHeight();
511*35238bceSAndroid Build Coastguard Worker         tcu::Surface renderedFrame(viewportW, viewportH);
512*35238bceSAndroid Build Coastguard Worker         tcu::Surface referenceFrame(viewportW, viewportH);
513*35238bceSAndroid Build Coastguard Worker 
514*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log = context.getTestContext().getLog();
515*35238bceSAndroid Build Coastguard Worker 
516*35238bceSAndroid Build Coastguard Worker         for (int y = 0; y < renderedFrame.getHeight(); y++)
517*35238bceSAndroid Build Coastguard Worker         {
518*35238bceSAndroid Build Coastguard Worker             float yCoord = (float)(y) / (float)renderedFrame.getHeight();
519*35238bceSAndroid Build Coastguard Worker 
520*35238bceSAndroid Build Coastguard Worker             for (int x = 0; x < renderedFrame.getWidth(); x++)
521*35238bceSAndroid Build Coastguard Worker             {
522*35238bceSAndroid Build Coastguard Worker 
523*35238bceSAndroid Build Coastguard Worker                 float xCoord = (float)(x) / (float)renderedFrame.getWidth();
524*35238bceSAndroid Build Coastguard Worker 
525*35238bceSAndroid Build Coastguard Worker                 bool greenQuadrant;
526*35238bceSAndroid Build Coastguard Worker 
527*35238bceSAndroid Build Coastguard Worker                 if (origin == GL_UPPER_LEFT)
528*35238bceSAndroid Build Coastguard Worker                 {
529*35238bceSAndroid Build Coastguard Worker                     greenQuadrant = (yCoord > 0.5 && xCoord <= 0.5);
530*35238bceSAndroid Build Coastguard Worker                 }
531*35238bceSAndroid Build Coastguard Worker                 else
532*35238bceSAndroid Build Coastguard Worker                 {
533*35238bceSAndroid Build Coastguard Worker                     greenQuadrant = (yCoord <= 0.5 && xCoord <= 0.5);
534*35238bceSAndroid Build Coastguard Worker                 }
535*35238bceSAndroid Build Coastguard Worker 
536*35238bceSAndroid Build Coastguard Worker                 if (greenQuadrant)
537*35238bceSAndroid Build Coastguard Worker                 {
538*35238bceSAndroid Build Coastguard Worker                     referenceFrame.setPixel(x, y, tcu::RGBA::green());
539*35238bceSAndroid Build Coastguard Worker                 }
540*35238bceSAndroid Build Coastguard Worker                 else
541*35238bceSAndroid Build Coastguard Worker                 {
542*35238bceSAndroid Build Coastguard Worker                     referenceFrame.setPixel(x, y, tcu::RGBA::red());
543*35238bceSAndroid Build Coastguard Worker                 }
544*35238bceSAndroid Build Coastguard Worker             }
545*35238bceSAndroid Build Coastguard Worker         }
546*35238bceSAndroid Build Coastguard Worker 
547*35238bceSAndroid Build Coastguard Worker         glu::readPixels(context.getRenderContext(), 0, 0, renderedFrame.getAccess());
548*35238bceSAndroid Build Coastguard Worker 
549*35238bceSAndroid Build Coastguard Worker         if (tcu::fuzzyCompare(log, "Result", "Image comparison result", referenceFrame, renderedFrame, 0.05f,
550*35238bceSAndroid Build Coastguard Worker                               tcu::COMPARE_LOG_RESULT))
551*35238bceSAndroid Build Coastguard Worker         {
552*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_PASS;
553*35238bceSAndroid Build Coastguard Worker         }
554*35238bceSAndroid Build Coastguard Worker         else
555*35238bceSAndroid Build Coastguard Worker         {
556*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_FAIL;
557*35238bceSAndroid Build Coastguard Worker         }
558*35238bceSAndroid Build Coastguard Worker     }
559*35238bceSAndroid Build Coastguard Worker 
560*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vao, m_vbo;
561*35238bceSAndroid Build Coastguard Worker };
562*35238bceSAndroid Build Coastguard Worker 
563*35238bceSAndroid Build Coastguard Worker /*
564*35238bceSAndroid Build Coastguard Worker  Clip Control Origin With Face Culling Test
565*35238bceSAndroid Build Coastguard Worker 
566*35238bceSAndroid Build Coastguard Worker  * Face culling should be tested with both <origin> settings.
567*35238bceSAndroid Build Coastguard Worker  The reason for that is, when doing Y-inversion, implementation
568*35238bceSAndroid Build Coastguard Worker  should not flip the calculated area sign for the triangle.
569*35238bceSAndroid Build Coastguard Worker  In other words, culling of CCW and CW triangles should
570*35238bceSAndroid Build Coastguard Worker  be orthogonal to used <origin> mode. Both triangle windings
571*35238bceSAndroid Build Coastguard Worker  and both <origin> modes should be tested. Here is the basic
572*35238bceSAndroid Build Coastguard Worker  outline of the test:
573*35238bceSAndroid Build Coastguard Worker 
574*35238bceSAndroid Build Coastguard Worker  - Clear the framebuffer to red (1,0,0).
575*35238bceSAndroid Build Coastguard Worker  - Enable GL_CULL_FACE, leave default front face & cull face (CCW, BACK)
576*35238bceSAndroid Build Coastguard Worker  - Set ClipControl(UPPER_LEFT, NEGATIVE_ONE_TO_ONE)
577*35238bceSAndroid Build Coastguard Worker  - Render a counter-clockwise triangles covering
578*35238bceSAndroid Build Coastguard Worker  (-1.0, -1.0) to (0.0, 1.0) and write a pixel value of green (0,1,0).
579*35238bceSAndroid Build Coastguard Worker  - Render a clockwise triangles covering
580*35238bceSAndroid Build Coastguard Worker  (0.0, -1.0) to (1.0, 1.0) and write a pixel value of green (0,1,0).
581*35238bceSAndroid Build Coastguard Worker  - Read back the framebuffer with ReadPixels
582*35238bceSAndroid Build Coastguard Worker  - Verify the green pixels at the left and red at the right.
583*35238bceSAndroid Build Coastguard Worker 
584*35238bceSAndroid Build Coastguard Worker  Repeat above test for ClipControl(LOWER_LEFT, NEGATIVE_ONE_TO_ONE)
585*35238bceSAndroid Build Coastguard Worker  */
586*35238bceSAndroid Build Coastguard Worker class ClipControlFaceCulling : public ClipControlRenderBaseTest
587*35238bceSAndroid Build Coastguard Worker {
588*35238bceSAndroid Build Coastguard Worker public:
ClipControlFaceCulling(Context & context,const char * name)589*35238bceSAndroid Build Coastguard Worker     ClipControlFaceCulling(Context &context, const char *name)
590*35238bceSAndroid Build Coastguard Worker         : ClipControlRenderBaseTest(context, name, "Face culling test, both origins")
591*35238bceSAndroid Build Coastguard Worker         , m_vao(0)
592*35238bceSAndroid Build Coastguard Worker         , m_vbo(0)
593*35238bceSAndroid Build Coastguard Worker     {
594*35238bceSAndroid Build Coastguard Worker     }
595*35238bceSAndroid Build Coastguard Worker 
deinit()596*35238bceSAndroid Build Coastguard Worker     void deinit()
597*35238bceSAndroid Build Coastguard Worker     {
598*35238bceSAndroid Build Coastguard Worker         ClipControlRenderBaseTest::deinit();
599*35238bceSAndroid Build Coastguard Worker 
600*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
601*35238bceSAndroid Build Coastguard Worker 
602*35238bceSAndroid Build Coastguard Worker         if (ClipControlApi::Supported(m_context))
603*35238bceSAndroid Build Coastguard Worker         {
604*35238bceSAndroid Build Coastguard Worker             ClipControlApi cc(m_context);
605*35238bceSAndroid Build Coastguard Worker             cc.clipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
606*35238bceSAndroid Build Coastguard Worker         }
607*35238bceSAndroid Build Coastguard Worker 
608*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_CULL_FACE);
609*35238bceSAndroid Build Coastguard Worker 
610*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.0, 0.0, 0.0, 0.0);
611*35238bceSAndroid Build Coastguard Worker 
612*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_DEPTH_TEST);
613*35238bceSAndroid Build Coastguard Worker         gl.depthFunc(GL_LESS);
614*35238bceSAndroid Build Coastguard Worker 
615*35238bceSAndroid Build Coastguard Worker         if (m_vao)
616*35238bceSAndroid Build Coastguard Worker         {
617*35238bceSAndroid Build Coastguard Worker             gl.deleteVertexArrays(1, &m_vao);
618*35238bceSAndroid Build Coastguard Worker         }
619*35238bceSAndroid Build Coastguard Worker         if (m_vbo)
620*35238bceSAndroid Build Coastguard Worker         {
621*35238bceSAndroid Build Coastguard Worker             gl.deleteBuffers(1, &m_vbo);
622*35238bceSAndroid Build Coastguard Worker         }
623*35238bceSAndroid Build Coastguard Worker     }
624*35238bceSAndroid Build Coastguard Worker 
iterate()625*35238bceSAndroid Build Coastguard Worker     IterateResult iterate()
626*35238bceSAndroid Build Coastguard Worker     {
627*35238bceSAndroid Build Coastguard Worker 
628*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log        = m_testCtx.getLog();
629*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
630*35238bceSAndroid Build Coastguard Worker         ClipControlApi cc(m_context);
631*35238bceSAndroid Build Coastguard Worker 
632*35238bceSAndroid Build Coastguard Worker         //Enable GL_CULL_FACE, leave default front face & cull face(CCW, BACK)
633*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_CULL_FACE);
634*35238bceSAndroid Build Coastguard Worker 
635*35238bceSAndroid Build Coastguard Worker         //Render a counter-clockwise triangles covering
636*35238bceSAndroid Build Coastguard Worker         //(-1.0, -1.0) to(0.0, 1.0) and write a pixel value of green(0, 1, 0).
637*35238bceSAndroid Build Coastguard Worker         //Render a clockwise triangles covering
638*35238bceSAndroid Build Coastguard Worker         //(0.0, -1.0) to(1.0, 1.0) and write a pixel value of green(0, 1, 0).
639*35238bceSAndroid Build Coastguard Worker         de::SharedPtr<glu::ShaderProgram> program(
640*35238bceSAndroid Build Coastguard Worker             new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vsh(), fsh())));
641*35238bceSAndroid Build Coastguard Worker 
642*35238bceSAndroid Build Coastguard Worker         log << (*program);
643*35238bceSAndroid Build Coastguard Worker         if (!program->isOk())
644*35238bceSAndroid Build Coastguard Worker         {
645*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Program compilation failed");
646*35238bceSAndroid Build Coastguard Worker         }
647*35238bceSAndroid Build Coastguard Worker 
648*35238bceSAndroid Build Coastguard Worker         gl.genVertexArrays(1, &m_vao);
649*35238bceSAndroid Build Coastguard Worker         gl.bindVertexArray(m_vao);
650*35238bceSAndroid Build Coastguard Worker 
651*35238bceSAndroid Build Coastguard Worker         gl.genBuffers(1, &m_vbo);
652*35238bceSAndroid Build Coastguard Worker 
653*35238bceSAndroid Build Coastguard Worker         const float vertex_data0[] = {
654*35238bceSAndroid Build Coastguard Worker             //CCW
655*35238bceSAndroid Build Coastguard Worker             -1.0,
656*35238bceSAndroid Build Coastguard Worker             -1.0,
657*35238bceSAndroid Build Coastguard Worker             0.0,
658*35238bceSAndroid Build Coastguard Worker             -1.0,
659*35238bceSAndroid Build Coastguard Worker             -1.0,
660*35238bceSAndroid Build Coastguard Worker             1.0,
661*35238bceSAndroid Build Coastguard Worker             0.0,
662*35238bceSAndroid Build Coastguard Worker             -1.0,
663*35238bceSAndroid Build Coastguard Worker             0.0,
664*35238bceSAndroid Build Coastguard Worker             1.0,
665*35238bceSAndroid Build Coastguard Worker             -1.0,
666*35238bceSAndroid Build Coastguard Worker             1.0,
667*35238bceSAndroid Build Coastguard Worker             //CW
668*35238bceSAndroid Build Coastguard Worker             0.0,
669*35238bceSAndroid Build Coastguard Worker             -1.0,
670*35238bceSAndroid Build Coastguard Worker             0.0,
671*35238bceSAndroid Build Coastguard Worker             1.0,
672*35238bceSAndroid Build Coastguard Worker             1.0,
673*35238bceSAndroid Build Coastguard Worker             -1.0,
674*35238bceSAndroid Build Coastguard Worker             1.0,
675*35238bceSAndroid Build Coastguard Worker             -1.0,
676*35238bceSAndroid Build Coastguard Worker             0.0,
677*35238bceSAndroid Build Coastguard Worker             1.0,
678*35238bceSAndroid Build Coastguard Worker             1.0,
679*35238bceSAndroid Build Coastguard Worker             1.0,
680*35238bceSAndroid Build Coastguard Worker         };
681*35238bceSAndroid Build Coastguard Worker 
682*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo);
683*35238bceSAndroid Build Coastguard Worker         gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertex_data0), vertex_data0, GL_STATIC_DRAW);
684*35238bceSAndroid Build Coastguard Worker 
685*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
686*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(0);
687*35238bceSAndroid Build Coastguard Worker 
688*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program->getProgram());
689*35238bceSAndroid Build Coastguard Worker 
690*35238bceSAndroid Build Coastguard Worker         glw::GLenum origins[] = {GL_UPPER_LEFT, GL_LOWER_LEFT};
691*35238bceSAndroid Build Coastguard Worker 
692*35238bceSAndroid Build Coastguard Worker         qpTestResult result = QP_TEST_RESULT_PASS;
693*35238bceSAndroid Build Coastguard Worker 
694*35238bceSAndroid Build Coastguard Worker         for (size_t orig = 0; orig < DE_LENGTH_OF_ARRAY(origins); orig++)
695*35238bceSAndroid Build Coastguard Worker         {
696*35238bceSAndroid Build Coastguard Worker             //Clear the framebuffer to red (1,0,0).
697*35238bceSAndroid Build Coastguard Worker             gl.clearColor(1.0, 0.0, 0.0, 1.0);
698*35238bceSAndroid Build Coastguard Worker             gl.clear(GL_COLOR_BUFFER_BIT);
699*35238bceSAndroid Build Coastguard Worker 
700*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 12);
701*35238bceSAndroid Build Coastguard Worker 
702*35238bceSAndroid Build Coastguard Worker             //Set ClipControl(<origin>, NEGATIVE_ONE_TO_ONE)
703*35238bceSAndroid Build Coastguard Worker             cc.clipControl(origins[orig], GL_NEGATIVE_ONE_TO_ONE);
704*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "ClipControl()");
705*35238bceSAndroid Build Coastguard Worker 
706*35238bceSAndroid Build Coastguard Worker             //Read back the framebuffer with ReadPixels
707*35238bceSAndroid Build Coastguard Worker             //Verify the green pixels at the left and red at the right.
708*35238bceSAndroid Build Coastguard Worker             qpTestResult loopResult = ValidateFramebuffer(m_context);
709*35238bceSAndroid Build Coastguard Worker             if (loopResult != QP_TEST_RESULT_PASS)
710*35238bceSAndroid Build Coastguard Worker             {
711*35238bceSAndroid Build Coastguard Worker                 result = loopResult;
712*35238bceSAndroid Build Coastguard Worker             }
713*35238bceSAndroid Build Coastguard Worker         }
714*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(result, qpGetTestResultName(result));
715*35238bceSAndroid Build Coastguard Worker 
716*35238bceSAndroid Build Coastguard Worker         return STOP;
717*35238bceSAndroid Build Coastguard Worker     }
718*35238bceSAndroid Build Coastguard Worker 
vsh()719*35238bceSAndroid Build Coastguard Worker     const char *vsh()
720*35238bceSAndroid Build Coastguard Worker     {
721*35238bceSAndroid Build Coastguard Worker         return "attribute  highp vec3 Position;"
722*35238bceSAndroid Build Coastguard Worker                "\n"
723*35238bceSAndroid Build Coastguard Worker                "void main() {"
724*35238bceSAndroid Build Coastguard Worker                "\n"
725*35238bceSAndroid Build Coastguard Worker                "    gl_Position = vec4(Position, 1.0);"
726*35238bceSAndroid Build Coastguard Worker                "\n"
727*35238bceSAndroid Build Coastguard Worker                "}";
728*35238bceSAndroid Build Coastguard Worker     }
729*35238bceSAndroid Build Coastguard Worker 
ValidateFramebuffer(Context & context)730*35238bceSAndroid Build Coastguard Worker     qpTestResult ValidateFramebuffer(Context &context)
731*35238bceSAndroid Build Coastguard Worker     {
732*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = context.getRenderContext().getRenderTarget();
733*35238bceSAndroid Build Coastguard Worker         glw::GLsizei viewportW                = renderTarget.getWidth();
734*35238bceSAndroid Build Coastguard Worker         glw::GLsizei viewportH                = renderTarget.getHeight();
735*35238bceSAndroid Build Coastguard Worker         tcu::Surface renderedColorFrame(viewportW, viewportH);
736*35238bceSAndroid Build Coastguard Worker         tcu::Surface referenceColorFrame(viewportW, viewportH);
737*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log = context.getTestContext().getLog();
738*35238bceSAndroid Build Coastguard Worker 
739*35238bceSAndroid Build Coastguard Worker         for (int y = 0; y < renderedColorFrame.getHeight(); y++)
740*35238bceSAndroid Build Coastguard Worker         {
741*35238bceSAndroid Build Coastguard Worker             for (int x = 0; x < renderedColorFrame.getWidth(); x++)
742*35238bceSAndroid Build Coastguard Worker             {
743*35238bceSAndroid Build Coastguard Worker                 float xCoord = (float)(x) / (float)renderedColorFrame.getWidth();
744*35238bceSAndroid Build Coastguard Worker 
745*35238bceSAndroid Build Coastguard Worker                 if (xCoord < 0.5f)
746*35238bceSAndroid Build Coastguard Worker                 {
747*35238bceSAndroid Build Coastguard Worker                     referenceColorFrame.setPixel(x, y, tcu::RGBA::green());
748*35238bceSAndroid Build Coastguard Worker                 }
749*35238bceSAndroid Build Coastguard Worker                 else
750*35238bceSAndroid Build Coastguard Worker                 {
751*35238bceSAndroid Build Coastguard Worker                     referenceColorFrame.setPixel(x, y, tcu::RGBA::red());
752*35238bceSAndroid Build Coastguard Worker                 }
753*35238bceSAndroid Build Coastguard Worker             }
754*35238bceSAndroid Build Coastguard Worker         }
755*35238bceSAndroid Build Coastguard Worker 
756*35238bceSAndroid Build Coastguard Worker         glu::readPixels(context.getRenderContext(), 0, 0, renderedColorFrame.getAccess());
757*35238bceSAndroid Build Coastguard Worker         if (!tcu::fuzzyCompare(log, "Result", "Color image comparison result", referenceColorFrame, renderedColorFrame,
758*35238bceSAndroid Build Coastguard Worker                                0.05f, tcu::COMPARE_LOG_RESULT))
759*35238bceSAndroid Build Coastguard Worker         {
760*35238bceSAndroid Build Coastguard Worker 
761*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_FAIL;
762*35238bceSAndroid Build Coastguard Worker         }
763*35238bceSAndroid Build Coastguard Worker         return QP_TEST_RESULT_PASS;
764*35238bceSAndroid Build Coastguard Worker     }
765*35238bceSAndroid Build Coastguard Worker 
766*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vao, m_vbo;
767*35238bceSAndroid Build Coastguard Worker };
768*35238bceSAndroid Build Coastguard Worker 
769*35238bceSAndroid Build Coastguard Worker /*
770*35238bceSAndroid Build Coastguard Worker  Viewport Bounds Test
771*35238bceSAndroid Build Coastguard Worker 
772*35238bceSAndroid Build Coastguard Worker  * Viewport bounds should be tested, to ensure that rendering with flipped
773*35238bceSAndroid Build Coastguard Worker  origin affects only viewport area.
774*35238bceSAndroid Build Coastguard Worker 
775*35238bceSAndroid Build Coastguard Worker  This can be done by clearing the window to blue, making viewport
776*35238bceSAndroid Build Coastguard Worker  a non-symmetric-in-any-way subset of the window, than rendering
777*35238bceSAndroid Build Coastguard Worker  full-viewport multiple color quad. The (-1.0, -1.0)..(0.0, 0.0) quadrant
778*35238bceSAndroid Build Coastguard Worker  of a quad is red, the rest is green.
779*35238bceSAndroid Build Coastguard Worker  Whatever the origin is, the area outside of the viewport should stay blue.
780*35238bceSAndroid Build Coastguard Worker  If origin is LOWER_LEFT the "lower left" portion of the viewport is red,
781*35238bceSAndroid Build Coastguard Worker  if origin is UPPER_LEFT the "top left" portion of the viewport is red
782*35238bceSAndroid Build Coastguard Worker  (and in both cases the rest of viewport is green).
783*35238bceSAndroid Build Coastguard Worker 
784*35238bceSAndroid Build Coastguard Worker  Here is the basic outline of the test:
785*35238bceSAndroid Build Coastguard Worker 
786*35238bceSAndroid Build Coastguard Worker  - Clear the default framebuffer to blue (0,0,1).
787*35238bceSAndroid Build Coastguard Worker  - Set viewport to A = (x, y, w, h) = (1/8, 1/4, 1/2, 1/4)  in terms of proportional window size
788*35238bceSAndroid Build Coastguard Worker  - Set ClipControl(UPPER_LEFT, NEGATIVE_ONE_TO_ONE)
789*35238bceSAndroid Build Coastguard Worker  - Render a triangle strip covering (-1.0, -1.0) to (1.0, 1.0).
790*35238bceSAndroid Build Coastguard Worker  Write a pixel value of red (0,1,0) to (-1.0, -1.0)..(0.0, 0.0), other parts are green
791*35238bceSAndroid Build Coastguard Worker  - Reset viewport to defaults
792*35238bceSAndroid Build Coastguard Worker  - Read back the default framebuffer with ReadPixels
793*35238bceSAndroid Build Coastguard Worker  - Verify:
794*35238bceSAndroid Build Coastguard Worker  - regions outside A viewport are green
795*35238bceSAndroid Build Coastguard Worker  - Inside A viewport upper upper left portion is red, rest is green.
796*35238bceSAndroid Build Coastguard Worker 
797*35238bceSAndroid Build Coastguard Worker  Repeat the above test with LOWER_LEFT origin and lower left portion of A is red,
798*35238bceSAndroid Build Coastguard Worker  rest is green.
799*35238bceSAndroid Build Coastguard Worker  */
800*35238bceSAndroid Build Coastguard Worker class ClipControlViewportBounds : public ClipControlRenderBaseTest
801*35238bceSAndroid Build Coastguard Worker {
802*35238bceSAndroid Build Coastguard Worker public:
ClipControlViewportBounds(Context & context,const char * name)803*35238bceSAndroid Build Coastguard Worker     ClipControlViewportBounds(Context &context, const char *name)
804*35238bceSAndroid Build Coastguard Worker         : ClipControlRenderBaseTest(context, name, "Clip Control Origin Test")
805*35238bceSAndroid Build Coastguard Worker         , m_vao(0)
806*35238bceSAndroid Build Coastguard Worker         , m_vbo(0)
807*35238bceSAndroid Build Coastguard Worker     {
808*35238bceSAndroid Build Coastguard Worker     }
809*35238bceSAndroid Build Coastguard Worker 
deinit()810*35238bceSAndroid Build Coastguard Worker     void deinit() override
811*35238bceSAndroid Build Coastguard Worker     {
812*35238bceSAndroid Build Coastguard Worker         ClipControlRenderBaseTest::deinit();
813*35238bceSAndroid Build Coastguard Worker 
814*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = m_context.getRenderContext().getRenderTarget();
815*35238bceSAndroid Build Coastguard Worker         glw::GLsizei windowW                  = renderTarget.getWidth();
816*35238bceSAndroid Build Coastguard Worker         glw::GLsizei windowH                  = renderTarget.getHeight();
817*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl              = m_context.getRenderContext().getFunctions();
818*35238bceSAndroid Build Coastguard Worker 
819*35238bceSAndroid Build Coastguard Worker         if (ClipControlApi::Supported(m_context))
820*35238bceSAndroid Build Coastguard Worker         {
821*35238bceSAndroid Build Coastguard Worker             ClipControlApi cc(m_context);
822*35238bceSAndroid Build Coastguard Worker             cc.clipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
823*35238bceSAndroid Build Coastguard Worker         }
824*35238bceSAndroid Build Coastguard Worker 
825*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.0, 0.0, 0.0, 0.0);
826*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, windowW, windowH);
827*35238bceSAndroid Build Coastguard Worker 
828*35238bceSAndroid Build Coastguard Worker         if (m_vao)
829*35238bceSAndroid Build Coastguard Worker         {
830*35238bceSAndroid Build Coastguard Worker             gl.deleteVertexArrays(1, &m_vao);
831*35238bceSAndroid Build Coastguard Worker         }
832*35238bceSAndroid Build Coastguard Worker         if (m_vbo)
833*35238bceSAndroid Build Coastguard Worker         {
834*35238bceSAndroid Build Coastguard Worker             gl.deleteBuffers(1, &m_vbo);
835*35238bceSAndroid Build Coastguard Worker         }
836*35238bceSAndroid Build Coastguard Worker     }
837*35238bceSAndroid Build Coastguard Worker 
iterate()838*35238bceSAndroid Build Coastguard Worker     IterateResult iterate() override
839*35238bceSAndroid Build Coastguard Worker     {
840*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log                     = m_testCtx.getLog();
841*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl              = m_context.getRenderContext().getFunctions();
842*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = m_context.getRenderContext().getRenderTarget();
843*35238bceSAndroid Build Coastguard Worker         glw::GLsizei windowW                  = renderTarget.getWidth();
844*35238bceSAndroid Build Coastguard Worker         glw::GLsizei windowH                  = renderTarget.getHeight();
845*35238bceSAndroid Build Coastguard Worker         ClipControlApi cc(m_context);
846*35238bceSAndroid Build Coastguard Worker 
847*35238bceSAndroid Build Coastguard Worker         //Clear the default framebuffer to blue (0,0,1).
848*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.0, 0.0, 1.0, 1.0);
849*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
850*35238bceSAndroid Build Coastguard Worker 
851*35238bceSAndroid Build Coastguard Worker         de::SharedPtr<glu::ShaderProgram> program(
852*35238bceSAndroid Build Coastguard Worker             new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vsh(), fsh())));
853*35238bceSAndroid Build Coastguard Worker 
854*35238bceSAndroid Build Coastguard Worker         log << (*program);
855*35238bceSAndroid Build Coastguard Worker         if (!program->isOk())
856*35238bceSAndroid Build Coastguard Worker         {
857*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Program compilation failed");
858*35238bceSAndroid Build Coastguard Worker         }
859*35238bceSAndroid Build Coastguard Worker         gl.genVertexArrays(1, &m_vao);
860*35238bceSAndroid Build Coastguard Worker         gl.bindVertexArray(m_vao);
861*35238bceSAndroid Build Coastguard Worker 
862*35238bceSAndroid Build Coastguard Worker         gl.genBuffers(1, &m_vbo);
863*35238bceSAndroid Build Coastguard Worker 
864*35238bceSAndroid Build Coastguard Worker         const float vertex_data0[] = {-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0};
865*35238bceSAndroid Build Coastguard Worker 
866*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo);
867*35238bceSAndroid Build Coastguard Worker         gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertex_data0), vertex_data0, GL_STATIC_DRAW);
868*35238bceSAndroid Build Coastguard Worker 
869*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
870*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(0);
871*35238bceSAndroid Build Coastguard Worker 
872*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program->getProgram());
873*35238bceSAndroid Build Coastguard Worker 
874*35238bceSAndroid Build Coastguard Worker         glw::GLenum origins[] = {GL_UPPER_LEFT, GL_LOWER_LEFT};
875*35238bceSAndroid Build Coastguard Worker 
876*35238bceSAndroid Build Coastguard Worker         qpTestResult result = QP_TEST_RESULT_PASS;
877*35238bceSAndroid Build Coastguard Worker 
878*35238bceSAndroid Build Coastguard Worker         for (size_t orig = 0; orig < DE_LENGTH_OF_ARRAY(origins); orig++)
879*35238bceSAndroid Build Coastguard Worker         {
880*35238bceSAndroid Build Coastguard Worker             //Set viewport to A = (x, y, w, h) = (1/8, 1/4, 1/2, 1/4) in terms of proportional window size
881*35238bceSAndroid Build Coastguard Worker             gl.viewport(static_cast<glw::GLint>((0.125f * static_cast<float>(windowW)) + 0.5f),
882*35238bceSAndroid Build Coastguard Worker                         static_cast<glw::GLint>((0.25f * static_cast<float>(windowH)) + 0.5f),
883*35238bceSAndroid Build Coastguard Worker                         static_cast<glw::GLsizei>((0.5f * static_cast<float>(windowW)) + 0.5f),
884*35238bceSAndroid Build Coastguard Worker                         static_cast<glw::GLsizei>((0.25f * static_cast<float>(windowH)) + 0.5f));
885*35238bceSAndroid Build Coastguard Worker 
886*35238bceSAndroid Build Coastguard Worker             //Set ClipControl(<origin>, NEGATIVE_ONE_TO_ONE)
887*35238bceSAndroid Build Coastguard Worker             cc.clipControl(origins[orig], GL_NEGATIVE_ONE_TO_ONE);
888*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "ClipControl()");
889*35238bceSAndroid Build Coastguard Worker 
890*35238bceSAndroid Build Coastguard Worker             //Render a triangle strip covering (-1.0, -1.0) to (1.0, 1.0).
891*35238bceSAndroid Build Coastguard Worker             //Write a pixel value of red (0,1,0) to (-1.0, -1.0)..(0.0, 0.0), other parts are green
892*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
893*35238bceSAndroid Build Coastguard Worker 
894*35238bceSAndroid Build Coastguard Worker             gl.viewport(0, 0, windowW, windowH);
895*35238bceSAndroid Build Coastguard Worker 
896*35238bceSAndroid Build Coastguard Worker             //Read back the default framebuffer with ReadPixels
897*35238bceSAndroid Build Coastguard Worker             //Verify the green pixels at the top and red at the bottom.
898*35238bceSAndroid Build Coastguard Worker             qpTestResult loopResult = ValidateFramebuffer(m_context, origins[orig]);
899*35238bceSAndroid Build Coastguard Worker             if (loopResult != QP_TEST_RESULT_PASS)
900*35238bceSAndroid Build Coastguard Worker             {
901*35238bceSAndroid Build Coastguard Worker                 result = loopResult;
902*35238bceSAndroid Build Coastguard Worker             }
903*35238bceSAndroid Build Coastguard Worker         }
904*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(result, qpGetTestResultName(result));
905*35238bceSAndroid Build Coastguard Worker         return STOP;
906*35238bceSAndroid Build Coastguard Worker     }
907*35238bceSAndroid Build Coastguard Worker 
vsh()908*35238bceSAndroid Build Coastguard Worker     const char *vsh()
909*35238bceSAndroid Build Coastguard Worker     {
910*35238bceSAndroid Build Coastguard Worker         return "attribute highp vec2 Position;"
911*35238bceSAndroid Build Coastguard Worker                "\n"
912*35238bceSAndroid Build Coastguard Worker                "varying highp vec2 PositionOut;"
913*35238bceSAndroid Build Coastguard Worker                "\n"
914*35238bceSAndroid Build Coastguard Worker                "void main() {"
915*35238bceSAndroid Build Coastguard Worker                "\n"
916*35238bceSAndroid Build Coastguard Worker                "    gl_Position = vec4(Position, 0.0, 1.0);"
917*35238bceSAndroid Build Coastguard Worker                "\n"
918*35238bceSAndroid Build Coastguard Worker                "    PositionOut = Position;"
919*35238bceSAndroid Build Coastguard Worker                "\n"
920*35238bceSAndroid Build Coastguard Worker                "}";
921*35238bceSAndroid Build Coastguard Worker     }
922*35238bceSAndroid Build Coastguard Worker 
fsh()923*35238bceSAndroid Build Coastguard Worker     const char *fsh()
924*35238bceSAndroid Build Coastguard Worker     {
925*35238bceSAndroid Build Coastguard Worker         return "varying highp vec2 PositionOut;"
926*35238bceSAndroid Build Coastguard Worker                "\n"
927*35238bceSAndroid Build Coastguard Worker                "void main() {"
928*35238bceSAndroid Build Coastguard Worker                "\n"
929*35238bceSAndroid Build Coastguard Worker                "    if (PositionOut.x < 0.0 && PositionOut.y < 0.0)"
930*35238bceSAndroid Build Coastguard Worker                "\n"
931*35238bceSAndroid Build Coastguard Worker                "       gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);"
932*35238bceSAndroid Build Coastguard Worker                "\n"
933*35238bceSAndroid Build Coastguard Worker                "    else"
934*35238bceSAndroid Build Coastguard Worker                "\n"
935*35238bceSAndroid Build Coastguard Worker                "       gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);"
936*35238bceSAndroid Build Coastguard Worker                "\n"
937*35238bceSAndroid Build Coastguard Worker                "}";
938*35238bceSAndroid Build Coastguard Worker     }
939*35238bceSAndroid Build Coastguard Worker 
ValidateFramebuffer(Context & context,glw::GLenum origin)940*35238bceSAndroid Build Coastguard Worker     qpTestResult ValidateFramebuffer(Context &context, glw::GLenum origin)
941*35238bceSAndroid Build Coastguard Worker     {
942*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = context.getRenderContext().getRenderTarget();
943*35238bceSAndroid Build Coastguard Worker         glw::GLsizei windowW                  = renderTarget.getWidth();
944*35238bceSAndroid Build Coastguard Worker         glw::GLsizei windowH                  = renderTarget.getHeight();
945*35238bceSAndroid Build Coastguard Worker         tcu::Surface renderedFrame(windowW, windowH);
946*35238bceSAndroid Build Coastguard Worker         tcu::Surface referenceFrame(windowW, windowH);
947*35238bceSAndroid Build Coastguard Worker 
948*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log = context.getTestContext().getLog();
949*35238bceSAndroid Build Coastguard Worker 
950*35238bceSAndroid Build Coastguard Worker         for (int y = 0; y < renderedFrame.getHeight(); y++)
951*35238bceSAndroid Build Coastguard Worker         {
952*35238bceSAndroid Build Coastguard Worker             float yCoord   = static_cast<float>(y) / static_cast<float>(renderedFrame.getHeight());
953*35238bceSAndroid Build Coastguard Worker             float yVPCoord = (yCoord - 0.25f) * 4.0f;
954*35238bceSAndroid Build Coastguard Worker 
955*35238bceSAndroid Build Coastguard Worker             for (int x = 0; x < renderedFrame.getWidth(); x++)
956*35238bceSAndroid Build Coastguard Worker             {
957*35238bceSAndroid Build Coastguard Worker                 float xCoord   = static_cast<float>(x) / static_cast<float>(renderedFrame.getWidth());
958*35238bceSAndroid Build Coastguard Worker                 float xVPCoord = (xCoord - 0.125f) * 2.0f;
959*35238bceSAndroid Build Coastguard Worker 
960*35238bceSAndroid Build Coastguard Worker                 if (xVPCoord > 0.0f && xVPCoord < 1.0f && yVPCoord > 0.0f && yVPCoord < 1.0f)
961*35238bceSAndroid Build Coastguard Worker                 {
962*35238bceSAndroid Build Coastguard Worker 
963*35238bceSAndroid Build Coastguard Worker                     bool greenQuadrant;
964*35238bceSAndroid Build Coastguard Worker 
965*35238bceSAndroid Build Coastguard Worker                     //inside viewport
966*35238bceSAndroid Build Coastguard Worker                     if (origin == GL_UPPER_LEFT)
967*35238bceSAndroid Build Coastguard Worker                     {
968*35238bceSAndroid Build Coastguard Worker                         greenQuadrant = (yVPCoord > 0.5f && xVPCoord <= 0.5f);
969*35238bceSAndroid Build Coastguard Worker                     }
970*35238bceSAndroid Build Coastguard Worker                     else
971*35238bceSAndroid Build Coastguard Worker                     {
972*35238bceSAndroid Build Coastguard Worker                         greenQuadrant = (yVPCoord <= 0.5f && xVPCoord <= 0.5f);
973*35238bceSAndroid Build Coastguard Worker                     }
974*35238bceSAndroid Build Coastguard Worker 
975*35238bceSAndroid Build Coastguard Worker                     if (greenQuadrant)
976*35238bceSAndroid Build Coastguard Worker                     {
977*35238bceSAndroid Build Coastguard Worker                         referenceFrame.setPixel(x, y, tcu::RGBA::green());
978*35238bceSAndroid Build Coastguard Worker                     }
979*35238bceSAndroid Build Coastguard Worker                     else
980*35238bceSAndroid Build Coastguard Worker                     {
981*35238bceSAndroid Build Coastguard Worker                         referenceFrame.setPixel(x, y, tcu::RGBA::red());
982*35238bceSAndroid Build Coastguard Worker                     }
983*35238bceSAndroid Build Coastguard Worker                 }
984*35238bceSAndroid Build Coastguard Worker                 else
985*35238bceSAndroid Build Coastguard Worker                 {
986*35238bceSAndroid Build Coastguard Worker                     //outside viewport
987*35238bceSAndroid Build Coastguard Worker                     referenceFrame.setPixel(x, y, tcu::RGBA::blue());
988*35238bceSAndroid Build Coastguard Worker                 }
989*35238bceSAndroid Build Coastguard Worker             }
990*35238bceSAndroid Build Coastguard Worker         }
991*35238bceSAndroid Build Coastguard Worker 
992*35238bceSAndroid Build Coastguard Worker         glu::readPixels(context.getRenderContext(), 0, 0, renderedFrame.getAccess());
993*35238bceSAndroid Build Coastguard Worker 
994*35238bceSAndroid Build Coastguard Worker         if (tcu::fuzzyCompare(log, "Result", "Image comparison result", referenceFrame, renderedFrame, 0.05f,
995*35238bceSAndroid Build Coastguard Worker                               tcu::COMPARE_LOG_RESULT))
996*35238bceSAndroid Build Coastguard Worker         {
997*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_PASS;
998*35238bceSAndroid Build Coastguard Worker         }
999*35238bceSAndroid Build Coastguard Worker         else
1000*35238bceSAndroid Build Coastguard Worker         {
1001*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_FAIL;
1002*35238bceSAndroid Build Coastguard Worker         }
1003*35238bceSAndroid Build Coastguard Worker     }
1004*35238bceSAndroid Build Coastguard Worker 
1005*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vao, m_vbo;
1006*35238bceSAndroid Build Coastguard Worker };
1007*35238bceSAndroid Build Coastguard Worker 
1008*35238bceSAndroid Build Coastguard Worker /*   Depth Mode Test
1009*35238bceSAndroid Build Coastguard Worker 
1010*35238bceSAndroid Build Coastguard Worker  * Basic <depth> behavior can be tested by writing specific z_c (z
1011*35238bceSAndroid Build Coastguard Worker  clip coordinates) and observing its clipping and transformation.
1012*35238bceSAndroid Build Coastguard Worker  Create and bind a framebuffer object with a floating-point depth
1013*35238bceSAndroid Build Coastguard Worker  buffer attachment. Make sure depth clamping is disabled. The best
1014*35238bceSAndroid Build Coastguard Worker  steps for verifying the correct depth mode:
1015*35238bceSAndroid Build Coastguard Worker 
1016*35238bceSAndroid Build Coastguard Worker  - Clear the depth buffer to 0.5.
1017*35238bceSAndroid Build Coastguard Worker  - Set ClipControl(LOWER_LEFT, ZERO_TO_ONE)
1018*35238bceSAndroid Build Coastguard Worker  - Enable(DEPTH_TEST) with DepthFunc(ALWAYS)
1019*35238bceSAndroid Build Coastguard Worker  - Render a triangle fan coverage (-1.0,-1.0,-1.0) to (1.0,1.0,1.0).
1020*35238bceSAndroid Build Coastguard Worker  - Read back the floating-point depth buffer with ReadPixels
1021*35238bceSAndroid Build Coastguard Worker  - Verify that the pixels with a Z clip coordinate less than 0.0 are
1022*35238bceSAndroid Build Coastguard Worker  clipped and those coordinates from 0.0 to 1.0 update the depth
1023*35238bceSAndroid Build Coastguard Worker  buffer with values 0.0 to 1.0.
1024*35238bceSAndroid Build Coastguard Worker  */
1025*35238bceSAndroid Build Coastguard Worker 
1026*35238bceSAndroid Build Coastguard Worker class ClipControlDepthModeTest : public ClipControlRenderBaseTest
1027*35238bceSAndroid Build Coastguard Worker {
1028*35238bceSAndroid Build Coastguard Worker public:
ClipControlDepthModeTest(Context & context,const char * name,const char * subname)1029*35238bceSAndroid Build Coastguard Worker     ClipControlDepthModeTest(Context &context, const char *name, const char *subname)
1030*35238bceSAndroid Build Coastguard Worker         : ClipControlRenderBaseTest(context, name, subname)
1031*35238bceSAndroid Build Coastguard Worker     {
1032*35238bceSAndroid Build Coastguard Worker     }
1033*35238bceSAndroid Build Coastguard Worker 
init()1034*35238bceSAndroid Build Coastguard Worker     void init() override
1035*35238bceSAndroid Build Coastguard Worker     {
1036*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl              = m_context.getRenderContext().getFunctions();
1037*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = m_context.getRenderContext().getRenderTarget();
1038*35238bceSAndroid Build Coastguard Worker         glw::GLuint viewportW                 = renderTarget.getWidth();
1039*35238bceSAndroid Build Coastguard Worker         glw::GLuint viewportH                 = renderTarget.getHeight();
1040*35238bceSAndroid Build Coastguard Worker 
1041*35238bceSAndroid Build Coastguard Worker         ClipControlRenderBaseTest::init();
1042*35238bceSAndroid Build Coastguard Worker 
1043*35238bceSAndroid Build Coastguard Worker         gl.genFramebuffers(1, &m_fboD);
1044*35238bceSAndroid Build Coastguard Worker 
1045*35238bceSAndroid Build Coastguard Worker         gl.genTextures(1, &m_texDepthResolve);
1046*35238bceSAndroid Build Coastguard Worker         gl.bindTexture(GL_TEXTURE_2D, m_texDepthResolve);
1047*35238bceSAndroid Build Coastguard Worker         setupTexture();
1048*35238bceSAndroid Build Coastguard Worker         gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, viewportW, viewportH, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
1049*35238bceSAndroid Build Coastguard Worker     }
1050*35238bceSAndroid Build Coastguard Worker 
deinit()1051*35238bceSAndroid Build Coastguard Worker     void deinit() override
1052*35238bceSAndroid Build Coastguard Worker     {
1053*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1054*35238bceSAndroid Build Coastguard Worker 
1055*35238bceSAndroid Build Coastguard Worker         gl.deleteTextures(1, &m_texDepthResolve);
1056*35238bceSAndroid Build Coastguard Worker         gl.deleteFramebuffers(1, &m_fboD);
1057*35238bceSAndroid Build Coastguard Worker 
1058*35238bceSAndroid Build Coastguard Worker         ClipControlRenderBaseTest::deinit();
1059*35238bceSAndroid Build Coastguard Worker     }
1060*35238bceSAndroid Build Coastguard Worker 
setupTexture()1061*35238bceSAndroid Build Coastguard Worker     void setupTexture()
1062*35238bceSAndroid Build Coastguard Worker     {
1063*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1064*35238bceSAndroid Build Coastguard Worker         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1065*35238bceSAndroid Build Coastguard Worker         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1066*35238bceSAndroid Build Coastguard Worker         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1067*35238bceSAndroid Build Coastguard Worker         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1068*35238bceSAndroid Build Coastguard Worker     }
1069*35238bceSAndroid Build Coastguard Worker 
readDepthPixels(const tcu::PixelBufferAccess & pixelBuf)1070*35238bceSAndroid Build Coastguard Worker     void readDepthPixels(const tcu::PixelBufferAccess &pixelBuf)
1071*35238bceSAndroid Build Coastguard Worker     {
1072*35238bceSAndroid Build Coastguard Worker 
1073*35238bceSAndroid Build Coastguard Worker         const char *vs = "\n"
1074*35238bceSAndroid Build Coastguard Worker                          "attribute vec4 pos;\n"
1075*35238bceSAndroid Build Coastguard Worker                          "attribute vec2 UV;\n"
1076*35238bceSAndroid Build Coastguard Worker                          "varying highp vec2 vUV;\n"
1077*35238bceSAndroid Build Coastguard Worker                          "void main() {\n"
1078*35238bceSAndroid Build Coastguard Worker                          "  gl_Position = pos;\n"
1079*35238bceSAndroid Build Coastguard Worker                          "  vUV = UV;\n"
1080*35238bceSAndroid Build Coastguard Worker                          "}\n";
1081*35238bceSAndroid Build Coastguard Worker 
1082*35238bceSAndroid Build Coastguard Worker         const char *fs = "\n"
1083*35238bceSAndroid Build Coastguard Worker                          "precision mediump float;\n"
1084*35238bceSAndroid Build Coastguard Worker                          "varying vec2 vUV;\n"
1085*35238bceSAndroid Build Coastguard Worker                          "uniform sampler2D tex;\n"
1086*35238bceSAndroid Build Coastguard Worker                          "void main() {\n"
1087*35238bceSAndroid Build Coastguard Worker                          "  gl_FragColor = texture2D(tex, vUV).rrrr;\n"
1088*35238bceSAndroid Build Coastguard Worker                          "}\n";
1089*35238bceSAndroid Build Coastguard Worker 
1090*35238bceSAndroid Build Coastguard Worker         const glu::RenderContext &renderContext = m_context.getRenderContext();
1091*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl                = renderContext.getFunctions();
1092*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget   = renderContext.getRenderTarget();
1093*35238bceSAndroid Build Coastguard Worker         glw::GLsizei windowW                    = renderTarget.getWidth();
1094*35238bceSAndroid Build Coastguard Worker         glw::GLsizei windowH                    = renderTarget.getHeight();
1095*35238bceSAndroid Build Coastguard Worker 
1096*35238bceSAndroid Build Coastguard Worker         glu::ShaderProgram program(renderContext, glu::makeVtxFragSources(vs, fs));
1097*35238bceSAndroid Build Coastguard Worker 
1098*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_FRAMEBUFFER, m_fboD);
1099*35238bceSAndroid Build Coastguard Worker         gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texDepthResolve, 0);
1100*35238bceSAndroid Build Coastguard Worker 
1101*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_DEPTH_TEST);
1102*35238bceSAndroid Build Coastguard Worker         gl.depthMask(GL_FALSE);
1103*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_STENCIL_TEST);
1104*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, windowW, windowH);
1105*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.0f, 0.2f, 1.0f, 1.0f);
1106*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
1107*35238bceSAndroid Build Coastguard Worker 
1108*35238bceSAndroid Build Coastguard Worker         const int texLoc = gl.getUniformLocation(program.getProgram(), "tex");
1109*35238bceSAndroid Build Coastguard Worker 
1110*35238bceSAndroid Build Coastguard Worker         gl.bindVertexArray(0);
1111*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ARRAY_BUFFER, 0);
1112*35238bceSAndroid Build Coastguard Worker 
1113*35238bceSAndroid Build Coastguard Worker         gl.bindTexture(GL_TEXTURE_2D, getDepthTexture());
1114*35238bceSAndroid Build Coastguard Worker         setupTexture();
1115*35238bceSAndroid Build Coastguard Worker 
1116*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program.getProgram());
1117*35238bceSAndroid Build Coastguard Worker         gl.uniform1i(texLoc, 0);
1118*35238bceSAndroid Build Coastguard Worker 
1119*35238bceSAndroid Build Coastguard Worker         {
1120*35238bceSAndroid Build Coastguard Worker             const GLfloat vertices[] = {
1121*35238bceSAndroid Build Coastguard Worker                 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
1122*35238bceSAndroid Build Coastguard Worker             };
1123*35238bceSAndroid Build Coastguard Worker             const GLfloat texCoords[] = {
1124*35238bceSAndroid Build Coastguard Worker                 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
1125*35238bceSAndroid Build Coastguard Worker             };
1126*35238bceSAndroid Build Coastguard Worker             const uint16_t indices[] = {0, 1, 2, 2, 1, 3};
1127*35238bceSAndroid Build Coastguard Worker 
1128*35238bceSAndroid Build Coastguard Worker             const glu::VertexArrayBinding vertexArray[] = {glu::va::Float("pos", 4, 4, 0, vertices),
1129*35238bceSAndroid Build Coastguard Worker                                                            glu::va::Float("UV", 2, 4, 0, texCoords)};
1130*35238bceSAndroid Build Coastguard Worker 
1131*35238bceSAndroid Build Coastguard Worker             glu::draw(renderContext, program.getProgram(), 2, vertexArray,
1132*35238bceSAndroid Build Coastguard Worker                       glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indices), indices));
1133*35238bceSAndroid Build Coastguard Worker         }
1134*35238bceSAndroid Build Coastguard Worker         glu::readPixels(renderContext, 0, 0, pixelBuf);
1135*35238bceSAndroid Build Coastguard Worker     }
1136*35238bceSAndroid Build Coastguard Worker 
1137*35238bceSAndroid Build Coastguard Worker     GLuint m_fboD;
1138*35238bceSAndroid Build Coastguard Worker     GLuint m_texDepthResolve;
1139*35238bceSAndroid Build Coastguard Worker };
1140*35238bceSAndroid Build Coastguard Worker 
1141*35238bceSAndroid Build Coastguard Worker class ClipControlDepthModeZeroToOneTest : public ClipControlDepthModeTest
1142*35238bceSAndroid Build Coastguard Worker {
1143*35238bceSAndroid Build Coastguard Worker public:
ClipControlDepthModeZeroToOneTest(Context & context,const char * name)1144*35238bceSAndroid Build Coastguard Worker     ClipControlDepthModeZeroToOneTest(Context &context, const char *name)
1145*35238bceSAndroid Build Coastguard Worker         : ClipControlDepthModeTest(context, name, "Depth Mode Test, ZERO_TO_ONE")
1146*35238bceSAndroid Build Coastguard Worker         , m_vao(0)
1147*35238bceSAndroid Build Coastguard Worker         , m_vbo(0)
1148*35238bceSAndroid Build Coastguard Worker     {
1149*35238bceSAndroid Build Coastguard Worker     }
1150*35238bceSAndroid Build Coastguard Worker 
deinit()1151*35238bceSAndroid Build Coastguard Worker     void deinit() override
1152*35238bceSAndroid Build Coastguard Worker     {
1153*35238bceSAndroid Build Coastguard Worker         ClipControlDepthModeTest::deinit();
1154*35238bceSAndroid Build Coastguard Worker 
1155*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1156*35238bceSAndroid Build Coastguard Worker 
1157*35238bceSAndroid Build Coastguard Worker         if (ClipControlApi::Supported(m_context))
1158*35238bceSAndroid Build Coastguard Worker         {
1159*35238bceSAndroid Build Coastguard Worker             ClipControlApi cc(m_context);
1160*35238bceSAndroid Build Coastguard Worker             cc.clipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
1161*35238bceSAndroid Build Coastguard Worker         }
1162*35238bceSAndroid Build Coastguard Worker 
1163*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(0.0f);
1164*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.0, 0.0, 0.0, 0.0);
1165*35238bceSAndroid Build Coastguard Worker 
1166*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_DEPTH_TEST);
1167*35238bceSAndroid Build Coastguard Worker         gl.depthFunc(GL_LESS);
1168*35238bceSAndroid Build Coastguard Worker 
1169*35238bceSAndroid Build Coastguard Worker         if (m_vao)
1170*35238bceSAndroid Build Coastguard Worker         {
1171*35238bceSAndroid Build Coastguard Worker             gl.deleteVertexArrays(1, &m_vao);
1172*35238bceSAndroid Build Coastguard Worker         }
1173*35238bceSAndroid Build Coastguard Worker         if (m_vbo)
1174*35238bceSAndroid Build Coastguard Worker         {
1175*35238bceSAndroid Build Coastguard Worker             gl.deleteBuffers(1, &m_vbo);
1176*35238bceSAndroid Build Coastguard Worker         }
1177*35238bceSAndroid Build Coastguard Worker     }
1178*35238bceSAndroid Build Coastguard Worker 
iterate()1179*35238bceSAndroid Build Coastguard Worker     IterateResult iterate() override
1180*35238bceSAndroid Build Coastguard Worker     {
1181*35238bceSAndroid Build Coastguard Worker 
1182*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log        = m_testCtx.getLog();
1183*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1184*35238bceSAndroid Build Coastguard Worker         ClipControlApi cc(m_context);
1185*35238bceSAndroid Build Coastguard Worker 
1186*35238bceSAndroid Build Coastguard Worker         gl.clearColor(1.0, 0.0, 0.0, 1.0);
1187*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
1188*35238bceSAndroid Build Coastguard Worker 
1189*35238bceSAndroid Build Coastguard Worker         //Clear the depth buffer to 0.5.
1190*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(0.5);
1191*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_DEPTH_BUFFER_BIT);
1192*35238bceSAndroid Build Coastguard Worker 
1193*35238bceSAndroid Build Coastguard Worker         //Set ClipControl(LOWER_LEFT, ZERO_TO_ONE)
1194*35238bceSAndroid Build Coastguard Worker         cc.clipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
1195*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "ClipControl()");
1196*35238bceSAndroid Build Coastguard Worker 
1197*35238bceSAndroid Build Coastguard Worker         //Enable(DEPTH_TEST) with DepthFunc(ALWAYS)
1198*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
1199*35238bceSAndroid Build Coastguard Worker         gl.depthFunc(GL_ALWAYS);
1200*35238bceSAndroid Build Coastguard Worker 
1201*35238bceSAndroid Build Coastguard Worker         //Render a triangle fan coverage (-1.0,-1.0,-1.0) to (1.0,1.0,1.0).
1202*35238bceSAndroid Build Coastguard Worker         de::SharedPtr<glu::ShaderProgram> program(
1203*35238bceSAndroid Build Coastguard Worker             new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vsh(), fsh())));
1204*35238bceSAndroid Build Coastguard Worker 
1205*35238bceSAndroid Build Coastguard Worker         log << (*program);
1206*35238bceSAndroid Build Coastguard Worker         if (!program->isOk())
1207*35238bceSAndroid Build Coastguard Worker         {
1208*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Program compilation failed");
1209*35238bceSAndroid Build Coastguard Worker         }
1210*35238bceSAndroid Build Coastguard Worker 
1211*35238bceSAndroid Build Coastguard Worker         gl.genVertexArrays(1, &m_vao);
1212*35238bceSAndroid Build Coastguard Worker         gl.bindVertexArray(m_vao);
1213*35238bceSAndroid Build Coastguard Worker 
1214*35238bceSAndroid Build Coastguard Worker         gl.genBuffers(1, &m_vbo);
1215*35238bceSAndroid Build Coastguard Worker 
1216*35238bceSAndroid Build Coastguard Worker         const float vertex_data0[] = {
1217*35238bceSAndroid Build Coastguard Worker             -1.0, -1.0, -1.0, 1.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
1218*35238bceSAndroid Build Coastguard Worker         };
1219*35238bceSAndroid Build Coastguard Worker 
1220*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo);
1221*35238bceSAndroid Build Coastguard Worker         gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertex_data0), vertex_data0, GL_STATIC_DRAW);
1222*35238bceSAndroid Build Coastguard Worker 
1223*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
1224*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(0);
1225*35238bceSAndroid Build Coastguard Worker 
1226*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program->getProgram());
1227*35238bceSAndroid Build Coastguard Worker 
1228*35238bceSAndroid Build Coastguard Worker         //test method modification: use GL_TRIANGLE_STRIP, not FAN.
1229*35238bceSAndroid Build Coastguard Worker         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
1230*35238bceSAndroid Build Coastguard Worker 
1231*35238bceSAndroid Build Coastguard Worker         //Read back the floating-point depth buffer with ReadPixels
1232*35238bceSAndroid Build Coastguard Worker         //Verify that the pixels with a Z clip coordinate less than 0.0 are
1233*35238bceSAndroid Build Coastguard Worker         //  clipped and those coordinates from 0.0 to 1.0 update the depth
1234*35238bceSAndroid Build Coastguard Worker         //  buffer with values 0.0 to 1.0.
1235*35238bceSAndroid Build Coastguard Worker         qpTestResult result = ValidateFramebuffer(m_context);
1236*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(result, qpGetTestResultName(result));
1237*35238bceSAndroid Build Coastguard Worker 
1238*35238bceSAndroid Build Coastguard Worker         return STOP;
1239*35238bceSAndroid Build Coastguard Worker     }
1240*35238bceSAndroid Build Coastguard Worker 
vsh()1241*35238bceSAndroid Build Coastguard Worker     const char *vsh()
1242*35238bceSAndroid Build Coastguard Worker     {
1243*35238bceSAndroid Build Coastguard Worker         return "attribute vec3 Position;"
1244*35238bceSAndroid Build Coastguard Worker                "\n"
1245*35238bceSAndroid Build Coastguard Worker                "void main() {"
1246*35238bceSAndroid Build Coastguard Worker                "\n"
1247*35238bceSAndroid Build Coastguard Worker                "    gl_Position = vec4(Position, 1.0);"
1248*35238bceSAndroid Build Coastguard Worker                "\n"
1249*35238bceSAndroid Build Coastguard Worker                "}";
1250*35238bceSAndroid Build Coastguard Worker     }
1251*35238bceSAndroid Build Coastguard Worker 
ValidateFramebuffer(Context & context)1252*35238bceSAndroid Build Coastguard Worker     qpTestResult ValidateFramebuffer(Context &context)
1253*35238bceSAndroid Build Coastguard Worker     {
1254*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = context.getRenderContext().getRenderTarget();
1255*35238bceSAndroid Build Coastguard Worker         glw::GLuint viewportW                 = renderTarget.getWidth();
1256*35238bceSAndroid Build Coastguard Worker         glw::GLuint viewportH                 = renderTarget.getHeight();
1257*35238bceSAndroid Build Coastguard Worker         tcu::Surface renderedColorFrame(viewportW, viewportH);
1258*35238bceSAndroid Build Coastguard Worker         tcu::Surface referenceColorFrame(viewportW, viewportH);
1259*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthReadbackFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
1260*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
1261*35238bceSAndroid Build Coastguard Worker         tcu::TextureLevel renderedDepthFrame(depthReadbackFormat, viewportW, viewportH);
1262*35238bceSAndroid Build Coastguard Worker         tcu::TextureLevel referenceDepthFrame(depthFormat, viewportW, viewportH);
1263*35238bceSAndroid Build Coastguard Worker         tcu::TextureLevel importanceMaskFrame(depthFormat, viewportW, viewportH);
1264*35238bceSAndroid Build Coastguard Worker 
1265*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log = context.getTestContext().getLog();
1266*35238bceSAndroid Build Coastguard Worker 
1267*35238bceSAndroid Build Coastguard Worker         const float rasterizationError =
1268*35238bceSAndroid Build Coastguard Worker             2.0f / (float)renderedColorFrame.getHeight() + 2.0f / (float)renderedColorFrame.getWidth();
1269*35238bceSAndroid Build Coastguard Worker 
1270*35238bceSAndroid Build Coastguard Worker         for (int y = 0; y < renderedColorFrame.getHeight(); y++)
1271*35238bceSAndroid Build Coastguard Worker         {
1272*35238bceSAndroid Build Coastguard Worker             float yCoord = ((float)(y) + 0.5f) / (float)renderedColorFrame.getHeight();
1273*35238bceSAndroid Build Coastguard Worker 
1274*35238bceSAndroid Build Coastguard Worker             for (int x = 0; x < renderedColorFrame.getWidth(); x++)
1275*35238bceSAndroid Build Coastguard Worker             {
1276*35238bceSAndroid Build Coastguard Worker                 float xCoord = ((float)(x) + 0.5f) / (float)renderedColorFrame.getWidth();
1277*35238bceSAndroid Build Coastguard Worker 
1278*35238bceSAndroid Build Coastguard Worker                 if (yCoord >= 1.0 - xCoord - rasterizationError && yCoord <= 1.0 - xCoord + rasterizationError)
1279*35238bceSAndroid Build Coastguard Worker                 {
1280*35238bceSAndroid Build Coastguard Worker                     importanceMaskFrame.getAccess().setPixDepth(0.0f, x, y);
1281*35238bceSAndroid Build Coastguard Worker                 }
1282*35238bceSAndroid Build Coastguard Worker                 else
1283*35238bceSAndroid Build Coastguard Worker                 {
1284*35238bceSAndroid Build Coastguard Worker                     importanceMaskFrame.getAccess().setPixDepth(1.0f, x, y);
1285*35238bceSAndroid Build Coastguard Worker                 }
1286*35238bceSAndroid Build Coastguard Worker 
1287*35238bceSAndroid Build Coastguard Worker                 if (yCoord < 1.0 - xCoord)
1288*35238bceSAndroid Build Coastguard Worker                 {
1289*35238bceSAndroid Build Coastguard Worker                     referenceColorFrame.setPixel(x, y, tcu::RGBA::red());
1290*35238bceSAndroid Build Coastguard Worker                     referenceDepthFrame.getAccess().setPixDepth(0.5f, x, y);
1291*35238bceSAndroid Build Coastguard Worker                 }
1292*35238bceSAndroid Build Coastguard Worker                 else
1293*35238bceSAndroid Build Coastguard Worker                 {
1294*35238bceSAndroid Build Coastguard Worker                     referenceColorFrame.setPixel(x, y, tcu::RGBA::green());
1295*35238bceSAndroid Build Coastguard Worker 
1296*35238bceSAndroid Build Coastguard Worker                     referenceDepthFrame.getAccess().setPixDepth(-1.0f + xCoord + yCoord, x, y);
1297*35238bceSAndroid Build Coastguard Worker                 }
1298*35238bceSAndroid Build Coastguard Worker             }
1299*35238bceSAndroid Build Coastguard Worker         }
1300*35238bceSAndroid Build Coastguard Worker 
1301*35238bceSAndroid Build Coastguard Worker         glu::readPixels(context.getRenderContext(), 0, 0, renderedColorFrame.getAccess());
1302*35238bceSAndroid Build Coastguard Worker         if (!tcu::fuzzyCompare(log, "Result", "Color image comparison result", referenceColorFrame, renderedColorFrame,
1303*35238bceSAndroid Build Coastguard Worker                                0.05f, tcu::COMPARE_LOG_RESULT))
1304*35238bceSAndroid Build Coastguard Worker         {
1305*35238bceSAndroid Build Coastguard Worker 
1306*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_FAIL;
1307*35238bceSAndroid Build Coastguard Worker         }
1308*35238bceSAndroid Build Coastguard Worker 
1309*35238bceSAndroid Build Coastguard Worker         readDepthPixels(renderedDepthFrame.getAccess());
1310*35238bceSAndroid Build Coastguard Worker         if (!fuzzyDepthCompare(log, "Result", "Depth image comparison result", referenceDepthFrame, renderedDepthFrame,
1311*35238bceSAndroid Build Coastguard Worker                                0.05f, &importanceMaskFrame))
1312*35238bceSAndroid Build Coastguard Worker         {
1313*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_FAIL;
1314*35238bceSAndroid Build Coastguard Worker         }
1315*35238bceSAndroid Build Coastguard Worker         return QP_TEST_RESULT_PASS;
1316*35238bceSAndroid Build Coastguard Worker     }
1317*35238bceSAndroid Build Coastguard Worker 
1318*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vao, m_vbo;
1319*35238bceSAndroid Build Coastguard Worker };
1320*35238bceSAndroid Build Coastguard Worker 
1321*35238bceSAndroid Build Coastguard Worker /*
1322*35238bceSAndroid Build Coastguard Worker  Do the same as above, but use the default NEGATIVE_ONE_TO_ONE depth mode:
1323*35238bceSAndroid Build Coastguard Worker 
1324*35238bceSAndroid Build Coastguard Worker  - Clear the depth buffer to 0.5.
1325*35238bceSAndroid Build Coastguard Worker  - Set ClipControl(LOWER_LEFT, NEGATIVE_ONE_TO_ONE)
1326*35238bceSAndroid Build Coastguard Worker  - Enable(DEPTH_TEST) with DepthFunc(ALWAYS)
1327*35238bceSAndroid Build Coastguard Worker  - Render a triangle fan coverage (-1.0,-1.0,-1.0) to (1.0,1.0,1.0).
1328*35238bceSAndroid Build Coastguard Worker  - Read back the floating-point depth buffer with ReadPixels
1329*35238bceSAndroid Build Coastguard Worker  - Verify that no pixels are clipped and the depth buffer contains
1330*35238bceSAndroid Build Coastguard Worker  values from 0.0 to 1.0.
1331*35238bceSAndroid Build Coastguard Worker  */
1332*35238bceSAndroid Build Coastguard Worker class ClipControlDepthModeOneToOneTest : public ClipControlDepthModeTest
1333*35238bceSAndroid Build Coastguard Worker {
1334*35238bceSAndroid Build Coastguard Worker public:
ClipControlDepthModeOneToOneTest(Context & context,const char * name)1335*35238bceSAndroid Build Coastguard Worker     ClipControlDepthModeOneToOneTest(Context &context, const char *name)
1336*35238bceSAndroid Build Coastguard Worker         : ClipControlDepthModeTest(context, name, "Depth Mode Test, ONE_TO_ONE")
1337*35238bceSAndroid Build Coastguard Worker         , m_vao(0)
1338*35238bceSAndroid Build Coastguard Worker         , m_vbo(0)
1339*35238bceSAndroid Build Coastguard Worker     {
1340*35238bceSAndroid Build Coastguard Worker     }
1341*35238bceSAndroid Build Coastguard Worker 
deinit()1342*35238bceSAndroid Build Coastguard Worker     void deinit() override
1343*35238bceSAndroid Build Coastguard Worker     {
1344*35238bceSAndroid Build Coastguard Worker         ClipControlDepthModeTest::deinit();
1345*35238bceSAndroid Build Coastguard Worker 
1346*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1347*35238bceSAndroid Build Coastguard Worker 
1348*35238bceSAndroid Build Coastguard Worker         if (ClipControlApi::Supported(m_context))
1349*35238bceSAndroid Build Coastguard Worker         {
1350*35238bceSAndroid Build Coastguard Worker             ClipControlApi cc(m_context);
1351*35238bceSAndroid Build Coastguard Worker             cc.clipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
1352*35238bceSAndroid Build Coastguard Worker         }
1353*35238bceSAndroid Build Coastguard Worker 
1354*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(0.0);
1355*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.0, 0.0, 0.0, 0.0);
1356*35238bceSAndroid Build Coastguard Worker 
1357*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_DEPTH_TEST);
1358*35238bceSAndroid Build Coastguard Worker         gl.depthFunc(GL_LESS);
1359*35238bceSAndroid Build Coastguard Worker 
1360*35238bceSAndroid Build Coastguard Worker         if (m_vao)
1361*35238bceSAndroid Build Coastguard Worker         {
1362*35238bceSAndroid Build Coastguard Worker             gl.deleteVertexArrays(1, &m_vao);
1363*35238bceSAndroid Build Coastguard Worker         }
1364*35238bceSAndroid Build Coastguard Worker         if (m_vbo)
1365*35238bceSAndroid Build Coastguard Worker         {
1366*35238bceSAndroid Build Coastguard Worker             gl.deleteBuffers(1, &m_vbo);
1367*35238bceSAndroid Build Coastguard Worker         }
1368*35238bceSAndroid Build Coastguard Worker     }
1369*35238bceSAndroid Build Coastguard Worker 
iterate()1370*35238bceSAndroid Build Coastguard Worker     IterateResult iterate() override
1371*35238bceSAndroid Build Coastguard Worker     {
1372*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log        = m_testCtx.getLog();
1373*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1374*35238bceSAndroid Build Coastguard Worker         ClipControlApi cc(m_context);
1375*35238bceSAndroid Build Coastguard Worker 
1376*35238bceSAndroid Build Coastguard Worker         gl.clearColor(1.0, 0.0, 0.0, 1.0);
1377*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
1378*35238bceSAndroid Build Coastguard Worker 
1379*35238bceSAndroid Build Coastguard Worker         //Clear the depth buffer to 0.5.
1380*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(0.5f);
1381*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_DEPTH_BUFFER_BIT);
1382*35238bceSAndroid Build Coastguard Worker 
1383*35238bceSAndroid Build Coastguard Worker         //Set ClipControl(LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE)
1384*35238bceSAndroid Build Coastguard Worker         cc.clipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
1385*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "ClipControl()");
1386*35238bceSAndroid Build Coastguard Worker 
1387*35238bceSAndroid Build Coastguard Worker         //Enable(DEPTH_TEST) with DepthFunc(ALWAYS)
1388*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
1389*35238bceSAndroid Build Coastguard Worker         gl.depthFunc(GL_ALWAYS);
1390*35238bceSAndroid Build Coastguard Worker 
1391*35238bceSAndroid Build Coastguard Worker         //Render a triangle fan coverage (-1.0,-1.0,-1.0) to (1.0,1.0,1.0).
1392*35238bceSAndroid Build Coastguard Worker         de::SharedPtr<glu::ShaderProgram> program(
1393*35238bceSAndroid Build Coastguard Worker             new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vsh(), fsh())));
1394*35238bceSAndroid Build Coastguard Worker 
1395*35238bceSAndroid Build Coastguard Worker         log << (*program);
1396*35238bceSAndroid Build Coastguard Worker         if (!program->isOk())
1397*35238bceSAndroid Build Coastguard Worker         {
1398*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Program compilation failed");
1399*35238bceSAndroid Build Coastguard Worker         }
1400*35238bceSAndroid Build Coastguard Worker 
1401*35238bceSAndroid Build Coastguard Worker         gl.genVertexArrays(1, &m_vao);
1402*35238bceSAndroid Build Coastguard Worker         gl.bindVertexArray(m_vao);
1403*35238bceSAndroid Build Coastguard Worker 
1404*35238bceSAndroid Build Coastguard Worker         gl.genBuffers(1, &m_vbo);
1405*35238bceSAndroid Build Coastguard Worker 
1406*35238bceSAndroid Build Coastguard Worker         const float vertex_data0[] = {
1407*35238bceSAndroid Build Coastguard Worker             -1.0, -1.0, -1.0, 1.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
1408*35238bceSAndroid Build Coastguard Worker         };
1409*35238bceSAndroid Build Coastguard Worker 
1410*35238bceSAndroid Build Coastguard Worker         gl.bindBuffer(GL_ARRAY_BUFFER, m_vbo);
1411*35238bceSAndroid Build Coastguard Worker         gl.bufferData(GL_ARRAY_BUFFER, sizeof(vertex_data0), vertex_data0, GL_STATIC_DRAW);
1412*35238bceSAndroid Build Coastguard Worker 
1413*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
1414*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(0);
1415*35238bceSAndroid Build Coastguard Worker 
1416*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program->getProgram());
1417*35238bceSAndroid Build Coastguard Worker 
1418*35238bceSAndroid Build Coastguard Worker         //test method modification: use GL_TRIANGLE_STRIP, not FAN.
1419*35238bceSAndroid Build Coastguard Worker         gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
1420*35238bceSAndroid Build Coastguard Worker 
1421*35238bceSAndroid Build Coastguard Worker         //Read back the floating-point depth buffer with ReadPixels
1422*35238bceSAndroid Build Coastguard Worker         //Verify that the pixels with a Z clip coordinate less than 0.0 are
1423*35238bceSAndroid Build Coastguard Worker         //  clipped and those coordinates from 0.0 to 1.0 update the depth
1424*35238bceSAndroid Build Coastguard Worker         //  buffer with values 0.0 to 1.0.
1425*35238bceSAndroid Build Coastguard Worker         qpTestResult result = ValidateFramebuffer(m_context);
1426*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(result, qpGetTestResultName(result));
1427*35238bceSAndroid Build Coastguard Worker 
1428*35238bceSAndroid Build Coastguard Worker         return STOP;
1429*35238bceSAndroid Build Coastguard Worker     }
1430*35238bceSAndroid Build Coastguard Worker 
vsh()1431*35238bceSAndroid Build Coastguard Worker     const char *vsh()
1432*35238bceSAndroid Build Coastguard Worker     {
1433*35238bceSAndroid Build Coastguard Worker         return "attribute vec3 Position;"
1434*35238bceSAndroid Build Coastguard Worker                "\n"
1435*35238bceSAndroid Build Coastguard Worker                "void main() {"
1436*35238bceSAndroid Build Coastguard Worker                "\n"
1437*35238bceSAndroid Build Coastguard Worker                "    gl_Position = vec4(Position, 1.0);"
1438*35238bceSAndroid Build Coastguard Worker                "\n"
1439*35238bceSAndroid Build Coastguard Worker                "}";
1440*35238bceSAndroid Build Coastguard Worker     }
1441*35238bceSAndroid Build Coastguard Worker 
ValidateFramebuffer(Context & context)1442*35238bceSAndroid Build Coastguard Worker     qpTestResult ValidateFramebuffer(Context &context)
1443*35238bceSAndroid Build Coastguard Worker     {
1444*35238bceSAndroid Build Coastguard Worker         const tcu::RenderTarget &renderTarget = context.getRenderContext().getRenderTarget();
1445*35238bceSAndroid Build Coastguard Worker         glw::GLuint viewportW                 = renderTarget.getWidth();
1446*35238bceSAndroid Build Coastguard Worker         glw::GLuint viewportH                 = renderTarget.getHeight();
1447*35238bceSAndroid Build Coastguard Worker         tcu::Surface renderedColorFrame(viewportW, viewportH);
1448*35238bceSAndroid Build Coastguard Worker         tcu::Surface referenceColorFrame(viewportW, viewportH);
1449*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthReadbackFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
1450*35238bceSAndroid Build Coastguard Worker         tcu::TextureFormat depthFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
1451*35238bceSAndroid Build Coastguard Worker         tcu::TextureLevel renderedDepthFrame(depthReadbackFormat, viewportW, viewportH);
1452*35238bceSAndroid Build Coastguard Worker         tcu::TextureLevel referenceDepthFrame(depthFormat, viewportW, viewportH);
1453*35238bceSAndroid Build Coastguard Worker 
1454*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log = context.getTestContext().getLog();
1455*35238bceSAndroid Build Coastguard Worker 
1456*35238bceSAndroid Build Coastguard Worker         for (int y = 0; y < renderedColorFrame.getHeight(); y++)
1457*35238bceSAndroid Build Coastguard Worker         {
1458*35238bceSAndroid Build Coastguard Worker             float yCoord = (float)(y) / (float)renderedColorFrame.getHeight();
1459*35238bceSAndroid Build Coastguard Worker             for (int x = 0; x < renderedColorFrame.getWidth(); x++)
1460*35238bceSAndroid Build Coastguard Worker             {
1461*35238bceSAndroid Build Coastguard Worker                 float xCoord = (float)(x) / (float)renderedColorFrame.getWidth();
1462*35238bceSAndroid Build Coastguard Worker 
1463*35238bceSAndroid Build Coastguard Worker                 referenceColorFrame.setPixel(x, y, tcu::RGBA::green());
1464*35238bceSAndroid Build Coastguard Worker                 referenceDepthFrame.getAccess().setPixDepth((xCoord + yCoord) * 0.5f, x, y);
1465*35238bceSAndroid Build Coastguard Worker             }
1466*35238bceSAndroid Build Coastguard Worker         }
1467*35238bceSAndroid Build Coastguard Worker 
1468*35238bceSAndroid Build Coastguard Worker         glu::readPixels(context.getRenderContext(), 0, 0, renderedColorFrame.getAccess());
1469*35238bceSAndroid Build Coastguard Worker         if (!tcu::fuzzyCompare(log, "Result", "Color image comparison result", referenceColorFrame, renderedColorFrame,
1470*35238bceSAndroid Build Coastguard Worker                                0.05f, tcu::COMPARE_LOG_RESULT))
1471*35238bceSAndroid Build Coastguard Worker         {
1472*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_FAIL;
1473*35238bceSAndroid Build Coastguard Worker         }
1474*35238bceSAndroid Build Coastguard Worker 
1475*35238bceSAndroid Build Coastguard Worker         readDepthPixels(renderedDepthFrame.getAccess());
1476*35238bceSAndroid Build Coastguard Worker         if (!fuzzyDepthCompare(log, "Result", "Depth image comparison result", referenceDepthFrame, renderedDepthFrame,
1477*35238bceSAndroid Build Coastguard Worker                                0.05f))
1478*35238bceSAndroid Build Coastguard Worker         {
1479*35238bceSAndroid Build Coastguard Worker             return QP_TEST_RESULT_FAIL;
1480*35238bceSAndroid Build Coastguard Worker         }
1481*35238bceSAndroid Build Coastguard Worker 
1482*35238bceSAndroid Build Coastguard Worker         return QP_TEST_RESULT_PASS;
1483*35238bceSAndroid Build Coastguard Worker     }
1484*35238bceSAndroid Build Coastguard Worker 
1485*35238bceSAndroid Build Coastguard Worker     glw::GLuint m_vao, m_vbo;
1486*35238bceSAndroid Build Coastguard Worker };
1487*35238bceSAndroid Build Coastguard Worker 
1488*35238bceSAndroid Build Coastguard Worker /** Constructor.
1489*35238bceSAndroid Build Coastguard Worker  *
1490*35238bceSAndroid Build Coastguard Worker  *  @param context Rendering context.
1491*35238bceSAndroid Build Coastguard Worker  **/
ClipControlTests(Context & context)1492*35238bceSAndroid Build Coastguard Worker ClipControlTests::ClipControlTests(Context &context)
1493*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "clip_control", "Verifies \"clip_control\" functionality")
1494*35238bceSAndroid Build Coastguard Worker {
1495*35238bceSAndroid Build Coastguard Worker     /* Left blank on purpose */
1496*35238bceSAndroid Build Coastguard Worker }
1497*35238bceSAndroid Build Coastguard Worker 
1498*35238bceSAndroid Build Coastguard Worker /** Destructor.
1499*35238bceSAndroid Build Coastguard Worker  *
1500*35238bceSAndroid Build Coastguard Worker  **/
~ClipControlTests()1501*35238bceSAndroid Build Coastguard Worker ClipControlTests::~ClipControlTests()
1502*35238bceSAndroid Build Coastguard Worker {
1503*35238bceSAndroid Build Coastguard Worker }
1504*35238bceSAndroid Build Coastguard Worker 
1505*35238bceSAndroid Build Coastguard Worker /** Initializes a texture_storage_multisample test group.
1506*35238bceSAndroid Build Coastguard Worker  *
1507*35238bceSAndroid Build Coastguard Worker  **/
init(void)1508*35238bceSAndroid Build Coastguard Worker void ClipControlTests::init(void)
1509*35238bceSAndroid Build Coastguard Worker {
1510*35238bceSAndroid Build Coastguard Worker     addChild(new ClipControlInitialState(m_context, "initial"));
1511*35238bceSAndroid Build Coastguard Worker     addChild(new ClipControlModifyGetState(m_context, "modify_get"));
1512*35238bceSAndroid Build Coastguard Worker     addChild(new ClipControlErrors(m_context, "errors"));
1513*35238bceSAndroid Build Coastguard Worker     addChild(new ClipControlOriginTest(m_context, "origin"));
1514*35238bceSAndroid Build Coastguard Worker     addChild(new ClipControlDepthModeZeroToOneTest(m_context, "depth_mode_zero_to_one"));
1515*35238bceSAndroid Build Coastguard Worker     addChild(new ClipControlDepthModeOneToOneTest(m_context, "depth_mode_one_to_one"));
1516*35238bceSAndroid Build Coastguard Worker     addChild(new ClipControlFaceCulling(m_context, "face_culling"));
1517*35238bceSAndroid Build Coastguard Worker     addChild(new ClipControlViewportBounds(m_context, "viewport_bounds"));
1518*35238bceSAndroid Build Coastguard Worker }
1519*35238bceSAndroid Build Coastguard Worker } // namespace Functional
1520*35238bceSAndroid Build Coastguard Worker } // namespace gles2
1521*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1522