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