xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fClippingTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Clipping tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es3fClippingTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceContext.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "sglrGLContext.hpp"
34*35238bceSAndroid Build Coastguard Worker 
35*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "glwDefs.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
38*35238bceSAndroid Build Coastguard Worker 
39*35238bceSAndroid Build Coastguard Worker using namespace glw; // GLint and other GL types
40*35238bceSAndroid Build Coastguard Worker 
41*35238bceSAndroid Build Coastguard Worker namespace deqp
42*35238bceSAndroid Build Coastguard Worker {
43*35238bceSAndroid Build Coastguard Worker namespace gles3
44*35238bceSAndroid Build Coastguard Worker {
45*35238bceSAndroid Build Coastguard Worker namespace Functional
46*35238bceSAndroid Build Coastguard Worker {
47*35238bceSAndroid Build Coastguard Worker namespace
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker 
50*35238bceSAndroid Build Coastguard Worker using tcu::ConstPixelBufferAccess;
51*35238bceSAndroid Build Coastguard Worker using tcu::PixelBufferAccess;
52*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
53*35238bceSAndroid Build Coastguard Worker 
54*35238bceSAndroid Build Coastguard Worker static const tcu::Vec4 MASK_COLOR_OK   = tcu::Vec4(0.0f, 0.1f, 0.0f, 1.0f);
55*35238bceSAndroid Build Coastguard Worker static const tcu::Vec4 MASK_COLOR_DEV  = tcu::Vec4(0.8f, 0.5f, 0.0f, 1.0f);
56*35238bceSAndroid Build Coastguard Worker static const tcu::Vec4 MASK_COLOR_FAIL = tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f);
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker const int TEST_CANVAS_SIZE = 200;
59*35238bceSAndroid Build Coastguard Worker const rr::WindowRectangle VIEWPORT_WHOLE(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
60*35238bceSAndroid Build Coastguard Worker const rr::WindowRectangle VIEWPORT_CENTER(TEST_CANVAS_SIZE / 4, TEST_CANVAS_SIZE / 4, TEST_CANVAS_SIZE / 2,
61*35238bceSAndroid Build Coastguard Worker                                           TEST_CANVAS_SIZE / 2);
62*35238bceSAndroid Build Coastguard Worker const rr::WindowRectangle VIEWPORT_CORNER(TEST_CANVAS_SIZE / 2, TEST_CANVAS_SIZE / 2, TEST_CANVAS_SIZE / 2,
63*35238bceSAndroid Build Coastguard Worker                                           TEST_CANVAS_SIZE / 2);
64*35238bceSAndroid Build Coastguard Worker 
65*35238bceSAndroid Build Coastguard Worker const char *shaderSourceVertex   = "#version 300 es\n"
66*35238bceSAndroid Build Coastguard Worker                                    "in highp vec4 a_position;\n"
67*35238bceSAndroid Build Coastguard Worker                                    "in highp vec4 a_color;\n"
68*35238bceSAndroid Build Coastguard Worker                                    "in highp float a_pointSize;\n"
69*35238bceSAndroid Build Coastguard Worker                                    "out highp vec4 varFragColor;\n"
70*35238bceSAndroid Build Coastguard Worker                                    "void main (void)\n"
71*35238bceSAndroid Build Coastguard Worker                                    "{\n"
72*35238bceSAndroid Build Coastguard Worker                                    "    gl_Position = a_position;\n"
73*35238bceSAndroid Build Coastguard Worker                                    "    gl_PointSize = a_pointSize;\n"
74*35238bceSAndroid Build Coastguard Worker                                    "    varFragColor = a_color;\n"
75*35238bceSAndroid Build Coastguard Worker                                    "}\n";
76*35238bceSAndroid Build Coastguard Worker const char *shaderSourceFragment = "#version 300 es\n"
77*35238bceSAndroid Build Coastguard Worker                                    "layout(location = 0) out mediump vec4 fragColor;"
78*35238bceSAndroid Build Coastguard Worker                                    "in highp vec4 varFragColor;\n"
79*35238bceSAndroid Build Coastguard Worker                                    "void main (void)\n"
80*35238bceSAndroid Build Coastguard Worker                                    "{\n"
81*35238bceSAndroid Build Coastguard Worker                                    "    fragColor = varFragColor;\n"
82*35238bceSAndroid Build Coastguard Worker                                    "}\n";
83*35238bceSAndroid Build Coastguard Worker 
isBlack(const tcu::IVec4 & a)84*35238bceSAndroid Build Coastguard Worker inline bool isBlack(const tcu::IVec4 &a)
85*35238bceSAndroid Build Coastguard Worker {
86*35238bceSAndroid Build Coastguard Worker     return a.x() == 0 && a.y() == 0 && a.z() == 0;
87*35238bceSAndroid Build Coastguard Worker }
88*35238bceSAndroid Build Coastguard Worker 
isHalfFilled(const tcu::IVec4 & a)89*35238bceSAndroid Build Coastguard Worker inline bool isHalfFilled(const tcu::IVec4 &a)
90*35238bceSAndroid Build Coastguard Worker {
91*35238bceSAndroid Build Coastguard Worker     const tcu::IVec4 halfFilled(127, 0, 0, 0);
92*35238bceSAndroid Build Coastguard Worker     const tcu::IVec4 threshold(20, 256, 256, 256);
93*35238bceSAndroid Build Coastguard Worker 
94*35238bceSAndroid Build Coastguard Worker     return tcu::boolAll(tcu::lessThanEqual(tcu::abs(a - halfFilled), threshold));
95*35238bceSAndroid Build Coastguard Worker }
96*35238bceSAndroid Build Coastguard Worker 
isLessThanHalfFilled(const tcu::IVec4 & a)97*35238bceSAndroid Build Coastguard Worker inline bool isLessThanHalfFilled(const tcu::IVec4 &a)
98*35238bceSAndroid Build Coastguard Worker {
99*35238bceSAndroid Build Coastguard Worker     const int halfFilled = 127;
100*35238bceSAndroid Build Coastguard Worker     const int threshold  = 20;
101*35238bceSAndroid Build Coastguard Worker 
102*35238bceSAndroid Build Coastguard Worker     return a.x() + threshold < halfFilled;
103*35238bceSAndroid Build Coastguard Worker }
104*35238bceSAndroid Build Coastguard Worker 
compareBlackNonBlackPixels(const tcu::IVec4 & a,const tcu::IVec4 & b)105*35238bceSAndroid Build Coastguard Worker inline bool compareBlackNonBlackPixels(const tcu::IVec4 &a, const tcu::IVec4 &b)
106*35238bceSAndroid Build Coastguard Worker {
107*35238bceSAndroid Build Coastguard Worker     return isBlack(a) == isBlack(b);
108*35238bceSAndroid Build Coastguard Worker }
109*35238bceSAndroid Build Coastguard Worker 
compareColoredPixels(const tcu::IVec4 & a,const tcu::IVec4 & b)110*35238bceSAndroid Build Coastguard Worker inline bool compareColoredPixels(const tcu::IVec4 &a, const tcu::IVec4 &b)
111*35238bceSAndroid Build Coastguard Worker {
112*35238bceSAndroid Build Coastguard Worker     const bool aIsBlack = isBlack(a);
113*35238bceSAndroid Build Coastguard Worker     const bool bIsBlack = isBlack(b);
114*35238bceSAndroid Build Coastguard Worker     const tcu::IVec4 threshold(20, 20, 20, 0);
115*35238bceSAndroid Build Coastguard Worker 
116*35238bceSAndroid Build Coastguard Worker     if (aIsBlack && bIsBlack)
117*35238bceSAndroid Build Coastguard Worker         return true;
118*35238bceSAndroid Build Coastguard Worker     if (aIsBlack != bIsBlack)
119*35238bceSAndroid Build Coastguard Worker         return false;
120*35238bceSAndroid Build Coastguard Worker 
121*35238bceSAndroid Build Coastguard Worker     return tcu::boolAll(tcu::lessThanEqual(tcu::abs(a - b), threshold));
122*35238bceSAndroid Build Coastguard Worker }
123*35238bceSAndroid Build Coastguard Worker 
blitImageOnBlackSurface(const ConstPixelBufferAccess & src,const PixelBufferAccess & dst)124*35238bceSAndroid Build Coastguard Worker void blitImageOnBlackSurface(const ConstPixelBufferAccess &src, const PixelBufferAccess &dst)
125*35238bceSAndroid Build Coastguard Worker {
126*35238bceSAndroid Build Coastguard Worker     const int height = src.getHeight();
127*35238bceSAndroid Build Coastguard Worker     const int width  = src.getWidth();
128*35238bceSAndroid Build Coastguard Worker 
129*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < height; y++)
130*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < width; x++)
131*35238bceSAndroid Build Coastguard Worker         {
132*35238bceSAndroid Build Coastguard Worker             const tcu::IVec4 cSrc = src.getPixelInt(x, y);
133*35238bceSAndroid Build Coastguard Worker             const tcu::IVec4 cDst = tcu::IVec4(cSrc.x(), cSrc.y(), cSrc.z(), 255);
134*35238bceSAndroid Build Coastguard Worker 
135*35238bceSAndroid Build Coastguard Worker             dst.setPixel(cDst, x, y);
136*35238bceSAndroid Build Coastguard Worker         }
137*35238bceSAndroid Build Coastguard Worker }
138*35238bceSAndroid Build Coastguard Worker 
139*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
140*35238bceSAndroid Build Coastguard Worker  * \brief Pixelwise comparison of two images.
141*35238bceSAndroid Build Coastguard Worker  * \note copied & modified from glsRasterizationTests
142*35238bceSAndroid Build Coastguard Worker  *
143*35238bceSAndroid Build Coastguard Worker  * Kernel radius defines maximum allowed distance. If radius is 0, only
144*35238bceSAndroid Build Coastguard Worker  * perfect match is allowed. Radius of 1 gives a 3x3 kernel. Pixels are
145*35238bceSAndroid Build Coastguard Worker  * equal if pixelCmp returns true..
146*35238bceSAndroid Build Coastguard Worker  *
147*35238bceSAndroid Build Coastguard Worker  * Return values:  -1 = Perfect match
148*35238bceSAndroid Build Coastguard Worker  *                    0 = Deviation within kernel
149*35238bceSAndroid Build Coastguard Worker  *                   >0 = Number of faulty pixels
150*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
compareImages(tcu::TestLog & log,const ConstPixelBufferAccess & test,const ConstPixelBufferAccess & ref,const PixelBufferAccess & diffMask,int kernelRadius,bool (* pixelCmp)(const tcu::IVec4 & a,const tcu::IVec4 & b))151*35238bceSAndroid Build Coastguard Worker inline int compareImages(tcu::TestLog &log, const ConstPixelBufferAccess &test, const ConstPixelBufferAccess &ref,
152*35238bceSAndroid Build Coastguard Worker                          const PixelBufferAccess &diffMask, int kernelRadius,
153*35238bceSAndroid Build Coastguard Worker                          bool (*pixelCmp)(const tcu::IVec4 &a, const tcu::IVec4 &b))
154*35238bceSAndroid Build Coastguard Worker {
155*35238bceSAndroid Build Coastguard Worker     const int height    = test.getHeight();
156*35238bceSAndroid Build Coastguard Worker     const int width     = test.getWidth();
157*35238bceSAndroid Build Coastguard Worker     int deviatingPixels = 0;
158*35238bceSAndroid Build Coastguard Worker     int faultyPixels    = 0;
159*35238bceSAndroid Build Coastguard Worker     int compareFailed   = -1;
160*35238bceSAndroid Build Coastguard Worker 
161*35238bceSAndroid Build Coastguard Worker     tcu::clear(diffMask, MASK_COLOR_OK);
162*35238bceSAndroid Build Coastguard Worker 
163*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < height; y++)
164*35238bceSAndroid Build Coastguard Worker     {
165*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < width; x++)
166*35238bceSAndroid Build Coastguard Worker         {
167*35238bceSAndroid Build Coastguard Worker             const tcu::IVec4 cRef  = ref.getPixelInt(x, y);
168*35238bceSAndroid Build Coastguard Worker             const tcu::IVec4 cTest = test.getPixelInt(x, y);
169*35238bceSAndroid Build Coastguard Worker 
170*35238bceSAndroid Build Coastguard Worker             // Pixelwise match, no deviation or fault
171*35238bceSAndroid Build Coastguard Worker             if ((*pixelCmp)(cRef, cTest))
172*35238bceSAndroid Build Coastguard Worker                 continue;
173*35238bceSAndroid Build Coastguard Worker 
174*35238bceSAndroid Build Coastguard Worker             // Deviation
175*35238bceSAndroid Build Coastguard Worker             {
176*35238bceSAndroid Build Coastguard Worker                 const int radius = kernelRadius;
177*35238bceSAndroid Build Coastguard Worker                 bool foundRef    = false;
178*35238bceSAndroid Build Coastguard Worker                 bool foundTest   = false;
179*35238bceSAndroid Build Coastguard Worker 
180*35238bceSAndroid Build Coastguard Worker                 // edges are considered a "deviation" too. The suitable pixel could be "behind" the edge
181*35238bceSAndroid Build Coastguard Worker                 if (y < radius || x < radius || y + radius >= height || x + radius >= width)
182*35238bceSAndroid Build Coastguard Worker                 {
183*35238bceSAndroid Build Coastguard Worker                     foundRef  = true;
184*35238bceSAndroid Build Coastguard Worker                     foundTest = true;
185*35238bceSAndroid Build Coastguard Worker                 }
186*35238bceSAndroid Build Coastguard Worker                 else
187*35238bceSAndroid Build Coastguard Worker                 {
188*35238bceSAndroid Build Coastguard Worker                     // find ref
189*35238bceSAndroid Build Coastguard Worker                     for (int kY = y - radius; kY <= y + radius; kY++)
190*35238bceSAndroid Build Coastguard Worker                         for (int kX = x - radius; kX <= x + radius; kX++)
191*35238bceSAndroid Build Coastguard Worker                         {
192*35238bceSAndroid Build Coastguard Worker                             if ((*pixelCmp)(cRef, test.getPixelInt(kX, kY)))
193*35238bceSAndroid Build Coastguard Worker                             {
194*35238bceSAndroid Build Coastguard Worker                                 foundRef = true;
195*35238bceSAndroid Build Coastguard Worker                                 break;
196*35238bceSAndroid Build Coastguard Worker                             }
197*35238bceSAndroid Build Coastguard Worker                         }
198*35238bceSAndroid Build Coastguard Worker 
199*35238bceSAndroid Build Coastguard Worker                     // find result
200*35238bceSAndroid Build Coastguard Worker                     for (int kY = y - radius; kY <= y + radius; kY++)
201*35238bceSAndroid Build Coastguard Worker                         for (int kX = x - radius; kX <= x + radius; kX++)
202*35238bceSAndroid Build Coastguard Worker                         {
203*35238bceSAndroid Build Coastguard Worker                             if ((*pixelCmp)(cTest, ref.getPixelInt(kX, kY)))
204*35238bceSAndroid Build Coastguard Worker                             {
205*35238bceSAndroid Build Coastguard Worker                                 foundTest = true;
206*35238bceSAndroid Build Coastguard Worker                                 break;
207*35238bceSAndroid Build Coastguard Worker                             }
208*35238bceSAndroid Build Coastguard Worker                         }
209*35238bceSAndroid Build Coastguard Worker                 }
210*35238bceSAndroid Build Coastguard Worker 
211*35238bceSAndroid Build Coastguard Worker                 // A pixel is deviating if the reference color is found inside the kernel and (~= every pixel reference draws must be drawn by the gl too)
212*35238bceSAndroid Build Coastguard Worker                 // the result color is found in the reference image inside the kernel         (~= every pixel gl draws must be drawn by the reference too)
213*35238bceSAndroid Build Coastguard Worker                 if (foundRef && foundTest)
214*35238bceSAndroid Build Coastguard Worker                 {
215*35238bceSAndroid Build Coastguard Worker                     diffMask.setPixel(MASK_COLOR_DEV, x, y);
216*35238bceSAndroid Build Coastguard Worker                     if (compareFailed == -1)
217*35238bceSAndroid Build Coastguard Worker                         compareFailed = 0;
218*35238bceSAndroid Build Coastguard Worker                     deviatingPixels++;
219*35238bceSAndroid Build Coastguard Worker                     continue;
220*35238bceSAndroid Build Coastguard Worker                 }
221*35238bceSAndroid Build Coastguard Worker             }
222*35238bceSAndroid Build Coastguard Worker 
223*35238bceSAndroid Build Coastguard Worker             diffMask.setPixel(MASK_COLOR_FAIL, x, y);
224*35238bceSAndroid Build Coastguard Worker             faultyPixels++; // The pixel is faulty if the color is not found
225*35238bceSAndroid Build Coastguard Worker             compareFailed = 1;
226*35238bceSAndroid Build Coastguard Worker         }
227*35238bceSAndroid Build Coastguard Worker     }
228*35238bceSAndroid Build Coastguard Worker 
229*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << deviatingPixels << " deviating pixel(s) found." << TestLog::EndMessage;
230*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << faultyPixels << " faulty pixel(s) found." << TestLog::EndMessage;
231*35238bceSAndroid Build Coastguard Worker 
232*35238bceSAndroid Build Coastguard Worker     return (compareFailed == 1 ? faultyPixels : compareFailed);
233*35238bceSAndroid Build Coastguard Worker }
234*35238bceSAndroid Build Coastguard Worker 
235*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
236*35238bceSAndroid Build Coastguard Worker  * \brief Pixelwise comparison of two images.
237*35238bceSAndroid Build Coastguard Worker  *
238*35238bceSAndroid Build Coastguard Worker  * Kernel radius defines maximum allowed distance. If radius is 0, only
239*35238bceSAndroid Build Coastguard Worker  * perfect match is allowed. Radius of 1 gives a 3x3 kernel. Pixels are
240*35238bceSAndroid Build Coastguard Worker  * equal if they both are black, or both are non-black.
241*35238bceSAndroid Build Coastguard Worker  *
242*35238bceSAndroid Build Coastguard Worker  * Return values:  -1 = Perfect match
243*35238bceSAndroid Build Coastguard Worker  *                    0 = Deviation within kernel
244*35238bceSAndroid Build Coastguard Worker  *                   >0 = Number of faulty pixels
245*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
compareBlackNonBlackImages(tcu::TestLog & log,const ConstPixelBufferAccess & test,const ConstPixelBufferAccess & ref,const PixelBufferAccess & diffMask,int kernelRadius)246*35238bceSAndroid Build Coastguard Worker int compareBlackNonBlackImages(tcu::TestLog &log, const ConstPixelBufferAccess &test, const ConstPixelBufferAccess &ref,
247*35238bceSAndroid Build Coastguard Worker                                const PixelBufferAccess &diffMask, int kernelRadius)
248*35238bceSAndroid Build Coastguard Worker {
249*35238bceSAndroid Build Coastguard Worker     return compareImages(log, test, ref, diffMask, kernelRadius, compareBlackNonBlackPixels);
250*35238bceSAndroid Build Coastguard Worker }
251*35238bceSAndroid Build Coastguard Worker 
252*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
253*35238bceSAndroid Build Coastguard Worker  * \brief Pixelwise comparison of two images.
254*35238bceSAndroid Build Coastguard Worker  *
255*35238bceSAndroid Build Coastguard Worker  * Kernel radius defines maximum allowed distance. If radius is 0, only
256*35238bceSAndroid Build Coastguard Worker  * perfect match is allowed. Radius of 1 gives a 3x3 kernel. Pixels are
257*35238bceSAndroid Build Coastguard Worker  * equal if they both are black, or both are non-black with color values
258*35238bceSAndroid Build Coastguard Worker  * close to each other.
259*35238bceSAndroid Build Coastguard Worker  *
260*35238bceSAndroid Build Coastguard Worker  * Return values:  -1 = Perfect match
261*35238bceSAndroid Build Coastguard Worker  *                    0 = Deviation within kernel
262*35238bceSAndroid Build Coastguard Worker  *                   >0 = Number of faulty pixels
263*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
compareColoredImages(tcu::TestLog & log,const ConstPixelBufferAccess & test,const ConstPixelBufferAccess & ref,const PixelBufferAccess & diffMask,int kernelRadius)264*35238bceSAndroid Build Coastguard Worker int compareColoredImages(tcu::TestLog &log, const ConstPixelBufferAccess &test, const ConstPixelBufferAccess &ref,
265*35238bceSAndroid Build Coastguard Worker                          const PixelBufferAccess &diffMask, int kernelRadius)
266*35238bceSAndroid Build Coastguard Worker {
267*35238bceSAndroid Build Coastguard Worker     return compareImages(log, test, ref, diffMask, kernelRadius, compareColoredPixels);
268*35238bceSAndroid Build Coastguard Worker }
269*35238bceSAndroid Build Coastguard Worker 
270*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
271*35238bceSAndroid Build Coastguard Worker  * \brief Overdraw check verification
272*35238bceSAndroid Build Coastguard Worker  *
273*35238bceSAndroid Build Coastguard Worker  * Check that image does not have at any point a
274*35238bceSAndroid Build Coastguard Worker  * pixel with red component value > 0.5
275*35238bceSAndroid Build Coastguard Worker  *
276*35238bceSAndroid Build Coastguard Worker  * Return values:  false = area not filled, or leaking
277*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
checkHalfFilledImageOverdraw(tcu::TestLog & log,const tcu::RenderTarget & m_renderTarget,const ConstPixelBufferAccess & image,const PixelBufferAccess & output)278*35238bceSAndroid Build Coastguard Worker bool checkHalfFilledImageOverdraw(tcu::TestLog &log, const tcu::RenderTarget &m_renderTarget,
279*35238bceSAndroid Build Coastguard Worker                                   const ConstPixelBufferAccess &image, const PixelBufferAccess &output)
280*35238bceSAndroid Build Coastguard Worker {
281*35238bceSAndroid Build Coastguard Worker     const int height = image.getHeight();
282*35238bceSAndroid Build Coastguard Worker     const int width  = image.getWidth();
283*35238bceSAndroid Build Coastguard Worker 
284*35238bceSAndroid Build Coastguard Worker     bool faulty = false;
285*35238bceSAndroid Build Coastguard Worker 
286*35238bceSAndroid Build Coastguard Worker     tcu::clear(output, MASK_COLOR_OK);
287*35238bceSAndroid Build Coastguard Worker 
288*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < height; y++)
289*35238bceSAndroid Build Coastguard Worker     {
290*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < width; x++)
291*35238bceSAndroid Build Coastguard Worker         {
292*35238bceSAndroid Build Coastguard Worker             const tcu::IVec4 cTest = image.getPixelInt(x, y);
293*35238bceSAndroid Build Coastguard Worker 
294*35238bceSAndroid Build Coastguard Worker             const bool pixelValid = isBlack(cTest) || isHalfFilled(cTest) ||
295*35238bceSAndroid Build Coastguard Worker                                     (m_renderTarget.getNumSamples() > 1 && isLessThanHalfFilled(cTest));
296*35238bceSAndroid Build Coastguard Worker 
297*35238bceSAndroid Build Coastguard Worker             if (!pixelValid)
298*35238bceSAndroid Build Coastguard Worker             {
299*35238bceSAndroid Build Coastguard Worker                 output.setPixel(MASK_COLOR_FAIL, x, y);
300*35238bceSAndroid Build Coastguard Worker                 faulty = true;
301*35238bceSAndroid Build Coastguard Worker             }
302*35238bceSAndroid Build Coastguard Worker         }
303*35238bceSAndroid Build Coastguard Worker     }
304*35238bceSAndroid Build Coastguard Worker 
305*35238bceSAndroid Build Coastguard Worker     if (faulty)
306*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Faulty pixel(s) found." << TestLog::EndMessage;
307*35238bceSAndroid Build Coastguard Worker 
308*35238bceSAndroid Build Coastguard Worker     return !faulty;
309*35238bceSAndroid Build Coastguard Worker }
310*35238bceSAndroid Build Coastguard Worker 
checkPointSize(const glw::Functions & gl,float pointSize)311*35238bceSAndroid Build Coastguard Worker void checkPointSize(const glw::Functions &gl, float pointSize)
312*35238bceSAndroid Build Coastguard Worker {
313*35238bceSAndroid Build Coastguard Worker     GLfloat pointSizeRange[2] = {0, 0};
314*35238bceSAndroid Build Coastguard Worker     gl.getFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
315*35238bceSAndroid Build Coastguard Worker     if (pointSizeRange[1] < pointSize)
316*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Maximum point size is too low for this test");
317*35238bceSAndroid Build Coastguard Worker }
318*35238bceSAndroid Build Coastguard Worker 
checkLineWidth(const glw::Functions & gl,float lineWidth)319*35238bceSAndroid Build Coastguard Worker void checkLineWidth(const glw::Functions &gl, float lineWidth)
320*35238bceSAndroid Build Coastguard Worker {
321*35238bceSAndroid Build Coastguard Worker     GLfloat lineWidthRange[2] = {0, 0};
322*35238bceSAndroid Build Coastguard Worker     gl.getFloatv(GL_ALIASED_LINE_WIDTH_RANGE, lineWidthRange);
323*35238bceSAndroid Build Coastguard Worker     if (lineWidthRange[1] < lineWidth)
324*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Maximum line width is too low for this test");
325*35238bceSAndroid Build Coastguard Worker }
326*35238bceSAndroid Build Coastguard Worker 
IVec3ToVec3(const tcu::IVec3 & v)327*35238bceSAndroid Build Coastguard Worker tcu::Vec3 IVec3ToVec3(const tcu::IVec3 &v)
328*35238bceSAndroid Build Coastguard Worker {
329*35238bceSAndroid Build Coastguard Worker     return tcu::Vec3((float)v.x(), (float)v.y(), (float)v.z());
330*35238bceSAndroid Build Coastguard Worker }
331*35238bceSAndroid Build Coastguard Worker 
pointOnTriangle(const tcu::IVec3 & p,const tcu::IVec3 & t0,const tcu::IVec3 & t1,const tcu::IVec3 & t2)332*35238bceSAndroid Build Coastguard Worker bool pointOnTriangle(const tcu::IVec3 &p, const tcu::IVec3 &t0, const tcu::IVec3 &t1, const tcu::IVec3 &t2)
333*35238bceSAndroid Build Coastguard Worker {
334*35238bceSAndroid Build Coastguard Worker     // Must be on the plane
335*35238bceSAndroid Build Coastguard Worker     const tcu::IVec3 n = tcu::cross(t1 - t0, t2 - t0);
336*35238bceSAndroid Build Coastguard Worker     const tcu::IVec3 d = (p - t0);
337*35238bceSAndroid Build Coastguard Worker 
338*35238bceSAndroid Build Coastguard Worker     if (tcu::dot(n, d))
339*35238bceSAndroid Build Coastguard Worker         return false;
340*35238bceSAndroid Build Coastguard Worker 
341*35238bceSAndroid Build Coastguard Worker     // Must be within the triangle area
342*35238bceSAndroid Build Coastguard Worker     if (deSign32(tcu::dot(n, tcu::cross(t1 - t0, p - t0))) == deSign32(tcu::dot(n, tcu::cross(t2 - t0, p - t0))))
343*35238bceSAndroid Build Coastguard Worker         return false;
344*35238bceSAndroid Build Coastguard Worker     if (deSign32(tcu::dot(n, tcu::cross(t2 - t1, p - t1))) == deSign32(tcu::dot(n, tcu::cross(t0 - t1, p - t1))))
345*35238bceSAndroid Build Coastguard Worker         return false;
346*35238bceSAndroid Build Coastguard Worker     if (deSign32(tcu::dot(n, tcu::cross(t0 - t2, p - t2))) == deSign32(tcu::dot(n, tcu::cross(t1 - t2, p - t2))))
347*35238bceSAndroid Build Coastguard Worker         return false;
348*35238bceSAndroid Build Coastguard Worker 
349*35238bceSAndroid Build Coastguard Worker     return true;
350*35238bceSAndroid Build Coastguard Worker }
351*35238bceSAndroid Build Coastguard Worker 
pointsOnLine(const tcu::IVec2 & t0,const tcu::IVec2 & t1,const tcu::IVec2 & t2)352*35238bceSAndroid Build Coastguard Worker bool pointsOnLine(const tcu::IVec2 &t0, const tcu::IVec2 &t1, const tcu::IVec2 &t2)
353*35238bceSAndroid Build Coastguard Worker {
354*35238bceSAndroid Build Coastguard Worker     return (t1 - t0).x() * (t2 - t0).y() - (t2 - t0).x() * (t1 - t0).y() == 0;
355*35238bceSAndroid Build Coastguard Worker }
356*35238bceSAndroid Build Coastguard Worker 
357*35238bceSAndroid Build Coastguard Worker // returns true for cases where polygon is (almost) along xz or yz planes (normal.z < 0.1)
358*35238bceSAndroid Build Coastguard Worker // \note[jarkko] Doesn't have to be accurate, just to detect some obviously bad cases
twoPointClippedTriangleInvisible(const tcu::Vec3 & p,const tcu::IVec3 & dir1,const tcu::IVec3 & dir2)359*35238bceSAndroid Build Coastguard Worker bool twoPointClippedTriangleInvisible(const tcu::Vec3 &p, const tcu::IVec3 &dir1, const tcu::IVec3 &dir2)
360*35238bceSAndroid Build Coastguard Worker {
361*35238bceSAndroid Build Coastguard Worker     // fixed-point-like coords
362*35238bceSAndroid Build Coastguard Worker     const int64_t fixedScale         = 64;
363*35238bceSAndroid Build Coastguard Worker     const int64_t farValue           = 1024;
364*35238bceSAndroid Build Coastguard Worker     const tcu::Vector<int64_t, 3> d1 = tcu::Vector<int64_t, 3>(dir1.x(), dir1.y(), dir1.z());
365*35238bceSAndroid Build Coastguard Worker     const tcu::Vector<int64_t, 3> d2 = tcu::Vector<int64_t, 3>(dir2.x(), dir2.y(), dir2.z());
366*35238bceSAndroid Build Coastguard Worker     const tcu::Vector<int64_t, 3> pfixed =
367*35238bceSAndroid Build Coastguard Worker         tcu::Vector<int64_t, 3>(deFloorFloatToInt32(p.x() * fixedScale), deFloorFloatToInt32(p.y() * fixedScale),
368*35238bceSAndroid Build Coastguard Worker                                 deFloorFloatToInt32(p.z() * fixedScale));
369*35238bceSAndroid Build Coastguard Worker     const tcu::Vector<int64_t, 3> normalDir = tcu::cross(d1 * farValue - pfixed, d2 * farValue - pfixed);
370*35238bceSAndroid Build Coastguard Worker     const int64_t normalLen2                = tcu::lengthSquared(normalDir);
371*35238bceSAndroid Build Coastguard Worker 
372*35238bceSAndroid Build Coastguard Worker     return (normalDir.z() * normalDir.z() - normalLen2 / 100) < 0;
373*35238bceSAndroid Build Coastguard Worker }
374*35238bceSAndroid Build Coastguard Worker 
genClippingPointInfoString(const tcu::Vec4 & p)375*35238bceSAndroid Build Coastguard Worker std::string genClippingPointInfoString(const tcu::Vec4 &p)
376*35238bceSAndroid Build Coastguard Worker {
377*35238bceSAndroid Build Coastguard Worker     std::ostringstream msg;
378*35238bceSAndroid Build Coastguard Worker 
379*35238bceSAndroid Build Coastguard Worker     if (p.x() < -p.w())
380*35238bceSAndroid Build Coastguard Worker         msg << "\t(-X clip)";
381*35238bceSAndroid Build Coastguard Worker     if (p.x() > p.w())
382*35238bceSAndroid Build Coastguard Worker         msg << "\t(+X clip)";
383*35238bceSAndroid Build Coastguard Worker     if (p.y() < -p.w())
384*35238bceSAndroid Build Coastguard Worker         msg << "\t(-Y clip)";
385*35238bceSAndroid Build Coastguard Worker     if (p.y() > p.w())
386*35238bceSAndroid Build Coastguard Worker         msg << "\t(+Y clip)";
387*35238bceSAndroid Build Coastguard Worker     if (p.z() < -p.w())
388*35238bceSAndroid Build Coastguard Worker         msg << "\t(-Z clip)";
389*35238bceSAndroid Build Coastguard Worker     if (p.z() > p.w())
390*35238bceSAndroid Build Coastguard Worker         msg << "\t(+Z clip)";
391*35238bceSAndroid Build Coastguard Worker 
392*35238bceSAndroid Build Coastguard Worker     return msg.str();
393*35238bceSAndroid Build Coastguard Worker }
394*35238bceSAndroid Build Coastguard Worker 
genColorString(const tcu::Vec4 & p)395*35238bceSAndroid Build Coastguard Worker std::string genColorString(const tcu::Vec4 &p)
396*35238bceSAndroid Build Coastguard Worker {
397*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 white(1.0f, 1.0f, 1.0f, 1.0f);
398*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 red(1.0f, 0.0f, 0.0f, 1.0f);
399*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 yellow(1.0f, 1.0f, 0.0f, 1.0f);
400*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 blue(0.0f, 0.0f, 1.0f, 1.0f);
401*35238bceSAndroid Build Coastguard Worker 
402*35238bceSAndroid Build Coastguard Worker     if (p == white)
403*35238bceSAndroid Build Coastguard Worker         return "(white)";
404*35238bceSAndroid Build Coastguard Worker     if (p == red)
405*35238bceSAndroid Build Coastguard Worker         return "(red)";
406*35238bceSAndroid Build Coastguard Worker     if (p == yellow)
407*35238bceSAndroid Build Coastguard Worker         return "(yellow)";
408*35238bceSAndroid Build Coastguard Worker     if (p == blue)
409*35238bceSAndroid Build Coastguard Worker         return "(blue)";
410*35238bceSAndroid Build Coastguard Worker     return "";
411*35238bceSAndroid Build Coastguard Worker }
412*35238bceSAndroid Build Coastguard Worker 
413*35238bceSAndroid Build Coastguard Worker class PositionColorShader : public sglr::ShaderProgram
414*35238bceSAndroid Build Coastguard Worker {
415*35238bceSAndroid Build Coastguard Worker public:
416*35238bceSAndroid Build Coastguard Worker     enum
417*35238bceSAndroid Build Coastguard Worker     {
418*35238bceSAndroid Build Coastguard Worker         VARYINGLOC_COLOR = 0
419*35238bceSAndroid Build Coastguard Worker     };
420*35238bceSAndroid Build Coastguard Worker 
421*35238bceSAndroid Build Coastguard Worker     PositionColorShader(void);
422*35238bceSAndroid Build Coastguard Worker 
423*35238bceSAndroid Build Coastguard Worker     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
424*35238bceSAndroid Build Coastguard Worker     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
425*35238bceSAndroid Build Coastguard Worker                         const rr::FragmentShadingContext &context) const;
426*35238bceSAndroid Build Coastguard Worker };
427*35238bceSAndroid Build Coastguard Worker 
PositionColorShader(void)428*35238bceSAndroid Build Coastguard Worker PositionColorShader::PositionColorShader(void)
429*35238bceSAndroid Build Coastguard Worker     : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
430*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
431*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
432*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexAttribute("a_pointSize", rr::GENERICVECTYPE_FLOAT)
433*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
434*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
435*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexSource(shaderSourceVertex)
436*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::FragmentSource(shaderSourceFragment))
437*35238bceSAndroid Build Coastguard Worker {
438*35238bceSAndroid Build Coastguard Worker }
439*35238bceSAndroid Build Coastguard Worker 
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const440*35238bceSAndroid Build Coastguard Worker void PositionColorShader::shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets,
441*35238bceSAndroid Build Coastguard Worker                                         const int numPackets) const
442*35238bceSAndroid Build Coastguard Worker {
443*35238bceSAndroid Build Coastguard Worker     for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
444*35238bceSAndroid Build Coastguard Worker     {
445*35238bceSAndroid Build Coastguard Worker         const int positionAttrLoc  = 0;
446*35238bceSAndroid Build Coastguard Worker         const int colorAttrLoc     = 1;
447*35238bceSAndroid Build Coastguard Worker         const int pointSizeAttrLoc = 2;
448*35238bceSAndroid Build Coastguard Worker 
449*35238bceSAndroid Build Coastguard Worker         rr::VertexPacket &packet = *packets[packetNdx];
450*35238bceSAndroid Build Coastguard Worker 
451*35238bceSAndroid Build Coastguard Worker         // Transform to position
452*35238bceSAndroid Build Coastguard Worker         packet.position = rr::readVertexAttribFloat(inputs[positionAttrLoc], packet.instanceNdx, packet.vertexNdx);
453*35238bceSAndroid Build Coastguard Worker 
454*35238bceSAndroid Build Coastguard Worker         // output point size
455*35238bceSAndroid Build Coastguard Worker         packet.pointSize =
456*35238bceSAndroid Build Coastguard Worker             rr::readVertexAttribFloat(inputs[pointSizeAttrLoc], packet.instanceNdx, packet.vertexNdx).x();
457*35238bceSAndroid Build Coastguard Worker 
458*35238bceSAndroid Build Coastguard Worker         // Pass color to FS
459*35238bceSAndroid Build Coastguard Worker         packet.outputs[VARYINGLOC_COLOR] =
460*35238bceSAndroid Build Coastguard Worker             rr::readVertexAttribFloat(inputs[colorAttrLoc], packet.instanceNdx, packet.vertexNdx);
461*35238bceSAndroid Build Coastguard Worker     }
462*35238bceSAndroid Build Coastguard Worker }
463*35238bceSAndroid Build Coastguard Worker 
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const464*35238bceSAndroid Build Coastguard Worker void PositionColorShader::shadeFragments(rr::FragmentPacket *packets, const int numPackets,
465*35238bceSAndroid Build Coastguard Worker                                          const rr::FragmentShadingContext &context) const
466*35238bceSAndroid Build Coastguard Worker {
467*35238bceSAndroid Build Coastguard Worker     for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
468*35238bceSAndroid Build Coastguard Worker     {
469*35238bceSAndroid Build Coastguard Worker         rr::FragmentPacket &packet = packets[packetNdx];
470*35238bceSAndroid Build Coastguard Worker 
471*35238bceSAndroid Build Coastguard Worker         for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
472*35238bceSAndroid Build Coastguard Worker             rr::writeFragmentOutput(context, packetNdx, fragNdx, 0,
473*35238bceSAndroid Build Coastguard Worker                                     rr::readVarying<float>(packet, context, VARYINGLOC_COLOR, fragNdx));
474*35238bceSAndroid Build Coastguard Worker     }
475*35238bceSAndroid Build Coastguard Worker }
476*35238bceSAndroid Build Coastguard Worker 
477*35238bceSAndroid Build Coastguard Worker class RenderTestCase : public TestCase
478*35238bceSAndroid Build Coastguard Worker {
479*35238bceSAndroid Build Coastguard Worker public:
480*35238bceSAndroid Build Coastguard Worker     RenderTestCase(Context &context, const char *name, const char *description);
481*35238bceSAndroid Build Coastguard Worker 
482*35238bceSAndroid Build Coastguard Worker     virtual void testRender(void) = DE_NULL;
init(void)483*35238bceSAndroid Build Coastguard Worker     virtual void init(void)
484*35238bceSAndroid Build Coastguard Worker     {
485*35238bceSAndroid Build Coastguard Worker     }
486*35238bceSAndroid Build Coastguard Worker 
487*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
488*35238bceSAndroid Build Coastguard Worker };
489*35238bceSAndroid Build Coastguard Worker 
RenderTestCase(Context & context,const char * name,const char * description)490*35238bceSAndroid Build Coastguard Worker RenderTestCase::RenderTestCase(Context &context, const char *name, const char *description)
491*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
492*35238bceSAndroid Build Coastguard Worker {
493*35238bceSAndroid Build Coastguard Worker }
494*35238bceSAndroid Build Coastguard Worker 
iterate(void)495*35238bceSAndroid Build Coastguard Worker RenderTestCase::IterateResult RenderTestCase::iterate(void)
496*35238bceSAndroid Build Coastguard Worker {
497*35238bceSAndroid Build Coastguard Worker     const int width  = m_context.getRenderTarget().getWidth();
498*35238bceSAndroid Build Coastguard Worker     const int height = m_context.getRenderTarget().getHeight();
499*35238bceSAndroid Build Coastguard Worker 
500*35238bceSAndroid Build Coastguard Worker     m_testCtx.getLog() << TestLog::Message << "Render target size: " << width << "x" << height << TestLog::EndMessage;
501*35238bceSAndroid Build Coastguard Worker     if (width < TEST_CANVAS_SIZE || height < TEST_CANVAS_SIZE)
502*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError(std::string("Render target size must be at least ") +
503*35238bceSAndroid Build Coastguard Worker                                      de::toString(TEST_CANVAS_SIZE) + "x" + de::toString(TEST_CANVAS_SIZE));
504*35238bceSAndroid Build Coastguard Worker 
505*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); // success by default
506*35238bceSAndroid Build Coastguard Worker     testRender();
507*35238bceSAndroid Build Coastguard Worker 
508*35238bceSAndroid Build Coastguard Worker     return STOP;
509*35238bceSAndroid Build Coastguard Worker }
510*35238bceSAndroid Build Coastguard Worker 
511*35238bceSAndroid Build Coastguard Worker class PointCase : public RenderTestCase
512*35238bceSAndroid Build Coastguard Worker {
513*35238bceSAndroid Build Coastguard Worker public:
514*35238bceSAndroid Build Coastguard Worker     PointCase(Context &context, const char *name, const char *description, const tcu::Vec4 *pointsBegin,
515*35238bceSAndroid Build Coastguard Worker               const tcu::Vec4 *pointsEnd, float pointSize, const rr::WindowRectangle &viewport);
516*35238bceSAndroid Build Coastguard Worker 
517*35238bceSAndroid Build Coastguard Worker     void init(void);
518*35238bceSAndroid Build Coastguard Worker     void testRender(void);
519*35238bceSAndroid Build Coastguard Worker 
520*35238bceSAndroid Build Coastguard Worker private:
521*35238bceSAndroid Build Coastguard Worker     const std::vector<tcu::Vec4> m_points;
522*35238bceSAndroid Build Coastguard Worker     const float m_pointSize;
523*35238bceSAndroid Build Coastguard Worker     const rr::WindowRectangle m_viewport;
524*35238bceSAndroid Build Coastguard Worker };
525*35238bceSAndroid Build Coastguard Worker 
PointCase(Context & context,const char * name,const char * description,const tcu::Vec4 * pointsBegin,const tcu::Vec4 * pointsEnd,float pointSize,const rr::WindowRectangle & viewport)526*35238bceSAndroid Build Coastguard Worker PointCase::PointCase(Context &context, const char *name, const char *description, const tcu::Vec4 *pointsBegin,
527*35238bceSAndroid Build Coastguard Worker                      const tcu::Vec4 *pointsEnd, float pointSize, const rr::WindowRectangle &viewport)
528*35238bceSAndroid Build Coastguard Worker     : RenderTestCase(context, name, description)
529*35238bceSAndroid Build Coastguard Worker     , m_points(pointsBegin, pointsEnd)
530*35238bceSAndroid Build Coastguard Worker     , m_pointSize(pointSize)
531*35238bceSAndroid Build Coastguard Worker     , m_viewport(viewport)
532*35238bceSAndroid Build Coastguard Worker {
533*35238bceSAndroid Build Coastguard Worker }
534*35238bceSAndroid Build Coastguard Worker 
init(void)535*35238bceSAndroid Build Coastguard Worker void PointCase::init(void)
536*35238bceSAndroid Build Coastguard Worker {
537*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
538*35238bceSAndroid Build Coastguard Worker     checkPointSize(gl, m_pointSize);
539*35238bceSAndroid Build Coastguard Worker }
540*35238bceSAndroid Build Coastguard Worker 
testRender(void)541*35238bceSAndroid Build Coastguard Worker void PointCase::testRender(void)
542*35238bceSAndroid Build Coastguard Worker {
543*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
544*35238bceSAndroid Build Coastguard Worker 
545*35238bceSAndroid Build Coastguard Worker     const int numSamples = de::max(m_context.getRenderTarget().getNumSamples(), 1);
546*35238bceSAndroid Build Coastguard Worker 
547*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
548*35238bceSAndroid Build Coastguard Worker     sglr::GLContext glesContext(m_context.getRenderContext(), log, 0,
549*35238bceSAndroid Build Coastguard Worker                                 tcu::IVec4(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE));
550*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContextLimits limits;
551*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContextBuffers buffers(m_context.getRenderTarget().getPixelFormat(),
552*35238bceSAndroid Build Coastguard Worker                                           m_context.getRenderTarget().getDepthBits(), 0, TEST_CANVAS_SIZE,
553*35238bceSAndroid Build Coastguard Worker                                           TEST_CANVAS_SIZE, numSamples);
554*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContext refContext(limits, buffers.getColorbuffer(), buffers.getDepthbuffer(),
555*35238bceSAndroid Build Coastguard Worker                                       buffers.getStencilbuffer());
556*35238bceSAndroid Build Coastguard Worker     PositionColorShader program;
557*35238bceSAndroid Build Coastguard Worker     tcu::Surface testSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
558*35238bceSAndroid Build Coastguard Worker     tcu::Surface refSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
559*35238bceSAndroid Build Coastguard Worker     sglr::Context *contexts[2] = {&glesContext, &refContext};
560*35238bceSAndroid Build Coastguard Worker     tcu::Surface *surfaces[2]  = {&testSurface, &refSurface};
561*35238bceSAndroid Build Coastguard Worker 
562*35238bceSAndroid Build Coastguard Worker     // log the purpose of the test
563*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Viewport: left=" << m_viewport.left << "\tbottom=" << m_viewport.bottom
564*35238bceSAndroid Build Coastguard Worker         << "\twidth=" << m_viewport.width << "\theight=" << m_viewport.height << TestLog::EndMessage;
565*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Rendering points with point size " << m_pointSize
566*35238bceSAndroid Build Coastguard Worker         << ". Coordinates:" << TestLog::EndMessage;
567*35238bceSAndroid Build Coastguard Worker     for (size_t ndx = 0; ndx < m_points.size(); ++ndx)
568*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tx=" << m_points[ndx].x() << "\ty=" << m_points[ndx].y()
569*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_points[ndx].z() << "\tw=" << m_points[ndx].w() << "\t"
570*35238bceSAndroid Build Coastguard Worker             << genClippingPointInfoString(m_points[ndx]) << TestLog::EndMessage;
571*35238bceSAndroid Build Coastguard Worker 
572*35238bceSAndroid Build Coastguard Worker     for (int contextNdx = 0; contextNdx < 2; ++contextNdx)
573*35238bceSAndroid Build Coastguard Worker     {
574*35238bceSAndroid Build Coastguard Worker         sglr::Context &ctx       = *contexts[contextNdx];
575*35238bceSAndroid Build Coastguard Worker         tcu::Surface &dstSurface = *surfaces[contextNdx];
576*35238bceSAndroid Build Coastguard Worker         const uint32_t programId = ctx.createProgram(&program);
577*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc  = ctx.getAttribLocation(programId, "a_position");
578*35238bceSAndroid Build Coastguard Worker         const GLint pointSizeLoc = ctx.getAttribLocation(programId, "a_pointSize");
579*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc     = ctx.getAttribLocation(programId, "a_color");
580*35238bceSAndroid Build Coastguard Worker 
581*35238bceSAndroid Build Coastguard Worker         ctx.clearColor(0, 0, 0, 1);
582*35238bceSAndroid Build Coastguard Worker         ctx.clearDepthf(1.0f);
583*35238bceSAndroid Build Coastguard Worker         ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
584*35238bceSAndroid Build Coastguard Worker         ctx.viewport(m_viewport.left, m_viewport.bottom, m_viewport.width, m_viewport.height);
585*35238bceSAndroid Build Coastguard Worker         ctx.useProgram(programId);
586*35238bceSAndroid Build Coastguard Worker         ctx.enableVertexAttribArray(positionLoc);
587*35238bceSAndroid Build Coastguard Worker         ctx.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, &m_points[0]);
588*35238bceSAndroid Build Coastguard Worker         ctx.vertexAttrib1f(pointSizeLoc, m_pointSize);
589*35238bceSAndroid Build Coastguard Worker         ctx.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
590*35238bceSAndroid Build Coastguard Worker         ctx.drawArrays(GL_POINTS, 0, (glw::GLsizei)m_points.size());
591*35238bceSAndroid Build Coastguard Worker         ctx.disableVertexAttribArray(positionLoc);
592*35238bceSAndroid Build Coastguard Worker         ctx.useProgram(0);
593*35238bceSAndroid Build Coastguard Worker         ctx.deleteProgram(programId);
594*35238bceSAndroid Build Coastguard Worker         ctx.finish();
595*35238bceSAndroid Build Coastguard Worker 
596*35238bceSAndroid Build Coastguard Worker         ctx.readPixels(dstSurface, 0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
597*35238bceSAndroid Build Coastguard Worker     }
598*35238bceSAndroid Build Coastguard Worker 
599*35238bceSAndroid Build Coastguard Worker     // do the comparison
600*35238bceSAndroid Build Coastguard Worker     {
601*35238bceSAndroid Build Coastguard Worker         tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
602*35238bceSAndroid Build Coastguard Worker         const int kernelRadius = 1;
603*35238bceSAndroid Build Coastguard Worker         int faultyPixels;
604*35238bceSAndroid Build Coastguard Worker 
605*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
606*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Deviation within radius of " << kernelRadius << " is allowed."
607*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
608*35238bceSAndroid Build Coastguard Worker 
609*35238bceSAndroid Build Coastguard Worker         faultyPixels = compareBlackNonBlackImages(log, testSurface.getAccess(), refSurface.getAccess(),
610*35238bceSAndroid Build Coastguard Worker                                                   diffMask.getAccess(), kernelRadius);
611*35238bceSAndroid Build Coastguard Worker 
612*35238bceSAndroid Build Coastguard Worker         if (faultyPixels > 0)
613*35238bceSAndroid Build Coastguard Worker         {
614*35238bceSAndroid Build Coastguard Worker             log << TestLog::ImageSet("Images", "Image comparison")
615*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("TestImage", "Test image", testSurface.getAccess())
616*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("ReferenceImage", "Reference image", refSurface.getAccess())
617*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
618*35238bceSAndroid Build Coastguard Worker                 << tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
619*35238bceSAndroid Build Coastguard Worker 
620*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
621*35238bceSAndroid Build Coastguard Worker         }
622*35238bceSAndroid Build Coastguard Worker     }
623*35238bceSAndroid Build Coastguard Worker }
624*35238bceSAndroid Build Coastguard Worker 
625*35238bceSAndroid Build Coastguard Worker class LineRenderTestCase : public RenderTestCase
626*35238bceSAndroid Build Coastguard Worker {
627*35238bceSAndroid Build Coastguard Worker public:
628*35238bceSAndroid Build Coastguard Worker     struct ColoredLineData
629*35238bceSAndroid Build Coastguard Worker     {
630*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 p0;
631*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 c0;
632*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 p1;
633*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 c1;
634*35238bceSAndroid Build Coastguard Worker     };
635*35238bceSAndroid Build Coastguard Worker 
636*35238bceSAndroid Build Coastguard Worker     struct ColorlessLineData
637*35238bceSAndroid Build Coastguard Worker     {
638*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 p0;
639*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 p1;
640*35238bceSAndroid Build Coastguard Worker     };
641*35238bceSAndroid Build Coastguard Worker     LineRenderTestCase(Context &context, const char *name, const char *description, const ColoredLineData *linesBegin,
642*35238bceSAndroid Build Coastguard Worker                        const ColoredLineData *linesEnd, float lineWidth, const rr::WindowRectangle &viewport);
643*35238bceSAndroid Build Coastguard Worker     LineRenderTestCase(Context &context, const char *name, const char *description, const ColorlessLineData *linesBegin,
644*35238bceSAndroid Build Coastguard Worker                        const ColorlessLineData *linesEnd, float lineWidth, const rr::WindowRectangle &viewport);
645*35238bceSAndroid Build Coastguard Worker 
646*35238bceSAndroid Build Coastguard Worker     virtual void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
647*35238bceSAndroid Build Coastguard Worker                              const tcu::ConstPixelBufferAccess &referenceImageAccess) = DE_NULL;
648*35238bceSAndroid Build Coastguard Worker     void init(void);
649*35238bceSAndroid Build Coastguard Worker     void testRender(void);
650*35238bceSAndroid Build Coastguard Worker 
651*35238bceSAndroid Build Coastguard Worker protected:
652*35238bceSAndroid Build Coastguard Worker     const float m_lineWidth;
653*35238bceSAndroid Build Coastguard Worker 
654*35238bceSAndroid Build Coastguard Worker private:
655*35238bceSAndroid Build Coastguard Worker     std::vector<ColoredLineData> convertToColoredLines(const ColorlessLineData *linesBegin,
656*35238bceSAndroid Build Coastguard Worker                                                        const ColorlessLineData *linesEnd);
657*35238bceSAndroid Build Coastguard Worker 
658*35238bceSAndroid Build Coastguard Worker     const std::vector<ColoredLineData> m_lines;
659*35238bceSAndroid Build Coastguard Worker     const rr::WindowRectangle m_viewport;
660*35238bceSAndroid Build Coastguard Worker };
661*35238bceSAndroid Build Coastguard Worker 
LineRenderTestCase(Context & context,const char * name,const char * description,const ColoredLineData * linesBegin,const ColoredLineData * linesEnd,float lineWidth,const rr::WindowRectangle & viewport)662*35238bceSAndroid Build Coastguard Worker LineRenderTestCase::LineRenderTestCase(Context &context, const char *name, const char *description,
663*35238bceSAndroid Build Coastguard Worker                                        const ColoredLineData *linesBegin, const ColoredLineData *linesEnd,
664*35238bceSAndroid Build Coastguard Worker                                        float lineWidth, const rr::WindowRectangle &viewport)
665*35238bceSAndroid Build Coastguard Worker     : RenderTestCase(context, name, description)
666*35238bceSAndroid Build Coastguard Worker     , m_lineWidth(lineWidth)
667*35238bceSAndroid Build Coastguard Worker     , m_lines(linesBegin, linesEnd)
668*35238bceSAndroid Build Coastguard Worker     , m_viewport(viewport)
669*35238bceSAndroid Build Coastguard Worker {
670*35238bceSAndroid Build Coastguard Worker }
671*35238bceSAndroid Build Coastguard Worker 
LineRenderTestCase(Context & context,const char * name,const char * description,const ColorlessLineData * linesBegin,const ColorlessLineData * linesEnd,float lineWidth,const rr::WindowRectangle & viewport)672*35238bceSAndroid Build Coastguard Worker LineRenderTestCase::LineRenderTestCase(Context &context, const char *name, const char *description,
673*35238bceSAndroid Build Coastguard Worker                                        const ColorlessLineData *linesBegin, const ColorlessLineData *linesEnd,
674*35238bceSAndroid Build Coastguard Worker                                        float lineWidth, const rr::WindowRectangle &viewport)
675*35238bceSAndroid Build Coastguard Worker     : RenderTestCase(context, name, description)
676*35238bceSAndroid Build Coastguard Worker     , m_lineWidth(lineWidth)
677*35238bceSAndroid Build Coastguard Worker     , m_lines(convertToColoredLines(linesBegin, linesEnd))
678*35238bceSAndroid Build Coastguard Worker     , m_viewport(viewport)
679*35238bceSAndroid Build Coastguard Worker {
680*35238bceSAndroid Build Coastguard Worker }
681*35238bceSAndroid Build Coastguard Worker 
init(void)682*35238bceSAndroid Build Coastguard Worker void LineRenderTestCase::init(void)
683*35238bceSAndroid Build Coastguard Worker {
684*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
685*35238bceSAndroid Build Coastguard Worker     checkLineWidth(gl, m_lineWidth);
686*35238bceSAndroid Build Coastguard Worker }
687*35238bceSAndroid Build Coastguard Worker 
testRender(void)688*35238bceSAndroid Build Coastguard Worker void LineRenderTestCase::testRender(void)
689*35238bceSAndroid Build Coastguard Worker {
690*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
691*35238bceSAndroid Build Coastguard Worker 
692*35238bceSAndroid Build Coastguard Worker     const int numSamples      = de::max(m_context.getRenderTarget().getNumSamples(), 1);
693*35238bceSAndroid Build Coastguard Worker     const int verticesPerLine = 2;
694*35238bceSAndroid Build Coastguard Worker 
695*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
696*35238bceSAndroid Build Coastguard Worker     sglr::GLContext glesContext(m_context.getRenderContext(), log, 0,
697*35238bceSAndroid Build Coastguard Worker                                 tcu::IVec4(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE));
698*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContextLimits limits;
699*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContextBuffers buffers(m_context.getRenderTarget().getPixelFormat(),
700*35238bceSAndroid Build Coastguard Worker                                           m_context.getRenderTarget().getDepthBits(), 0, TEST_CANVAS_SIZE,
701*35238bceSAndroid Build Coastguard Worker                                           TEST_CANVAS_SIZE, numSamples);
702*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContext refContext(limits, buffers.getColorbuffer(), buffers.getDepthbuffer(),
703*35238bceSAndroid Build Coastguard Worker                                       buffers.getStencilbuffer());
704*35238bceSAndroid Build Coastguard Worker     PositionColorShader program;
705*35238bceSAndroid Build Coastguard Worker     tcu::Surface testSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
706*35238bceSAndroid Build Coastguard Worker     tcu::Surface refSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
707*35238bceSAndroid Build Coastguard Worker     sglr::Context *contexts[2] = {&glesContext, &refContext};
708*35238bceSAndroid Build Coastguard Worker     tcu::Surface *surfaces[2]  = {&testSurface, &refSurface};
709*35238bceSAndroid Build Coastguard Worker 
710*35238bceSAndroid Build Coastguard Worker     // log the purpose of the test
711*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Viewport: left=" << m_viewport.left << "\tbottom=" << m_viewport.bottom
712*35238bceSAndroid Build Coastguard Worker         << "\twidth=" << m_viewport.width << "\theight=" << m_viewport.height << TestLog::EndMessage;
713*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Rendering lines with line width " << m_lineWidth
714*35238bceSAndroid Build Coastguard Worker         << ". Coordinates:" << TestLog::EndMessage;
715*35238bceSAndroid Build Coastguard Worker     for (size_t ndx = 0; ndx < m_lines.size(); ++ndx)
716*35238bceSAndroid Build Coastguard Worker     {
717*35238bceSAndroid Build Coastguard Worker         const std::string fromProperties = genClippingPointInfoString(m_lines[ndx].p0);
718*35238bceSAndroid Build Coastguard Worker         const std::string toProperties   = genClippingPointInfoString(m_lines[ndx].p1);
719*35238bceSAndroid Build Coastguard Worker 
720*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tfrom (x=" << m_lines[ndx].p0.x() << "\ty=" << m_lines[ndx].p0.y()
721*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_lines[ndx].p0.z() << "\tw=" << m_lines[ndx].p0.w() << ")\t" << fromProperties
722*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
723*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tto   (x=" << m_lines[ndx].p1.x() << "\ty=" << m_lines[ndx].p1.y()
724*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_lines[ndx].p1.z() << "\tw=" << m_lines[ndx].p1.w() << ")\t" << toProperties
725*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
726*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << TestLog::EndMessage;
727*35238bceSAndroid Build Coastguard Worker     }
728*35238bceSAndroid Build Coastguard Worker 
729*35238bceSAndroid Build Coastguard Worker     // render test image
730*35238bceSAndroid Build Coastguard Worker     for (int contextNdx = 0; contextNdx < 2; ++contextNdx)
731*35238bceSAndroid Build Coastguard Worker     {
732*35238bceSAndroid Build Coastguard Worker         sglr::Context &ctx       = *contexts[contextNdx];
733*35238bceSAndroid Build Coastguard Worker         tcu::Surface &dstSurface = *surfaces[contextNdx];
734*35238bceSAndroid Build Coastguard Worker         const uint32_t programId = ctx.createProgram(&program);
735*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc  = ctx.getAttribLocation(programId, "a_position");
736*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc     = ctx.getAttribLocation(programId, "a_color");
737*35238bceSAndroid Build Coastguard Worker 
738*35238bceSAndroid Build Coastguard Worker         ctx.clearColor(0, 0, 0, 1);
739*35238bceSAndroid Build Coastguard Worker         ctx.clearDepthf(1.0f);
740*35238bceSAndroid Build Coastguard Worker         ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
741*35238bceSAndroid Build Coastguard Worker         ctx.viewport(m_viewport.left, m_viewport.bottom, m_viewport.width, m_viewport.height);
742*35238bceSAndroid Build Coastguard Worker         ctx.useProgram(programId);
743*35238bceSAndroid Build Coastguard Worker         ctx.enableVertexAttribArray(positionLoc);
744*35238bceSAndroid Build Coastguard Worker         ctx.enableVertexAttribArray(colorLoc);
745*35238bceSAndroid Build Coastguard Worker         ctx.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat[8]), &m_lines[0].p0);
746*35238bceSAndroid Build Coastguard Worker         ctx.vertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat[8]), &m_lines[0].c0);
747*35238bceSAndroid Build Coastguard Worker         ctx.lineWidth(m_lineWidth);
748*35238bceSAndroid Build Coastguard Worker         ctx.drawArrays(GL_LINES, 0, verticesPerLine * (glw::GLsizei)m_lines.size());
749*35238bceSAndroid Build Coastguard Worker         ctx.disableVertexAttribArray(positionLoc);
750*35238bceSAndroid Build Coastguard Worker         ctx.disableVertexAttribArray(colorLoc);
751*35238bceSAndroid Build Coastguard Worker         ctx.useProgram(0);
752*35238bceSAndroid Build Coastguard Worker         ctx.deleteProgram(programId);
753*35238bceSAndroid Build Coastguard Worker         ctx.finish();
754*35238bceSAndroid Build Coastguard Worker 
755*35238bceSAndroid Build Coastguard Worker         ctx.readPixels(dstSurface, 0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
756*35238bceSAndroid Build Coastguard Worker     }
757*35238bceSAndroid Build Coastguard Worker 
758*35238bceSAndroid Build Coastguard Worker     // compare
759*35238bceSAndroid Build Coastguard Worker     verifyImage(testSurface.getAccess(), refSurface.getAccess());
760*35238bceSAndroid Build Coastguard Worker }
761*35238bceSAndroid Build Coastguard Worker 
convertToColoredLines(const ColorlessLineData * linesBegin,const ColorlessLineData * linesEnd)762*35238bceSAndroid Build Coastguard Worker std::vector<LineRenderTestCase::ColoredLineData> LineRenderTestCase::convertToColoredLines(
763*35238bceSAndroid Build Coastguard Worker     const ColorlessLineData *linesBegin, const ColorlessLineData *linesEnd)
764*35238bceSAndroid Build Coastguard Worker {
765*35238bceSAndroid Build Coastguard Worker     std::vector<ColoredLineData> ret;
766*35238bceSAndroid Build Coastguard Worker 
767*35238bceSAndroid Build Coastguard Worker     for (const ColorlessLineData *it = linesBegin; it != linesEnd; ++it)
768*35238bceSAndroid Build Coastguard Worker     {
769*35238bceSAndroid Build Coastguard Worker         ColoredLineData r;
770*35238bceSAndroid Build Coastguard Worker 
771*35238bceSAndroid Build Coastguard Worker         r.p0 = (*it).p0;
772*35238bceSAndroid Build Coastguard Worker         r.c0 = tcu::Vec4(1, 1, 1, 1);
773*35238bceSAndroid Build Coastguard Worker         r.p1 = (*it).p1;
774*35238bceSAndroid Build Coastguard Worker         r.c1 = tcu::Vec4(1, 1, 1, 1);
775*35238bceSAndroid Build Coastguard Worker 
776*35238bceSAndroid Build Coastguard Worker         ret.push_back(r);
777*35238bceSAndroid Build Coastguard Worker     }
778*35238bceSAndroid Build Coastguard Worker 
779*35238bceSAndroid Build Coastguard Worker     return ret;
780*35238bceSAndroid Build Coastguard Worker }
781*35238bceSAndroid Build Coastguard Worker 
782*35238bceSAndroid Build Coastguard Worker class LineCase : public LineRenderTestCase
783*35238bceSAndroid Build Coastguard Worker {
784*35238bceSAndroid Build Coastguard Worker public:
785*35238bceSAndroid Build Coastguard Worker     LineCase(Context &context, const char *name, const char *description,
786*35238bceSAndroid Build Coastguard Worker              const LineRenderTestCase::ColorlessLineData *linesBegin,
787*35238bceSAndroid Build Coastguard Worker              const LineRenderTestCase::ColorlessLineData *linesEnd, float lineWidth,
788*35238bceSAndroid Build Coastguard Worker              const rr::WindowRectangle &viewport, int searchKernelSize = 1);
789*35238bceSAndroid Build Coastguard Worker 
790*35238bceSAndroid Build Coastguard Worker     void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
791*35238bceSAndroid Build Coastguard Worker                      const tcu::ConstPixelBufferAccess &referenceImageAccess);
792*35238bceSAndroid Build Coastguard Worker 
793*35238bceSAndroid Build Coastguard Worker private:
794*35238bceSAndroid Build Coastguard Worker     const int m_searchKernelSize;
795*35238bceSAndroid Build Coastguard Worker };
796*35238bceSAndroid Build Coastguard Worker 
LineCase(Context & context,const char * name,const char * description,const LineRenderTestCase::ColorlessLineData * linesBegin,const LineRenderTestCase::ColorlessLineData * linesEnd,float lineWidth,const rr::WindowRectangle & viewport,int searchKernelSize)797*35238bceSAndroid Build Coastguard Worker LineCase::LineCase(Context &context, const char *name, const char *description,
798*35238bceSAndroid Build Coastguard Worker                    const LineRenderTestCase::ColorlessLineData *linesBegin,
799*35238bceSAndroid Build Coastguard Worker                    const LineRenderTestCase::ColorlessLineData *linesEnd, float lineWidth,
800*35238bceSAndroid Build Coastguard Worker                    const rr::WindowRectangle &viewport, int searchKernelSize)
801*35238bceSAndroid Build Coastguard Worker     : LineRenderTestCase(context, name, description, linesBegin, linesEnd, lineWidth, viewport)
802*35238bceSAndroid Build Coastguard Worker     , m_searchKernelSize(searchKernelSize)
803*35238bceSAndroid Build Coastguard Worker {
804*35238bceSAndroid Build Coastguard Worker }
805*35238bceSAndroid Build Coastguard Worker 
verifyImage(const tcu::ConstPixelBufferAccess & testImageAccess,const tcu::ConstPixelBufferAccess & referenceImageAccess)806*35238bceSAndroid Build Coastguard Worker void LineCase::verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
807*35238bceSAndroid Build Coastguard Worker                            const tcu::ConstPixelBufferAccess &referenceImageAccess)
808*35238bceSAndroid Build Coastguard Worker {
809*35238bceSAndroid Build Coastguard Worker     const int faultyLimit = 6;
810*35238bceSAndroid Build Coastguard Worker     int faultyPixels;
811*35238bceSAndroid Build Coastguard Worker 
812*35238bceSAndroid Build Coastguard Worker     const bool isMsaa = m_context.getRenderTarget().getNumSamples() > 1;
813*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
814*35238bceSAndroid Build Coastguard Worker     tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
815*35238bceSAndroid Build Coastguard Worker 
816*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
817*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Deviation within radius of " << m_searchKernelSize << " is allowed."
818*35238bceSAndroid Build Coastguard Worker         << TestLog::EndMessage;
819*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << faultyLimit << " faulty pixels are allowed." << TestLog::EndMessage;
820*35238bceSAndroid Build Coastguard Worker 
821*35238bceSAndroid Build Coastguard Worker     faultyPixels = compareBlackNonBlackImages(log, testImageAccess, referenceImageAccess, diffMask.getAccess(),
822*35238bceSAndroid Build Coastguard Worker                                               m_searchKernelSize);
823*35238bceSAndroid Build Coastguard Worker 
824*35238bceSAndroid Build Coastguard Worker     if (faultyPixels > faultyLimit)
825*35238bceSAndroid Build Coastguard Worker     {
826*35238bceSAndroid Build Coastguard Worker         log << TestLog::ImageSet("Images", "Image comparison")
827*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("TestImage", "Test image", testImageAccess)
828*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("ReferenceImage", "Reference image", referenceImageAccess)
829*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
830*35238bceSAndroid Build Coastguard Worker             << tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
831*35238bceSAndroid Build Coastguard Worker 
832*35238bceSAndroid Build Coastguard Worker         if (m_lineWidth != 1.0f && isMsaa)
833*35238bceSAndroid Build Coastguard Worker         {
834*35238bceSAndroid Build Coastguard Worker             log << TestLog::Message << "Wide line support is optional, reporting compatibility warning."
835*35238bceSAndroid Build Coastguard Worker                 << TestLog::EndMessage;
836*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Wide line clipping failed");
837*35238bceSAndroid Build Coastguard Worker         }
838*35238bceSAndroid Build Coastguard Worker         else
839*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
840*35238bceSAndroid Build Coastguard Worker     }
841*35238bceSAndroid Build Coastguard Worker }
842*35238bceSAndroid Build Coastguard Worker 
843*35238bceSAndroid Build Coastguard Worker class ColoredLineCase : public LineRenderTestCase
844*35238bceSAndroid Build Coastguard Worker {
845*35238bceSAndroid Build Coastguard Worker public:
846*35238bceSAndroid Build Coastguard Worker     ColoredLineCase(Context &context, const char *name, const char *description,
847*35238bceSAndroid Build Coastguard Worker                     const LineRenderTestCase::ColoredLineData *linesBegin,
848*35238bceSAndroid Build Coastguard Worker                     const LineRenderTestCase::ColoredLineData *linesEnd, float lineWidth,
849*35238bceSAndroid Build Coastguard Worker                     const rr::WindowRectangle &viewport);
850*35238bceSAndroid Build Coastguard Worker 
851*35238bceSAndroid Build Coastguard Worker     void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
852*35238bceSAndroid Build Coastguard Worker                      const tcu::ConstPixelBufferAccess &referenceImageAccess);
853*35238bceSAndroid Build Coastguard Worker };
854*35238bceSAndroid Build Coastguard Worker 
ColoredLineCase(Context & context,const char * name,const char * description,const LineRenderTestCase::ColoredLineData * linesBegin,const LineRenderTestCase::ColoredLineData * linesEnd,float lineWidth,const rr::WindowRectangle & viewport)855*35238bceSAndroid Build Coastguard Worker ColoredLineCase::ColoredLineCase(Context &context, const char *name, const char *description,
856*35238bceSAndroid Build Coastguard Worker                                  const LineRenderTestCase::ColoredLineData *linesBegin,
857*35238bceSAndroid Build Coastguard Worker                                  const LineRenderTestCase::ColoredLineData *linesEnd, float lineWidth,
858*35238bceSAndroid Build Coastguard Worker                                  const rr::WindowRectangle &viewport)
859*35238bceSAndroid Build Coastguard Worker     : LineRenderTestCase(context, name, description, linesBegin, linesEnd, lineWidth, viewport)
860*35238bceSAndroid Build Coastguard Worker {
861*35238bceSAndroid Build Coastguard Worker }
862*35238bceSAndroid Build Coastguard Worker 
verifyImage(const tcu::ConstPixelBufferAccess & testImageAccess,const tcu::ConstPixelBufferAccess & referenceImageAccess)863*35238bceSAndroid Build Coastguard Worker void ColoredLineCase::verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
864*35238bceSAndroid Build Coastguard Worker                                   const tcu::ConstPixelBufferAccess &referenceImageAccess)
865*35238bceSAndroid Build Coastguard Worker {
866*35238bceSAndroid Build Coastguard Worker     const bool msaa   = m_context.getRenderTarget().getNumSamples() > 1;
867*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
868*35238bceSAndroid Build Coastguard Worker 
869*35238bceSAndroid Build Coastguard Worker     if (!msaa)
870*35238bceSAndroid Build Coastguard Worker     {
871*35238bceSAndroid Build Coastguard Worker         const int kernelRadius = 1;
872*35238bceSAndroid Build Coastguard Worker         const int faultyLimit  = 6;
873*35238bceSAndroid Build Coastguard Worker         int faultyPixels;
874*35238bceSAndroid Build Coastguard Worker 
875*35238bceSAndroid Build Coastguard Worker         tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
876*35238bceSAndroid Build Coastguard Worker 
877*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
878*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Deviation within radius of " << kernelRadius << " is allowed."
879*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
880*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << faultyLimit << " faulty pixels are allowed." << TestLog::EndMessage;
881*35238bceSAndroid Build Coastguard Worker 
882*35238bceSAndroid Build Coastguard Worker         faultyPixels =
883*35238bceSAndroid Build Coastguard Worker             compareColoredImages(log, testImageAccess, referenceImageAccess, diffMask.getAccess(), kernelRadius);
884*35238bceSAndroid Build Coastguard Worker 
885*35238bceSAndroid Build Coastguard Worker         if (faultyPixels > faultyLimit)
886*35238bceSAndroid Build Coastguard Worker         {
887*35238bceSAndroid Build Coastguard Worker             log << TestLog::ImageSet("Images", "Image comparison")
888*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("TestImage", "Test image", testImageAccess)
889*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("ReferenceImage", "Reference image", referenceImageAccess)
890*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
891*35238bceSAndroid Build Coastguard Worker                 << tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
892*35238bceSAndroid Build Coastguard Worker 
893*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
894*35238bceSAndroid Build Coastguard Worker         }
895*35238bceSAndroid Build Coastguard Worker     }
896*35238bceSAndroid Build Coastguard Worker     else
897*35238bceSAndroid Build Coastguard Worker     {
898*35238bceSAndroid Build Coastguard Worker         const float threshold = 0.3f;
899*35238bceSAndroid Build Coastguard Worker         if (!tcu::fuzzyCompare(log, "Images", "", referenceImageAccess, testImageAccess, threshold,
900*35238bceSAndroid Build Coastguard Worker                                tcu::COMPARE_LOG_ON_ERROR))
901*35238bceSAndroid Build Coastguard Worker         {
902*35238bceSAndroid Build Coastguard Worker             if (m_lineWidth != 1.0f)
903*35238bceSAndroid Build Coastguard Worker             {
904*35238bceSAndroid Build Coastguard Worker                 log << TestLog::Message << "Wide line support is optional, reporting compatibility warning."
905*35238bceSAndroid Build Coastguard Worker                     << TestLog::EndMessage;
906*35238bceSAndroid Build Coastguard Worker                 m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Wide line clipping failed");
907*35238bceSAndroid Build Coastguard Worker             }
908*35238bceSAndroid Build Coastguard Worker             else
909*35238bceSAndroid Build Coastguard Worker                 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
910*35238bceSAndroid Build Coastguard Worker         }
911*35238bceSAndroid Build Coastguard Worker     }
912*35238bceSAndroid Build Coastguard Worker }
913*35238bceSAndroid Build Coastguard Worker 
914*35238bceSAndroid Build Coastguard Worker class TriangleCaseBase : public RenderTestCase
915*35238bceSAndroid Build Coastguard Worker {
916*35238bceSAndroid Build Coastguard Worker public:
917*35238bceSAndroid Build Coastguard Worker     struct TriangleData
918*35238bceSAndroid Build Coastguard Worker     {
919*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 p0;
920*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 c0;
921*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 p1;
922*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 c1;
923*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 p2;
924*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 c2;
925*35238bceSAndroid Build Coastguard Worker     };
926*35238bceSAndroid Build Coastguard Worker 
927*35238bceSAndroid Build Coastguard Worker     TriangleCaseBase(Context &context, const char *name, const char *description, const TriangleData *polysBegin,
928*35238bceSAndroid Build Coastguard Worker                      const TriangleData *polysEnd, const rr::WindowRectangle &viewport);
929*35238bceSAndroid Build Coastguard Worker 
930*35238bceSAndroid Build Coastguard Worker     virtual void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
931*35238bceSAndroid Build Coastguard Worker                              const tcu::ConstPixelBufferAccess &referenceImageAccess) = DE_NULL;
932*35238bceSAndroid Build Coastguard Worker     void testRender(void);
933*35238bceSAndroid Build Coastguard Worker 
934*35238bceSAndroid Build Coastguard Worker private:
935*35238bceSAndroid Build Coastguard Worker     const std::vector<TriangleData> m_polys;
936*35238bceSAndroid Build Coastguard Worker     const rr::WindowRectangle m_viewport;
937*35238bceSAndroid Build Coastguard Worker };
938*35238bceSAndroid Build Coastguard Worker 
TriangleCaseBase(Context & context,const char * name,const char * description,const TriangleData * polysBegin,const TriangleData * polysEnd,const rr::WindowRectangle & viewport)939*35238bceSAndroid Build Coastguard Worker TriangleCaseBase::TriangleCaseBase(Context &context, const char *name, const char *description,
940*35238bceSAndroid Build Coastguard Worker                                    const TriangleData *polysBegin, const TriangleData *polysEnd,
941*35238bceSAndroid Build Coastguard Worker                                    const rr::WindowRectangle &viewport)
942*35238bceSAndroid Build Coastguard Worker     : RenderTestCase(context, name, description)
943*35238bceSAndroid Build Coastguard Worker     , m_polys(polysBegin, polysEnd)
944*35238bceSAndroid Build Coastguard Worker     , m_viewport(viewport)
945*35238bceSAndroid Build Coastguard Worker {
946*35238bceSAndroid Build Coastguard Worker }
947*35238bceSAndroid Build Coastguard Worker 
testRender(void)948*35238bceSAndroid Build Coastguard Worker void TriangleCaseBase::testRender(void)
949*35238bceSAndroid Build Coastguard Worker {
950*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
951*35238bceSAndroid Build Coastguard Worker 
952*35238bceSAndroid Build Coastguard Worker     const int numSamples          = de::max(m_context.getRenderTarget().getNumSamples(), 1);
953*35238bceSAndroid Build Coastguard Worker     const int verticesPerTriangle = 3;
954*35238bceSAndroid Build Coastguard Worker 
955*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
956*35238bceSAndroid Build Coastguard Worker     sglr::GLContext glesContext(m_context.getRenderContext(), log, 0,
957*35238bceSAndroid Build Coastguard Worker                                 tcu::IVec4(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE));
958*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContextLimits limits;
959*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContextBuffers buffers(m_context.getRenderTarget().getPixelFormat(),
960*35238bceSAndroid Build Coastguard Worker                                           m_context.getRenderTarget().getDepthBits(), 0, TEST_CANVAS_SIZE,
961*35238bceSAndroid Build Coastguard Worker                                           TEST_CANVAS_SIZE, numSamples);
962*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContext refContext(limits, buffers.getColorbuffer(), buffers.getDepthbuffer(),
963*35238bceSAndroid Build Coastguard Worker                                       buffers.getStencilbuffer());
964*35238bceSAndroid Build Coastguard Worker     PositionColorShader program;
965*35238bceSAndroid Build Coastguard Worker     tcu::Surface testSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
966*35238bceSAndroid Build Coastguard Worker     tcu::Surface refSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
967*35238bceSAndroid Build Coastguard Worker     sglr::Context *contexts[2] = {&glesContext, &refContext};
968*35238bceSAndroid Build Coastguard Worker     tcu::Surface *surfaces[2]  = {&testSurface, &refSurface};
969*35238bceSAndroid Build Coastguard Worker 
970*35238bceSAndroid Build Coastguard Worker     // log the purpose of the test
971*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Viewport: left=" << m_viewport.left << "\tbottom=" << m_viewport.bottom
972*35238bceSAndroid Build Coastguard Worker         << "\twidth=" << m_viewport.width << "\theight=" << m_viewport.height << TestLog::EndMessage;
973*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Rendering triangles. Coordinates:" << TestLog::EndMessage;
974*35238bceSAndroid Build Coastguard Worker     for (size_t ndx = 0; ndx < m_polys.size(); ++ndx)
975*35238bceSAndroid Build Coastguard Worker     {
976*35238bceSAndroid Build Coastguard Worker         const std::string v0Properties = genClippingPointInfoString(m_polys[ndx].p0);
977*35238bceSAndroid Build Coastguard Worker         const std::string v1Properties = genClippingPointInfoString(m_polys[ndx].p1);
978*35238bceSAndroid Build Coastguard Worker         const std::string v2Properties = genClippingPointInfoString(m_polys[ndx].p2);
979*35238bceSAndroid Build Coastguard Worker         const std::string c0Properties = genColorString(m_polys[ndx].c0);
980*35238bceSAndroid Build Coastguard Worker         const std::string c1Properties = genColorString(m_polys[ndx].c1);
981*35238bceSAndroid Build Coastguard Worker         const std::string c2Properties = genColorString(m_polys[ndx].c2);
982*35238bceSAndroid Build Coastguard Worker 
983*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tv0 (x=" << m_polys[ndx].p0.x() << "\ty=" << m_polys[ndx].p0.y()
984*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_polys[ndx].p0.z() << "\tw=" << m_polys[ndx].p0.w() << ")\t" << v0Properties << "\t"
985*35238bceSAndroid Build Coastguard Worker             << c0Properties << TestLog::EndMessage;
986*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tv1 (x=" << m_polys[ndx].p1.x() << "\ty=" << m_polys[ndx].p1.y()
987*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_polys[ndx].p1.z() << "\tw=" << m_polys[ndx].p1.w() << ")\t" << v1Properties << "\t"
988*35238bceSAndroid Build Coastguard Worker             << c1Properties << TestLog::EndMessage;
989*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tv2 (x=" << m_polys[ndx].p2.x() << "\ty=" << m_polys[ndx].p2.y()
990*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_polys[ndx].p2.z() << "\tw=" << m_polys[ndx].p2.w() << ")\t" << v2Properties << "\t"
991*35238bceSAndroid Build Coastguard Worker             << c2Properties << TestLog::EndMessage;
992*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << TestLog::EndMessage;
993*35238bceSAndroid Build Coastguard Worker     }
994*35238bceSAndroid Build Coastguard Worker 
995*35238bceSAndroid Build Coastguard Worker     // render test image
996*35238bceSAndroid Build Coastguard Worker     for (int contextNdx = 0; contextNdx < 2; ++contextNdx)
997*35238bceSAndroid Build Coastguard Worker     {
998*35238bceSAndroid Build Coastguard Worker         sglr::Context &ctx       = *contexts[contextNdx];
999*35238bceSAndroid Build Coastguard Worker         tcu::Surface &dstSurface = *surfaces[contextNdx];
1000*35238bceSAndroid Build Coastguard Worker         const uint32_t programId = ctx.createProgram(&program);
1001*35238bceSAndroid Build Coastguard Worker         const GLint positionLoc  = ctx.getAttribLocation(programId, "a_position");
1002*35238bceSAndroid Build Coastguard Worker         const GLint colorLoc     = ctx.getAttribLocation(programId, "a_color");
1003*35238bceSAndroid Build Coastguard Worker 
1004*35238bceSAndroid Build Coastguard Worker         ctx.clearColor(0, 0, 0, 1);
1005*35238bceSAndroid Build Coastguard Worker         ctx.clearDepthf(1.0f);
1006*35238bceSAndroid Build Coastguard Worker         ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1007*35238bceSAndroid Build Coastguard Worker         ctx.viewport(m_viewport.left, m_viewport.bottom, m_viewport.width, m_viewport.height);
1008*35238bceSAndroid Build Coastguard Worker         ctx.useProgram(programId);
1009*35238bceSAndroid Build Coastguard Worker         ctx.enableVertexAttribArray(positionLoc);
1010*35238bceSAndroid Build Coastguard Worker         ctx.enableVertexAttribArray(colorLoc);
1011*35238bceSAndroid Build Coastguard Worker         ctx.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat[8]), &m_polys[0].p0);
1012*35238bceSAndroid Build Coastguard Worker         ctx.vertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat[8]), &m_polys[0].c0);
1013*35238bceSAndroid Build Coastguard Worker         ctx.drawArrays(GL_TRIANGLES, 0, verticesPerTriangle * (glw::GLsizei)m_polys.size());
1014*35238bceSAndroid Build Coastguard Worker         ctx.disableVertexAttribArray(positionLoc);
1015*35238bceSAndroid Build Coastguard Worker         ctx.disableVertexAttribArray(colorLoc);
1016*35238bceSAndroid Build Coastguard Worker         ctx.useProgram(0);
1017*35238bceSAndroid Build Coastguard Worker         ctx.deleteProgram(programId);
1018*35238bceSAndroid Build Coastguard Worker         ctx.finish();
1019*35238bceSAndroid Build Coastguard Worker 
1020*35238bceSAndroid Build Coastguard Worker         ctx.readPixels(dstSurface, 0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1021*35238bceSAndroid Build Coastguard Worker     }
1022*35238bceSAndroid Build Coastguard Worker 
1023*35238bceSAndroid Build Coastguard Worker     verifyImage(testSurface.getAccess(), refSurface.getAccess());
1024*35238bceSAndroid Build Coastguard Worker }
1025*35238bceSAndroid Build Coastguard Worker 
1026*35238bceSAndroid Build Coastguard Worker class TriangleCase : public TriangleCaseBase
1027*35238bceSAndroid Build Coastguard Worker {
1028*35238bceSAndroid Build Coastguard Worker public:
1029*35238bceSAndroid Build Coastguard Worker     TriangleCase(Context &context, const char *name, const char *description, const TriangleData *polysBegin,
1030*35238bceSAndroid Build Coastguard Worker                  const TriangleData *polysEnd, const rr::WindowRectangle &viewport);
1031*35238bceSAndroid Build Coastguard Worker 
1032*35238bceSAndroid Build Coastguard Worker     void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
1033*35238bceSAndroid Build Coastguard Worker                      const tcu::ConstPixelBufferAccess &referenceImageAccess);
1034*35238bceSAndroid Build Coastguard Worker };
1035*35238bceSAndroid Build Coastguard Worker 
TriangleCase(Context & context,const char * name,const char * description,const TriangleData * polysBegin,const TriangleData * polysEnd,const rr::WindowRectangle & viewport)1036*35238bceSAndroid Build Coastguard Worker TriangleCase::TriangleCase(Context &context, const char *name, const char *description, const TriangleData *polysBegin,
1037*35238bceSAndroid Build Coastguard Worker                            const TriangleData *polysEnd, const rr::WindowRectangle &viewport)
1038*35238bceSAndroid Build Coastguard Worker     : TriangleCaseBase(context, name, description, polysBegin, polysEnd, viewport)
1039*35238bceSAndroid Build Coastguard Worker {
1040*35238bceSAndroid Build Coastguard Worker }
1041*35238bceSAndroid Build Coastguard Worker 
verifyImage(const tcu::ConstPixelBufferAccess & testImageAccess,const tcu::ConstPixelBufferAccess & referenceImageAccess)1042*35238bceSAndroid Build Coastguard Worker void TriangleCase::verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
1043*35238bceSAndroid Build Coastguard Worker                                const tcu::ConstPixelBufferAccess &referenceImageAccess)
1044*35238bceSAndroid Build Coastguard Worker {
1045*35238bceSAndroid Build Coastguard Worker     const int kernelRadius = 1;
1046*35238bceSAndroid Build Coastguard Worker     const int faultyLimit  = 6;
1047*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log      = m_testCtx.getLog();
1048*35238bceSAndroid Build Coastguard Worker     tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1049*35238bceSAndroid Build Coastguard Worker     int faultyPixels;
1050*35238bceSAndroid Build Coastguard Worker 
1051*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
1052*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Deviation within radius of " << kernelRadius << " is allowed." << TestLog::EndMessage;
1053*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << faultyLimit << " faulty pixels are allowed." << TestLog::EndMessage;
1054*35238bceSAndroid Build Coastguard Worker 
1055*35238bceSAndroid Build Coastguard Worker     faultyPixels =
1056*35238bceSAndroid Build Coastguard Worker         compareBlackNonBlackImages(log, testImageAccess, referenceImageAccess, diffMask.getAccess(), kernelRadius);
1057*35238bceSAndroid Build Coastguard Worker 
1058*35238bceSAndroid Build Coastguard Worker     if (faultyPixels > faultyLimit)
1059*35238bceSAndroid Build Coastguard Worker     {
1060*35238bceSAndroid Build Coastguard Worker         log << TestLog::ImageSet("Images", "Image comparison")
1061*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("TestImage", "Test image", testImageAccess)
1062*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("ReferenceImage", "Reference image", referenceImageAccess)
1063*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
1064*35238bceSAndroid Build Coastguard Worker             << tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
1065*35238bceSAndroid Build Coastguard Worker 
1066*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
1067*35238bceSAndroid Build Coastguard Worker     }
1068*35238bceSAndroid Build Coastguard Worker }
1069*35238bceSAndroid Build Coastguard Worker 
1070*35238bceSAndroid Build Coastguard Worker class TriangleAttributeCase : public TriangleCaseBase
1071*35238bceSAndroid Build Coastguard Worker {
1072*35238bceSAndroid Build Coastguard Worker public:
1073*35238bceSAndroid Build Coastguard Worker     TriangleAttributeCase(Context &context, const char *name, const char *description, const TriangleData *polysBegin,
1074*35238bceSAndroid Build Coastguard Worker                           const TriangleData *polysEnd, const rr::WindowRectangle &viewport);
1075*35238bceSAndroid Build Coastguard Worker 
1076*35238bceSAndroid Build Coastguard Worker     void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
1077*35238bceSAndroid Build Coastguard Worker                      const tcu::ConstPixelBufferAccess &referenceImageAccess);
1078*35238bceSAndroid Build Coastguard Worker };
1079*35238bceSAndroid Build Coastguard Worker 
TriangleAttributeCase(Context & context,const char * name,const char * description,const TriangleData * polysBegin,const TriangleData * polysEnd,const rr::WindowRectangle & viewport)1080*35238bceSAndroid Build Coastguard Worker TriangleAttributeCase::TriangleAttributeCase(Context &context, const char *name, const char *description,
1081*35238bceSAndroid Build Coastguard Worker                                              const TriangleData *polysBegin, const TriangleData *polysEnd,
1082*35238bceSAndroid Build Coastguard Worker                                              const rr::WindowRectangle &viewport)
1083*35238bceSAndroid Build Coastguard Worker     : TriangleCaseBase(context, name, description, polysBegin, polysEnd, viewport)
1084*35238bceSAndroid Build Coastguard Worker {
1085*35238bceSAndroid Build Coastguard Worker }
1086*35238bceSAndroid Build Coastguard Worker 
verifyImage(const tcu::ConstPixelBufferAccess & testImageAccess,const tcu::ConstPixelBufferAccess & referenceImageAccess)1087*35238bceSAndroid Build Coastguard Worker void TriangleAttributeCase::verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
1088*35238bceSAndroid Build Coastguard Worker                                         const tcu::ConstPixelBufferAccess &referenceImageAccess)
1089*35238bceSAndroid Build Coastguard Worker {
1090*35238bceSAndroid Build Coastguard Worker     const bool msaa   = m_context.getRenderTarget().getNumSamples() > 1;
1091*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
1092*35238bceSAndroid Build Coastguard Worker 
1093*35238bceSAndroid Build Coastguard Worker     if (!msaa)
1094*35238bceSAndroid Build Coastguard Worker     {
1095*35238bceSAndroid Build Coastguard Worker         const int kernelRadius = 1;
1096*35238bceSAndroid Build Coastguard Worker         const int faultyLimit  = 6;
1097*35238bceSAndroid Build Coastguard Worker         int faultyPixels;
1098*35238bceSAndroid Build Coastguard Worker         tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1099*35238bceSAndroid Build Coastguard Worker 
1100*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
1101*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Deviation within radius of " << kernelRadius << " is allowed."
1102*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
1103*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << faultyLimit << " faulty pixels are allowed." << TestLog::EndMessage;
1104*35238bceSAndroid Build Coastguard Worker         faultyPixels =
1105*35238bceSAndroid Build Coastguard Worker             compareColoredImages(log, testImageAccess, referenceImageAccess, diffMask.getAccess(), kernelRadius);
1106*35238bceSAndroid Build Coastguard Worker 
1107*35238bceSAndroid Build Coastguard Worker         if (faultyPixels > faultyLimit)
1108*35238bceSAndroid Build Coastguard Worker         {
1109*35238bceSAndroid Build Coastguard Worker             log << TestLog::ImageSet("Images", "Image comparison")
1110*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("TestImage", "Test image", testImageAccess)
1111*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("ReferenceImage", "Reference image", referenceImageAccess)
1112*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
1113*35238bceSAndroid Build Coastguard Worker                 << tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
1114*35238bceSAndroid Build Coastguard Worker 
1115*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
1116*35238bceSAndroid Build Coastguard Worker         }
1117*35238bceSAndroid Build Coastguard Worker     }
1118*35238bceSAndroid Build Coastguard Worker     else
1119*35238bceSAndroid Build Coastguard Worker     {
1120*35238bceSAndroid Build Coastguard Worker         const float threshold = 0.3f;
1121*35238bceSAndroid Build Coastguard Worker         if (!tcu::fuzzyCompare(log, "Images", "", referenceImageAccess, testImageAccess, threshold,
1122*35238bceSAndroid Build Coastguard Worker                                tcu::COMPARE_LOG_ON_ERROR))
1123*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
1124*35238bceSAndroid Build Coastguard Worker     }
1125*35238bceSAndroid Build Coastguard Worker }
1126*35238bceSAndroid Build Coastguard Worker 
1127*35238bceSAndroid Build Coastguard Worker class FillTest : public RenderTestCase
1128*35238bceSAndroid Build Coastguard Worker {
1129*35238bceSAndroid Build Coastguard Worker public:
1130*35238bceSAndroid Build Coastguard Worker     FillTest(Context &context, const char *name, const char *description, const rr::WindowRectangle &viewport);
1131*35238bceSAndroid Build Coastguard Worker 
1132*35238bceSAndroid Build Coastguard Worker     virtual void render(sglr::Context &ctx) = DE_NULL;
1133*35238bceSAndroid Build Coastguard Worker     void testRender(void);
1134*35238bceSAndroid Build Coastguard Worker 
1135*35238bceSAndroid Build Coastguard Worker protected:
1136*35238bceSAndroid Build Coastguard Worker     const rr::WindowRectangle m_viewport;
1137*35238bceSAndroid Build Coastguard Worker };
1138*35238bceSAndroid Build Coastguard Worker 
FillTest(Context & context,const char * name,const char * description,const rr::WindowRectangle & viewport)1139*35238bceSAndroid Build Coastguard Worker FillTest::FillTest(Context &context, const char *name, const char *description, const rr::WindowRectangle &viewport)
1140*35238bceSAndroid Build Coastguard Worker     : RenderTestCase(context, name, description)
1141*35238bceSAndroid Build Coastguard Worker     , m_viewport(viewport)
1142*35238bceSAndroid Build Coastguard Worker {
1143*35238bceSAndroid Build Coastguard Worker }
1144*35238bceSAndroid Build Coastguard Worker 
testRender(void)1145*35238bceSAndroid Build Coastguard Worker void FillTest::testRender(void)
1146*35238bceSAndroid Build Coastguard Worker {
1147*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
1148*35238bceSAndroid Build Coastguard Worker 
1149*35238bceSAndroid Build Coastguard Worker     const int numSamples = 1;
1150*35238bceSAndroid Build Coastguard Worker 
1151*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
1152*35238bceSAndroid Build Coastguard Worker     sglr::GLContext glesContext(m_context.getRenderContext(), log, 0,
1153*35238bceSAndroid Build Coastguard Worker                                 tcu::IVec4(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE));
1154*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContextLimits limits;
1155*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContextBuffers buffers(m_context.getRenderTarget().getPixelFormat(),
1156*35238bceSAndroid Build Coastguard Worker                                           m_context.getRenderTarget().getDepthBits(), 0, TEST_CANVAS_SIZE,
1157*35238bceSAndroid Build Coastguard Worker                                           TEST_CANVAS_SIZE, numSamples);
1158*35238bceSAndroid Build Coastguard Worker     sglr::ReferenceContext refContext(limits, buffers.getColorbuffer(), buffers.getDepthbuffer(),
1159*35238bceSAndroid Build Coastguard Worker                                       buffers.getStencilbuffer());
1160*35238bceSAndroid Build Coastguard Worker     tcu::Surface testSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1161*35238bceSAndroid Build Coastguard Worker     tcu::Surface refSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1162*35238bceSAndroid Build Coastguard Worker 
1163*35238bceSAndroid Build Coastguard Worker     render(glesContext);
1164*35238bceSAndroid Build Coastguard Worker     glesContext.readPixels(testSurface, 0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1165*35238bceSAndroid Build Coastguard Worker 
1166*35238bceSAndroid Build Coastguard Worker     render(refContext);
1167*35238bceSAndroid Build Coastguard Worker     refContext.readPixels(refSurface, 0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1168*35238bceSAndroid Build Coastguard Worker 
1169*35238bceSAndroid Build Coastguard Worker     // check overdraw
1170*35238bceSAndroid Build Coastguard Worker     {
1171*35238bceSAndroid Build Coastguard Worker         bool overdrawOk;
1172*35238bceSAndroid Build Coastguard Worker         tcu::Surface outputImage(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1173*35238bceSAndroid Build Coastguard Worker 
1174*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Checking for overdraw " << TestLog::EndMessage;
1175*35238bceSAndroid Build Coastguard Worker         overdrawOk = checkHalfFilledImageOverdraw(log, m_context.getRenderTarget(), testSurface.getAccess(),
1176*35238bceSAndroid Build Coastguard Worker                                                   outputImage.getAccess());
1177*35238bceSAndroid Build Coastguard Worker 
1178*35238bceSAndroid Build Coastguard Worker         if (!overdrawOk)
1179*35238bceSAndroid Build Coastguard Worker         {
1180*35238bceSAndroid Build Coastguard Worker             log << TestLog::ImageSet("Images", "Image comparison")
1181*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("TestImage", "Test image", testSurface.getAccess())
1182*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("InvalidPixels", "Invalid pixels", outputImage.getAccess()) << TestLog::EndImageSet
1183*35238bceSAndroid Build Coastguard Worker                 << tcu::TestLog::Message << "Got overdraw." << tcu::TestLog::EndMessage;
1184*35238bceSAndroid Build Coastguard Worker 
1185*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got overdraw");
1186*35238bceSAndroid Build Coastguard Worker         }
1187*35238bceSAndroid Build Coastguard Worker     }
1188*35238bceSAndroid Build Coastguard Worker 
1189*35238bceSAndroid Build Coastguard Worker     // compare & check missing pixels
1190*35238bceSAndroid Build Coastguard Worker     {
1191*35238bceSAndroid Build Coastguard Worker         const int kernelRadius = 1;
1192*35238bceSAndroid Build Coastguard Worker         tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
1193*35238bceSAndroid Build Coastguard Worker         int faultyPixels;
1194*35238bceSAndroid Build Coastguard Worker 
1195*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
1196*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Deviation within radius of " << kernelRadius << " is allowed."
1197*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
1198*35238bceSAndroid Build Coastguard Worker 
1199*35238bceSAndroid Build Coastguard Worker         blitImageOnBlackSurface(refSurface.getAccess(), refSurface.getAccess()); // makes images look right in Candy
1200*35238bceSAndroid Build Coastguard Worker 
1201*35238bceSAndroid Build Coastguard Worker         faultyPixels = compareBlackNonBlackImages(log, testSurface.getAccess(), refSurface.getAccess(),
1202*35238bceSAndroid Build Coastguard Worker                                                   diffMask.getAccess(), kernelRadius);
1203*35238bceSAndroid Build Coastguard Worker 
1204*35238bceSAndroid Build Coastguard Worker         if (faultyPixels > 0)
1205*35238bceSAndroid Build Coastguard Worker         {
1206*35238bceSAndroid Build Coastguard Worker             log << TestLog::ImageSet("Images", "Image comparison")
1207*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("TestImage", "Test image", testSurface.getAccess())
1208*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("ReferenceImage", "Reference image", refSurface.getAccess())
1209*35238bceSAndroid Build Coastguard Worker                 << TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
1210*35238bceSAndroid Build Coastguard Worker                 << tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
1211*35238bceSAndroid Build Coastguard Worker 
1212*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
1213*35238bceSAndroid Build Coastguard Worker         }
1214*35238bceSAndroid Build Coastguard Worker     }
1215*35238bceSAndroid Build Coastguard Worker }
1216*35238bceSAndroid Build Coastguard Worker 
1217*35238bceSAndroid Build Coastguard Worker class TriangleFillTest : public FillTest
1218*35238bceSAndroid Build Coastguard Worker {
1219*35238bceSAndroid Build Coastguard Worker public:
1220*35238bceSAndroid Build Coastguard Worker     struct FillTriangle
1221*35238bceSAndroid Build Coastguard Worker     {
1222*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 v0;
1223*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 c0;
1224*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 v1;
1225*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 c1;
1226*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 v2;
1227*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 c2;
1228*35238bceSAndroid Build Coastguard Worker     };
1229*35238bceSAndroid Build Coastguard Worker 
1230*35238bceSAndroid Build Coastguard Worker     TriangleFillTest(Context &context, const char *name, const char *description, const rr::WindowRectangle &viewport);
1231*35238bceSAndroid Build Coastguard Worker 
1232*35238bceSAndroid Build Coastguard Worker     void render(sglr::Context &ctx);
1233*35238bceSAndroid Build Coastguard Worker 
1234*35238bceSAndroid Build Coastguard Worker protected:
1235*35238bceSAndroid Build Coastguard Worker     std::vector<FillTriangle> m_triangles;
1236*35238bceSAndroid Build Coastguard Worker };
1237*35238bceSAndroid Build Coastguard Worker 
TriangleFillTest(Context & context,const char * name,const char * description,const rr::WindowRectangle & viewport)1238*35238bceSAndroid Build Coastguard Worker TriangleFillTest::TriangleFillTest(Context &context, const char *name, const char *description,
1239*35238bceSAndroid Build Coastguard Worker                                    const rr::WindowRectangle &viewport)
1240*35238bceSAndroid Build Coastguard Worker     : FillTest(context, name, description, viewport)
1241*35238bceSAndroid Build Coastguard Worker {
1242*35238bceSAndroid Build Coastguard Worker }
1243*35238bceSAndroid Build Coastguard Worker 
render(sglr::Context & ctx)1244*35238bceSAndroid Build Coastguard Worker void TriangleFillTest::render(sglr::Context &ctx)
1245*35238bceSAndroid Build Coastguard Worker {
1246*35238bceSAndroid Build Coastguard Worker     const int verticesPerTriangle = 3;
1247*35238bceSAndroid Build Coastguard Worker     PositionColorShader program;
1248*35238bceSAndroid Build Coastguard Worker     const uint32_t programId = ctx.createProgram(&program);
1249*35238bceSAndroid Build Coastguard Worker     const GLint positionLoc  = ctx.getAttribLocation(programId, "a_position");
1250*35238bceSAndroid Build Coastguard Worker     const GLint colorLoc     = ctx.getAttribLocation(programId, "a_color");
1251*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log        = m_testCtx.getLog();
1252*35238bceSAndroid Build Coastguard Worker 
1253*35238bceSAndroid Build Coastguard Worker     // log the purpose of the test
1254*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Viewport: left=" << m_viewport.left << "\tbottom=" << m_viewport.bottom
1255*35238bceSAndroid Build Coastguard Worker         << "\twidth=" << m_viewport.width << "\theight=" << m_viewport.height << TestLog::EndMessage;
1256*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Rendering triangles. Coordinates:" << TestLog::EndMessage;
1257*35238bceSAndroid Build Coastguard Worker     for (size_t ndx = 0; ndx < m_triangles.size(); ++ndx)
1258*35238bceSAndroid Build Coastguard Worker     {
1259*35238bceSAndroid Build Coastguard Worker         const std::string v0Properties = genClippingPointInfoString(m_triangles[ndx].v0);
1260*35238bceSAndroid Build Coastguard Worker         const std::string v1Properties = genClippingPointInfoString(m_triangles[ndx].v1);
1261*35238bceSAndroid Build Coastguard Worker         const std::string v2Properties = genClippingPointInfoString(m_triangles[ndx].v2);
1262*35238bceSAndroid Build Coastguard Worker 
1263*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tv0 (x=" << m_triangles[ndx].v0.x() << "\ty=" << m_triangles[ndx].v0.y()
1264*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_triangles[ndx].v0.z() << "\tw=" << m_triangles[ndx].v0.w() << ")\t" << v0Properties
1265*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
1266*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tv1 (x=" << m_triangles[ndx].v1.x() << "\ty=" << m_triangles[ndx].v1.y()
1267*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_triangles[ndx].v1.z() << "\tw=" << m_triangles[ndx].v1.w() << ")\t" << v1Properties
1268*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
1269*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "\tv2 (x=" << m_triangles[ndx].v2.x() << "\ty=" << m_triangles[ndx].v2.y()
1270*35238bceSAndroid Build Coastguard Worker             << "\tz=" << m_triangles[ndx].v2.z() << "\tw=" << m_triangles[ndx].v2.w() << ")\t" << v2Properties
1271*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
1272*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << TestLog::EndMessage;
1273*35238bceSAndroid Build Coastguard Worker     }
1274*35238bceSAndroid Build Coastguard Worker 
1275*35238bceSAndroid Build Coastguard Worker     ctx.clearColor(0, 0, 0, 1);
1276*35238bceSAndroid Build Coastguard Worker     ctx.clearDepthf(1.0f);
1277*35238bceSAndroid Build Coastguard Worker     ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1278*35238bceSAndroid Build Coastguard Worker     ctx.viewport(m_viewport.left, m_viewport.bottom, m_viewport.width, m_viewport.height);
1279*35238bceSAndroid Build Coastguard Worker     ctx.useProgram(programId);
1280*35238bceSAndroid Build Coastguard Worker     ctx.blendFunc(GL_ONE, GL_ONE);
1281*35238bceSAndroid Build Coastguard Worker     ctx.enable(GL_BLEND);
1282*35238bceSAndroid Build Coastguard Worker     ctx.enableVertexAttribArray(positionLoc);
1283*35238bceSAndroid Build Coastguard Worker     ctx.enableVertexAttribArray(colorLoc);
1284*35238bceSAndroid Build Coastguard Worker     ctx.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat[8]), &m_triangles[0].v0);
1285*35238bceSAndroid Build Coastguard Worker     ctx.vertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat[8]), &m_triangles[0].c0);
1286*35238bceSAndroid Build Coastguard Worker     ctx.drawArrays(GL_TRIANGLES, 0, verticesPerTriangle * (glw::GLsizei)m_triangles.size());
1287*35238bceSAndroid Build Coastguard Worker     ctx.disableVertexAttribArray(positionLoc);
1288*35238bceSAndroid Build Coastguard Worker     ctx.disableVertexAttribArray(colorLoc);
1289*35238bceSAndroid Build Coastguard Worker     ctx.useProgram(0);
1290*35238bceSAndroid Build Coastguard Worker     ctx.deleteProgram(programId);
1291*35238bceSAndroid Build Coastguard Worker     ctx.finish();
1292*35238bceSAndroid Build Coastguard Worker }
1293*35238bceSAndroid Build Coastguard Worker 
1294*35238bceSAndroid Build Coastguard Worker class QuadFillTest : public TriangleFillTest
1295*35238bceSAndroid Build Coastguard Worker {
1296*35238bceSAndroid Build Coastguard Worker public:
1297*35238bceSAndroid Build Coastguard Worker     QuadFillTest(Context &context, const char *name, const char *description, const rr::WindowRectangle &viewport,
1298*35238bceSAndroid Build Coastguard Worker                  const tcu::Vec3 &d1, const tcu::Vec3 &d2, const tcu::Vec3 &center_ = tcu::Vec3(0, 0, 0));
1299*35238bceSAndroid Build Coastguard Worker };
1300*35238bceSAndroid Build Coastguard Worker 
QuadFillTest(Context & context,const char * name,const char * description,const rr::WindowRectangle & viewport,const tcu::Vec3 & d1,const tcu::Vec3 & d2,const tcu::Vec3 & center_)1301*35238bceSAndroid Build Coastguard Worker QuadFillTest::QuadFillTest(Context &context, const char *name, const char *description,
1302*35238bceSAndroid Build Coastguard Worker                            const rr::WindowRectangle &viewport, const tcu::Vec3 &d1, const tcu::Vec3 &d2,
1303*35238bceSAndroid Build Coastguard Worker                            const tcu::Vec3 &center_)
1304*35238bceSAndroid Build Coastguard Worker     : TriangleFillTest(context, name, description, viewport)
1305*35238bceSAndroid Build Coastguard Worker {
1306*35238bceSAndroid Build Coastguard Worker     const float radius        = 40000.0f;
1307*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 center    = tcu::Vec4(center_.x(), center_.y(), center_.z(), 1.0f);
1308*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 halfWhite = tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f);
1309*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 halfRed   = tcu::Vec4(0.5f, 0.0f, 0.0f, 0.5f);
1310*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 e1        = radius * tcu::Vec4(d1.x(), d1.y(), d1.z(), 0.0f);
1311*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 e2        = radius * tcu::Vec4(d2.x(), d2.y(), d2.z(), 0.0f);
1312*35238bceSAndroid Build Coastguard Worker 
1313*35238bceSAndroid Build Coastguard Worker     FillTriangle triangle1;
1314*35238bceSAndroid Build Coastguard Worker     FillTriangle triangle2;
1315*35238bceSAndroid Build Coastguard Worker 
1316*35238bceSAndroid Build Coastguard Worker     triangle1.c0 = halfWhite;
1317*35238bceSAndroid Build Coastguard Worker     triangle1.c1 = halfWhite;
1318*35238bceSAndroid Build Coastguard Worker     triangle1.c2 = halfWhite;
1319*35238bceSAndroid Build Coastguard Worker     triangle1.v0 = center + e1 + e2;
1320*35238bceSAndroid Build Coastguard Worker     triangle1.v1 = center + e1 - e2;
1321*35238bceSAndroid Build Coastguard Worker     triangle1.v2 = center - e1 - e2;
1322*35238bceSAndroid Build Coastguard Worker     m_triangles.push_back(triangle1);
1323*35238bceSAndroid Build Coastguard Worker 
1324*35238bceSAndroid Build Coastguard Worker     triangle2.c0 = halfRed;
1325*35238bceSAndroid Build Coastguard Worker     triangle2.c1 = halfRed;
1326*35238bceSAndroid Build Coastguard Worker     triangle2.c2 = halfRed;
1327*35238bceSAndroid Build Coastguard Worker     triangle2.v0 = center + e1 + e2;
1328*35238bceSAndroid Build Coastguard Worker     triangle2.v1 = center - e1 - e2;
1329*35238bceSAndroid Build Coastguard Worker     triangle2.v2 = center - e1 + e2;
1330*35238bceSAndroid Build Coastguard Worker     m_triangles.push_back(triangle2);
1331*35238bceSAndroid Build Coastguard Worker }
1332*35238bceSAndroid Build Coastguard Worker 
1333*35238bceSAndroid Build Coastguard Worker class TriangleFanFillTest : public TriangleFillTest
1334*35238bceSAndroid Build Coastguard Worker {
1335*35238bceSAndroid Build Coastguard Worker public:
1336*35238bceSAndroid Build Coastguard Worker     TriangleFanFillTest(Context &context, const char *name, const char *description,
1337*35238bceSAndroid Build Coastguard Worker                         const rr::WindowRectangle &viewport);
1338*35238bceSAndroid Build Coastguard Worker };
1339*35238bceSAndroid Build Coastguard Worker 
TriangleFanFillTest(Context & context,const char * name,const char * description,const rr::WindowRectangle & viewport)1340*35238bceSAndroid Build Coastguard Worker TriangleFanFillTest::TriangleFanFillTest(Context &context, const char *name, const char *description,
1341*35238bceSAndroid Build Coastguard Worker                                          const rr::WindowRectangle &viewport)
1342*35238bceSAndroid Build Coastguard Worker     : TriangleFillTest(context, name, description, viewport)
1343*35238bceSAndroid Build Coastguard Worker {
1344*35238bceSAndroid Build Coastguard Worker     const float radius            = 70000.0f;
1345*35238bceSAndroid Build Coastguard Worker     const int trianglesPerVisit   = 40;
1346*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 center        = tcu::Vec4(0, 0, 0, 1.0f);
1347*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 halfWhite     = tcu::Vec4(0.5f, 0.5f, 0.5f, 0.5f);
1348*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 oddSliceColor = tcu::Vec4(0.0f, 0.0f, 0.5f, 0.0f);
1349*35238bceSAndroid Build Coastguard Worker 
1350*35238bceSAndroid Build Coastguard Worker     // create a continuous surface that goes through all 6 clip planes
1351*35238bceSAndroid Build Coastguard Worker 
1352*35238bceSAndroid Build Coastguard Worker     /*
1353*35238bceSAndroid Build Coastguard Worker      *   /           /
1354*35238bceSAndroid Build Coastguard Worker      *  /_ _ _ _ _  /x
1355*35238bceSAndroid Build Coastguard Worker      * |           |  |
1356*35238bceSAndroid Build Coastguard Worker      * |           | /
1357*35238bceSAndroid Build Coastguard Worker      * |       / --xe /
1358*35238bceSAndroid Build Coastguard Worker      * |      |    | /
1359*35238bceSAndroid Build Coastguard Worker      * |_ _ _ e _ _|/
1360*35238bceSAndroid Build Coastguard Worker      *
1361*35238bceSAndroid Build Coastguard Worker      * e = enter
1362*35238bceSAndroid Build Coastguard Worker      * x = exit
1363*35238bceSAndroid Build Coastguard Worker      */
1364*35238bceSAndroid Build Coastguard Worker     const struct ClipPlaneVisit
1365*35238bceSAndroid Build Coastguard Worker     {
1366*35238bceSAndroid Build Coastguard Worker         const tcu::Vec3 corner;
1367*35238bceSAndroid Build Coastguard Worker         const tcu::Vec3 entryPoint;
1368*35238bceSAndroid Build Coastguard Worker         const tcu::Vec3 exitPoint;
1369*35238bceSAndroid Build Coastguard Worker     } visits[] = {
1370*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(1, 1, 1), tcu::Vec3(0, 1, 1), tcu::Vec3(1, 0, 1)},
1371*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(1, -1, 1), tcu::Vec3(1, 0, 1), tcu::Vec3(1, -1, 0)},
1372*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(1, -1, -1), tcu::Vec3(1, -1, 0), tcu::Vec3(0, -1, -1)},
1373*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(-1, -1, -1), tcu::Vec3(0, -1, -1), tcu::Vec3(-1, 0, -1)},
1374*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(-1, 1, -1), tcu::Vec3(-1, 0, -1), tcu::Vec3(-1, 1, 0)},
1375*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(-1, 1, 1), tcu::Vec3(-1, 1, 0), tcu::Vec3(0, 1, 1)},
1376*35238bceSAndroid Build Coastguard Worker     };
1377*35238bceSAndroid Build Coastguard Worker 
1378*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(visits); ++ndx)
1379*35238bceSAndroid Build Coastguard Worker     {
1380*35238bceSAndroid Build Coastguard Worker         const ClipPlaneVisit &visit = visits[ndx];
1381*35238bceSAndroid Build Coastguard Worker 
1382*35238bceSAndroid Build Coastguard Worker         for (int tri = 0; tri < trianglesPerVisit; ++tri)
1383*35238bceSAndroid Build Coastguard Worker         {
1384*35238bceSAndroid Build Coastguard Worker             tcu::Vec3 vertex0;
1385*35238bceSAndroid Build Coastguard Worker             tcu::Vec3 vertex1;
1386*35238bceSAndroid Build Coastguard Worker 
1387*35238bceSAndroid Build Coastguard Worker             if (tri == 0) // first vertex is magic
1388*35238bceSAndroid Build Coastguard Worker             {
1389*35238bceSAndroid Build Coastguard Worker                 vertex0 = visit.entryPoint;
1390*35238bceSAndroid Build Coastguard Worker             }
1391*35238bceSAndroid Build Coastguard Worker             else
1392*35238bceSAndroid Build Coastguard Worker             {
1393*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec3 v1 = visit.entryPoint - visit.corner;
1394*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec3 v2 = visit.exitPoint - visit.corner;
1395*35238bceSAndroid Build Coastguard Worker 
1396*35238bceSAndroid Build Coastguard Worker                 vertex0 = visit.corner + tcu::normalize(tcu::mix(v1, v2, tcu::Vec3(float(tri) / trianglesPerVisit)));
1397*35238bceSAndroid Build Coastguard Worker             }
1398*35238bceSAndroid Build Coastguard Worker 
1399*35238bceSAndroid Build Coastguard Worker             if (tri == trianglesPerVisit - 1) // last vertex is magic
1400*35238bceSAndroid Build Coastguard Worker             {
1401*35238bceSAndroid Build Coastguard Worker                 vertex1 = visit.exitPoint;
1402*35238bceSAndroid Build Coastguard Worker             }
1403*35238bceSAndroid Build Coastguard Worker             else
1404*35238bceSAndroid Build Coastguard Worker             {
1405*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec3 v1 = visit.entryPoint - visit.corner;
1406*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec3 v2 = visit.exitPoint - visit.corner;
1407*35238bceSAndroid Build Coastguard Worker 
1408*35238bceSAndroid Build Coastguard Worker                 vertex1 =
1409*35238bceSAndroid Build Coastguard Worker                     visit.corner + tcu::normalize(tcu::mix(v1, v2, tcu::Vec3(float(tri + 1) / trianglesPerVisit)));
1410*35238bceSAndroid Build Coastguard Worker             }
1411*35238bceSAndroid Build Coastguard Worker 
1412*35238bceSAndroid Build Coastguard Worker             // write vec out
1413*35238bceSAndroid Build Coastguard Worker             {
1414*35238bceSAndroid Build Coastguard Worker                 FillTriangle triangle;
1415*35238bceSAndroid Build Coastguard Worker 
1416*35238bceSAndroid Build Coastguard Worker                 triangle.c0 = (tri % 2) ? halfWhite : halfWhite + oddSliceColor;
1417*35238bceSAndroid Build Coastguard Worker                 triangle.c1 = (tri % 2) ? halfWhite : halfWhite + oddSliceColor;
1418*35238bceSAndroid Build Coastguard Worker                 triangle.c2 = (tri % 2) ? halfWhite : halfWhite + oddSliceColor;
1419*35238bceSAndroid Build Coastguard Worker                 triangle.v0 = center;
1420*35238bceSAndroid Build Coastguard Worker                 triangle.v1 = tcu::Vec4(vertex0.x() * radius, vertex0.y() * radius, vertex0.z() * radius, 1.0f);
1421*35238bceSAndroid Build Coastguard Worker                 triangle.v2 = tcu::Vec4(vertex1.x() * radius, vertex1.y() * radius, vertex1.z() * radius, 1.0f);
1422*35238bceSAndroid Build Coastguard Worker 
1423*35238bceSAndroid Build Coastguard Worker                 m_triangles.push_back(triangle);
1424*35238bceSAndroid Build Coastguard Worker             }
1425*35238bceSAndroid Build Coastguard Worker         }
1426*35238bceSAndroid Build Coastguard Worker     }
1427*35238bceSAndroid Build Coastguard Worker }
1428*35238bceSAndroid Build Coastguard Worker 
1429*35238bceSAndroid Build Coastguard Worker class PointsTestGroup : public TestCaseGroup
1430*35238bceSAndroid Build Coastguard Worker {
1431*35238bceSAndroid Build Coastguard Worker public:
1432*35238bceSAndroid Build Coastguard Worker     PointsTestGroup(Context &context);
1433*35238bceSAndroid Build Coastguard Worker 
1434*35238bceSAndroid Build Coastguard Worker     void init(void);
1435*35238bceSAndroid Build Coastguard Worker };
1436*35238bceSAndroid Build Coastguard Worker 
PointsTestGroup(Context & context)1437*35238bceSAndroid Build Coastguard Worker PointsTestGroup::PointsTestGroup(Context &context) : TestCaseGroup(context, "point", "Point clipping tests")
1438*35238bceSAndroid Build Coastguard Worker {
1439*35238bceSAndroid Build Coastguard Worker }
1440*35238bceSAndroid Build Coastguard Worker 
init(void)1441*35238bceSAndroid Build Coastguard Worker void PointsTestGroup::init(void)
1442*35238bceSAndroid Build Coastguard Worker {
1443*35238bceSAndroid Build Coastguard Worker     const float littleOverViewport =
1444*35238bceSAndroid Build Coastguard Worker         1.0f +
1445*35238bceSAndroid Build Coastguard Worker         (2.0f /
1446*35238bceSAndroid Build Coastguard Worker          (TEST_CANVAS_SIZE)); // one pixel over the viewport edge in VIEWPORT_WHOLE, half pixels over in the reduced viewport.
1447*35238bceSAndroid Build Coastguard Worker 
1448*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 viewportTestPoints[] = {
1449*35238bceSAndroid Build Coastguard Worker         // in clip volume
1450*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
1451*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0.1f, 0.1f, 0.1f, 1.0f),
1452*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-0.1f, 0.1f, -0.1f, 1.0f),
1453*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-0.1f, -0.1f, 0.1f, 1.0f),
1454*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0.1f, -0.1f, -0.1f, 1.0f),
1455*35238bceSAndroid Build Coastguard Worker 
1456*35238bceSAndroid Build Coastguard Worker         // in clip volume with w != 1
1457*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(2.0f, 2.0f, 2.0f, 3.0f),
1458*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-2.0f, -2.0f, 2.0f, 3.0f),
1459*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0.5f, -0.5f, 0.5f, 0.7f),
1460*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-0.5f, 0.5f, -0.5f, 0.7f),
1461*35238bceSAndroid Build Coastguard Worker 
1462*35238bceSAndroid Build Coastguard Worker         // near the edge
1463*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-2.0f, -2.0f, 0.0f, 2.2f),
1464*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1.0f, -1.0f, 0.0f, 1.1f),
1465*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.1f),
1466*35238bceSAndroid Build Coastguard Worker 
1467*35238bceSAndroid Build Coastguard Worker         // not in the volume but still between near and far planes
1468*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1.3f, 0.0f, 0.0f, 1.0f),
1469*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1.3f, 0.0f, 0.0f, 1.0f),
1470*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0.0f, 1.3f, 0.0f, 1.0f),
1471*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0.0f, -1.3f, 0.0f, 1.0f),
1472*35238bceSAndroid Build Coastguard Worker 
1473*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1.3f, -1.3f, 0.0f, 1.0f),
1474*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(-1.3f, 1.3f, 0.0f, 1.0f),
1475*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1.3f, 1.3f, 0.0f, 1.0f),
1476*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(1.3f, -1.3f, 0.0f, 1.0f),
1477*35238bceSAndroid Build Coastguard Worker 
1478*35238bceSAndroid Build Coastguard Worker         // outside the viewport, wide points have fragments in the viewport
1479*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(littleOverViewport, littleOverViewport, 0.0f, 1.0f),
1480*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0.0f, littleOverViewport, 0.0f, 1.0f),
1481*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(littleOverViewport, 0.0f, 0.0f, 1.0f),
1482*35238bceSAndroid Build Coastguard Worker     };
1483*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 depthTestPoints[] = {// in clip volume
1484*35238bceSAndroid Build Coastguard Worker                                          tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.1f, 0.1f, 0.1f, 1.0f),
1485*35238bceSAndroid Build Coastguard Worker                                          tcu::Vec4(-0.1f, 0.1f, -0.1f, 1.0f), tcu::Vec4(-0.1f, -0.1f, 0.1f, 1.0f),
1486*35238bceSAndroid Build Coastguard Worker                                          tcu::Vec4(0.1f, -0.1f, -0.1f, 1.0f),
1487*35238bceSAndroid Build Coastguard Worker 
1488*35238bceSAndroid Build Coastguard Worker                                          // not between the near and the far planes. These should be clipped
1489*35238bceSAndroid Build Coastguard Worker                                          tcu::Vec4(0.1f, 0.0f, 1.1f, 1.0f), tcu::Vec4(-0.1f, 0.0f, -1.1f, 1.0f),
1490*35238bceSAndroid Build Coastguard Worker                                          tcu::Vec4(-0.0f, -0.1f, 1.1f, 1.0f), tcu::Vec4(0.0f, 0.1f, -1.1f, 1.0f)};
1491*35238bceSAndroid Build Coastguard Worker 
1492*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "point_z_clip", "point z clipping", DE_ARRAY_BEGIN(depthTestPoints),
1493*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_END(depthTestPoints), 1.0f, VIEWPORT_WHOLE));
1494*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "point_z_clip_viewport_center", "point z clipping",
1495*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_BEGIN(depthTestPoints), DE_ARRAY_END(depthTestPoints), 1.0f, VIEWPORT_CENTER));
1496*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "point_z_clip_viewport_corner", "point z clipping",
1497*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_BEGIN(depthTestPoints), DE_ARRAY_END(depthTestPoints), 1.0f, VIEWPORT_CORNER));
1498*35238bceSAndroid Build Coastguard Worker 
1499*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "point_clip_viewport_center", "point viewport clipping",
1500*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_BEGIN(viewportTestPoints), DE_ARRAY_END(viewportTestPoints), 1.0f,
1501*35238bceSAndroid Build Coastguard Worker                            VIEWPORT_CENTER));
1502*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "point_clip_viewport_corner", "point viewport clipping",
1503*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_BEGIN(viewportTestPoints), DE_ARRAY_END(viewportTestPoints), 1.0f,
1504*35238bceSAndroid Build Coastguard Worker                            VIEWPORT_CORNER));
1505*35238bceSAndroid Build Coastguard Worker 
1506*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "wide_point_z_clip", "point z clipping", DE_ARRAY_BEGIN(depthTestPoints),
1507*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_END(depthTestPoints), 5.0f, VIEWPORT_WHOLE));
1508*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "wide_point_z_clip_viewport_center", "point z clipping",
1509*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_BEGIN(depthTestPoints), DE_ARRAY_END(depthTestPoints), 5.0f, VIEWPORT_CENTER));
1510*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "wide_point_z_clip_viewport_corner", "point z clipping",
1511*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_BEGIN(depthTestPoints), DE_ARRAY_END(depthTestPoints), 5.0f, VIEWPORT_CORNER));
1512*35238bceSAndroid Build Coastguard Worker 
1513*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "wide_point_clip", "point viewport clipping", DE_ARRAY_BEGIN(viewportTestPoints),
1514*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_END(viewportTestPoints), 5.0f, VIEWPORT_WHOLE));
1515*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "wide_point_clip_viewport_center", "point viewport clipping",
1516*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_BEGIN(viewportTestPoints), DE_ARRAY_END(viewportTestPoints), 5.0f,
1517*35238bceSAndroid Build Coastguard Worker                            VIEWPORT_CENTER));
1518*35238bceSAndroid Build Coastguard Worker     addChild(new PointCase(m_context, "wide_point_clip_viewport_corner", "point viewport clipping",
1519*35238bceSAndroid Build Coastguard Worker                            DE_ARRAY_BEGIN(viewportTestPoints), DE_ARRAY_END(viewportTestPoints), 5.0f,
1520*35238bceSAndroid Build Coastguard Worker                            VIEWPORT_CORNER));
1521*35238bceSAndroid Build Coastguard Worker }
1522*35238bceSAndroid Build Coastguard Worker 
1523*35238bceSAndroid Build Coastguard Worker class LinesTestGroup : public TestCaseGroup
1524*35238bceSAndroid Build Coastguard Worker {
1525*35238bceSAndroid Build Coastguard Worker public:
1526*35238bceSAndroid Build Coastguard Worker     LinesTestGroup(Context &context);
1527*35238bceSAndroid Build Coastguard Worker 
1528*35238bceSAndroid Build Coastguard Worker     void init(void);
1529*35238bceSAndroid Build Coastguard Worker };
1530*35238bceSAndroid Build Coastguard Worker 
LinesTestGroup(Context & context)1531*35238bceSAndroid Build Coastguard Worker LinesTestGroup::LinesTestGroup(Context &context) : TestCaseGroup(context, "line", "Line clipping tests")
1532*35238bceSAndroid Build Coastguard Worker {
1533*35238bceSAndroid Build Coastguard Worker }
1534*35238bceSAndroid Build Coastguard Worker 
init(void)1535*35238bceSAndroid Build Coastguard Worker void LinesTestGroup::init(void)
1536*35238bceSAndroid Build Coastguard Worker {
1537*35238bceSAndroid Build Coastguard Worker     const float littleOverViewport =
1538*35238bceSAndroid Build Coastguard Worker         1.0f +
1539*35238bceSAndroid Build Coastguard Worker         (2.0f /
1540*35238bceSAndroid Build Coastguard Worker          (TEST_CANVAS_SIZE)); // one pixel over the viewport edge in VIEWPORT_WHOLE, half pixels over in the reduced viewport.
1541*35238bceSAndroid Build Coastguard Worker 
1542*35238bceSAndroid Build Coastguard Worker     // lines
1543*35238bceSAndroid Build Coastguard Worker     const LineRenderTestCase::ColorlessLineData viewportTestLines[] = {
1544*35238bceSAndroid Build Coastguard Worker         // from center to outside of viewport
1545*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.0f, 1.5f, 0.0f, 1.0f)},
1546*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(-1.5f, 1.0f, 0.0f, 1.0f)},
1547*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(-1.5f, 0.0f, 0.0f, 1.0f)},
1548*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.2f, 0.4f, 1.5f, 1.0f)},
1549*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(-2.0f, -1.0f, 0.0f, 1.0f)},
1550*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.1f, 0.0f, 0.6f)},
1551*35238bceSAndroid Build Coastguard Worker 
1552*35238bceSAndroid Build Coastguard Worker         // from outside to inside of viewport
1553*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(1.5f, 0.0f, 0.0f, 1.0f), tcu::Vec4(0.8f, -0.2f, 0.0f, 1.0f)},
1554*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, -1.5f, 0.0f, 1.0f), tcu::Vec4(0.9f, -0.7f, 0.0f, 1.0f)},
1555*35238bceSAndroid Build Coastguard Worker 
1556*35238bceSAndroid Build Coastguard Worker         // from outside to outside
1557*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, -1.3f, 0.0f, 1.0f), tcu::Vec4(1.3f, 0.0f, 0.0f, 1.0f)},
1558*35238bceSAndroid Build Coastguard Worker 
1559*35238bceSAndroid Build Coastguard Worker         // outside the viewport, wide lines have fragments in the viewport
1560*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(-0.8f, -littleOverViewport, 0.0f, 1.0f), tcu::Vec4(0.0f, -littleOverViewport, 0.0f, 1.0f)},
1561*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(-littleOverViewport - 1.0f, 0.0f, 0.0f, 1.0f),
1562*35238bceSAndroid Build Coastguard Worker          tcu::Vec4(0.0f, -littleOverViewport - 1.0f, 0.0f, 1.0f)},
1563*35238bceSAndroid Build Coastguard Worker     };
1564*35238bceSAndroid Build Coastguard Worker     const LineRenderTestCase::ColorlessLineData depthTestLines[] = {
1565*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.3f, 1.0f, 2.0f, 1.0f)},
1566*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.3f, -1.0f, 2.0f, 1.0f)},
1567*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(-1.0f, -1.1f, -2.0f, 1.0f)},
1568*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(-1.0f, 1.1f, -2.0f, 1.0f)},
1569*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 0.1f, 2.0f, 0.6f)},
1570*35238bceSAndroid Build Coastguard Worker     };
1571*35238bceSAndroid Build Coastguard Worker     const LineRenderTestCase::ColorlessLineData longTestLines[] = {
1572*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(-41000.0f, -40000.0f, -1000000.0f, 1.0f), tcu::Vec4(41000.0f, 40000.0f, 1000000.0f, 1.0f)},
1573*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(41000.0f, -40000.0f, 1000000.0f, 1.0f), tcu::Vec4(-41000.0f, 40000.0f, -1000000.0f, 1.0f)},
1574*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.5f, -40000.0f, 100000.0f, 1.0f), tcu::Vec4(0.5f, 40000.0f, -100000.0f, 1.0f)},
1575*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(-0.5f, 40000.0f, 100000.0f, 1.0f), tcu::Vec4(-0.5f, -40000.0f, -100000.0f, 1.0f)},
1576*35238bceSAndroid Build Coastguard Worker     };
1577*35238bceSAndroid Build Coastguard Worker 
1578*35238bceSAndroid Build Coastguard Worker     // line attribute clipping
1579*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 red(1.0f, 0.0f, 0.0f, 1.0f);
1580*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 yellow(1.0f, 1.0f, 0.0f, 1.0f);
1581*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 lightBlue(0.3f, 0.3f, 1.0f, 1.0f);
1582*35238bceSAndroid Build Coastguard Worker     const LineRenderTestCase::ColoredLineData colorTestLines[] = {
1583*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), red, tcu::Vec4(1.3f, 1.0f, 2.0f, 1.0f), yellow},
1584*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), red, tcu::Vec4(1.3f, -1.0f, 2.0f, 1.0f), lightBlue},
1585*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), red, tcu::Vec4(-1.0f, -1.0f, -2.0f, 1.0f), yellow},
1586*35238bceSAndroid Build Coastguard Worker         {tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), red, tcu::Vec4(-1.0f, 1.0f, -2.0f, 1.0f), lightBlue},
1587*35238bceSAndroid Build Coastguard Worker     };
1588*35238bceSAndroid Build Coastguard Worker 
1589*35238bceSAndroid Build Coastguard Worker     // line clipping
1590*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "line_z_clip", "line z clipping", DE_ARRAY_BEGIN(depthTestLines),
1591*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_END(depthTestLines), 1.0f, VIEWPORT_WHOLE));
1592*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "line_z_clip_viewport_center", "line z clipping", DE_ARRAY_BEGIN(depthTestLines),
1593*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_END(depthTestLines), 1.0f, VIEWPORT_CENTER));
1594*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "line_z_clip_viewport_corner", "line z clipping", DE_ARRAY_BEGIN(depthTestLines),
1595*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_END(depthTestLines), 1.0f, VIEWPORT_CORNER));
1596*35238bceSAndroid Build Coastguard Worker 
1597*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "line_clip_viewport_center", "line viewport clipping",
1598*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_BEGIN(viewportTestLines), DE_ARRAY_END(viewportTestLines), 1.0f, VIEWPORT_CENTER));
1599*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "line_clip_viewport_corner", "line viewport clipping",
1600*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_BEGIN(viewportTestLines), DE_ARRAY_END(viewportTestLines), 1.0f, VIEWPORT_CORNER));
1601*35238bceSAndroid Build Coastguard Worker 
1602*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "wide_line_z_clip", "line z clipping", DE_ARRAY_BEGIN(depthTestLines),
1603*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_END(depthTestLines), 5.0f, VIEWPORT_WHOLE));
1604*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "wide_line_z_clip_viewport_center", "line z clipping",
1605*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_BEGIN(depthTestLines), DE_ARRAY_END(depthTestLines), 5.0f, VIEWPORT_CENTER));
1606*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "wide_line_z_clip_viewport_corner", "line z clipping",
1607*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_BEGIN(depthTestLines), DE_ARRAY_END(depthTestLines), 5.0f, VIEWPORT_CORNER));
1608*35238bceSAndroid Build Coastguard Worker 
1609*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "wide_line_clip", "line viewport clipping", DE_ARRAY_BEGIN(viewportTestLines),
1610*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_END(viewportTestLines), 5.0f, VIEWPORT_WHOLE));
1611*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "wide_line_clip_viewport_center", "line viewport clipping",
1612*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_BEGIN(viewportTestLines), DE_ARRAY_END(viewportTestLines), 5.0f, VIEWPORT_CENTER));
1613*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "wide_line_clip_viewport_corner", "line viewport clipping",
1614*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_BEGIN(viewportTestLines), DE_ARRAY_END(viewportTestLines), 5.0f, VIEWPORT_CORNER));
1615*35238bceSAndroid Build Coastguard Worker 
1616*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "long_line_clip", "line viewport clipping", DE_ARRAY_BEGIN(longTestLines),
1617*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_END(longTestLines), 1.0f, VIEWPORT_WHOLE, 2));
1618*35238bceSAndroid Build Coastguard Worker     addChild(new LineCase(m_context, "long_wide_line_clip", "line viewport clipping", DE_ARRAY_BEGIN(longTestLines),
1619*35238bceSAndroid Build Coastguard Worker                           DE_ARRAY_END(longTestLines), 5.0f, VIEWPORT_WHOLE, 2));
1620*35238bceSAndroid Build Coastguard Worker 
1621*35238bceSAndroid Build Coastguard Worker     // line attribute clipping
1622*35238bceSAndroid Build Coastguard Worker     addChild(new ColoredLineCase(m_context, "line_attrib_clip", "line attribute clipping",
1623*35238bceSAndroid Build Coastguard Worker                                  DE_ARRAY_BEGIN(colorTestLines), DE_ARRAY_END(colorTestLines), 1.0f, VIEWPORT_WHOLE));
1624*35238bceSAndroid Build Coastguard Worker     addChild(new ColoredLineCase(m_context, "wide_line_attrib_clip", "line attribute clipping",
1625*35238bceSAndroid Build Coastguard Worker                                  DE_ARRAY_BEGIN(colorTestLines), DE_ARRAY_END(colorTestLines), 5.0f, VIEWPORT_WHOLE));
1626*35238bceSAndroid Build Coastguard Worker }
1627*35238bceSAndroid Build Coastguard Worker 
1628*35238bceSAndroid Build Coastguard Worker class PolysTestGroup : public TestCaseGroup
1629*35238bceSAndroid Build Coastguard Worker {
1630*35238bceSAndroid Build Coastguard Worker public:
1631*35238bceSAndroid Build Coastguard Worker     PolysTestGroup(Context &context);
1632*35238bceSAndroid Build Coastguard Worker 
1633*35238bceSAndroid Build Coastguard Worker     void init(void);
1634*35238bceSAndroid Build Coastguard Worker };
1635*35238bceSAndroid Build Coastguard Worker 
PolysTestGroup(Context & context)1636*35238bceSAndroid Build Coastguard Worker PolysTestGroup::PolysTestGroup(Context &context) : TestCaseGroup(context, "polygon", "Polygon clipping tests")
1637*35238bceSAndroid Build Coastguard Worker {
1638*35238bceSAndroid Build Coastguard Worker }
1639*35238bceSAndroid Build Coastguard Worker 
init(void)1640*35238bceSAndroid Build Coastguard Worker void PolysTestGroup::init(void)
1641*35238bceSAndroid Build Coastguard Worker {
1642*35238bceSAndroid Build Coastguard Worker     const float large  = 100000.0f;
1643*35238bceSAndroid Build Coastguard Worker     const float offset = 0.9f;
1644*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 white(1.0f, 1.0f, 1.0f, 1.0f);
1645*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 red(1.0f, 0.0f, 0.0f, 1.0f);
1646*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 yellow(1.0f, 1.0f, 0.0f, 1.0f);
1647*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 blue(0.0f, 0.0f, 1.0f, 1.0f);
1648*35238bceSAndroid Build Coastguard Worker 
1649*35238bceSAndroid Build Coastguard Worker     // basic cases
1650*35238bceSAndroid Build Coastguard Worker     {
1651*35238bceSAndroid Build Coastguard Worker         const TriangleCase::TriangleData viewportPolys[] = {
1652*35238bceSAndroid Build Coastguard Worker             // one vertex clipped
1653*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.8f, -0.2f, 0.0f, 1.0f), white, tcu::Vec4(-0.8f, 0.2f, 0.0f, 1.0f), white,
1654*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(-1.3f, 0.05f, 0.0f, 1.0f), white},
1655*35238bceSAndroid Build Coastguard Worker 
1656*35238bceSAndroid Build Coastguard Worker             // two vertices clipped
1657*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), white, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), white,
1658*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), white},
1659*35238bceSAndroid Build Coastguard Worker 
1660*35238bceSAndroid Build Coastguard Worker             // three vertices clipped
1661*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-1.1f, 0.6f, 0.0f, 1.0f), white, tcu::Vec4(-1.1f, 1.1f, 0.0f, 1.0f), white,
1662*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(-0.6f, 1.1f, 0.0f, 1.0f), white},
1663*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(0.8f, 1.1f, 0.0f, 1.0f), white, tcu::Vec4(0.95f, -1.1f, 0.0f, 1.0f), white,
1664*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(3.0f, 0.0f, 0.0f, 1.0f), white},
1665*35238bceSAndroid Build Coastguard Worker         };
1666*35238bceSAndroid Build Coastguard Worker         const TriangleCase::TriangleData depthPolys[] = {
1667*35238bceSAndroid Build Coastguard Worker             // one vertex clipped to Z+
1668*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.2f, 0.7f, 0.0f, 1.0f), white, tcu::Vec4(0.2f, 0.7f, 0.0f, 1.0f), white,
1669*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(0.0f, 0.9f, 2.0f, 1.0f), white},
1670*35238bceSAndroid Build Coastguard Worker 
1671*35238bceSAndroid Build Coastguard Worker             // two vertices clipped to Z-
1672*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(0.9f, 0.4f, -1.5f, 1.0f), white, tcu::Vec4(0.9f, -0.4f, -1.5f, 1.0f), white,
1673*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(0.6f, 0.0f, 0.0f, 1.0f), white},
1674*35238bceSAndroid Build Coastguard Worker 
1675*35238bceSAndroid Build Coastguard Worker             // three vertices clipped
1676*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.9f, 0.6f, -2.0f, 1.0f), white, tcu::Vec4(-0.9f, -0.6f, -2.0f, 1.0f), white,
1677*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(-0.4f, 0.0f, 2.0f, 1.0f), white},
1678*35238bceSAndroid Build Coastguard Worker 
1679*35238bceSAndroid Build Coastguard Worker             // three vertices clipped by X, Y and Z
1680*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(0.0f, -1.2f, 0.0f, 1.0f), white, tcu::Vec4(0.0f, 0.5f, -1.5f, 1.0f), white,
1681*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(1.2f, -0.9f, 0.0f, 1.0f), white},
1682*35238bceSAndroid Build Coastguard Worker         };
1683*35238bceSAndroid Build Coastguard Worker         const TriangleCase::TriangleData largePolys[] = {
1684*35238bceSAndroid Build Coastguard Worker             // one vertex clipped
1685*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), white, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), white,
1686*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(0.0f, -large, 2.0f, 1.0f), white},
1687*35238bceSAndroid Build Coastguard Worker 
1688*35238bceSAndroid Build Coastguard Worker             // two vertices clipped
1689*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f), white, tcu::Vec4(large, 0.5f, 0.0f, 1.0f), white,
1690*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(0.5f, large, 0.0f, 1.0f), white},
1691*35238bceSAndroid Build Coastguard Worker 
1692*35238bceSAndroid Build Coastguard Worker             // three vertices clipped
1693*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.9f, -large, 0.0f, 1.0f), white, tcu::Vec4(-1.1f, -large, 0.0f, 1.0f), white,
1694*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(-0.9f, large, 0.0f, 1.0f), white},
1695*35238bceSAndroid Build Coastguard Worker         };
1696*35238bceSAndroid Build Coastguard Worker         const TriangleCase::TriangleData largeDepthPolys[] = {
1697*35238bceSAndroid Build Coastguard Worker             // one vertex clipped
1698*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), white, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), white,
1699*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(0.0f, -large, large, 1.0f), white},
1700*35238bceSAndroid Build Coastguard Worker 
1701*35238bceSAndroid Build Coastguard Worker             // two vertices clipped
1702*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f), white, tcu::Vec4(0.9f, large / 2, -large, 1.0f), white,
1703*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(large / 4, 0.0f, -large, 1.0f), white},
1704*35238bceSAndroid Build Coastguard Worker 
1705*35238bceSAndroid Build Coastguard Worker             // three vertices clipped
1706*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.9f, large / 4, large, 1.0f), white, tcu::Vec4(-0.5f, -large / 4, -large, 1.0f), white,
1707*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(-0.2f, large / 4, large, 1.0f), white},
1708*35238bceSAndroid Build Coastguard Worker         };
1709*35238bceSAndroid Build Coastguard Worker         const TriangleCase::TriangleData attribPolys[] = {
1710*35238bceSAndroid Build Coastguard Worker             // one vertex clipped to edge, large
1711*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
1712*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(0.0f, -large, 2.0f, 1.0f), blue},
1713*35238bceSAndroid Build Coastguard Worker 
1714*35238bceSAndroid Build Coastguard Worker             // two vertices clipped to edges
1715*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1716*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1717*35238bceSAndroid Build Coastguard Worker 
1718*35238bceSAndroid Build Coastguard Worker             // two vertices clipped to edges, with non-uniform w
1719*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1720*35238bceSAndroid Build Coastguard Worker              16.0f * tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1721*35238bceSAndroid Build Coastguard Worker 
1722*35238bceSAndroid Build Coastguard Worker             // three vertices clipped, large, Z
1723*35238bceSAndroid Build Coastguard Worker             {tcu::Vec4(-0.9f, large / 4, large, 1.0f), red, tcu::Vec4(-0.5f, -large / 4, -large, 1.0f), yellow,
1724*35238bceSAndroid Build Coastguard Worker              tcu::Vec4(-0.2f, large / 4, large, 1.0f), blue},
1725*35238bceSAndroid Build Coastguard Worker         };
1726*35238bceSAndroid Build Coastguard Worker 
1727*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "poly_clip_viewport_center", "polygon viewport clipping",
1728*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_BEGIN(viewportPolys), DE_ARRAY_END(viewportPolys), VIEWPORT_CENTER));
1729*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "poly_clip_viewport_corner", "polygon viewport clipping",
1730*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_BEGIN(viewportPolys), DE_ARRAY_END(viewportPolys), VIEWPORT_CORNER));
1731*35238bceSAndroid Build Coastguard Worker 
1732*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "poly_z_clip", "polygon z clipping", DE_ARRAY_BEGIN(depthPolys),
1733*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_END(depthPolys), VIEWPORT_WHOLE));
1734*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "poly_z_clip_viewport_center", "polygon z clipping",
1735*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_BEGIN(depthPolys), DE_ARRAY_END(depthPolys), VIEWPORT_CENTER));
1736*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "poly_z_clip_viewport_corner", "polygon z clipping",
1737*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_BEGIN(depthPolys), DE_ARRAY_END(depthPolys), VIEWPORT_CORNER));
1738*35238bceSAndroid Build Coastguard Worker 
1739*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "large_poly_clip_viewport_center", "polygon viewport clipping",
1740*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_BEGIN(largePolys), DE_ARRAY_END(largePolys), VIEWPORT_CENTER));
1741*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "large_poly_clip_viewport_corner", "polygon viewport clipping",
1742*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_BEGIN(largePolys), DE_ARRAY_END(largePolys), VIEWPORT_CORNER));
1743*35238bceSAndroid Build Coastguard Worker 
1744*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "large_poly_z_clip", "polygon z clipping", DE_ARRAY_BEGIN(largeDepthPolys),
1745*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_END(largeDepthPolys), VIEWPORT_WHOLE));
1746*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "large_poly_z_clip_viewport_center", "polygon z clipping",
1747*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_BEGIN(largeDepthPolys), DE_ARRAY_END(largeDepthPolys), VIEWPORT_CENTER));
1748*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleCase(m_context, "large_poly_z_clip_viewport_corner", "polygon z clipping",
1749*35238bceSAndroid Build Coastguard Worker                                   DE_ARRAY_BEGIN(largeDepthPolys), DE_ARRAY_END(largeDepthPolys), VIEWPORT_CORNER));
1750*35238bceSAndroid Build Coastguard Worker 
1751*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleAttributeCase(m_context, "poly_attrib_clip", "polygon clipping",
1752*35238bceSAndroid Build Coastguard Worker                                            DE_ARRAY_BEGIN(attribPolys), DE_ARRAY_END(attribPolys), VIEWPORT_WHOLE));
1753*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleAttributeCase(m_context, "poly_attrib_clip_viewport_center", "polygon clipping",
1754*35238bceSAndroid Build Coastguard Worker                                            DE_ARRAY_BEGIN(attribPolys), DE_ARRAY_END(attribPolys), VIEWPORT_CENTER));
1755*35238bceSAndroid Build Coastguard Worker         addChild(new TriangleAttributeCase(m_context, "poly_attrib_clip_viewport_corner", "polygon clipping",
1756*35238bceSAndroid Build Coastguard Worker                                            DE_ARRAY_BEGIN(attribPolys), DE_ARRAY_END(attribPolys), VIEWPORT_CORNER));
1757*35238bceSAndroid Build Coastguard Worker     }
1758*35238bceSAndroid Build Coastguard Worker 
1759*35238bceSAndroid Build Coastguard Worker     // multiple polygons
1760*35238bceSAndroid Build Coastguard Worker     {
1761*35238bceSAndroid Build Coastguard Worker         {
1762*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1763*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to edge
1764*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
1765*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, -offset, 2.0f, 1.0f), blue},
1766*35238bceSAndroid Build Coastguard Worker 
1767*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1768*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1769*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1770*35238bceSAndroid Build Coastguard Worker 
1771*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges, with non-uniform w
1772*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1773*35238bceSAndroid Build Coastguard Worker                  16.0f * tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1774*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1775*35238bceSAndroid Build Coastguard Worker                  16.0f * tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1776*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, 0.6f, 0.0f, 1.0f), yellow,
1777*35238bceSAndroid Build Coastguard Worker                  16.0f * tcu::Vec4(-0.6f, 0.6f, 0.0f, 1.0f), blue},
1778*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), yellow,
1779*35238bceSAndroid Build Coastguard Worker                  16.0f * tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), blue},
1780*35238bceSAndroid Build Coastguard Worker 
1781*35238bceSAndroid Build Coastguard Worker                 // three vertices clipped, Z
1782*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.9f, offset / 4, offset, 1.0f), red, tcu::Vec4(-0.5f, -offset / 4, -offset, 1.0f), yellow,
1783*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.2f, offset / 4, offset, 1.0f), blue},
1784*35238bceSAndroid Build Coastguard Worker             };
1785*35238bceSAndroid Build Coastguard Worker 
1786*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_0", "polygon clipping", DE_ARRAY_BEGIN(polys),
1787*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1788*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_0_viewport_center", "polygon clipping",
1789*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1790*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_0_viewport_corner", "polygon clipping",
1791*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1792*35238bceSAndroid Build Coastguard Worker         }
1793*35238bceSAndroid Build Coastguard Worker 
1794*35238bceSAndroid Build Coastguard Worker         {
1795*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1796*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
1797*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
1798*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, -offset, 2.0f, 1.0f), blue},
1799*35238bceSAndroid Build Coastguard Worker 
1800*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1801*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1802*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1803*35238bceSAndroid Build Coastguard Worker 
1804*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges, with non-uniform w
1805*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1806*35238bceSAndroid Build Coastguard Worker                  16.0f * tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1807*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1808*35238bceSAndroid Build Coastguard Worker                  16.0f * tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1809*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, 0.6f, 0.0f, 1.0f), yellow,
1810*35238bceSAndroid Build Coastguard Worker                  16.0f * tcu::Vec4(-0.6f, 0.6f, 0.0f, 1.0f), blue},
1811*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), yellow,
1812*35238bceSAndroid Build Coastguard Worker                  16.0f * tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), blue},
1813*35238bceSAndroid Build Coastguard Worker             };
1814*35238bceSAndroid Build Coastguard Worker 
1815*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_1", "polygon clipping", DE_ARRAY_BEGIN(polys),
1816*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1817*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_1_viewport_center", "polygon clipping",
1818*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1819*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_1_viewport_corner", "polygon clipping",
1820*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1821*35238bceSAndroid Build Coastguard Worker         }
1822*35238bceSAndroid Build Coastguard Worker 
1823*35238bceSAndroid Build Coastguard Worker         {
1824*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1825*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
1826*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
1827*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, -offset, 2.0f, 1.0f), blue},
1828*35238bceSAndroid Build Coastguard Worker 
1829*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1830*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1831*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1832*35238bceSAndroid Build Coastguard Worker 
1833*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1834*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1835*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1836*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1837*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1838*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, 0.6f, 0.0f, 1.0f), yellow,
1839*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, 0.6f, 0.0f, 1.0f), blue},
1840*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), yellow,
1841*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), blue},
1842*35238bceSAndroid Build Coastguard Worker             };
1843*35238bceSAndroid Build Coastguard Worker 
1844*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_2", "polygon clipping", DE_ARRAY_BEGIN(polys),
1845*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1846*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_2_viewport_center", "polygon clipping",
1847*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1848*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_2_viewport_corner", "polygon clipping",
1849*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1850*35238bceSAndroid Build Coastguard Worker         }
1851*35238bceSAndroid Build Coastguard Worker 
1852*35238bceSAndroid Build Coastguard Worker         {
1853*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1854*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
1855*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
1856*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, -offset, -2.0f, 1.0f), blue},
1857*35238bceSAndroid Build Coastguard Worker 
1858*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1859*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1860*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1861*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1862*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1863*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, 0.6f, 0.0f, 1.0f), yellow,
1864*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, 0.6f, 0.0f, 1.0f), blue},
1865*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), yellow,
1866*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), blue},
1867*35238bceSAndroid Build Coastguard Worker             };
1868*35238bceSAndroid Build Coastguard Worker 
1869*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_3", "polygon clipping", DE_ARRAY_BEGIN(polys),
1870*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1871*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_3_viewport_center", "polygon clipping",
1872*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1873*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_3_viewport_corner", "polygon clipping",
1874*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1875*35238bceSAndroid Build Coastguard Worker         }
1876*35238bceSAndroid Build Coastguard Worker 
1877*35238bceSAndroid Build Coastguard Worker         {
1878*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1879*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
1880*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.3f, 0.2f, 0.0f, 1.0f), red, tcu::Vec4(0.3f, -0.2f, 0.0f, 1.0f), yellow,
1881*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(offset, 0.0f, 2.0f, 1.0f), blue},
1882*35238bceSAndroid Build Coastguard Worker 
1883*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1884*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1885*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1886*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1887*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1888*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, 0.6f, 0.0f, 1.0f), yellow,
1889*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, 0.6f, 0.0f, 1.0f), blue},
1890*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), yellow,
1891*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), blue},
1892*35238bceSAndroid Build Coastguard Worker             };
1893*35238bceSAndroid Build Coastguard Worker 
1894*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_4", "polygon clipping", DE_ARRAY_BEGIN(polys),
1895*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1896*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_4_viewport_center", "polygon clipping",
1897*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1898*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_4_viewport_corner", "polygon clipping",
1899*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1900*35238bceSAndroid Build Coastguard Worker         }
1901*35238bceSAndroid Build Coastguard Worker 
1902*35238bceSAndroid Build Coastguard Worker         {
1903*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1904*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
1905*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.3f, 0.2f, 0.0f, 1.0f), red, tcu::Vec4(-0.3f, -0.2f, 0.0f, 1.0f), yellow,
1906*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-offset, 0.0f, 2.0f, 1.0f), blue},
1907*35238bceSAndroid Build Coastguard Worker 
1908*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1909*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1910*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1911*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1912*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1913*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, 0.6f, 0.0f, 1.0f), yellow,
1914*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, 0.6f, 0.0f, 1.0f), blue},
1915*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), yellow,
1916*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), blue},
1917*35238bceSAndroid Build Coastguard Worker             };
1918*35238bceSAndroid Build Coastguard Worker 
1919*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_5", "polygon clipping", DE_ARRAY_BEGIN(polys),
1920*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1921*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_5_viewport_center", "polygon clipping",
1922*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1923*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_5_viewport_corner", "polygon clipping",
1924*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1925*35238bceSAndroid Build Coastguard Worker         }
1926*35238bceSAndroid Build Coastguard Worker 
1927*35238bceSAndroid Build Coastguard Worker         {
1928*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1929*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
1930*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, 0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, 0.3f, 0.0f, 1.0f), yellow,
1931*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, offset, 2.0f, 1.0f), blue},
1932*35238bceSAndroid Build Coastguard Worker 
1933*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1934*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1935*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1936*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1937*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1938*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, 0.6f, 0.0f, 1.0f), yellow,
1939*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, 0.6f, 0.0f, 1.0f), blue},
1940*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), yellow,
1941*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), blue},
1942*35238bceSAndroid Build Coastguard Worker             };
1943*35238bceSAndroid Build Coastguard Worker 
1944*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_6", "polygon clipping", DE_ARRAY_BEGIN(polys),
1945*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1946*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_6_viewport_center", "polygon clipping",
1947*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1948*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_6_viewport_corner", "polygon clipping",
1949*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1950*35238bceSAndroid Build Coastguard Worker         }
1951*35238bceSAndroid Build Coastguard Worker 
1952*35238bceSAndroid Build Coastguard Worker         {
1953*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1954*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1955*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1956*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1957*35238bceSAndroid Build Coastguard Worker 
1958*35238bceSAndroid Build Coastguard Worker                 // two vertices clipped to edges
1959*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, -0.6f, 0.0f, 1.0f), yellow,
1960*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, -0.6f, 0.0f, 1.0f), blue},
1961*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(1.2f, 0.6f, 0.0f, 1.0f), yellow,
1962*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.6f, 0.6f, 0.0f, 1.0f), blue},
1963*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, 1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, 0.6f, 0.0f, 1.0f), yellow,
1964*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, 0.6f, 0.0f, 1.0f), blue},
1965*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.6f, -1.2f, 0.0f, 1.0f), red, tcu::Vec4(-1.2f, -0.6f, 0.0f, 1.0f), yellow,
1966*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-0.6f, -0.6f, 0.0f, 1.0f), blue},
1967*35238bceSAndroid Build Coastguard Worker             };
1968*35238bceSAndroid Build Coastguard Worker 
1969*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_7", "polygon clipping", DE_ARRAY_BEGIN(polys),
1970*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1971*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_7_viewport_center", "polygon clipping",
1972*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1973*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_7_viewport_corner", "polygon clipping",
1974*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1975*35238bceSAndroid Build Coastguard Worker         }
1976*35238bceSAndroid Build Coastguard Worker 
1977*35238bceSAndroid Build Coastguard Worker         {
1978*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
1979*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
1980*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
1981*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, -offset, 2.0f, 1.0f), blue},
1982*35238bceSAndroid Build Coastguard Worker 
1983*35238bceSAndroid Build Coastguard Worker                 // fill
1984*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), white, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), white,
1985*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), white},
1986*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), blue, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), blue,
1987*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), blue},
1988*35238bceSAndroid Build Coastguard Worker             };
1989*35238bceSAndroid Build Coastguard Worker 
1990*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_8", "polygon clipping", DE_ARRAY_BEGIN(polys),
1991*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
1992*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_8_viewport_center", "polygon clipping",
1993*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
1994*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_8_viewport_corner", "polygon clipping",
1995*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
1996*35238bceSAndroid Build Coastguard Worker         }
1997*35238bceSAndroid Build Coastguard Worker 
1998*35238bceSAndroid Build Coastguard Worker         {
1999*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
2000*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
2001*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
2002*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, -offset, 2.0f, 1.0f), blue},
2003*35238bceSAndroid Build Coastguard Worker 
2004*35238bceSAndroid Build Coastguard Worker                 // fill
2005*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), red, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), red,
2006*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), red},
2007*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), blue, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), blue,
2008*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), blue},
2009*35238bceSAndroid Build Coastguard Worker             };
2010*35238bceSAndroid Build Coastguard Worker 
2011*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_9", "polygon clipping", DE_ARRAY_BEGIN(polys),
2012*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
2013*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_9_viewport_center", "polygon clipping",
2014*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
2015*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_9_viewport_corner", "polygon clipping",
2016*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
2017*35238bceSAndroid Build Coastguard Worker         }
2018*35238bceSAndroid Build Coastguard Worker 
2019*35238bceSAndroid Build Coastguard Worker         {
2020*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
2021*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
2022*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
2023*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, -offset, 2.0f, 1.0f), blue},
2024*35238bceSAndroid Build Coastguard Worker 
2025*35238bceSAndroid Build Coastguard Worker                 // fill
2026*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), white, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), white,
2027*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), white},
2028*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), red, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), red,
2029*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), red},
2030*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), blue, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), blue,
2031*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), blue},
2032*35238bceSAndroid Build Coastguard Worker             };
2033*35238bceSAndroid Build Coastguard Worker 
2034*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_10", "polygon clipping", DE_ARRAY_BEGIN(polys),
2035*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
2036*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_10_viewport_center", "polygon clipping",
2037*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
2038*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_10_viewport_corner", "polygon clipping",
2039*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
2040*35238bceSAndroid Build Coastguard Worker         }
2041*35238bceSAndroid Build Coastguard Worker 
2042*35238bceSAndroid Build Coastguard Worker         {
2043*35238bceSAndroid Build Coastguard Worker             const TriangleAttributeCase::TriangleData polys[] = {
2044*35238bceSAndroid Build Coastguard Worker                 // one vertex clipped to z
2045*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-0.2f, -0.3f, 0.0f, 1.0f), red, tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f), yellow,
2046*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(0.0f, -offset, 2.0f, 1.0f), blue},
2047*35238bceSAndroid Build Coastguard Worker 
2048*35238bceSAndroid Build Coastguard Worker                 // fill
2049*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), white, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), white,
2050*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), white},
2051*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), red, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), red,
2052*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), red},
2053*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), blue, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), blue,
2054*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), blue},
2055*35238bceSAndroid Build Coastguard Worker                 {tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), yellow, tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), yellow,
2056*35238bceSAndroid Build Coastguard Worker                  tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), yellow},
2057*35238bceSAndroid Build Coastguard Worker             };
2058*35238bceSAndroid Build Coastguard Worker 
2059*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_11", "polygon clipping", DE_ARRAY_BEGIN(polys),
2060*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_END(polys), VIEWPORT_WHOLE));
2061*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_11_viewport_center", "polygon clipping",
2062*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CENTER));
2063*35238bceSAndroid Build Coastguard Worker             addChild(new TriangleAttributeCase(m_context, "multiple_11_viewport_corner", "polygon clipping",
2064*35238bceSAndroid Build Coastguard Worker                                                DE_ARRAY_BEGIN(polys), DE_ARRAY_END(polys), VIEWPORT_CORNER));
2065*35238bceSAndroid Build Coastguard Worker         }
2066*35238bceSAndroid Build Coastguard Worker     }
2067*35238bceSAndroid Build Coastguard Worker }
2068*35238bceSAndroid Build Coastguard Worker 
2069*35238bceSAndroid Build Coastguard Worker class PolyEdgesTestGroup : public TestCaseGroup
2070*35238bceSAndroid Build Coastguard Worker {
2071*35238bceSAndroid Build Coastguard Worker public:
2072*35238bceSAndroid Build Coastguard Worker     PolyEdgesTestGroup(Context &context);
2073*35238bceSAndroid Build Coastguard Worker 
2074*35238bceSAndroid Build Coastguard Worker     void init(void);
2075*35238bceSAndroid Build Coastguard Worker };
2076*35238bceSAndroid Build Coastguard Worker 
PolyEdgesTestGroup(Context & context)2077*35238bceSAndroid Build Coastguard Worker PolyEdgesTestGroup::PolyEdgesTestGroup(Context &context)
2078*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "polygon_edge", "Polygon clipping edge tests")
2079*35238bceSAndroid Build Coastguard Worker {
2080*35238bceSAndroid Build Coastguard Worker }
2081*35238bceSAndroid Build Coastguard Worker 
init(void)2082*35238bceSAndroid Build Coastguard Worker void PolyEdgesTestGroup::init(void)
2083*35238bceSAndroid Build Coastguard Worker {
2084*35238bceSAndroid Build Coastguard Worker     // Quads via origin
2085*35238bceSAndroid Build Coastguard Worker     const struct Quad
2086*35238bceSAndroid Build Coastguard Worker     {
2087*35238bceSAndroid Build Coastguard Worker         tcu::Vec3 d1; // tangent
2088*35238bceSAndroid Build Coastguard Worker         tcu::Vec3 d2; // bi-tangent
2089*35238bceSAndroid Build Coastguard Worker     } quads[] = {
2090*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(1, 1, 1), tcu::Vec3(1, -1, 1)},   {tcu::Vec3(1, 1, 1), tcu::Vec3(-1, 1.1f, 1)},
2091*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(1, 1, 0), tcu::Vec3(-1, 1, 0)},   {tcu::Vec3(0, 1, 0), tcu::Vec3(1, 0, 0)},
2092*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(0, 1, 0), tcu::Vec3(1, 0.1f, 0)},
2093*35238bceSAndroid Build Coastguard Worker     };
2094*35238bceSAndroid Build Coastguard Worker 
2095*35238bceSAndroid Build Coastguard Worker     // Quad near edge
2096*35238bceSAndroid Build Coastguard Worker     const struct EdgeQuad
2097*35238bceSAndroid Build Coastguard Worker     {
2098*35238bceSAndroid Build Coastguard Worker         tcu::Vec3 d1;     // tangent
2099*35238bceSAndroid Build Coastguard Worker         tcu::Vec3 d2;     // bi-tangent
2100*35238bceSAndroid Build Coastguard Worker         tcu::Vec3 center; // center
2101*35238bceSAndroid Build Coastguard Worker     } edgeQuads[] = {
2102*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(1, 0.01f, 0), tcu::Vec3(0, 0.01f, 0), tcu::Vec3(0, 0.99f, 0)},      // edge near x-plane
2103*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(0.01f, 1, 0), tcu::Vec3(0.01f, 0, 0), tcu::Vec3(0.99f, 0, 0)},      // edge near y-plane
2104*35238bceSAndroid Build Coastguard Worker         {tcu::Vec3(1, 1, 0.01f), tcu::Vec3(0.01f, -0.01f, 0), tcu::Vec3(0, 0, 0.99f)}, // edge near z-plane
2105*35238bceSAndroid Build Coastguard Worker     };
2106*35238bceSAndroid Build Coastguard Worker 
2107*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(quads); ++ndx)
2108*35238bceSAndroid Build Coastguard Worker         addChild(new QuadFillTest(m_context, (std::string("quad_at_origin_") + de::toString(ndx)).c_str(),
2109*35238bceSAndroid Build Coastguard Worker                                   "polygon edge clipping", VIEWPORT_CENTER, quads[ndx].d1, quads[ndx].d2));
2110*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(edgeQuads); ++ndx)
2111*35238bceSAndroid Build Coastguard Worker         addChild(new QuadFillTest(m_context, (std::string("quad_near_edge_") + de::toString(ndx)).c_str(),
2112*35238bceSAndroid Build Coastguard Worker                                   "polygon edge clipping", VIEWPORT_CENTER, edgeQuads[ndx].d1, edgeQuads[ndx].d2,
2113*35238bceSAndroid Build Coastguard Worker                                   edgeQuads[ndx].center));
2114*35238bceSAndroid Build Coastguard Worker 
2115*35238bceSAndroid Build Coastguard Worker     // Polyfan
2116*35238bceSAndroid Build Coastguard Worker     addChild(new TriangleFanFillTest(m_context, "poly_fan", "polygon edge clipping", VIEWPORT_CENTER));
2117*35238bceSAndroid Build Coastguard Worker }
2118*35238bceSAndroid Build Coastguard Worker 
2119*35238bceSAndroid Build Coastguard Worker class PolyVertexClipTestGroup : public TestCaseGroup
2120*35238bceSAndroid Build Coastguard Worker {
2121*35238bceSAndroid Build Coastguard Worker public:
2122*35238bceSAndroid Build Coastguard Worker     PolyVertexClipTestGroup(Context &context);
2123*35238bceSAndroid Build Coastguard Worker 
2124*35238bceSAndroid Build Coastguard Worker     void init(void);
2125*35238bceSAndroid Build Coastguard Worker };
2126*35238bceSAndroid Build Coastguard Worker 
PolyVertexClipTestGroup(Context & context)2127*35238bceSAndroid Build Coastguard Worker PolyVertexClipTestGroup::PolyVertexClipTestGroup(Context &context)
2128*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "triangle_vertex", "Clip n vertices")
2129*35238bceSAndroid Build Coastguard Worker {
2130*35238bceSAndroid Build Coastguard Worker }
2131*35238bceSAndroid Build Coastguard Worker 
init(void)2132*35238bceSAndroid Build Coastguard Worker void PolyVertexClipTestGroup::init(void)
2133*35238bceSAndroid Build Coastguard Worker {
2134*35238bceSAndroid Build Coastguard Worker     const float far            = 30000.0f;
2135*35238bceSAndroid Build Coastguard Worker     const tcu::IVec3 outside[] = {
2136*35238bceSAndroid Build Coastguard Worker         // outside one clipping plane
2137*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, 0, 0),
2138*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, 0, 0),
2139*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(0, 1, 0),
2140*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(0, -1, 0),
2141*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(0, 0, 1),
2142*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(0, 0, -1),
2143*35238bceSAndroid Build Coastguard Worker 
2144*35238bceSAndroid Build Coastguard Worker         // outside two clipping planes
2145*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, -1, 0),
2146*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, -1, 0),
2147*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, 1, 0),
2148*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, 1, 0),
2149*35238bceSAndroid Build Coastguard Worker 
2150*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, 0, -1),
2151*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, 0, -1),
2152*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, 0, 1),
2153*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, 0, 1),
2154*35238bceSAndroid Build Coastguard Worker 
2155*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(0, -1, -1),
2156*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(0, 1, -1),
2157*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(0, 1, 1),
2158*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(0, -1, 1),
2159*35238bceSAndroid Build Coastguard Worker 
2160*35238bceSAndroid Build Coastguard Worker         // outside three clipping planes
2161*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, -1, 1),
2162*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, -1, 1),
2163*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, 1, 1),
2164*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, 1, 1),
2165*35238bceSAndroid Build Coastguard Worker 
2166*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, -1, -1),
2167*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, -1, -1),
2168*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(1, 1, -1),
2169*35238bceSAndroid Build Coastguard Worker         tcu::IVec3(-1, 1, -1),
2170*35238bceSAndroid Build Coastguard Worker     };
2171*35238bceSAndroid Build Coastguard Worker 
2172*35238bceSAndroid Build Coastguard Worker     de::Random rnd(0xabcdef);
2173*35238bceSAndroid Build Coastguard Worker 
2174*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *clipOne   = new TestCaseGroup(m_context, "clip_one", "Clip one vertex");
2175*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *clipTwo   = new TestCaseGroup(m_context, "clip_two", "Clip two vertices");
2176*35238bceSAndroid Build Coastguard Worker     TestCaseGroup *clipThree = new TestCaseGroup(m_context, "clip_three", "Clip three vertices");
2177*35238bceSAndroid Build Coastguard Worker 
2178*35238bceSAndroid Build Coastguard Worker     addChild(clipOne);
2179*35238bceSAndroid Build Coastguard Worker     addChild(clipTwo);
2180*35238bceSAndroid Build Coastguard Worker     addChild(clipThree);
2181*35238bceSAndroid Build Coastguard Worker 
2182*35238bceSAndroid Build Coastguard Worker     // Test 1 point clipped
2183*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(outside); ++ndx)
2184*35238bceSAndroid Build Coastguard Worker     {
2185*35238bceSAndroid Build Coastguard Worker         const float w0        = rnd.getFloat(0.2f, 16.0f);
2186*35238bceSAndroid Build Coastguard Worker         const float w1        = rnd.getFloat(0.2f, 16.0f);
2187*35238bceSAndroid Build Coastguard Worker         const float w2        = rnd.getFloat(0.2f, 16.0f);
2188*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 white = tcu::Vec4(1, 1, 1, 1);
2189*35238bceSAndroid Build Coastguard Worker         const tcu::Vec3 r0    = tcu::Vec3(0.2f, 0.3f, 0);
2190*35238bceSAndroid Build Coastguard Worker         const tcu::Vec3 r1    = tcu::Vec3(-0.3f, -0.4f, 0);
2191*35238bceSAndroid Build Coastguard Worker         const tcu::Vec3 r2    = IVec3ToVec3(outside[ndx]) * far;
2192*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 p0    = tcu::Vec4(r0.x() * w0, r0.y() * w0, r0.z() * w0, w0);
2193*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 p1    = tcu::Vec4(r1.x() * w1, r1.y() * w1, r1.z() * w1, w1);
2194*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 p2    = tcu::Vec4(r2.x() * w2, r2.y() * w2, r2.z() * w2, w2);
2195*35238bceSAndroid Build Coastguard Worker 
2196*35238bceSAndroid Build Coastguard Worker         const std::string name = std::string("clip") +
2197*35238bceSAndroid Build Coastguard Worker                                  (outside[ndx].x() > 0 ? "_pos_x" : (outside[ndx].x() < 0 ? "_neg_x" : "")) +
2198*35238bceSAndroid Build Coastguard Worker                                  (outside[ndx].y() > 0 ? "_pos_y" : (outside[ndx].y() < 0 ? "_neg_y" : "")) +
2199*35238bceSAndroid Build Coastguard Worker                                  (outside[ndx].z() > 0 ? "_pos_z" : (outside[ndx].z() < 0 ? "_neg_z" : ""));
2200*35238bceSAndroid Build Coastguard Worker 
2201*35238bceSAndroid Build Coastguard Worker         const TriangleCase::TriangleData triangle = {p0, white, p1, white, p2, white};
2202*35238bceSAndroid Build Coastguard Worker 
2203*35238bceSAndroid Build Coastguard Worker         // don't try to test with degenerate (or almost degenerate) triangles
2204*35238bceSAndroid Build Coastguard Worker         if (outside[ndx].x() == 0 && outside[ndx].y() == 0)
2205*35238bceSAndroid Build Coastguard Worker             continue;
2206*35238bceSAndroid Build Coastguard Worker 
2207*35238bceSAndroid Build Coastguard Worker         clipOne->addChild(
2208*35238bceSAndroid Build Coastguard Worker             new TriangleCase(m_context, name.c_str(), "clip one vertex", &triangle, &triangle + 1, VIEWPORT_CENTER));
2209*35238bceSAndroid Build Coastguard Worker     }
2210*35238bceSAndroid Build Coastguard Worker 
2211*35238bceSAndroid Build Coastguard Worker     // Special triangles for "clip_z" cases, default triangles is not good, since it has very small visible area => problems with MSAA
2212*35238bceSAndroid Build Coastguard Worker     {
2213*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 white = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
2214*35238bceSAndroid Build Coastguard Worker 
2215*35238bceSAndroid Build Coastguard Worker         const TriangleCase::TriangleData posZTriangle = {tcu::Vec4(0.0f, -0.7f, -0.9f, 1.0f), white,
2216*35238bceSAndroid Build Coastguard Worker                                                          tcu::Vec4(0.8f, 0.0f, -0.7f, 1.0f),  white,
2217*35238bceSAndroid Build Coastguard Worker                                                          tcu::Vec4(-0.9f, 0.9f, 3.0f, 1.0f),  white};
2218*35238bceSAndroid Build Coastguard Worker         const TriangleCase::TriangleData negZTriangle = {tcu::Vec4(0.0f, -0.7f, 0.9f, 1.0f),  white,
2219*35238bceSAndroid Build Coastguard Worker                                                          tcu::Vec4(0.4f, 0.0f, 0.7f, 1.0f),   white,
2220*35238bceSAndroid Build Coastguard Worker                                                          tcu::Vec4(-0.9f, 0.9f, -3.0f, 1.0f), white};
2221*35238bceSAndroid Build Coastguard Worker 
2222*35238bceSAndroid Build Coastguard Worker         clipOne->addChild(new TriangleCase(m_context, "clip_pos_z", "clip one vertex", &posZTriangle, &posZTriangle + 1,
2223*35238bceSAndroid Build Coastguard Worker                                            VIEWPORT_CENTER));
2224*35238bceSAndroid Build Coastguard Worker         clipOne->addChild(new TriangleCase(m_context, "clip_neg_z", "clip one vertex", &negZTriangle, &negZTriangle + 1,
2225*35238bceSAndroid Build Coastguard Worker                                            VIEWPORT_CENTER));
2226*35238bceSAndroid Build Coastguard Worker     }
2227*35238bceSAndroid Build Coastguard Worker 
2228*35238bceSAndroid Build Coastguard Worker     // Test 2 points clipped
2229*35238bceSAndroid Build Coastguard Worker     for (int ndx1 = 0; ndx1 < DE_LENGTH_OF_ARRAY(outside); ++ndx1)
2230*35238bceSAndroid Build Coastguard Worker         for (int ndx2 = ndx1 + 1; ndx2 < DE_LENGTH_OF_ARRAY(outside); ++ndx2)
2231*35238bceSAndroid Build Coastguard Worker         {
2232*35238bceSAndroid Build Coastguard Worker             const float w0        = rnd.getFloat(0.2f, 16.0f);
2233*35238bceSAndroid Build Coastguard Worker             const float w1        = rnd.getFloat(0.2f, 16.0f);
2234*35238bceSAndroid Build Coastguard Worker             const float w2        = rnd.getFloat(0.2f, 16.0f);
2235*35238bceSAndroid Build Coastguard Worker             const tcu::Vec4 white = tcu::Vec4(1, 1, 1, 1);
2236*35238bceSAndroid Build Coastguard Worker             const tcu::Vec3 r0    = tcu::Vec3(0.2f, 0.3f, 0);
2237*35238bceSAndroid Build Coastguard Worker             const tcu::IVec3 r1   = outside[ndx1];
2238*35238bceSAndroid Build Coastguard Worker             const tcu::IVec3 r2   = outside[ndx2];
2239*35238bceSAndroid Build Coastguard Worker             const tcu::Vec4 p0    = tcu::Vec4(r0.x() * w0, r0.y() * w0, r0.z() * w0, w0);
2240*35238bceSAndroid Build Coastguard Worker             const tcu::Vec4 p1 =
2241*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4(float(r1.x()) * far * w1, float(r1.y()) * far * w1, float(r1.z()) * far * w1, w1);
2242*35238bceSAndroid Build Coastguard Worker             const tcu::Vec4 p2 =
2243*35238bceSAndroid Build Coastguard Worker                 tcu::Vec4(float(r2.x()) * far * w2, float(r2.y()) * far * w2, float(r2.z()) * far * w2, w2);
2244*35238bceSAndroid Build Coastguard Worker 
2245*35238bceSAndroid Build Coastguard Worker             const std::string name =
2246*35238bceSAndroid Build Coastguard Worker                 std::string("clip") + (outside[ndx1].x() > 0 ? "_pos_x" : (outside[ndx1].x() < 0 ? "_neg_x" : "")) +
2247*35238bceSAndroid Build Coastguard Worker                 (outside[ndx1].y() > 0 ? "_pos_y" : (outside[ndx1].y() < 0 ? "_neg_y" : "")) +
2248*35238bceSAndroid Build Coastguard Worker                 (outside[ndx1].z() > 0 ? "_pos_z" : (outside[ndx1].z() < 0 ? "_neg_z" : "")) + "_and" +
2249*35238bceSAndroid Build Coastguard Worker                 (outside[ndx2].x() > 0 ? "_pos_x" : (outside[ndx2].x() < 0 ? "_neg_x" : "")) +
2250*35238bceSAndroid Build Coastguard Worker                 (outside[ndx2].y() > 0 ? "_pos_y" : (outside[ndx2].y() < 0 ? "_neg_y" : "")) +
2251*35238bceSAndroid Build Coastguard Worker                 (outside[ndx2].z() > 0 ? "_pos_z" : (outside[ndx2].z() < 0 ? "_neg_z" : ""));
2252*35238bceSAndroid Build Coastguard Worker 
2253*35238bceSAndroid Build Coastguard Worker             const TriangleCase::TriangleData triangle = {p0, white, p1, white, p2, white};
2254*35238bceSAndroid Build Coastguard Worker 
2255*35238bceSAndroid Build Coastguard Worker             if (twoPointClippedTriangleInvisible(r0, r1, r2))
2256*35238bceSAndroid Build Coastguard Worker                 continue;
2257*35238bceSAndroid Build Coastguard Worker 
2258*35238bceSAndroid Build Coastguard Worker             clipTwo->addChild(new TriangleCase(m_context, name.c_str(), "clip two vertices", &triangle, &triangle + 1,
2259*35238bceSAndroid Build Coastguard Worker                                                VIEWPORT_CENTER));
2260*35238bceSAndroid Build Coastguard Worker         }
2261*35238bceSAndroid Build Coastguard Worker 
2262*35238bceSAndroid Build Coastguard Worker     // Test 3 points clipped
2263*35238bceSAndroid Build Coastguard Worker     for (int ndx1 = 0; ndx1 < DE_LENGTH_OF_ARRAY(outside); ++ndx1)
2264*35238bceSAndroid Build Coastguard Worker         for (int ndx2 = ndx1 + 1; ndx2 < DE_LENGTH_OF_ARRAY(outside); ++ndx2)
2265*35238bceSAndroid Build Coastguard Worker             for (int ndx3 = ndx2 + 1; ndx3 < DE_LENGTH_OF_ARRAY(outside); ++ndx3)
2266*35238bceSAndroid Build Coastguard Worker             {
2267*35238bceSAndroid Build Coastguard Worker                 const float w0        = rnd.getFloat(0.2f, 16.0f);
2268*35238bceSAndroid Build Coastguard Worker                 const float w1        = rnd.getFloat(0.2f, 16.0f);
2269*35238bceSAndroid Build Coastguard Worker                 const float w2        = rnd.getFloat(0.2f, 16.0f);
2270*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec4 white = tcu::Vec4(1, 1, 1, 1);
2271*35238bceSAndroid Build Coastguard Worker                 const tcu::IVec3 r0   = outside[ndx1];
2272*35238bceSAndroid Build Coastguard Worker                 const tcu::IVec3 r1   = outside[ndx2];
2273*35238bceSAndroid Build Coastguard Worker                 const tcu::IVec3 r2   = outside[ndx3];
2274*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec4 p0 =
2275*35238bceSAndroid Build Coastguard Worker                     tcu::Vec4(float(r0.x()) * far * w0, float(r0.y()) * far * w0, float(r0.z()) * far * w0, w0);
2276*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec4 p1 =
2277*35238bceSAndroid Build Coastguard Worker                     tcu::Vec4(float(r1.x()) * far * w1, float(r1.y()) * far * w1, float(r1.z()) * far * w1, w1);
2278*35238bceSAndroid Build Coastguard Worker                 const tcu::Vec4 p2 =
2279*35238bceSAndroid Build Coastguard Worker                     tcu::Vec4(float(r2.x()) * far * w2, float(r2.y()) * far * w2, float(r2.z()) * far * w2, w2);
2280*35238bceSAndroid Build Coastguard Worker 
2281*35238bceSAndroid Build Coastguard Worker                 // ignore cases where polygon is along xz or yz planes
2282*35238bceSAndroid Build Coastguard Worker                 if (pointsOnLine(r0.swizzle(0, 1), r1.swizzle(0, 1), r2.swizzle(0, 1)))
2283*35238bceSAndroid Build Coastguard Worker                     continue;
2284*35238bceSAndroid Build Coastguard Worker 
2285*35238bceSAndroid Build Coastguard Worker                 // triangle is visible only if it intersects the origin
2286*35238bceSAndroid Build Coastguard Worker                 if (pointOnTriangle(tcu::IVec3(0, 0, 0), r0, r1, r2))
2287*35238bceSAndroid Build Coastguard Worker                 {
2288*35238bceSAndroid Build Coastguard Worker                     const TriangleCase::TriangleData triangle = {p0, white, p1, white, p2, white};
2289*35238bceSAndroid Build Coastguard Worker                     const std::string name =
2290*35238bceSAndroid Build Coastguard Worker                         std::string("clip") +
2291*35238bceSAndroid Build Coastguard Worker                         (outside[ndx1].x() > 0 ? "_pos_x" : (outside[ndx1].x() < 0 ? "_neg_x" : "")) +
2292*35238bceSAndroid Build Coastguard Worker                         (outside[ndx1].y() > 0 ? "_pos_y" : (outside[ndx1].y() < 0 ? "_neg_y" : "")) +
2293*35238bceSAndroid Build Coastguard Worker                         (outside[ndx1].z() > 0 ? "_pos_z" : (outside[ndx1].z() < 0 ? "_neg_z" : "")) + "_and" +
2294*35238bceSAndroid Build Coastguard Worker                         (outside[ndx2].x() > 0 ? "_pos_x" : (outside[ndx2].x() < 0 ? "_neg_x" : "")) +
2295*35238bceSAndroid Build Coastguard Worker                         (outside[ndx2].y() > 0 ? "_pos_y" : (outside[ndx2].y() < 0 ? "_neg_y" : "")) +
2296*35238bceSAndroid Build Coastguard Worker                         (outside[ndx2].z() > 0 ? "_pos_z" : (outside[ndx2].z() < 0 ? "_neg_z" : "")) + "_and" +
2297*35238bceSAndroid Build Coastguard Worker                         (outside[ndx3].x() > 0 ? "_pos_x" : (outside[ndx3].x() < 0 ? "_neg_x" : "")) +
2298*35238bceSAndroid Build Coastguard Worker                         (outside[ndx3].y() > 0 ? "_pos_y" : (outside[ndx3].y() < 0 ? "_neg_y" : "")) +
2299*35238bceSAndroid Build Coastguard Worker                         (outside[ndx3].z() > 0 ? "_pos_z" : (outside[ndx3].z() < 0 ? "_neg_z" : ""));
2300*35238bceSAndroid Build Coastguard Worker 
2301*35238bceSAndroid Build Coastguard Worker                     clipThree->addChild(new TriangleCase(m_context, name.c_str(), "clip three vertices", &triangle,
2302*35238bceSAndroid Build Coastguard Worker                                                          &triangle + 1, VIEWPORT_CENTER));
2303*35238bceSAndroid Build Coastguard Worker                 }
2304*35238bceSAndroid Build Coastguard Worker             }
2305*35238bceSAndroid Build Coastguard Worker }
2306*35238bceSAndroid Build Coastguard Worker 
2307*35238bceSAndroid Build Coastguard Worker } // namespace
2308*35238bceSAndroid Build Coastguard Worker 
ClippingTests(Context & context)2309*35238bceSAndroid Build Coastguard Worker ClippingTests::ClippingTests(Context &context) : TestCaseGroup(context, "clipping", "Clipping tests")
2310*35238bceSAndroid Build Coastguard Worker {
2311*35238bceSAndroid Build Coastguard Worker }
2312*35238bceSAndroid Build Coastguard Worker 
~ClippingTests(void)2313*35238bceSAndroid Build Coastguard Worker ClippingTests::~ClippingTests(void)
2314*35238bceSAndroid Build Coastguard Worker {
2315*35238bceSAndroid Build Coastguard Worker }
2316*35238bceSAndroid Build Coastguard Worker 
init(void)2317*35238bceSAndroid Build Coastguard Worker void ClippingTests::init(void)
2318*35238bceSAndroid Build Coastguard Worker {
2319*35238bceSAndroid Build Coastguard Worker     addChild(new PointsTestGroup(m_context));
2320*35238bceSAndroid Build Coastguard Worker     addChild(new LinesTestGroup(m_context));
2321*35238bceSAndroid Build Coastguard Worker     addChild(new PolysTestGroup(m_context));
2322*35238bceSAndroid Build Coastguard Worker     addChild(new PolyEdgesTestGroup(m_context));
2323*35238bceSAndroid Build Coastguard Worker     addChild(new PolyVertexClipTestGroup(m_context));
2324*35238bceSAndroid Build Coastguard Worker }
2325*35238bceSAndroid Build Coastguard Worker 
2326*35238bceSAndroid Build Coastguard Worker } // namespace Functional
2327*35238bceSAndroid Build Coastguard Worker } // namespace gles3
2328*35238bceSAndroid Build Coastguard Worker } // namespace deqp
2329