xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fPolygonOffsetTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
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 Polygon offset tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es3fPolygonOffsetTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "glwDefs.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuTestContext.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "rrRenderer.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "rrFragmentOperations.hpp"
42*35238bceSAndroid Build Coastguard Worker 
43*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceContext.hpp"
44*35238bceSAndroid Build Coastguard Worker 
45*35238bceSAndroid Build Coastguard Worker #include <string>
46*35238bceSAndroid Build Coastguard Worker #include <limits>
47*35238bceSAndroid Build Coastguard Worker 
48*35238bceSAndroid Build Coastguard Worker using namespace glw; // GLint and other GL types
49*35238bceSAndroid Build Coastguard Worker 
50*35238bceSAndroid Build Coastguard Worker namespace deqp
51*35238bceSAndroid Build Coastguard Worker {
52*35238bceSAndroid Build Coastguard Worker namespace gles3
53*35238bceSAndroid Build Coastguard Worker {
54*35238bceSAndroid Build Coastguard Worker namespace Functional
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker namespace
57*35238bceSAndroid Build Coastguard Worker {
58*35238bceSAndroid Build Coastguard Worker 
59*35238bceSAndroid Build Coastguard Worker const char *s_shaderSourceVertex   = "#version 300 es\n"
60*35238bceSAndroid Build Coastguard Worker                                      "in highp vec4 a_position;\n"
61*35238bceSAndroid Build Coastguard Worker                                      "in highp vec4 a_color;\n"
62*35238bceSAndroid Build Coastguard Worker                                      "out highp vec4 v_color;\n"
63*35238bceSAndroid Build Coastguard Worker                                      "void main (void)\n"
64*35238bceSAndroid Build Coastguard Worker                                      "{\n"
65*35238bceSAndroid Build Coastguard Worker                                      "    gl_Position = a_position;\n"
66*35238bceSAndroid Build Coastguard Worker                                      "    v_color = a_color;\n"
67*35238bceSAndroid Build Coastguard Worker                                      "}\n";
68*35238bceSAndroid Build Coastguard Worker const char *s_shaderSourceFragment = "#version 300 es\n"
69*35238bceSAndroid Build Coastguard Worker                                      "in highp vec4 v_color;\n"
70*35238bceSAndroid Build Coastguard Worker                                      "layout(location = 0) out mediump vec4 fragColor;"
71*35238bceSAndroid Build Coastguard Worker                                      "void main (void)\n"
72*35238bceSAndroid Build Coastguard Worker                                      "{\n"
73*35238bceSAndroid Build Coastguard Worker                                      "    fragColor = v_color;\n"
74*35238bceSAndroid Build Coastguard Worker                                      "}\n";
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker static const tcu::Vec4 MASK_COLOR_OK   = tcu::Vec4(0.0f, 0.1f, 0.0f, 1.0f);
77*35238bceSAndroid Build Coastguard Worker static const tcu::Vec4 MASK_COLOR_DEV  = tcu::Vec4(0.8f, 0.5f, 0.0f, 1.0f);
78*35238bceSAndroid Build Coastguard Worker static const tcu::Vec4 MASK_COLOR_FAIL = tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f);
79*35238bceSAndroid Build Coastguard Worker 
compareThreshold(const tcu::IVec4 & a,const tcu::IVec4 & b,const tcu::IVec4 & threshold)80*35238bceSAndroid Build Coastguard Worker inline bool compareThreshold(const tcu::IVec4 &a, const tcu::IVec4 &b, const tcu::IVec4 &threshold)
81*35238bceSAndroid Build Coastguard Worker {
82*35238bceSAndroid Build Coastguard Worker     return tcu::boolAll(tcu::lessThanEqual(tcu::abs(a - b), threshold));
83*35238bceSAndroid Build Coastguard Worker }
84*35238bceSAndroid Build Coastguard Worker 
85*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
86*35238bceSAndroid Build Coastguard Worker * \brief Pixelwise comparison of two images.
87*35238bceSAndroid Build Coastguard Worker * \note copied & modified from glsRasterizationTests
88*35238bceSAndroid Build Coastguard Worker *
89*35238bceSAndroid Build Coastguard Worker * Kernel radius defines maximum allowed distance. If radius is 0, only
90*35238bceSAndroid Build Coastguard Worker * perfect match is allowed. Radius of 1 gives a 3x3 kernel.
91*35238bceSAndroid Build Coastguard Worker *
92*35238bceSAndroid Build Coastguard Worker * Return values: -1 = Perfect match
93*35238bceSAndroid Build Coastguard Worker * 0 = Deviation within kernel
94*35238bceSAndroid Build Coastguard Worker * >0 = Number of faulty pixels
95*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
compareImages(tcu::TestLog & log,glu::RenderContext & renderCtx,const tcu::ConstPixelBufferAccess & test,const tcu::ConstPixelBufferAccess & ref,const tcu::PixelBufferAccess & diffMask,int radius)96*35238bceSAndroid Build Coastguard Worker int compareImages(tcu::TestLog &log, glu::RenderContext &renderCtx, const tcu::ConstPixelBufferAccess &test,
97*35238bceSAndroid Build Coastguard Worker                   const tcu::ConstPixelBufferAccess &ref, const tcu::PixelBufferAccess &diffMask, int radius)
98*35238bceSAndroid Build Coastguard Worker {
99*35238bceSAndroid Build Coastguard Worker     const int height                = test.getHeight();
100*35238bceSAndroid Build Coastguard Worker     const int width                 = test.getWidth();
101*35238bceSAndroid Build Coastguard Worker     const int colorThreshold        = 128;
102*35238bceSAndroid Build Coastguard Worker     const tcu::RGBA formatThreshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold();
103*35238bceSAndroid Build Coastguard Worker     const tcu::IVec4 threshold      = tcu::IVec4(colorThreshold, colorThreshold, colorThreshold,
104*35238bceSAndroid Build Coastguard Worker                                             formatThreshold.getAlpha() > 0 ? colorThreshold : 0) +
105*35238bceSAndroid Build Coastguard Worker                                  tcu::IVec4(formatThreshold.getRed(), formatThreshold.getGreen(),
106*35238bceSAndroid Build Coastguard Worker                                             formatThreshold.getBlue(), formatThreshold.getAlpha());
107*35238bceSAndroid Build Coastguard Worker 
108*35238bceSAndroid Build Coastguard Worker     int faultyPixels  = 0;
109*35238bceSAndroid Build Coastguard Worker     int compareFailed = -1;
110*35238bceSAndroid Build Coastguard Worker 
111*35238bceSAndroid Build Coastguard Worker     tcu::clear(diffMask, MASK_COLOR_OK);
112*35238bceSAndroid Build Coastguard Worker 
113*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < height; y++)
114*35238bceSAndroid Build Coastguard Worker     {
115*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < width; x++)
116*35238bceSAndroid Build Coastguard Worker         {
117*35238bceSAndroid Build Coastguard Worker             const tcu::IVec4 cRef = ref.getPixelInt(x, y);
118*35238bceSAndroid Build Coastguard Worker 
119*35238bceSAndroid Build Coastguard Worker             // Pixelwise match, no deviation or fault
120*35238bceSAndroid Build Coastguard Worker             {
121*35238bceSAndroid Build Coastguard Worker                 const tcu::IVec4 cTest = test.getPixelInt(x, y);
122*35238bceSAndroid Build Coastguard Worker                 if (compareThreshold(cRef, cTest, threshold))
123*35238bceSAndroid Build Coastguard Worker                     continue;
124*35238bceSAndroid Build Coastguard Worker             }
125*35238bceSAndroid Build Coastguard Worker 
126*35238bceSAndroid Build Coastguard Worker             // If not, search within kernel radius
127*35238bceSAndroid Build Coastguard Worker             {
128*35238bceSAndroid Build Coastguard Worker                 const int kYmin = deMax32(y - radius, 0);
129*35238bceSAndroid Build Coastguard Worker                 const int kYmax = deMin32(y + radius, height - 1);
130*35238bceSAndroid Build Coastguard Worker                 const int kXmin = deMax32(x - radius, 0);
131*35238bceSAndroid Build Coastguard Worker                 const int kXmax = deMin32(x + radius, width - 1);
132*35238bceSAndroid Build Coastguard Worker                 bool found      = false;
133*35238bceSAndroid Build Coastguard Worker 
134*35238bceSAndroid Build Coastguard Worker                 for (int kY = kYmin; kY <= kYmax; kY++)
135*35238bceSAndroid Build Coastguard Worker                     for (int kX = kXmin; kX <= kXmax; kX++)
136*35238bceSAndroid Build Coastguard Worker                     {
137*35238bceSAndroid Build Coastguard Worker                         const tcu::IVec4 cTest = test.getPixelInt(kX, kY);
138*35238bceSAndroid Build Coastguard Worker                         if (compareThreshold(cRef, cTest, threshold))
139*35238bceSAndroid Build Coastguard Worker                             found = true;
140*35238bceSAndroid Build Coastguard Worker                     }
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker                 if (found) // The pixel is deviating if the color is found inside the kernel
143*35238bceSAndroid Build Coastguard Worker                 {
144*35238bceSAndroid Build Coastguard Worker                     diffMask.setPixel(MASK_COLOR_DEV, x, y);
145*35238bceSAndroid Build Coastguard Worker                     if (compareFailed == -1)
146*35238bceSAndroid Build Coastguard Worker                         compareFailed = 0;
147*35238bceSAndroid Build Coastguard Worker                     continue;
148*35238bceSAndroid Build Coastguard Worker                 }
149*35238bceSAndroid Build Coastguard Worker             }
150*35238bceSAndroid Build Coastguard Worker 
151*35238bceSAndroid Build Coastguard Worker             diffMask.setPixel(MASK_COLOR_FAIL, x, y);
152*35238bceSAndroid Build Coastguard Worker             faultyPixels++; // The pixel is faulty if the color is not found
153*35238bceSAndroid Build Coastguard Worker             compareFailed = 1;
154*35238bceSAndroid Build Coastguard Worker         }
155*35238bceSAndroid Build Coastguard Worker     }
156*35238bceSAndroid Build Coastguard Worker 
157*35238bceSAndroid Build Coastguard Worker     log << tcu::TestLog::Message << faultyPixels << " faulty pixel(s) found." << tcu::TestLog::EndMessage;
158*35238bceSAndroid Build Coastguard Worker 
159*35238bceSAndroid Build Coastguard Worker     return (compareFailed == 1 ? faultyPixels : compareFailed);
160*35238bceSAndroid Build Coastguard Worker }
161*35238bceSAndroid Build Coastguard Worker 
verifyImages(tcu::TestLog & log,tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const tcu::ConstPixelBufferAccess & testImage,const tcu::ConstPixelBufferAccess & referenceImage)162*35238bceSAndroid Build Coastguard Worker void verifyImages(tcu::TestLog &log, tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
163*35238bceSAndroid Build Coastguard Worker                   const tcu::ConstPixelBufferAccess &testImage, const tcu::ConstPixelBufferAccess &referenceImage)
164*35238bceSAndroid Build Coastguard Worker {
165*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
166*35238bceSAndroid Build Coastguard Worker 
167*35238bceSAndroid Build Coastguard Worker     const int kernelRadius     = 1;
168*35238bceSAndroid Build Coastguard Worker     const int faultyPixelLimit = 20;
169*35238bceSAndroid Build Coastguard Worker     int faultyPixels;
170*35238bceSAndroid Build Coastguard Worker     tcu::Surface diffMask(testImage.getWidth(), testImage.getHeight());
171*35238bceSAndroid Build Coastguard Worker 
172*35238bceSAndroid Build Coastguard Worker     faultyPixels = compareImages(log, renderCtx, referenceImage, testImage, diffMask.getAccess(), kernelRadius);
173*35238bceSAndroid Build Coastguard Worker 
174*35238bceSAndroid Build Coastguard Worker     if (faultyPixels > faultyPixelLimit)
175*35238bceSAndroid Build Coastguard Worker     {
176*35238bceSAndroid Build Coastguard Worker         log << TestLog::ImageSet("Images", "Image comparison");
177*35238bceSAndroid Build Coastguard Worker         log << TestLog::Image("Test image", "Test image", testImage);
178*35238bceSAndroid Build Coastguard Worker         log << TestLog::Image("Reference image", "Reference image", referenceImage);
179*35238bceSAndroid Build Coastguard Worker         log << TestLog::Image("Difference mask", "Difference mask", diffMask.getAccess());
180*35238bceSAndroid Build Coastguard Worker         log << TestLog::EndImageSet;
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker         log << tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
183*35238bceSAndroid Build Coastguard Worker         testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
184*35238bceSAndroid Build Coastguard Worker     }
185*35238bceSAndroid Build Coastguard Worker }
186*35238bceSAndroid Build Coastguard Worker 
verifyError(tcu::TestContext & testCtx,const glw::Functions & gl,GLenum expected)187*35238bceSAndroid Build Coastguard Worker void verifyError(tcu::TestContext &testCtx, const glw::Functions &gl, GLenum expected)
188*35238bceSAndroid Build Coastguard Worker {
189*35238bceSAndroid Build Coastguard Worker     uint32_t got = gl.getError();
190*35238bceSAndroid Build Coastguard Worker     if (got != expected)
191*35238bceSAndroid Build Coastguard Worker     {
192*35238bceSAndroid Build Coastguard Worker         testCtx.getLog() << tcu::TestLog::Message << "// ERROR: expected " << glu::getErrorStr(expected) << "; got "
193*35238bceSAndroid Build Coastguard Worker                          << glu::getErrorStr(got) << tcu::TestLog::EndMessage;
194*35238bceSAndroid Build Coastguard Worker         if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
195*35238bceSAndroid Build Coastguard Worker             testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid error");
196*35238bceSAndroid Build Coastguard Worker     }
197*35238bceSAndroid Build Coastguard Worker }
198*35238bceSAndroid Build Coastguard Worker 
checkCanvasSize(int width,int height,int minWidth,int minHeight)199*35238bceSAndroid Build Coastguard Worker void checkCanvasSize(int width, int height, int minWidth, int minHeight)
200*35238bceSAndroid Build Coastguard Worker {
201*35238bceSAndroid Build Coastguard Worker     if (width < minWidth || height < minHeight)
202*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError(std::string("Render context size must be at least ") + de::toString(minWidth) +
203*35238bceSAndroid Build Coastguard Worker                                      "x" + de::toString(minWidth));
204*35238bceSAndroid Build Coastguard Worker }
205*35238bceSAndroid Build Coastguard Worker 
206*35238bceSAndroid Build Coastguard Worker class PositionColorShader : public sglr::ShaderProgram
207*35238bceSAndroid Build Coastguard Worker {
208*35238bceSAndroid Build Coastguard Worker public:
209*35238bceSAndroid Build Coastguard Worker     enum
210*35238bceSAndroid Build Coastguard Worker     {
211*35238bceSAndroid Build Coastguard Worker         VARYINGLOC_COLOR = 0
212*35238bceSAndroid Build Coastguard Worker     };
213*35238bceSAndroid Build Coastguard Worker 
214*35238bceSAndroid Build Coastguard Worker     PositionColorShader(void);
215*35238bceSAndroid Build Coastguard Worker     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
216*35238bceSAndroid Build Coastguard Worker     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
217*35238bceSAndroid Build Coastguard Worker                         const rr::FragmentShadingContext &context) const;
218*35238bceSAndroid Build Coastguard Worker };
219*35238bceSAndroid Build Coastguard Worker 
PositionColorShader(void)220*35238bceSAndroid Build Coastguard Worker PositionColorShader::PositionColorShader(void)
221*35238bceSAndroid Build Coastguard Worker     : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
222*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
223*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
224*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
225*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
226*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexSource(s_shaderSourceVertex)
227*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::FragmentSource(s_shaderSourceFragment))
228*35238bceSAndroid Build Coastguard Worker {
229*35238bceSAndroid Build Coastguard Worker }
230*35238bceSAndroid Build Coastguard Worker 
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const231*35238bceSAndroid Build Coastguard Worker void PositionColorShader::shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets,
232*35238bceSAndroid Build Coastguard Worker                                         const int numPackets) const
233*35238bceSAndroid Build Coastguard Worker {
234*35238bceSAndroid Build Coastguard Worker     for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
235*35238bceSAndroid Build Coastguard Worker     {
236*35238bceSAndroid Build Coastguard Worker         const int positionAttrLoc = 0;
237*35238bceSAndroid Build Coastguard Worker         const int colorAttrLoc    = 1;
238*35238bceSAndroid Build Coastguard Worker 
239*35238bceSAndroid Build Coastguard Worker         rr::VertexPacket &packet = *packets[packetNdx];
240*35238bceSAndroid Build Coastguard Worker 
241*35238bceSAndroid Build Coastguard Worker         // Transform to position
242*35238bceSAndroid Build Coastguard Worker         packet.position = rr::readVertexAttribFloat(inputs[positionAttrLoc], packet.instanceNdx, packet.vertexNdx);
243*35238bceSAndroid Build Coastguard Worker 
244*35238bceSAndroid Build Coastguard Worker         // Pass color to FS
245*35238bceSAndroid Build Coastguard Worker         packet.outputs[VARYINGLOC_COLOR] =
246*35238bceSAndroid Build Coastguard Worker             rr::readVertexAttribFloat(inputs[colorAttrLoc], packet.instanceNdx, packet.vertexNdx);
247*35238bceSAndroid Build Coastguard Worker     }
248*35238bceSAndroid Build Coastguard Worker }
249*35238bceSAndroid Build Coastguard Worker 
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const250*35238bceSAndroid Build Coastguard Worker void PositionColorShader::shadeFragments(rr::FragmentPacket *packets, const int numPackets,
251*35238bceSAndroid Build Coastguard Worker                                          const rr::FragmentShadingContext &context) const
252*35238bceSAndroid Build Coastguard Worker {
253*35238bceSAndroid Build Coastguard Worker     for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
254*35238bceSAndroid Build Coastguard Worker     {
255*35238bceSAndroid Build Coastguard Worker         rr::FragmentPacket &packet = packets[packetNdx];
256*35238bceSAndroid Build Coastguard Worker 
257*35238bceSAndroid Build Coastguard Worker         for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
258*35238bceSAndroid Build Coastguard Worker             rr::writeFragmentOutput(context, packetNdx, fragNdx, 0,
259*35238bceSAndroid Build Coastguard Worker                                     rr::readTriangleVarying<float>(packet, context, VARYINGLOC_COLOR, fragNdx));
260*35238bceSAndroid Build Coastguard Worker     }
261*35238bceSAndroid Build Coastguard Worker }
262*35238bceSAndroid Build Coastguard Worker 
263*35238bceSAndroid Build Coastguard Worker // PolygonOffsetTestCase
264*35238bceSAndroid Build Coastguard Worker 
265*35238bceSAndroid Build Coastguard Worker class PolygonOffsetTestCase : public TestCase
266*35238bceSAndroid Build Coastguard Worker {
267*35238bceSAndroid Build Coastguard Worker public:
268*35238bceSAndroid Build Coastguard Worker     PolygonOffsetTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
269*35238bceSAndroid Build Coastguard Worker                           const char *internalFormatName, int canvasSize);
270*35238bceSAndroid Build Coastguard Worker 
271*35238bceSAndroid Build Coastguard Worker     virtual void testPolygonOffset(void) = DE_NULL;
272*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
273*35238bceSAndroid Build Coastguard Worker 
274*35238bceSAndroid Build Coastguard Worker protected:
275*35238bceSAndroid Build Coastguard Worker     const GLenum m_internalFormat;
276*35238bceSAndroid Build Coastguard Worker     const char *m_internalFormatName;
277*35238bceSAndroid Build Coastguard Worker     const int m_targetSize;
278*35238bceSAndroid Build Coastguard Worker };
279*35238bceSAndroid Build Coastguard Worker 
PolygonOffsetTestCase(Context & context,const char * name,const char * description,GLenum internalFormat,const char * internalFormatName,int canvasSize)280*35238bceSAndroid Build Coastguard Worker PolygonOffsetTestCase::PolygonOffsetTestCase(Context &context, const char *name, const char *description,
281*35238bceSAndroid Build Coastguard Worker                                              GLenum internalFormat, const char *internalFormatName, int canvasSize)
282*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
283*35238bceSAndroid Build Coastguard Worker     , m_internalFormat(internalFormat)
284*35238bceSAndroid Build Coastguard Worker     , m_internalFormatName(internalFormatName)
285*35238bceSAndroid Build Coastguard Worker     , m_targetSize(canvasSize)
286*35238bceSAndroid Build Coastguard Worker {
287*35238bceSAndroid Build Coastguard Worker }
288*35238bceSAndroid Build Coastguard Worker 
iterate(void)289*35238bceSAndroid Build Coastguard Worker PolygonOffsetTestCase::IterateResult PolygonOffsetTestCase::iterate(void)
290*35238bceSAndroid Build Coastguard Worker {
291*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
292*35238bceSAndroid Build Coastguard Worker     m_testCtx.getLog() << tcu::TestLog::Message << "Testing PolygonOffset with " << m_internalFormatName
293*35238bceSAndroid Build Coastguard Worker                        << " depth buffer." << tcu::TestLog::EndMessage;
294*35238bceSAndroid Build Coastguard Worker 
295*35238bceSAndroid Build Coastguard Worker     if (m_internalFormat == 0)
296*35238bceSAndroid Build Coastguard Worker     {
297*35238bceSAndroid Build Coastguard Worker         // default framebuffer
298*35238bceSAndroid Build Coastguard Worker         const int width  = m_context.getRenderTarget().getWidth();
299*35238bceSAndroid Build Coastguard Worker         const int height = m_context.getRenderTarget().getHeight();
300*35238bceSAndroid Build Coastguard Worker 
301*35238bceSAndroid Build Coastguard Worker         checkCanvasSize(width, height, m_targetSize, m_targetSize);
302*35238bceSAndroid Build Coastguard Worker 
303*35238bceSAndroid Build Coastguard Worker         if (m_context.getRenderTarget().getDepthBits() == 0)
304*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("polygon offset tests require depth buffer");
305*35238bceSAndroid Build Coastguard Worker 
306*35238bceSAndroid Build Coastguard Worker         testPolygonOffset();
307*35238bceSAndroid Build Coastguard Worker     }
308*35238bceSAndroid Build Coastguard Worker     else
309*35238bceSAndroid Build Coastguard Worker     {
310*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
311*35238bceSAndroid Build Coastguard Worker 
312*35238bceSAndroid Build Coastguard Worker         // framebuffer object
313*35238bceSAndroid Build Coastguard Worker         GLuint colorRboId = 0;
314*35238bceSAndroid Build Coastguard Worker         GLuint depthRboId = 0;
315*35238bceSAndroid Build Coastguard Worker         GLuint fboId      = 0;
316*35238bceSAndroid Build Coastguard Worker         bool fboComplete;
317*35238bceSAndroid Build Coastguard Worker 
318*35238bceSAndroid Build Coastguard Worker         gl.genRenderbuffers(1, &colorRboId);
319*35238bceSAndroid Build Coastguard Worker         gl.bindRenderbuffer(GL_RENDERBUFFER, colorRboId);
320*35238bceSAndroid Build Coastguard Worker         gl.renderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, m_targetSize, m_targetSize);
321*35238bceSAndroid Build Coastguard Worker         verifyError(m_testCtx, gl, GL_NO_ERROR);
322*35238bceSAndroid Build Coastguard Worker 
323*35238bceSAndroid Build Coastguard Worker         gl.genRenderbuffers(1, &depthRboId);
324*35238bceSAndroid Build Coastguard Worker         gl.bindRenderbuffer(GL_RENDERBUFFER, depthRboId);
325*35238bceSAndroid Build Coastguard Worker         gl.renderbufferStorage(GL_RENDERBUFFER, m_internalFormat, m_targetSize, m_targetSize);
326*35238bceSAndroid Build Coastguard Worker         verifyError(m_testCtx, gl, GL_NO_ERROR);
327*35238bceSAndroid Build Coastguard Worker 
328*35238bceSAndroid Build Coastguard Worker         gl.genFramebuffers(1, &fboId);
329*35238bceSAndroid Build Coastguard Worker         gl.bindFramebuffer(GL_FRAMEBUFFER, fboId);
330*35238bceSAndroid Build Coastguard Worker         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRboId);
331*35238bceSAndroid Build Coastguard Worker         gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRboId);
332*35238bceSAndroid Build Coastguard Worker         verifyError(m_testCtx, gl, GL_NO_ERROR);
333*35238bceSAndroid Build Coastguard Worker 
334*35238bceSAndroid Build Coastguard Worker         fboComplete = gl.checkFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
335*35238bceSAndroid Build Coastguard Worker 
336*35238bceSAndroid Build Coastguard Worker         if (fboComplete)
337*35238bceSAndroid Build Coastguard Worker             testPolygonOffset();
338*35238bceSAndroid Build Coastguard Worker 
339*35238bceSAndroid Build Coastguard Worker         gl.deleteFramebuffers(1, &fboId);
340*35238bceSAndroid Build Coastguard Worker         gl.deleteRenderbuffers(1, &depthRboId);
341*35238bceSAndroid Build Coastguard Worker         gl.deleteRenderbuffers(1, &colorRboId);
342*35238bceSAndroid Build Coastguard Worker 
343*35238bceSAndroid Build Coastguard Worker         if (!fboComplete)
344*35238bceSAndroid Build Coastguard Worker             throw tcu::NotSupportedError("could not create fbo for testing.");
345*35238bceSAndroid Build Coastguard Worker     }
346*35238bceSAndroid Build Coastguard Worker 
347*35238bceSAndroid Build Coastguard Worker     return STOP;
348*35238bceSAndroid Build Coastguard Worker }
349*35238bceSAndroid Build Coastguard Worker 
350*35238bceSAndroid Build Coastguard Worker // UsageTestCase
351*35238bceSAndroid Build Coastguard Worker 
352*35238bceSAndroid Build Coastguard Worker class UsageTestCase : public PolygonOffsetTestCase
353*35238bceSAndroid Build Coastguard Worker {
354*35238bceSAndroid Build Coastguard Worker public:
355*35238bceSAndroid Build Coastguard Worker     UsageTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
356*35238bceSAndroid Build Coastguard Worker                   const char *internalFormatName);
357*35238bceSAndroid Build Coastguard Worker 
358*35238bceSAndroid Build Coastguard Worker     void testPolygonOffset(void);
359*35238bceSAndroid Build Coastguard Worker };
360*35238bceSAndroid Build Coastguard Worker 
UsageTestCase(Context & context,const char * name,const char * description,GLenum internalFormat,const char * internalFormatName)361*35238bceSAndroid Build Coastguard Worker UsageTestCase::UsageTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
362*35238bceSAndroid Build Coastguard Worker                              const char *internalFormatName)
363*35238bceSAndroid Build Coastguard Worker     : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
364*35238bceSAndroid Build Coastguard Worker {
365*35238bceSAndroid Build Coastguard Worker }
366*35238bceSAndroid Build Coastguard Worker 
testPolygonOffset(void)367*35238bceSAndroid Build Coastguard Worker void UsageTestCase::testPolygonOffset(void)
368*35238bceSAndroid Build Coastguard Worker {
369*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
370*35238bceSAndroid Build Coastguard Worker 
371*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangle[] = {
372*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, 1, 0, 1),
373*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, 1, 0, 1),
374*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, -1, 0, 1),
375*35238bceSAndroid Build Coastguard Worker     };
376*35238bceSAndroid Build Coastguard Worker 
377*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
378*35238bceSAndroid Build Coastguard Worker     tcu::Surface testImage(m_targetSize, m_targetSize);
379*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceImage(m_targetSize, m_targetSize);
380*35238bceSAndroid Build Coastguard Worker     int subpixelBits = 0;
381*35238bceSAndroid Build Coastguard Worker 
382*35238bceSAndroid Build Coastguard Worker     // render test image
383*35238bceSAndroid Build Coastguard Worker     {
384*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
385*35238bceSAndroid Build Coastguard Worker         const glu::ShaderProgram program(m_context.getRenderContext(),
386*35238bceSAndroid Build Coastguard Worker                                          glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
387*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
388*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc    = gl.getAttribLocation(program.getProgram(), "a_color");
389*35238bceSAndroid Build Coastguard Worker 
390*35238bceSAndroid Build Coastguard Worker         if (!program.isOk())
391*35238bceSAndroid Build Coastguard Worker         {
392*35238bceSAndroid Build Coastguard Worker             log << program;
393*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Shader compile failed.");
394*35238bceSAndroid Build Coastguard Worker         }
395*35238bceSAndroid Build Coastguard Worker 
396*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0, 0, 0, 1);
397*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(1.0f);
398*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
399*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, m_targetSize, m_targetSize);
400*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program.getProgram());
401*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
402*35238bceSAndroid Build Coastguard Worker         gl.depthFunc(
403*35238bceSAndroid Build Coastguard Worker             GL_LEQUAL); // make test pass if polygon offset doesn't do anything. It has its own test case. This test is only for to detect always-on cases.
404*35238bceSAndroid Build Coastguard Worker 
405*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "DepthFunc = GL_LEQUAL" << TestLog::EndMessage;
406*35238bceSAndroid Build Coastguard Worker 
407*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(positionLoc);
408*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangle);
409*35238bceSAndroid Build Coastguard Worker 
410*35238bceSAndroid Build Coastguard Worker         //draw back (offset disabled)
411*35238bceSAndroid Build Coastguard Worker 
412*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message
413*35238bceSAndroid Build Coastguard Worker             << "Draw bottom-right. Color = White.\tState: PolygonOffset(0, -2), POLYGON_OFFSET_FILL disabled."
414*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
415*35238bceSAndroid Build Coastguard Worker 
416*35238bceSAndroid Build Coastguard Worker         gl.polygonOffset(0, -2);
417*35238bceSAndroid Build Coastguard Worker         gl.disable(GL_POLYGON_OFFSET_FILL);
418*35238bceSAndroid Build Coastguard Worker         gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
419*35238bceSAndroid Build Coastguard Worker         gl.drawArrays(GL_TRIANGLES, 0, 3);
420*35238bceSAndroid Build Coastguard Worker 
421*35238bceSAndroid Build Coastguard Worker         //draw front
422*35238bceSAndroid Build Coastguard Worker 
423*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message
424*35238bceSAndroid Build Coastguard Worker             << "Draw bottom-right. Color = Red.\tState: PolygonOffset(0, -1), POLYGON_OFFSET_FILL enabled."
425*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
426*35238bceSAndroid Build Coastguard Worker 
427*35238bceSAndroid Build Coastguard Worker         gl.polygonOffset(0, -1);
428*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_POLYGON_OFFSET_FILL);
429*35238bceSAndroid Build Coastguard Worker         gl.vertexAttrib4f(colorLoc, 1.0f, 0.0f, 0.0f, 1.0f);
430*35238bceSAndroid Build Coastguard Worker         gl.drawArrays(GL_TRIANGLES, 0, 3);
431*35238bceSAndroid Build Coastguard Worker 
432*35238bceSAndroid Build Coastguard Worker         gl.disableVertexAttribArray(positionLoc);
433*35238bceSAndroid Build Coastguard Worker         gl.useProgram(0);
434*35238bceSAndroid Build Coastguard Worker         gl.finish();
435*35238bceSAndroid Build Coastguard Worker 
436*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
437*35238bceSAndroid Build Coastguard Worker 
438*35238bceSAndroid Build Coastguard Worker         gl.getIntegerv(GL_SUBPIXEL_BITS, &subpixelBits);
439*35238bceSAndroid Build Coastguard Worker     }
440*35238bceSAndroid Build Coastguard Worker 
441*35238bceSAndroid Build Coastguard Worker     // render reference image
442*35238bceSAndroid Build Coastguard Worker     {
443*35238bceSAndroid Build Coastguard Worker         rr::Renderer referenceRenderer;
444*35238bceSAndroid Build Coastguard Worker         rr::VertexAttrib attribs[2];
445*35238bceSAndroid Build Coastguard Worker         rr::RenderState state((rr::ViewportState)(rr::WindowRectangle(0, 0, m_targetSize, m_targetSize)), subpixelBits);
446*35238bceSAndroid Build Coastguard Worker 
447*35238bceSAndroid Build Coastguard Worker         PositionColorShader program;
448*35238bceSAndroid Build Coastguard Worker 
449*35238bceSAndroid Build Coastguard Worker         attribs[0].type            = rr::VERTEXATTRIBTYPE_FLOAT;
450*35238bceSAndroid Build Coastguard Worker         attribs[0].size            = 4;
451*35238bceSAndroid Build Coastguard Worker         attribs[0].stride          = 0;
452*35238bceSAndroid Build Coastguard Worker         attribs[0].instanceDivisor = 0;
453*35238bceSAndroid Build Coastguard Worker         attribs[0].pointer         = triangle;
454*35238bceSAndroid Build Coastguard Worker 
455*35238bceSAndroid Build Coastguard Worker         attribs[1].type    = rr::VERTEXATTRIBTYPE_DONT_CARE;
456*35238bceSAndroid Build Coastguard Worker         attribs[1].generic = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
457*35238bceSAndroid Build Coastguard Worker 
458*35238bceSAndroid Build Coastguard Worker         tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
459*35238bceSAndroid Build Coastguard Worker 
460*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Expecting: Bottom-right = Red." << TestLog::EndMessage;
461*35238bceSAndroid Build Coastguard Worker 
462*35238bceSAndroid Build Coastguard Worker         referenceRenderer.draw(rr::DrawCommand(
463*35238bceSAndroid Build Coastguard Worker             state,
464*35238bceSAndroid Build Coastguard Worker             rr::RenderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(referenceImage.getAccess())),
465*35238bceSAndroid Build Coastguard Worker             rr::Program(program.getVertexShader(), program.getFragmentShader()), 2, attribs,
466*35238bceSAndroid Build Coastguard Worker             rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, 3, 0)));
467*35238bceSAndroid Build Coastguard Worker     }
468*35238bceSAndroid Build Coastguard Worker 
469*35238bceSAndroid Build Coastguard Worker     // compare
470*35238bceSAndroid Build Coastguard Worker     verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
471*35238bceSAndroid Build Coastguard Worker }
472*35238bceSAndroid Build Coastguard Worker 
473*35238bceSAndroid Build Coastguard Worker // UsageDisplacementTestCase
474*35238bceSAndroid Build Coastguard Worker 
475*35238bceSAndroid Build Coastguard Worker class UsageDisplacementTestCase : public PolygonOffsetTestCase
476*35238bceSAndroid Build Coastguard Worker {
477*35238bceSAndroid Build Coastguard Worker public:
478*35238bceSAndroid Build Coastguard Worker     UsageDisplacementTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
479*35238bceSAndroid Build Coastguard Worker                               const char *internalFormatName);
480*35238bceSAndroid Build Coastguard Worker 
481*35238bceSAndroid Build Coastguard Worker private:
482*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 genRandomVec4(de::Random &rnd) const;
483*35238bceSAndroid Build Coastguard Worker     void testPolygonOffset(void);
484*35238bceSAndroid Build Coastguard Worker };
485*35238bceSAndroid Build Coastguard Worker 
UsageDisplacementTestCase(Context & context,const char * name,const char * description,GLenum internalFormat,const char * internalFormatName)486*35238bceSAndroid Build Coastguard Worker UsageDisplacementTestCase::UsageDisplacementTestCase(Context &context, const char *name, const char *description,
487*35238bceSAndroid Build Coastguard Worker                                                      GLenum internalFormat, const char *internalFormatName)
488*35238bceSAndroid Build Coastguard Worker     : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
489*35238bceSAndroid Build Coastguard Worker {
490*35238bceSAndroid Build Coastguard Worker }
491*35238bceSAndroid Build Coastguard Worker 
genRandomVec4(de::Random & rnd) const492*35238bceSAndroid Build Coastguard Worker tcu::Vec4 UsageDisplacementTestCase::genRandomVec4(de::Random &rnd) const
493*35238bceSAndroid Build Coastguard Worker {
494*35238bceSAndroid Build Coastguard Worker     // generater triangle endpoint with following properties
495*35238bceSAndroid Build Coastguard Worker     //    1) it will not be clipped
496*35238bceSAndroid Build Coastguard Worker     //    2) it is not near either far or near plane to prevent possible problems related to depth clamping
497*35238bceSAndroid Build Coastguard Worker     // => w >= 1.0 and z in (-0.9, 0.9) range
498*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 retVal;
499*35238bceSAndroid Build Coastguard Worker 
500*35238bceSAndroid Build Coastguard Worker     retVal.x() = rnd.getFloat(-1, 1);
501*35238bceSAndroid Build Coastguard Worker     retVal.y() = rnd.getFloat(-1, 1);
502*35238bceSAndroid Build Coastguard Worker     retVal.z() = 0.5f;
503*35238bceSAndroid Build Coastguard Worker     retVal.w() = 1.0f + rnd.getFloat();
504*35238bceSAndroid Build Coastguard Worker 
505*35238bceSAndroid Build Coastguard Worker     return retVal;
506*35238bceSAndroid Build Coastguard Worker }
507*35238bceSAndroid Build Coastguard Worker 
testPolygonOffset(void)508*35238bceSAndroid Build Coastguard Worker void UsageDisplacementTestCase::testPolygonOffset(void)
509*35238bceSAndroid Build Coastguard Worker {
510*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
511*35238bceSAndroid Build Coastguard Worker 
512*35238bceSAndroid Build Coastguard Worker     de::Random rnd(0xdec0de);
513*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
514*35238bceSAndroid Build Coastguard Worker     tcu::Surface testImage(m_targetSize, m_targetSize);
515*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceImage(m_targetSize, m_targetSize);
516*35238bceSAndroid Build Coastguard Worker 
517*35238bceSAndroid Build Coastguard Worker     // render test image
518*35238bceSAndroid Build Coastguard Worker     {
519*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
520*35238bceSAndroid Build Coastguard Worker         const glu::ShaderProgram program(m_context.getRenderContext(),
521*35238bceSAndroid Build Coastguard Worker                                          glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
522*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
523*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc    = gl.getAttribLocation(program.getProgram(), "a_color");
524*35238bceSAndroid Build Coastguard Worker         const int numIterations = 40;
525*35238bceSAndroid Build Coastguard Worker 
526*35238bceSAndroid Build Coastguard Worker         if (!program.isOk())
527*35238bceSAndroid Build Coastguard Worker         {
528*35238bceSAndroid Build Coastguard Worker             log << program;
529*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Shader compile failed.");
530*35238bceSAndroid Build Coastguard Worker         }
531*35238bceSAndroid Build Coastguard Worker 
532*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0, 0, 0, 1);
533*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(1.0f);
534*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
535*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, m_targetSize, m_targetSize);
536*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program.getProgram());
537*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
538*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_POLYGON_OFFSET_FILL);
539*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(positionLoc);
540*35238bceSAndroid Build Coastguard Worker         gl.vertexAttrib4f(colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
541*35238bceSAndroid Build Coastguard Worker 
542*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Framebuffer cleared, clear color = Black." << TestLog::EndMessage;
543*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
544*35238bceSAndroid Build Coastguard Worker 
545*35238bceSAndroid Build Coastguard Worker         // draw colorless (mask = 0,0,0) triangle at random* location, set offset and render green triangle with depthfunc = equal
546*35238bceSAndroid Build Coastguard Worker         // *) w >= 1.0 and z in (-1, 1) range
547*35238bceSAndroid Build Coastguard Worker         for (int iterationNdx = 0; iterationNdx < numIterations; ++iterationNdx)
548*35238bceSAndroid Build Coastguard Worker         {
549*35238bceSAndroid Build Coastguard Worker             const bool offsetDirection = rnd.getBool();
550*35238bceSAndroid Build Coastguard Worker             const float offset         = offsetDirection ? -1.0f : 1.0f;
551*35238bceSAndroid Build Coastguard Worker             tcu::Vec4 triangle[3];
552*35238bceSAndroid Build Coastguard Worker 
553*35238bceSAndroid Build Coastguard Worker             for (int vertexNdx = 0; vertexNdx < DE_LENGTH_OF_ARRAY(triangle); ++vertexNdx)
554*35238bceSAndroid Build Coastguard Worker                 triangle[vertexNdx] = genRandomVec4(rnd);
555*35238bceSAndroid Build Coastguard Worker 
556*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangle);
557*35238bceSAndroid Build Coastguard Worker 
558*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Setup triangle with random coordinates:" << TestLog::EndMessage;
559*35238bceSAndroid Build Coastguard Worker             for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(triangle); ++ndx)
560*35238bceSAndroid Build Coastguard Worker                 log << TestLog::Message << "\tx=" << triangle[ndx].x() << "\ty=" << triangle[ndx].y()
561*35238bceSAndroid Build Coastguard Worker                     << "\tz=" << triangle[ndx].z() << "\tw=" << triangle[ndx].w() << TestLog::EndMessage;
562*35238bceSAndroid Build Coastguard Worker 
563*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw colorless triangle.\tState: DepthFunc = GL_ALWAYS, PolygonOffset(0, 0)."
564*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
565*35238bceSAndroid Build Coastguard Worker 
566*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_ALWAYS);
567*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 0);
568*35238bceSAndroid Build Coastguard Worker             gl.colorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
569*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
570*35238bceSAndroid Build Coastguard Worker 
571*35238bceSAndroid Build Coastguard Worker             // all fragments should have different Z => DepthFunc == GL_EQUAL fails with every fragment
572*35238bceSAndroid Build Coastguard Worker 
573*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw green triangle.\tState: DepthFunc = GL_EQUAL, PolygonOffset(0, " << offset
574*35238bceSAndroid Build Coastguard Worker                 << ")." << TestLog::EndMessage;
575*35238bceSAndroid Build Coastguard Worker 
576*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_EQUAL);
577*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, offset);
578*35238bceSAndroid Build Coastguard Worker             gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
579*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
580*35238bceSAndroid Build Coastguard Worker 
581*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << TestLog::EndMessage; // empty line for clarity
582*35238bceSAndroid Build Coastguard Worker         }
583*35238bceSAndroid Build Coastguard Worker 
584*35238bceSAndroid Build Coastguard Worker         gl.disableVertexAttribArray(positionLoc);
585*35238bceSAndroid Build Coastguard Worker         gl.useProgram(0);
586*35238bceSAndroid Build Coastguard Worker         gl.finish();
587*35238bceSAndroid Build Coastguard Worker 
588*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
589*35238bceSAndroid Build Coastguard Worker     }
590*35238bceSAndroid Build Coastguard Worker 
591*35238bceSAndroid Build Coastguard Worker     // render reference image
592*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Expecting black framebuffer." << TestLog::EndMessage;
593*35238bceSAndroid Build Coastguard Worker     tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
594*35238bceSAndroid Build Coastguard Worker 
595*35238bceSAndroid Build Coastguard Worker     // compare
596*35238bceSAndroid Build Coastguard Worker     verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
597*35238bceSAndroid Build Coastguard Worker }
598*35238bceSAndroid Build Coastguard Worker 
599*35238bceSAndroid Build Coastguard Worker // UsagePositiveNegativeTestCase
600*35238bceSAndroid Build Coastguard Worker 
601*35238bceSAndroid Build Coastguard Worker class UsagePositiveNegativeTestCase : public PolygonOffsetTestCase
602*35238bceSAndroid Build Coastguard Worker {
603*35238bceSAndroid Build Coastguard Worker public:
604*35238bceSAndroid Build Coastguard Worker     UsagePositiveNegativeTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
605*35238bceSAndroid Build Coastguard Worker                                   const char *internalFormatName);
606*35238bceSAndroid Build Coastguard Worker 
607*35238bceSAndroid Build Coastguard Worker     void testPolygonOffset(void);
608*35238bceSAndroid Build Coastguard Worker };
609*35238bceSAndroid Build Coastguard Worker 
UsagePositiveNegativeTestCase(Context & context,const char * name,const char * description,GLenum internalFormat,const char * internalFormatName)610*35238bceSAndroid Build Coastguard Worker UsagePositiveNegativeTestCase::UsagePositiveNegativeTestCase(Context &context, const char *name,
611*35238bceSAndroid Build Coastguard Worker                                                              const char *description, GLenum internalFormat,
612*35238bceSAndroid Build Coastguard Worker                                                              const char *internalFormatName)
613*35238bceSAndroid Build Coastguard Worker     : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
614*35238bceSAndroid Build Coastguard Worker {
615*35238bceSAndroid Build Coastguard Worker }
616*35238bceSAndroid Build Coastguard Worker 
testPolygonOffset(void)617*35238bceSAndroid Build Coastguard Worker void UsagePositiveNegativeTestCase::testPolygonOffset(void)
618*35238bceSAndroid Build Coastguard Worker {
619*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
620*35238bceSAndroid Build Coastguard Worker 
621*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangleBottomRight[] = {
622*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, 1, 0, 1),
623*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, 1, 0, 1),
624*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, -1, 0, 1),
625*35238bceSAndroid Build Coastguard Worker     };
626*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangleTopLeft[] = {
627*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, -1, 0, 1),
628*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, 1, 0, 1),
629*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, -1, 0, 1),
630*35238bceSAndroid Build Coastguard Worker     };
631*35238bceSAndroid Build Coastguard Worker 
632*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
633*35238bceSAndroid Build Coastguard Worker     tcu::Surface testImage(m_targetSize, m_targetSize);
634*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceImage(m_targetSize, m_targetSize);
635*35238bceSAndroid Build Coastguard Worker     int subpixelBits = 0;
636*35238bceSAndroid Build Coastguard Worker     // render test image
637*35238bceSAndroid Build Coastguard Worker     {
638*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
639*35238bceSAndroid Build Coastguard Worker         const glu::ShaderProgram program(m_context.getRenderContext(),
640*35238bceSAndroid Build Coastguard Worker                                          glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
641*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
642*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc    = gl.getAttribLocation(program.getProgram(), "a_color");
643*35238bceSAndroid Build Coastguard Worker 
644*35238bceSAndroid Build Coastguard Worker         if (!program.isOk())
645*35238bceSAndroid Build Coastguard Worker         {
646*35238bceSAndroid Build Coastguard Worker             log << program;
647*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Shader compile failed.");
648*35238bceSAndroid Build Coastguard Worker         }
649*35238bceSAndroid Build Coastguard Worker 
650*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0, 0, 0, 1);
651*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(1.0f);
652*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
653*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, m_targetSize, m_targetSize);
654*35238bceSAndroid Build Coastguard Worker         gl.depthFunc(GL_LESS);
655*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program.getProgram());
656*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
657*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_POLYGON_OFFSET_FILL);
658*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(positionLoc);
659*35238bceSAndroid Build Coastguard Worker 
660*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "DepthFunc = GL_LESS." << TestLog::EndMessage;
661*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
662*35238bceSAndroid Build Coastguard Worker 
663*35238bceSAndroid Build Coastguard Worker         //draw top left (negative offset test)
664*35238bceSAndroid Build Coastguard Worker         {
665*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleTopLeft);
666*35238bceSAndroid Build Coastguard Worker 
667*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw top-left. Color = White.\tState: PolygonOffset(0, 0)."
668*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
669*35238bceSAndroid Build Coastguard Worker 
670*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 0);
671*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
672*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
673*35238bceSAndroid Build Coastguard Worker 
674*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw top-left. Color = Green.\tState: PolygonOffset(0, -1)."
675*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
676*35238bceSAndroid Build Coastguard Worker 
677*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, -1);
678*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
679*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
680*35238bceSAndroid Build Coastguard Worker         }
681*35238bceSAndroid Build Coastguard Worker 
682*35238bceSAndroid Build Coastguard Worker         //draw bottom right (positive offset test)
683*35238bceSAndroid Build Coastguard Worker         {
684*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleBottomRight);
685*35238bceSAndroid Build Coastguard Worker 
686*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw bottom-right. Color = White.\tState: PolygonOffset(0, 1)."
687*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
688*35238bceSAndroid Build Coastguard Worker 
689*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 1);
690*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
691*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
692*35238bceSAndroid Build Coastguard Worker 
693*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw bottom-right. Color = Yellow.\tState: PolygonOffset(0, 0)."
694*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
695*35238bceSAndroid Build Coastguard Worker 
696*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 0);
697*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 0.0f, 1.0f);
698*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
699*35238bceSAndroid Build Coastguard Worker         }
700*35238bceSAndroid Build Coastguard Worker 
701*35238bceSAndroid Build Coastguard Worker         gl.disableVertexAttribArray(positionLoc);
702*35238bceSAndroid Build Coastguard Worker         gl.useProgram(0);
703*35238bceSAndroid Build Coastguard Worker         gl.finish();
704*35238bceSAndroid Build Coastguard Worker 
705*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
706*35238bceSAndroid Build Coastguard Worker 
707*35238bceSAndroid Build Coastguard Worker         gl.getIntegerv(GL_SUBPIXEL_BITS, &subpixelBits);
708*35238bceSAndroid Build Coastguard Worker     }
709*35238bceSAndroid Build Coastguard Worker 
710*35238bceSAndroid Build Coastguard Worker     // render reference image
711*35238bceSAndroid Build Coastguard Worker     {
712*35238bceSAndroid Build Coastguard Worker         rr::Renderer referenceRenderer;
713*35238bceSAndroid Build Coastguard Worker         rr::VertexAttrib attribs[2];
714*35238bceSAndroid Build Coastguard Worker         rr::RenderState state((rr::ViewportState)(rr::WindowRectangle(0, 0, m_targetSize, m_targetSize)), subpixelBits);
715*35238bceSAndroid Build Coastguard Worker 
716*35238bceSAndroid Build Coastguard Worker         PositionColorShader program;
717*35238bceSAndroid Build Coastguard Worker 
718*35238bceSAndroid Build Coastguard Worker         attribs[0].type            = rr::VERTEXATTRIBTYPE_FLOAT;
719*35238bceSAndroid Build Coastguard Worker         attribs[0].size            = 4;
720*35238bceSAndroid Build Coastguard Worker         attribs[0].stride          = 0;
721*35238bceSAndroid Build Coastguard Worker         attribs[0].instanceDivisor = 0;
722*35238bceSAndroid Build Coastguard Worker         attribs[0].pointer         = triangleTopLeft;
723*35238bceSAndroid Build Coastguard Worker 
724*35238bceSAndroid Build Coastguard Worker         attribs[1].type    = rr::VERTEXATTRIBTYPE_DONT_CARE;
725*35238bceSAndroid Build Coastguard Worker         attribs[1].generic = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
726*35238bceSAndroid Build Coastguard Worker 
727*35238bceSAndroid Build Coastguard Worker         tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
728*35238bceSAndroid Build Coastguard Worker 
729*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Expecting: Top-left = Green, Bottom-right = Yellow." << TestLog::EndMessage;
730*35238bceSAndroid Build Coastguard Worker 
731*35238bceSAndroid Build Coastguard Worker         referenceRenderer.draw(rr::DrawCommand(
732*35238bceSAndroid Build Coastguard Worker             state,
733*35238bceSAndroid Build Coastguard Worker             rr::RenderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(referenceImage.getAccess())),
734*35238bceSAndroid Build Coastguard Worker             rr::Program(program.getVertexShader(), program.getFragmentShader()), 2, attribs,
735*35238bceSAndroid Build Coastguard Worker             rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, 3, 0)));
736*35238bceSAndroid Build Coastguard Worker 
737*35238bceSAndroid Build Coastguard Worker         attribs[0].pointer = triangleBottomRight;
738*35238bceSAndroid Build Coastguard Worker         attribs[1].generic = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
739*35238bceSAndroid Build Coastguard Worker 
740*35238bceSAndroid Build Coastguard Worker         referenceRenderer.draw(rr::DrawCommand(
741*35238bceSAndroid Build Coastguard Worker             state,
742*35238bceSAndroid Build Coastguard Worker             rr::RenderTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(referenceImage.getAccess())),
743*35238bceSAndroid Build Coastguard Worker             rr::Program(program.getVertexShader(), program.getFragmentShader()), 2, attribs,
744*35238bceSAndroid Build Coastguard Worker             rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, 3, 0)));
745*35238bceSAndroid Build Coastguard Worker     }
746*35238bceSAndroid Build Coastguard Worker 
747*35238bceSAndroid Build Coastguard Worker     // compare
748*35238bceSAndroid Build Coastguard Worker     verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
749*35238bceSAndroid Build Coastguard Worker }
750*35238bceSAndroid Build Coastguard Worker 
751*35238bceSAndroid Build Coastguard Worker // ResultClampingTestCase
752*35238bceSAndroid Build Coastguard Worker 
753*35238bceSAndroid Build Coastguard Worker class ResultClampingTestCase : public PolygonOffsetTestCase
754*35238bceSAndroid Build Coastguard Worker {
755*35238bceSAndroid Build Coastguard Worker public:
756*35238bceSAndroid Build Coastguard Worker     ResultClampingTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
757*35238bceSAndroid Build Coastguard Worker                            const char *internalFormatName);
758*35238bceSAndroid Build Coastguard Worker 
759*35238bceSAndroid Build Coastguard Worker     void testPolygonOffset(void);
760*35238bceSAndroid Build Coastguard Worker };
761*35238bceSAndroid Build Coastguard Worker 
ResultClampingTestCase(Context & context,const char * name,const char * description,GLenum internalFormat,const char * internalFormatName)762*35238bceSAndroid Build Coastguard Worker ResultClampingTestCase::ResultClampingTestCase(Context &context, const char *name, const char *description,
763*35238bceSAndroid Build Coastguard Worker                                                GLenum internalFormat, const char *internalFormatName)
764*35238bceSAndroid Build Coastguard Worker     : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
765*35238bceSAndroid Build Coastguard Worker {
766*35238bceSAndroid Build Coastguard Worker }
767*35238bceSAndroid Build Coastguard Worker 
testPolygonOffset(void)768*35238bceSAndroid Build Coastguard Worker void ResultClampingTestCase::testPolygonOffset(void)
769*35238bceSAndroid Build Coastguard Worker {
770*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
771*35238bceSAndroid Build Coastguard Worker 
772*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangleBottomRight[] = {
773*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, 1, 1, 1),
774*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, 1, 1, 1),
775*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, -1, 1, 1),
776*35238bceSAndroid Build Coastguard Worker     };
777*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangleTopLeft[] = {
778*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, -1, -1, 1),
779*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, 1, -1, 1),
780*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, -1, -1, 1),
781*35238bceSAndroid Build Coastguard Worker     };
782*35238bceSAndroid Build Coastguard Worker 
783*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
784*35238bceSAndroid Build Coastguard Worker     tcu::Surface testImage(m_targetSize, m_targetSize);
785*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceImage(m_targetSize, m_targetSize);
786*35238bceSAndroid Build Coastguard Worker 
787*35238bceSAndroid Build Coastguard Worker     // render test image
788*35238bceSAndroid Build Coastguard Worker     {
789*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
790*35238bceSAndroid Build Coastguard Worker         const glu::ShaderProgram program(m_context.getRenderContext(),
791*35238bceSAndroid Build Coastguard Worker                                          glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
792*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
793*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc    = gl.getAttribLocation(program.getProgram(), "a_color");
794*35238bceSAndroid Build Coastguard Worker 
795*35238bceSAndroid Build Coastguard Worker         if (!program.isOk())
796*35238bceSAndroid Build Coastguard Worker         {
797*35238bceSAndroid Build Coastguard Worker             log << program;
798*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Shader compile failed.");
799*35238bceSAndroid Build Coastguard Worker         }
800*35238bceSAndroid Build Coastguard Worker 
801*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0, 0, 0, 1);
802*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(1.0f);
803*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
804*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, m_targetSize, m_targetSize);
805*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program.getProgram());
806*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
807*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_POLYGON_OFFSET_FILL);
808*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(positionLoc);
809*35238bceSAndroid Build Coastguard Worker 
810*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
811*35238bceSAndroid Build Coastguard Worker 
812*35238bceSAndroid Build Coastguard Worker         //draw bottom right (far)
813*35238bceSAndroid Build Coastguard Worker         {
814*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleBottomRight);
815*35238bceSAndroid Build Coastguard Worker 
816*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message
817*35238bceSAndroid Build Coastguard Worker                 << "Draw bottom-right. Color = White.\tState: DepthFunc = ALWAYS, PolygonOffset(0, 8), Polygon Z = "
818*35238bceSAndroid Build Coastguard Worker                    "1.0. (Result depth should clamp to 1.0)."
819*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
820*35238bceSAndroid Build Coastguard Worker 
821*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_ALWAYS);
822*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 8);
823*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
824*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
825*35238bceSAndroid Build Coastguard Worker 
826*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message
827*35238bceSAndroid Build Coastguard Worker                 << "Draw bottom-right. Color = Red.\tState: DepthFunc = GREATER, PolygonOffset(0, 9), Polygon Z = 1.0. "
828*35238bceSAndroid Build Coastguard Worker                    "(Result depth should clamp to 1.0 too)"
829*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
830*35238bceSAndroid Build Coastguard Worker 
831*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_GREATER);
832*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 9);
833*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 0.0f, 0.0f, 1.0f);
834*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
835*35238bceSAndroid Build Coastguard Worker         }
836*35238bceSAndroid Build Coastguard Worker 
837*35238bceSAndroid Build Coastguard Worker         //draw top left (near)
838*35238bceSAndroid Build Coastguard Worker         {
839*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleTopLeft);
840*35238bceSAndroid Build Coastguard Worker 
841*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message
842*35238bceSAndroid Build Coastguard Worker                 << "Draw top-left. Color = White.\tState: DepthFunc = ALWAYS, PolygonOffset(0, -8), Polygon Z = -1.0. "
843*35238bceSAndroid Build Coastguard Worker                    "(Result depth should clamp to -1.0)"
844*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
845*35238bceSAndroid Build Coastguard Worker 
846*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_ALWAYS);
847*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, -8);
848*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
849*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
850*35238bceSAndroid Build Coastguard Worker 
851*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message
852*35238bceSAndroid Build Coastguard Worker                 << "Draw top-left. Color = Yellow.\tState: DepthFunc = LESS, PolygonOffset(0, -9), Polygon Z = -1.0. "
853*35238bceSAndroid Build Coastguard Worker                    "(Result depth should clamp to -1.0 too)."
854*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
855*35238bceSAndroid Build Coastguard Worker 
856*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_LESS);
857*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, -9);
858*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 0.0f, 1.0f);
859*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
860*35238bceSAndroid Build Coastguard Worker         }
861*35238bceSAndroid Build Coastguard Worker 
862*35238bceSAndroid Build Coastguard Worker         gl.disableVertexAttribArray(positionLoc);
863*35238bceSAndroid Build Coastguard Worker         gl.useProgram(0);
864*35238bceSAndroid Build Coastguard Worker         gl.finish();
865*35238bceSAndroid Build Coastguard Worker 
866*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
867*35238bceSAndroid Build Coastguard Worker     }
868*35238bceSAndroid Build Coastguard Worker 
869*35238bceSAndroid Build Coastguard Worker     // render reference image
870*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Expecting: Top-left = White, Bottom-right = White." << TestLog::EndMessage;
871*35238bceSAndroid Build Coastguard Worker     tcu::clear(referenceImage.getAccess(), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
872*35238bceSAndroid Build Coastguard Worker 
873*35238bceSAndroid Build Coastguard Worker     // compare
874*35238bceSAndroid Build Coastguard Worker     verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
875*35238bceSAndroid Build Coastguard Worker }
876*35238bceSAndroid Build Coastguard Worker 
877*35238bceSAndroid Build Coastguard Worker // UsageSlopeTestCase
878*35238bceSAndroid Build Coastguard Worker 
879*35238bceSAndroid Build Coastguard Worker class UsageSlopeTestCase : public PolygonOffsetTestCase
880*35238bceSAndroid Build Coastguard Worker {
881*35238bceSAndroid Build Coastguard Worker public:
882*35238bceSAndroid Build Coastguard Worker     UsageSlopeTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
883*35238bceSAndroid Build Coastguard Worker                        const char *internalFormatName);
884*35238bceSAndroid Build Coastguard Worker 
885*35238bceSAndroid Build Coastguard Worker     void testPolygonOffset(void);
886*35238bceSAndroid Build Coastguard Worker };
887*35238bceSAndroid Build Coastguard Worker 
UsageSlopeTestCase(Context & context,const char * name,const char * description,GLenum internalFormat,const char * internalFormatName)888*35238bceSAndroid Build Coastguard Worker UsageSlopeTestCase::UsageSlopeTestCase(Context &context, const char *name, const char *description,
889*35238bceSAndroid Build Coastguard Worker                                        GLenum internalFormat, const char *internalFormatName)
890*35238bceSAndroid Build Coastguard Worker     : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
891*35238bceSAndroid Build Coastguard Worker {
892*35238bceSAndroid Build Coastguard Worker }
893*35238bceSAndroid Build Coastguard Worker 
testPolygonOffset(void)894*35238bceSAndroid Build Coastguard Worker void UsageSlopeTestCase::testPolygonOffset(void)
895*35238bceSAndroid Build Coastguard Worker {
896*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
897*35238bceSAndroid Build Coastguard Worker 
898*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangleBottomRight[] = {
899*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, 1, 0.0f, 1),
900*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, 1, 0.9f, 1),
901*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, -1, 0.9f, 1),
902*35238bceSAndroid Build Coastguard Worker     };
903*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangleTopLeft[] = {
904*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, -1, -0.9f, 1),
905*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1, 1, 0.9f, 1),
906*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1, -1, 0.0f, 1),
907*35238bceSAndroid Build Coastguard Worker     };
908*35238bceSAndroid Build Coastguard Worker 
909*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
910*35238bceSAndroid Build Coastguard Worker     tcu::Surface testImage(m_targetSize, m_targetSize);
911*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceImage(m_targetSize, m_targetSize);
912*35238bceSAndroid Build Coastguard Worker 
913*35238bceSAndroid Build Coastguard Worker     // render test image
914*35238bceSAndroid Build Coastguard Worker     {
915*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
916*35238bceSAndroid Build Coastguard Worker         const glu::ShaderProgram program(m_context.getRenderContext(),
917*35238bceSAndroid Build Coastguard Worker                                          glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
918*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
919*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc    = gl.getAttribLocation(program.getProgram(), "a_color");
920*35238bceSAndroid Build Coastguard Worker 
921*35238bceSAndroid Build Coastguard Worker         if (!program.isOk())
922*35238bceSAndroid Build Coastguard Worker         {
923*35238bceSAndroid Build Coastguard Worker             log << program;
924*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Shader compile failed.");
925*35238bceSAndroid Build Coastguard Worker         }
926*35238bceSAndroid Build Coastguard Worker 
927*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0, 0, 0, 1);
928*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(1.0f);
929*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
930*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, m_targetSize, m_targetSize);
931*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program.getProgram());
932*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
933*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_POLYGON_OFFSET_FILL);
934*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(positionLoc);
935*35238bceSAndroid Build Coastguard Worker 
936*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
937*35238bceSAndroid Build Coastguard Worker 
938*35238bceSAndroid Build Coastguard Worker         //draw top left (negative offset test)
939*35238bceSAndroid Build Coastguard Worker         {
940*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleTopLeft);
941*35238bceSAndroid Build Coastguard Worker 
942*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw top-left. Color = White.\tState: DepthFunc = ALWAYS, PolygonOffset(0, 0)."
943*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
944*35238bceSAndroid Build Coastguard Worker 
945*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_ALWAYS);
946*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 0);
947*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
948*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
949*35238bceSAndroid Build Coastguard Worker 
950*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw top-left. Color = Green.\tState: DepthFunc = LESS, PolygonOffset(-1, 0)."
951*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
952*35238bceSAndroid Build Coastguard Worker 
953*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_LESS);
954*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(-1, 0);
955*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
956*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
957*35238bceSAndroid Build Coastguard Worker         }
958*35238bceSAndroid Build Coastguard Worker 
959*35238bceSAndroid Build Coastguard Worker         //draw bottom right (positive offset test)
960*35238bceSAndroid Build Coastguard Worker         {
961*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangleBottomRight);
962*35238bceSAndroid Build Coastguard Worker 
963*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message
964*35238bceSAndroid Build Coastguard Worker                 << "Draw bottom-right. Color = White.\tState: DepthFunc = ALWAYS, PolygonOffset(0, 0)."
965*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
966*35238bceSAndroid Build Coastguard Worker 
967*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_ALWAYS);
968*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 0);
969*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
970*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
971*35238bceSAndroid Build Coastguard Worker 
972*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message
973*35238bceSAndroid Build Coastguard Worker                 << "Draw bottom-right. Color = Green.\tState: DepthFunc = GREATER, PolygonOffset(1, 0)."
974*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
975*35238bceSAndroid Build Coastguard Worker 
976*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_GREATER);
977*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(1, 0);
978*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
979*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
980*35238bceSAndroid Build Coastguard Worker         }
981*35238bceSAndroid Build Coastguard Worker 
982*35238bceSAndroid Build Coastguard Worker         gl.disableVertexAttribArray(positionLoc);
983*35238bceSAndroid Build Coastguard Worker         gl.useProgram(0);
984*35238bceSAndroid Build Coastguard Worker         gl.finish();
985*35238bceSAndroid Build Coastguard Worker 
986*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
987*35238bceSAndroid Build Coastguard Worker     }
988*35238bceSAndroid Build Coastguard Worker 
989*35238bceSAndroid Build Coastguard Worker     // render reference image
990*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Expecting: Top-left = Green, Bottom-right = Green." << TestLog::EndMessage;
991*35238bceSAndroid Build Coastguard Worker     tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
992*35238bceSAndroid Build Coastguard Worker 
993*35238bceSAndroid Build Coastguard Worker     // compare
994*35238bceSAndroid Build Coastguard Worker     verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
995*35238bceSAndroid Build Coastguard Worker }
996*35238bceSAndroid Build Coastguard Worker 
997*35238bceSAndroid Build Coastguard Worker // ZeroSlopeTestCase
998*35238bceSAndroid Build Coastguard Worker 
999*35238bceSAndroid Build Coastguard Worker class ZeroSlopeTestCase : public PolygonOffsetTestCase
1000*35238bceSAndroid Build Coastguard Worker {
1001*35238bceSAndroid Build Coastguard Worker public:
1002*35238bceSAndroid Build Coastguard Worker     ZeroSlopeTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
1003*35238bceSAndroid Build Coastguard Worker                       const char *internalFormatName);
1004*35238bceSAndroid Build Coastguard Worker 
1005*35238bceSAndroid Build Coastguard Worker     void testPolygonOffset(void);
1006*35238bceSAndroid Build Coastguard Worker };
1007*35238bceSAndroid Build Coastguard Worker 
ZeroSlopeTestCase(Context & context,const char * name,const char * description,GLenum internalFormat,const char * internalFormatName)1008*35238bceSAndroid Build Coastguard Worker ZeroSlopeTestCase::ZeroSlopeTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
1009*35238bceSAndroid Build Coastguard Worker                                      const char *internalFormatName)
1010*35238bceSAndroid Build Coastguard Worker     : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
1011*35238bceSAndroid Build Coastguard Worker {
1012*35238bceSAndroid Build Coastguard Worker }
1013*35238bceSAndroid Build Coastguard Worker 
testPolygonOffset(void)1014*35238bceSAndroid Build Coastguard Worker void ZeroSlopeTestCase::testPolygonOffset(void)
1015*35238bceSAndroid Build Coastguard Worker {
1016*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
1017*35238bceSAndroid Build Coastguard Worker 
1018*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangle[] = {
1019*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-0.4f, 0.4f, 0.0f, 1.0f),
1020*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-0.8f, -0.5f, 0.0f, 1.0f),
1021*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0.7f, 0.2f, 0.0f, 1.0f),
1022*35238bceSAndroid Build Coastguard Worker     };
1023*35238bceSAndroid Build Coastguard Worker 
1024*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
1025*35238bceSAndroid Build Coastguard Worker     tcu::Surface testImage(m_targetSize, m_targetSize);
1026*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceImage(m_targetSize, m_targetSize);
1027*35238bceSAndroid Build Coastguard Worker 
1028*35238bceSAndroid Build Coastguard Worker     // log the triangle
1029*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Setup triangle with coordinates:" << TestLog::EndMessage;
1030*35238bceSAndroid Build Coastguard Worker     for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(triangle); ++ndx)
1031*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tx=" << triangle[ndx].x() << "\ty=" << triangle[ndx].y()
1032*35238bceSAndroid Build Coastguard Worker             << "\tz=" << triangle[ndx].z() << "\tw=" << triangle[ndx].w() << TestLog::EndMessage;
1033*35238bceSAndroid Build Coastguard Worker 
1034*35238bceSAndroid Build Coastguard Worker     // render test image
1035*35238bceSAndroid Build Coastguard Worker     {
1036*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1037*35238bceSAndroid Build Coastguard Worker         const glu::ShaderProgram program(m_context.getRenderContext(),
1038*35238bceSAndroid Build Coastguard Worker                                          glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
1039*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
1040*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc    = gl.getAttribLocation(program.getProgram(), "a_color");
1041*35238bceSAndroid Build Coastguard Worker 
1042*35238bceSAndroid Build Coastguard Worker         if (!program.isOk())
1043*35238bceSAndroid Build Coastguard Worker         {
1044*35238bceSAndroid Build Coastguard Worker             log << program;
1045*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Shader compile failed.");
1046*35238bceSAndroid Build Coastguard Worker         }
1047*35238bceSAndroid Build Coastguard Worker 
1048*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0, 0, 0, 1);
1049*35238bceSAndroid Build Coastguard Worker         gl.clearDepthf(1.0f);
1050*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1051*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, m_targetSize, m_targetSize);
1052*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program.getProgram());
1053*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
1054*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_POLYGON_OFFSET_FILL);
1055*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(positionLoc);
1056*35238bceSAndroid Build Coastguard Worker 
1057*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
1058*35238bceSAndroid Build Coastguard Worker 
1059*35238bceSAndroid Build Coastguard Worker         {
1060*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangle);
1061*35238bceSAndroid Build Coastguard Worker 
1062*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw triangle. Color = Red.\tState: DepthFunc = ALWAYS, PolygonOffset(0, 0)."
1063*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
1064*35238bceSAndroid Build Coastguard Worker 
1065*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_ALWAYS);
1066*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(0, 0);
1067*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 0.0f, 0.0f, 1.0f);
1068*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
1069*35238bceSAndroid Build Coastguard Worker 
1070*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Draw triangle. Color = Black.\tState: DepthFunc = EQUAL, PolygonOffset(4, 0)."
1071*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
1072*35238bceSAndroid Build Coastguard Worker 
1073*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_EQUAL);
1074*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(4, 0); // triangle slope == 0
1075*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 0.0f, 0.0f, 0.0f, 1.0f);
1076*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
1077*35238bceSAndroid Build Coastguard Worker         }
1078*35238bceSAndroid Build Coastguard Worker 
1079*35238bceSAndroid Build Coastguard Worker         gl.disableVertexAttribArray(positionLoc);
1080*35238bceSAndroid Build Coastguard Worker         gl.useProgram(0);
1081*35238bceSAndroid Build Coastguard Worker         gl.finish();
1082*35238bceSAndroid Build Coastguard Worker 
1083*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
1084*35238bceSAndroid Build Coastguard Worker     }
1085*35238bceSAndroid Build Coastguard Worker 
1086*35238bceSAndroid Build Coastguard Worker     // render reference image
1087*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Expecting black triangle." << TestLog::EndMessage;
1088*35238bceSAndroid Build Coastguard Worker     tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
1089*35238bceSAndroid Build Coastguard Worker 
1090*35238bceSAndroid Build Coastguard Worker     // compare
1091*35238bceSAndroid Build Coastguard Worker     verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
1092*35238bceSAndroid Build Coastguard Worker }
1093*35238bceSAndroid Build Coastguard Worker 
1094*35238bceSAndroid Build Coastguard Worker // OneSlopeTestCase
1095*35238bceSAndroid Build Coastguard Worker 
1096*35238bceSAndroid Build Coastguard Worker class OneSlopeTestCase : public PolygonOffsetTestCase
1097*35238bceSAndroid Build Coastguard Worker {
1098*35238bceSAndroid Build Coastguard Worker public:
1099*35238bceSAndroid Build Coastguard Worker     OneSlopeTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
1100*35238bceSAndroid Build Coastguard Worker                      const char *internalFormatName);
1101*35238bceSAndroid Build Coastguard Worker 
1102*35238bceSAndroid Build Coastguard Worker     void testPolygonOffset(void);
1103*35238bceSAndroid Build Coastguard Worker };
1104*35238bceSAndroid Build Coastguard Worker 
OneSlopeTestCase(Context & context,const char * name,const char * description,GLenum internalFormat,const char * internalFormatName)1105*35238bceSAndroid Build Coastguard Worker OneSlopeTestCase::OneSlopeTestCase(Context &context, const char *name, const char *description, GLenum internalFormat,
1106*35238bceSAndroid Build Coastguard Worker                                    const char *internalFormatName)
1107*35238bceSAndroid Build Coastguard Worker     : PolygonOffsetTestCase(context, name, description, internalFormat, internalFormatName, 200)
1108*35238bceSAndroid Build Coastguard Worker {
1109*35238bceSAndroid Build Coastguard Worker }
1110*35238bceSAndroid Build Coastguard Worker 
testPolygonOffset(void)1111*35238bceSAndroid Build Coastguard Worker void OneSlopeTestCase::testPolygonOffset(void)
1112*35238bceSAndroid Build Coastguard Worker {
1113*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
1114*35238bceSAndroid Build Coastguard Worker 
1115*35238bceSAndroid Build Coastguard Worker     /*
1116*35238bceSAndroid Build Coastguard Worker      * setup vertices subject to following properties
1117*35238bceSAndroid Build Coastguard Worker      *   dz_w / dx_w == 1
1118*35238bceSAndroid Build Coastguard Worker      *   dz_w / dy_w == 0
1119*35238bceSAndroid Build Coastguard Worker      * or
1120*35238bceSAndroid Build Coastguard Worker      *   dz_w / dx_w == 0
1121*35238bceSAndroid Build Coastguard Worker      *   dz_w / dy_w == 1
1122*35238bceSAndroid Build Coastguard Worker      * ==> m == 1
1123*35238bceSAndroid Build Coastguard Worker      */
1124*35238bceSAndroid Build Coastguard Worker     const float cornerDepth         = float(m_targetSize);
1125*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 triangles[2][3] = {
1126*35238bceSAndroid Build Coastguard Worker         {
1127*35238bceSAndroid Build Coastguard Worker             tcu::Vec4(-1, -1, -cornerDepth, 1),
1128*35238bceSAndroid Build Coastguard Worker             tcu::Vec4(-1, 1, -cornerDepth, 1),
1129*35238bceSAndroid Build Coastguard Worker             tcu::Vec4(1, -1, cornerDepth, 1),
1130*35238bceSAndroid Build Coastguard Worker         },
1131*35238bceSAndroid Build Coastguard Worker         {
1132*35238bceSAndroid Build Coastguard Worker             tcu::Vec4(-1, 1, cornerDepth, 1),
1133*35238bceSAndroid Build Coastguard Worker             tcu::Vec4(1, 1, cornerDepth, 1),
1134*35238bceSAndroid Build Coastguard Worker             tcu::Vec4(1, -1, -cornerDepth, 1),
1135*35238bceSAndroid Build Coastguard Worker         },
1136*35238bceSAndroid Build Coastguard Worker     };
1137*35238bceSAndroid Build Coastguard Worker 
1138*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
1139*35238bceSAndroid Build Coastguard Worker     tcu::Surface testImage(m_targetSize, m_targetSize);
1140*35238bceSAndroid Build Coastguard Worker     tcu::Surface referenceImage(m_targetSize, m_targetSize);
1141*35238bceSAndroid Build Coastguard Worker 
1142*35238bceSAndroid Build Coastguard Worker     // log triangle info
1143*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Setup triangle0 coordinates: (slope in window coordinates = 1.0)"
1144*35238bceSAndroid Build Coastguard Worker         << TestLog::EndMessage;
1145*35238bceSAndroid Build Coastguard Worker     for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(triangles[0]); ++ndx)
1146*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tx=" << triangles[0][ndx].x() << "\ty=" << triangles[0][ndx].y()
1147*35238bceSAndroid Build Coastguard Worker             << "\tz=" << triangles[0][ndx].z() << "\tw=" << triangles[0][ndx].w() << TestLog::EndMessage;
1148*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Setup triangle1 coordinates: (slope in window coordinates = 1.0)"
1149*35238bceSAndroid Build Coastguard Worker         << TestLog::EndMessage;
1150*35238bceSAndroid Build Coastguard Worker     for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(triangles[1]); ++ndx)
1151*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tx=" << triangles[1][ndx].x() << "\ty=" << triangles[1][ndx].y()
1152*35238bceSAndroid Build Coastguard Worker             << "\tz=" << triangles[1][ndx].z() << "\tw=" << triangles[1][ndx].w() << TestLog::EndMessage;
1153*35238bceSAndroid Build Coastguard Worker 
1154*35238bceSAndroid Build Coastguard Worker     // render test image
1155*35238bceSAndroid Build Coastguard Worker     {
1156*35238bceSAndroid Build Coastguard Worker         const glw::Functions &gl = m_context.getRenderContext().getFunctions();
1157*35238bceSAndroid Build Coastguard Worker         const glu::ShaderProgram program(m_context.getRenderContext(),
1158*35238bceSAndroid Build Coastguard Worker                                          glu::makeVtxFragSources(s_shaderSourceVertex, s_shaderSourceFragment));
1159*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc = gl.getAttribLocation(program.getProgram(), "a_position");
1160*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc    = gl.getAttribLocation(program.getProgram(), "a_color");
1161*35238bceSAndroid Build Coastguard Worker 
1162*35238bceSAndroid Build Coastguard Worker         if (!program.isOk())
1163*35238bceSAndroid Build Coastguard Worker         {
1164*35238bceSAndroid Build Coastguard Worker             log << program;
1165*35238bceSAndroid Build Coastguard Worker             TCU_FAIL("Shader compile failed.");
1166*35238bceSAndroid Build Coastguard Worker         }
1167*35238bceSAndroid Build Coastguard Worker 
1168*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0, 0, 0, 1);
1169*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
1170*35238bceSAndroid Build Coastguard Worker         gl.viewport(0, 0, m_targetSize, m_targetSize);
1171*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program.getProgram());
1172*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_DEPTH_TEST);
1173*35238bceSAndroid Build Coastguard Worker         gl.enable(GL_POLYGON_OFFSET_FILL);
1174*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(positionLoc);
1175*35238bceSAndroid Build Coastguard Worker 
1176*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Framebuffer cleared, clear color = Black." << TestLog::EndMessage;
1177*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "POLYGON_OFFSET_FILL enabled." << TestLog::EndMessage;
1178*35238bceSAndroid Build Coastguard Worker 
1179*35238bceSAndroid Build Coastguard Worker         // top left (positive offset)
1180*35238bceSAndroid Build Coastguard Worker         {
1181*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Clear depth to 1.0." << TestLog::EndMessage;
1182*35238bceSAndroid Build Coastguard Worker 
1183*35238bceSAndroid Build Coastguard Worker             gl.clearDepthf(1.0f); // far
1184*35238bceSAndroid Build Coastguard Worker             gl.clear(GL_DEPTH_BUFFER_BIT);
1185*35238bceSAndroid Build Coastguard Worker 
1186*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangles[0]);
1187*35238bceSAndroid Build Coastguard Worker 
1188*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message
1189*35238bceSAndroid Build Coastguard Worker                 << "Draw triangle0. Color = Red.\tState: DepthFunc = NOTEQUAL, PolygonOffset(10, 0). (Result depth "
1190*35238bceSAndroid Build Coastguard Worker                    "should clamp to 1.0)."
1191*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
1192*35238bceSAndroid Build Coastguard Worker 
1193*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(10, 0); // clamps any depth on the triangle to 1
1194*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_NOTEQUAL);
1195*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 1.0f, 0.0f, 0.0f, 1.0f);
1196*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
1197*35238bceSAndroid Build Coastguard Worker         }
1198*35238bceSAndroid Build Coastguard Worker         // bottom right (negative offset)
1199*35238bceSAndroid Build Coastguard Worker         {
1200*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Clear depth to 0.0." << TestLog::EndMessage;
1201*35238bceSAndroid Build Coastguard Worker 
1202*35238bceSAndroid Build Coastguard Worker             gl.clearDepthf(0.0f); // far
1203*35238bceSAndroid Build Coastguard Worker             gl.clear(GL_DEPTH_BUFFER_BIT);
1204*35238bceSAndroid Build Coastguard Worker 
1205*35238bceSAndroid Build Coastguard Worker             gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, triangles[1]);
1206*35238bceSAndroid Build Coastguard Worker 
1207*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message
1208*35238bceSAndroid Build Coastguard Worker                 << "Draw triangle1. Color = Green.\tState: DepthFunc = NOTEQUAL, PolygonOffset(-10, 0). (Result depth "
1209*35238bceSAndroid Build Coastguard Worker                    "should clamp to 0.0)."
1210*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
1211*35238bceSAndroid Build Coastguard Worker 
1212*35238bceSAndroid Build Coastguard Worker             gl.polygonOffset(-10, 0); // clamps depth to 0
1213*35238bceSAndroid Build Coastguard Worker             gl.depthFunc(GL_NOTEQUAL);
1214*35238bceSAndroid Build Coastguard Worker             gl.vertexAttrib4f(colorLoc, 0.0f, 1.0f, 0.0f, 1.0f);
1215*35238bceSAndroid Build Coastguard Worker             gl.drawArrays(GL_TRIANGLES, 0, 3);
1216*35238bceSAndroid Build Coastguard Worker         }
1217*35238bceSAndroid Build Coastguard Worker 
1218*35238bceSAndroid Build Coastguard Worker         gl.disableVertexAttribArray(positionLoc);
1219*35238bceSAndroid Build Coastguard Worker         gl.useProgram(0);
1220*35238bceSAndroid Build Coastguard Worker         gl.finish();
1221*35238bceSAndroid Build Coastguard Worker 
1222*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_context.getRenderContext(), 0, 0, testImage.getAccess());
1223*35238bceSAndroid Build Coastguard Worker     }
1224*35238bceSAndroid Build Coastguard Worker 
1225*35238bceSAndroid Build Coastguard Worker     // render reference image
1226*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Expecting black framebuffer." << TestLog::EndMessage;
1227*35238bceSAndroid Build Coastguard Worker     tcu::clear(referenceImage.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
1228*35238bceSAndroid Build Coastguard Worker 
1229*35238bceSAndroid Build Coastguard Worker     // compare
1230*35238bceSAndroid Build Coastguard Worker     verifyImages(log, m_testCtx, m_context.getRenderContext(), testImage.getAccess(), referenceImage.getAccess());
1231*35238bceSAndroid Build Coastguard Worker }
1232*35238bceSAndroid Build Coastguard Worker 
1233*35238bceSAndroid Build Coastguard Worker } // namespace
1234*35238bceSAndroid Build Coastguard Worker 
PolygonOffsetTests(Context & context)1235*35238bceSAndroid Build Coastguard Worker PolygonOffsetTests::PolygonOffsetTests(Context &context)
1236*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "polygon_offset", "Polygon offset tests")
1237*35238bceSAndroid Build Coastguard Worker {
1238*35238bceSAndroid Build Coastguard Worker }
1239*35238bceSAndroid Build Coastguard Worker 
~PolygonOffsetTests(void)1240*35238bceSAndroid Build Coastguard Worker PolygonOffsetTests::~PolygonOffsetTests(void)
1241*35238bceSAndroid Build Coastguard Worker {
1242*35238bceSAndroid Build Coastguard Worker }
1243*35238bceSAndroid Build Coastguard Worker 
init(void)1244*35238bceSAndroid Build Coastguard Worker void PolygonOffsetTests::init(void)
1245*35238bceSAndroid Build Coastguard Worker {
1246*35238bceSAndroid Build Coastguard Worker     const struct DepthBufferFormat
1247*35238bceSAndroid Build Coastguard Worker     {
1248*35238bceSAndroid Build Coastguard Worker         enum BufferType
1249*35238bceSAndroid Build Coastguard Worker         {
1250*35238bceSAndroid Build Coastguard Worker             TYPE_FIXED_POINT,
1251*35238bceSAndroid Build Coastguard Worker             TYPE_FLOATING_POINT,
1252*35238bceSAndroid Build Coastguard Worker             TYPE_UNKNOWN
1253*35238bceSAndroid Build Coastguard Worker         };
1254*35238bceSAndroid Build Coastguard Worker 
1255*35238bceSAndroid Build Coastguard Worker         GLenum internalFormat;
1256*35238bceSAndroid Build Coastguard Worker         int bits;
1257*35238bceSAndroid Build Coastguard Worker         BufferType floatingPoint;
1258*35238bceSAndroid Build Coastguard Worker         const char *name;
1259*35238bceSAndroid Build Coastguard Worker     } depthFormats[] = {
1260*35238bceSAndroid Build Coastguard Worker         {0, 0, DepthBufferFormat::TYPE_UNKNOWN, "default"},
1261*35238bceSAndroid Build Coastguard Worker         {GL_DEPTH_COMPONENT16, 16, DepthBufferFormat::TYPE_FIXED_POINT, "fixed16"},
1262*35238bceSAndroid Build Coastguard Worker         {GL_DEPTH_COMPONENT24, 24, DepthBufferFormat::TYPE_FIXED_POINT, "fixed24"},
1263*35238bceSAndroid Build Coastguard Worker         {GL_DEPTH_COMPONENT32F, 32, DepthBufferFormat::TYPE_FLOATING_POINT, "float32"},
1264*35238bceSAndroid Build Coastguard Worker     };
1265*35238bceSAndroid Build Coastguard Worker 
1266*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(depthFormats); ++ndx)
1267*35238bceSAndroid Build Coastguard Worker     {
1268*35238bceSAndroid Build Coastguard Worker         const DepthBufferFormat &format = depthFormats[ndx];
1269*35238bceSAndroid Build Coastguard Worker 
1270*35238bceSAndroid Build Coastguard Worker         // enable works?
1271*35238bceSAndroid Build Coastguard Worker         addChild(new UsageTestCase(m_context, (std::string(format.name) + "_enable").c_str(),
1272*35238bceSAndroid Build Coastguard Worker                                    "test enable GL_POLYGON_OFFSET_FILL", format.internalFormat, format.name));
1273*35238bceSAndroid Build Coastguard Worker 
1274*35238bceSAndroid Build Coastguard Worker         // Really moves the polygons ?
1275*35238bceSAndroid Build Coastguard Worker         addChild(new UsageDisplacementTestCase(m_context,
1276*35238bceSAndroid Build Coastguard Worker                                                (std::string(format.name) + "_displacement_with_units").c_str(),
1277*35238bceSAndroid Build Coastguard Worker                                                "test polygon offset", format.internalFormat, format.name));
1278*35238bceSAndroid Build Coastguard Worker 
1279*35238bceSAndroid Build Coastguard Worker         // Really moves the polygons to right direction ?
1280*35238bceSAndroid Build Coastguard Worker         addChild(new UsagePositiveNegativeTestCase(m_context, (std::string(format.name) + "_render_with_units").c_str(),
1281*35238bceSAndroid Build Coastguard Worker                                                    "test polygon offset", format.internalFormat, format.name));
1282*35238bceSAndroid Build Coastguard Worker 
1283*35238bceSAndroid Build Coastguard Worker         // Is total result clamped to [0,1] like promised?
1284*35238bceSAndroid Build Coastguard Worker         addChild(new ResultClampingTestCase(m_context, (std::string(format.name) + "_result_depth_clamp").c_str(),
1285*35238bceSAndroid Build Coastguard Worker                                             "test polygon offset clamping", format.internalFormat, format.name));
1286*35238bceSAndroid Build Coastguard Worker 
1287*35238bceSAndroid Build Coastguard Worker         // Slope really moves the polygon?
1288*35238bceSAndroid Build Coastguard Worker         addChild(new UsageSlopeTestCase(m_context, (std::string(format.name) + "_render_with_factor").c_str(),
1289*35238bceSAndroid Build Coastguard Worker                                         "test polygon offset factor", format.internalFormat, format.name));
1290*35238bceSAndroid Build Coastguard Worker 
1291*35238bceSAndroid Build Coastguard Worker         // Factor with zero slope
1292*35238bceSAndroid Build Coastguard Worker         addChild(new ZeroSlopeTestCase(m_context, (std::string(format.name) + "_factor_0_slope").c_str(),
1293*35238bceSAndroid Build Coastguard Worker                                        "test polygon offset factor", format.internalFormat, format.name));
1294*35238bceSAndroid Build Coastguard Worker 
1295*35238bceSAndroid Build Coastguard Worker         // Factor with 1.0 slope
1296*35238bceSAndroid Build Coastguard Worker         addChild(new OneSlopeTestCase(m_context, (std::string(format.name) + "_factor_1_slope").c_str(),
1297*35238bceSAndroid Build Coastguard Worker                                       "test polygon offset factor", format.internalFormat, format.name));
1298*35238bceSAndroid Build Coastguard Worker     }
1299*35238bceSAndroid Build Coastguard Worker }
1300*35238bceSAndroid Build Coastguard Worker 
1301*35238bceSAndroid Build Coastguard Worker } // namespace Functional
1302*35238bceSAndroid Build Coastguard Worker } // namespace gles3
1303*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1304