xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fDrawElementsBaseVertexTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.1 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2017 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 GL_EXT_draw_elements_base_vertex tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es31fDrawElementsBaseVertexTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "sglrGLContext.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "glsDrawTest.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
34*35238bceSAndroid Build Coastguard Worker 
35*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
37*35238bceSAndroid Build Coastguard Worker 
38*35238bceSAndroid Build Coastguard Worker #include <string>
39*35238bceSAndroid Build Coastguard Worker #include <set>
40*35238bceSAndroid Build Coastguard Worker 
41*35238bceSAndroid Build Coastguard Worker using std::string;
42*35238bceSAndroid Build Coastguard Worker using std::vector;
43*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
44*35238bceSAndroid Build Coastguard Worker 
45*35238bceSAndroid Build Coastguard Worker using namespace glw;
46*35238bceSAndroid Build Coastguard Worker 
47*35238bceSAndroid Build Coastguard Worker namespace deqp
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker namespace gles31
50*35238bceSAndroid Build Coastguard Worker {
51*35238bceSAndroid Build Coastguard Worker namespace Functional
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker namespace
54*35238bceSAndroid Build Coastguard Worker {
55*35238bceSAndroid Build Coastguard Worker 
56*35238bceSAndroid Build Coastguard Worker enum TestIterationType
57*35238bceSAndroid Build Coastguard Worker {
58*35238bceSAndroid Build Coastguard Worker     TYPE_DRAW_COUNT,     // !< test with 1, 5, and 25 primitives
59*35238bceSAndroid Build Coastguard Worker     TYPE_INSTANCE_COUNT, // !< test with 1, 4, and 11 instances
60*35238bceSAndroid Build Coastguard Worker 
61*35238bceSAndroid Build Coastguard Worker     TYPE_LAST
62*35238bceSAndroid Build Coastguard Worker };
63*35238bceSAndroid Build Coastguard Worker 
getElementCount(gls::DrawTestSpec::Primitive primitive,size_t primitiveCount)64*35238bceSAndroid Build Coastguard Worker static size_t getElementCount(gls::DrawTestSpec::Primitive primitive, size_t primitiveCount)
65*35238bceSAndroid Build Coastguard Worker {
66*35238bceSAndroid Build Coastguard Worker     switch (primitive)
67*35238bceSAndroid Build Coastguard Worker     {
68*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_POINTS:
69*35238bceSAndroid Build Coastguard Worker         return primitiveCount;
70*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_TRIANGLES:
71*35238bceSAndroid Build Coastguard Worker         return primitiveCount * 3;
72*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN:
73*35238bceSAndroid Build Coastguard Worker         return primitiveCount + 2;
74*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP:
75*35238bceSAndroid Build Coastguard Worker         return primitiveCount + 2;
76*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_LINES:
77*35238bceSAndroid Build Coastguard Worker         return primitiveCount * 2;
78*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_LINE_STRIP:
79*35238bceSAndroid Build Coastguard Worker         return primitiveCount + 1;
80*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_LINE_LOOP:
81*35238bceSAndroid Build Coastguard Worker         return (primitiveCount == 1) ? (2) : (primitiveCount);
82*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_LINES_ADJACENCY:
83*35238bceSAndroid Build Coastguard Worker         return primitiveCount * 4;
84*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_LINE_STRIP_ADJACENCY:
85*35238bceSAndroid Build Coastguard Worker         return primitiveCount + 3;
86*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_TRIANGLES_ADJACENCY:
87*35238bceSAndroid Build Coastguard Worker         return primitiveCount * 6;
88*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP_ADJACENCY:
89*35238bceSAndroid Build Coastguard Worker         return primitiveCount * 2 + 4;
90*35238bceSAndroid Build Coastguard Worker     default:
91*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
92*35238bceSAndroid Build Coastguard Worker         return 0;
93*35238bceSAndroid Build Coastguard Worker     }
94*35238bceSAndroid Build Coastguard Worker }
95*35238bceSAndroid Build Coastguard Worker 
addRangeElementsToSpec(gls::DrawTestSpec & spec)96*35238bceSAndroid Build Coastguard Worker static void addRangeElementsToSpec(gls::DrawTestSpec &spec)
97*35238bceSAndroid Build Coastguard Worker {
98*35238bceSAndroid Build Coastguard Worker     if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED_BASEVERTEX)
99*35238bceSAndroid Build Coastguard Worker     {
100*35238bceSAndroid Build Coastguard Worker         spec.indexMin = 0;
101*35238bceSAndroid Build Coastguard Worker         spec.indexMax = (int)getElementCount(spec.primitive, spec.primitiveCount);
102*35238bceSAndroid Build Coastguard Worker     }
103*35238bceSAndroid Build Coastguard Worker }
104*35238bceSAndroid Build Coastguard Worker 
addTestIterations(gls::DrawTest * test,gls::DrawTestSpec & spec,TestIterationType type)105*35238bceSAndroid Build Coastguard Worker static void addTestIterations(gls::DrawTest *test, gls::DrawTestSpec &spec, TestIterationType type)
106*35238bceSAndroid Build Coastguard Worker {
107*35238bceSAndroid Build Coastguard Worker     if (type == TYPE_DRAW_COUNT)
108*35238bceSAndroid Build Coastguard Worker     {
109*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount = 1;
110*35238bceSAndroid Build Coastguard Worker         addRangeElementsToSpec(spec);
111*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "draw count = 1");
112*35238bceSAndroid Build Coastguard Worker 
113*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount = 5;
114*35238bceSAndroid Build Coastguard Worker         addRangeElementsToSpec(spec);
115*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "draw count = 5");
116*35238bceSAndroid Build Coastguard Worker 
117*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount = 25;
118*35238bceSAndroid Build Coastguard Worker         addRangeElementsToSpec(spec);
119*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "draw count = 25");
120*35238bceSAndroid Build Coastguard Worker     }
121*35238bceSAndroid Build Coastguard Worker     else if (type == TYPE_INSTANCE_COUNT)
122*35238bceSAndroid Build Coastguard Worker     {
123*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = 1;
124*35238bceSAndroid Build Coastguard Worker         addRangeElementsToSpec(spec);
125*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "instance count = 1");
126*35238bceSAndroid Build Coastguard Worker 
127*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = 4;
128*35238bceSAndroid Build Coastguard Worker         addRangeElementsToSpec(spec);
129*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "instance count = 4");
130*35238bceSAndroid Build Coastguard Worker 
131*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = 11;
132*35238bceSAndroid Build Coastguard Worker         addRangeElementsToSpec(spec);
133*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "instance count = 11");
134*35238bceSAndroid Build Coastguard Worker     }
135*35238bceSAndroid Build Coastguard Worker     else
136*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
137*35238bceSAndroid Build Coastguard Worker }
138*35238bceSAndroid Build Coastguard Worker 
genBasicSpec(gls::DrawTestSpec & spec,glu::ContextType & contextType,gls::DrawTestSpec::DrawMethod method)139*35238bceSAndroid Build Coastguard Worker static void genBasicSpec(gls::DrawTestSpec &spec, glu::ContextType &contextType, gls::DrawTestSpec::DrawMethod method)
140*35238bceSAndroid Build Coastguard Worker {
141*35238bceSAndroid Build Coastguard Worker     spec.apiType            = glu::isContextTypeES(contextType) ? glu::ApiType::es(3, 1) : contextType.getAPI();
142*35238bceSAndroid Build Coastguard Worker     spec.primitive          = gls::DrawTestSpec::PRIMITIVE_TRIANGLES;
143*35238bceSAndroid Build Coastguard Worker     spec.primitiveCount     = 5;
144*35238bceSAndroid Build Coastguard Worker     spec.drawMethod         = method;
145*35238bceSAndroid Build Coastguard Worker     spec.indexType          = gls::DrawTestSpec::INDEXTYPE_LAST;
146*35238bceSAndroid Build Coastguard Worker     spec.indexPointerOffset = 0;
147*35238bceSAndroid Build Coastguard Worker     spec.indexStorage       = gls::DrawTestSpec::STORAGE_LAST;
148*35238bceSAndroid Build Coastguard Worker     spec.first              = 0;
149*35238bceSAndroid Build Coastguard Worker     spec.indexMin           = 0;
150*35238bceSAndroid Build Coastguard Worker     spec.indexMax           = 0;
151*35238bceSAndroid Build Coastguard Worker     spec.instanceCount      = 1;
152*35238bceSAndroid Build Coastguard Worker     spec.indirectOffset     = 0;
153*35238bceSAndroid Build Coastguard Worker 
154*35238bceSAndroid Build Coastguard Worker     spec.attribs.resize(2);
155*35238bceSAndroid Build Coastguard Worker 
156*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
157*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
158*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
159*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
160*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].componentCount      = 4;
161*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].offset              = 0;
162*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].stride              = 0;
163*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].normalize           = false;
164*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].instanceDivisor     = 0;
165*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].useDefaultAttribute = false;
166*35238bceSAndroid Build Coastguard Worker 
167*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
168*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
169*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
170*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
171*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].componentCount      = 2;
172*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].offset              = 0;
173*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].stride              = 0;
174*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].normalize           = false;
175*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].instanceDivisor     = 0;
176*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].useDefaultAttribute = false;
177*35238bceSAndroid Build Coastguard Worker 
178*35238bceSAndroid Build Coastguard Worker     addRangeElementsToSpec(spec);
179*35238bceSAndroid Build Coastguard Worker }
180*35238bceSAndroid Build Coastguard Worker 
181*35238bceSAndroid Build Coastguard Worker class VertexIDCase : public TestCase
182*35238bceSAndroid Build Coastguard Worker {
183*35238bceSAndroid Build Coastguard Worker public:
184*35238bceSAndroid Build Coastguard Worker     VertexIDCase(Context &context, gls::DrawTestSpec::DrawMethod drawMethod);
185*35238bceSAndroid Build Coastguard Worker     ~VertexIDCase(void);
186*35238bceSAndroid Build Coastguard Worker 
187*35238bceSAndroid Build Coastguard Worker     void init(void);
188*35238bceSAndroid Build Coastguard Worker     void deinit(void);
189*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
190*35238bceSAndroid Build Coastguard Worker 
191*35238bceSAndroid Build Coastguard Worker     void draw(GLenum mode, GLsizei count, GLenum type, GLvoid *indices, GLint baseVertex);
192*35238bceSAndroid Build Coastguard Worker     void verifyImage(const tcu::Surface &image);
193*35238bceSAndroid Build Coastguard Worker 
194*35238bceSAndroid Build Coastguard Worker private:
195*35238bceSAndroid Build Coastguard Worker     const glw::Functions &m_gl;
196*35238bceSAndroid Build Coastguard Worker     glu::ShaderProgram *m_program;
197*35238bceSAndroid Build Coastguard Worker     GLuint m_vao;
198*35238bceSAndroid Build Coastguard Worker     GLuint m_coordinatesBuffer;
199*35238bceSAndroid Build Coastguard Worker     GLuint m_elementsBuffer;
200*35238bceSAndroid Build Coastguard Worker     int m_iterNdx;
201*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
202*35238bceSAndroid Build Coastguard Worker 
203*35238bceSAndroid Build Coastguard Worker     enum
204*35238bceSAndroid Build Coastguard Worker     {
205*35238bceSAndroid Build Coastguard Worker         VIEWPORT_WIDTH  = 64,
206*35238bceSAndroid Build Coastguard Worker         VIEWPORT_HEIGHT = 64
207*35238bceSAndroid Build Coastguard Worker     };
208*35238bceSAndroid Build Coastguard Worker 
209*35238bceSAndroid Build Coastguard Worker     enum
210*35238bceSAndroid Build Coastguard Worker     {
211*35238bceSAndroid Build Coastguard Worker         MAX_VERTICES = 2 * 3 //!< 2 triangles, totals 6 vertices
212*35238bceSAndroid Build Coastguard Worker     };
213*35238bceSAndroid Build Coastguard Worker };
214*35238bceSAndroid Build Coastguard Worker 
VertexIDCase(Context & context,gls::DrawTestSpec::DrawMethod drawMethod)215*35238bceSAndroid Build Coastguard Worker VertexIDCase::VertexIDCase(Context &context, gls::DrawTestSpec::DrawMethod drawMethod)
216*35238bceSAndroid Build Coastguard Worker     : TestCase(context, "vertex_id", "gl_VertexID Test")
217*35238bceSAndroid Build Coastguard Worker     , m_gl(m_context.getRenderContext().getFunctions())
218*35238bceSAndroid Build Coastguard Worker     , m_program(DE_NULL)
219*35238bceSAndroid Build Coastguard Worker     , m_vao(0)
220*35238bceSAndroid Build Coastguard Worker     , m_coordinatesBuffer(0)
221*35238bceSAndroid Build Coastguard Worker     , m_elementsBuffer(0)
222*35238bceSAndroid Build Coastguard Worker     , m_iterNdx(0)
223*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
224*35238bceSAndroid Build Coastguard Worker {
225*35238bceSAndroid Build Coastguard Worker }
226*35238bceSAndroid Build Coastguard Worker 
~VertexIDCase(void)227*35238bceSAndroid Build Coastguard Worker VertexIDCase::~VertexIDCase(void)
228*35238bceSAndroid Build Coastguard Worker {
229*35238bceSAndroid Build Coastguard Worker     VertexIDCase::deinit();
230*35238bceSAndroid Build Coastguard Worker }
231*35238bceSAndroid Build Coastguard Worker 
init(void)232*35238bceSAndroid Build Coastguard Worker void VertexIDCase::init(void)
233*35238bceSAndroid Build Coastguard Worker {
234*35238bceSAndroid Build Coastguard Worker     auto ctxType = m_context.getRenderContext().getType();
235*35238bceSAndroid Build Coastguard Worker     if (m_method == deqp::gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_BASEVERTEX ||
236*35238bceSAndroid Build Coastguard Worker         m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED_BASEVERTEX ||
237*35238bceSAndroid Build Coastguard Worker         m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED_BASEVERTEX)
238*35238bceSAndroid Build Coastguard Worker     {
239*35238bceSAndroid Build Coastguard Worker         const bool supportsES32orGL45 =
240*35238bceSAndroid Build Coastguard Worker             contextSupports(ctxType, glu::ApiType::es(3, 2)) || contextSupports(ctxType, glu::ApiType::core(4, 5));
241*35238bceSAndroid Build Coastguard Worker         TCU_CHECK_AND_THROW(NotSupportedError,
242*35238bceSAndroid Build Coastguard Worker                             supportsES32orGL45 ||
243*35238bceSAndroid Build Coastguard Worker                                 m_context.getContextInfo().isExtensionSupported("GL_EXT_draw_elements_base_vertex"),
244*35238bceSAndroid Build Coastguard Worker                             "GL_EXT_draw_elements_base_vertex is not supported.");
245*35238bceSAndroid Build Coastguard Worker     }
246*35238bceSAndroid Build Coastguard Worker 
247*35238bceSAndroid Build Coastguard Worker     m_testCtx.getLog() << TestLog::Message
248*35238bceSAndroid Build Coastguard Worker                        << "gl_VertexID should be the index of the vertex that is being passed to the shader. i.e. "
249*35238bceSAndroid Build Coastguard Worker                           "indices[i] + basevertex"
250*35238bceSAndroid Build Coastguard Worker                        << TestLog::EndMessage;
251*35238bceSAndroid Build Coastguard Worker 
252*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_program);
253*35238bceSAndroid Build Coastguard Worker     m_program = new glu::ShaderProgram(m_context.getRenderContext(),
254*35238bceSAndroid Build Coastguard Worker                                        glu::makeVtxFragSources("#version 310 es\n"
255*35238bceSAndroid Build Coastguard Worker                                                                "in highp vec4 a_position;\n"
256*35238bceSAndroid Build Coastguard Worker                                                                "out mediump vec4 v_color;\n"
257*35238bceSAndroid Build Coastguard Worker                                                                "uniform highp vec4 u_colors[8];\n"
258*35238bceSAndroid Build Coastguard Worker                                                                "void main (void)\n"
259*35238bceSAndroid Build Coastguard Worker                                                                "{\n"
260*35238bceSAndroid Build Coastguard Worker                                                                "    gl_Position = a_position;\n"
261*35238bceSAndroid Build Coastguard Worker                                                                "    v_color = u_colors[gl_VertexID];\n"
262*35238bceSAndroid Build Coastguard Worker                                                                "}\n",
263*35238bceSAndroid Build Coastguard Worker 
264*35238bceSAndroid Build Coastguard Worker                                                                "#version 310 es\n"
265*35238bceSAndroid Build Coastguard Worker                                                                "in mediump vec4 v_color;\n"
266*35238bceSAndroid Build Coastguard Worker                                                                "layout(location = 0) out mediump vec4 o_color;\n"
267*35238bceSAndroid Build Coastguard Worker                                                                "void main (void)\n"
268*35238bceSAndroid Build Coastguard Worker                                                                "{\n"
269*35238bceSAndroid Build Coastguard Worker                                                                "    o_color = v_color;\n"
270*35238bceSAndroid Build Coastguard Worker                                                                "}\n"));
271*35238bceSAndroid Build Coastguard Worker 
272*35238bceSAndroid Build Coastguard Worker     m_testCtx.getLog() << *m_program;
273*35238bceSAndroid Build Coastguard Worker 
274*35238bceSAndroid Build Coastguard Worker     if (!m_program->isOk())
275*35238bceSAndroid Build Coastguard Worker     {
276*35238bceSAndroid Build Coastguard Worker         delete m_program;
277*35238bceSAndroid Build Coastguard Worker         m_program = DE_NULL;
278*35238bceSAndroid Build Coastguard Worker         TCU_FAIL("Failed to compile shader program");
279*35238bceSAndroid Build Coastguard Worker     }
280*35238bceSAndroid Build Coastguard Worker 
281*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, useProgram(m_program->getProgram()));
282*35238bceSAndroid Build Coastguard Worker 
283*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, genBuffers(1, &m_coordinatesBuffer));
284*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, genBuffers(1, &m_elementsBuffer));
285*35238bceSAndroid Build Coastguard Worker 
286*35238bceSAndroid Build Coastguard Worker     if (!glu::isContextTypeES(ctxType))
287*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, genVertexArrays(1, &m_vao));
288*35238bceSAndroid Build Coastguard Worker }
289*35238bceSAndroid Build Coastguard Worker 
deinit(void)290*35238bceSAndroid Build Coastguard Worker void VertexIDCase::deinit(void)
291*35238bceSAndroid Build Coastguard Worker {
292*35238bceSAndroid Build Coastguard Worker     delete m_program;
293*35238bceSAndroid Build Coastguard Worker     m_program = DE_NULL;
294*35238bceSAndroid Build Coastguard Worker 
295*35238bceSAndroid Build Coastguard Worker     if (m_elementsBuffer)
296*35238bceSAndroid Build Coastguard Worker     {
297*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, deleteBuffers(1, &m_elementsBuffer));
298*35238bceSAndroid Build Coastguard Worker         m_elementsBuffer = 0;
299*35238bceSAndroid Build Coastguard Worker     }
300*35238bceSAndroid Build Coastguard Worker 
301*35238bceSAndroid Build Coastguard Worker     if (m_coordinatesBuffer)
302*35238bceSAndroid Build Coastguard Worker     {
303*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, deleteBuffers(1, &m_coordinatesBuffer));
304*35238bceSAndroid Build Coastguard Worker         m_coordinatesBuffer = 0;
305*35238bceSAndroid Build Coastguard Worker     }
306*35238bceSAndroid Build Coastguard Worker 
307*35238bceSAndroid Build Coastguard Worker     if (m_vao)
308*35238bceSAndroid Build Coastguard Worker     {
309*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, deleteVertexArrays(1, &m_vao));
310*35238bceSAndroid Build Coastguard Worker         m_vao = 0;
311*35238bceSAndroid Build Coastguard Worker     }
312*35238bceSAndroid Build Coastguard Worker }
313*35238bceSAndroid Build Coastguard Worker 
draw(GLenum mode,GLsizei count,GLenum type,GLvoid * indices,GLint baseVertex)314*35238bceSAndroid Build Coastguard Worker void VertexIDCase::draw(GLenum mode, GLsizei count, GLenum type, GLvoid *indices, GLint baseVertex)
315*35238bceSAndroid Build Coastguard Worker {
316*35238bceSAndroid Build Coastguard Worker     switch (m_method)
317*35238bceSAndroid Build Coastguard Worker     {
318*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_BASEVERTEX:
319*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, drawElementsBaseVertex(mode, count, type, indices, baseVertex));
320*35238bceSAndroid Build Coastguard Worker         break;
321*35238bceSAndroid Build Coastguard Worker 
322*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED_BASEVERTEX:
323*35238bceSAndroid Build Coastguard Worker     {
324*35238bceSAndroid Build Coastguard Worker         GLint maxElementsVertices = 0;
325*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, getIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxElementsVertices));
326*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl,
327*35238bceSAndroid Build Coastguard Worker                            drawRangeElementsBaseVertex(mode, 0, maxElementsVertices, count, type, indices, baseVertex));
328*35238bceSAndroid Build Coastguard Worker         break;
329*35238bceSAndroid Build Coastguard Worker     }
330*35238bceSAndroid Build Coastguard Worker 
331*35238bceSAndroid Build Coastguard Worker     case gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED_BASEVERTEX:
332*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, drawElementsInstancedBaseVertex(mode, count, type, indices, 1, baseVertex));
333*35238bceSAndroid Build Coastguard Worker         break;
334*35238bceSAndroid Build Coastguard Worker 
335*35238bceSAndroid Build Coastguard Worker     default:
336*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Draw method not supported");
337*35238bceSAndroid Build Coastguard Worker     }
338*35238bceSAndroid Build Coastguard Worker }
339*35238bceSAndroid Build Coastguard Worker 
verifyImage(const tcu::Surface & image)340*35238bceSAndroid Build Coastguard Worker void VertexIDCase::verifyImage(const tcu::Surface &image)
341*35238bceSAndroid Build Coastguard Worker {
342*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
343*35238bceSAndroid Build Coastguard Worker     bool isOk         = true;
344*35238bceSAndroid Build Coastguard Worker 
345*35238bceSAndroid Build Coastguard Worker     const int colorThreshold = 0; // expect perfect match
346*35238bceSAndroid Build Coastguard Worker     tcu::Surface error(image.getWidth(), image.getHeight());
347*35238bceSAndroid Build Coastguard Worker 
348*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < image.getHeight(); y++)
349*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < image.getWidth(); x++)
350*35238bceSAndroid Build Coastguard Worker         {
351*35238bceSAndroid Build Coastguard Worker             const tcu::RGBA pixel = image.getPixel(x, y);
352*35238bceSAndroid Build Coastguard Worker             bool pixelOk          = true;
353*35238bceSAndroid Build Coastguard Worker 
354*35238bceSAndroid Build Coastguard Worker             // Ignore pixels not drawn with basevertex
355*35238bceSAndroid Build Coastguard Worker             if ((x < image.getWidth() * 1 / 4) || (x > image.getWidth() * 3 / 4) || (y < image.getHeight() * 1 / 4) ||
356*35238bceSAndroid Build Coastguard Worker                 (y > image.getHeight() * 3 / 4))
357*35238bceSAndroid Build Coastguard Worker                 continue;
358*35238bceSAndroid Build Coastguard Worker 
359*35238bceSAndroid Build Coastguard Worker             // Any pixel with !(B ~= 255) is faulty
360*35238bceSAndroid Build Coastguard Worker             if (de::abs(pixel.getBlue() - 255) > colorThreshold)
361*35238bceSAndroid Build Coastguard Worker                 pixelOk = false;
362*35238bceSAndroid Build Coastguard Worker 
363*35238bceSAndroid Build Coastguard Worker             error.setPixel(x, y, (pixelOk) ? (tcu::RGBA(0, 255, 0, 255)) : (tcu::RGBA(255, 0, 0, 255)));
364*35238bceSAndroid Build Coastguard Worker             isOk = isOk && pixelOk;
365*35238bceSAndroid Build Coastguard Worker         }
366*35238bceSAndroid Build Coastguard Worker 
367*35238bceSAndroid Build Coastguard Worker     if (!isOk)
368*35238bceSAndroid Build Coastguard Worker     {
369*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Image verification failed." << TestLog::EndMessage;
370*35238bceSAndroid Build Coastguard Worker         log << TestLog::ImageSet("Verification result", "Result of rendering")
371*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("Result", "Result", image) << TestLog::Image("Error Mask", "Error mask", error)
372*35238bceSAndroid Build Coastguard Worker             << TestLog::EndImageSet;
373*35238bceSAndroid Build Coastguard Worker     }
374*35238bceSAndroid Build Coastguard Worker     else
375*35238bceSAndroid Build Coastguard Worker     {
376*35238bceSAndroid Build Coastguard Worker         log << TestLog::ImageSet("Verification result", "Result of rendering")
377*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("Result", "Result", image) << TestLog::EndImageSet;
378*35238bceSAndroid Build Coastguard Worker     }
379*35238bceSAndroid Build Coastguard Worker 
380*35238bceSAndroid Build Coastguard Worker     if (isOk)
381*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
382*35238bceSAndroid Build Coastguard Worker     else
383*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Result image invalid");
384*35238bceSAndroid Build Coastguard Worker }
385*35238bceSAndroid Build Coastguard Worker 
iterate(void)386*35238bceSAndroid Build Coastguard Worker VertexIDCase::IterateResult VertexIDCase::iterate(void)
387*35238bceSAndroid Build Coastguard Worker {
388*35238bceSAndroid Build Coastguard Worker     const GLuint drawCount     = 6;
389*35238bceSAndroid Build Coastguard Worker     const GLuint baseVertex    = 4;
390*35238bceSAndroid Build Coastguard Worker     const GLuint coordLocation = m_gl.getAttribLocation(m_program->getProgram(), "a_position");
391*35238bceSAndroid Build Coastguard Worker     const GLuint colorLocation = m_gl.getUniformLocation(m_program->getProgram(), "u_colors[0]");
392*35238bceSAndroid Build Coastguard Worker 
393*35238bceSAndroid Build Coastguard Worker     tcu::Surface surface(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
394*35238bceSAndroid Build Coastguard Worker 
395*35238bceSAndroid Build Coastguard Worker     const GLfloat coords[] = {
396*35238bceSAndroid Build Coastguard Worker         // full viewport quad
397*35238bceSAndroid Build Coastguard Worker         -1.0f,
398*35238bceSAndroid Build Coastguard Worker         -1.0f,
399*35238bceSAndroid Build Coastguard Worker         +1.0f,
400*35238bceSAndroid Build Coastguard Worker         -1.0f,
401*35238bceSAndroid Build Coastguard Worker         +1.0f,
402*35238bceSAndroid Build Coastguard Worker         +1.0f,
403*35238bceSAndroid Build Coastguard Worker         -1.0f,
404*35238bceSAndroid Build Coastguard Worker         +1.0f,
405*35238bceSAndroid Build Coastguard Worker 
406*35238bceSAndroid Build Coastguard Worker         // half viewport quad centred
407*35238bceSAndroid Build Coastguard Worker         -0.5f,
408*35238bceSAndroid Build Coastguard Worker         -0.5f,
409*35238bceSAndroid Build Coastguard Worker         +0.5f,
410*35238bceSAndroid Build Coastguard Worker         -0.5f,
411*35238bceSAndroid Build Coastguard Worker         +0.5f,
412*35238bceSAndroid Build Coastguard Worker         +0.5f,
413*35238bceSAndroid Build Coastguard Worker         -0.5f,
414*35238bceSAndroid Build Coastguard Worker         +0.5f,
415*35238bceSAndroid Build Coastguard Worker     };
416*35238bceSAndroid Build Coastguard Worker 
417*35238bceSAndroid Build Coastguard Worker     const GLushort indices[] = {
418*35238bceSAndroid Build Coastguard Worker         0, 1, 2, 2, 3, 0,
419*35238bceSAndroid Build Coastguard Worker     };
420*35238bceSAndroid Build Coastguard Worker 
421*35238bceSAndroid Build Coastguard Worker     const GLfloat colors[] = {
422*35238bceSAndroid Build Coastguard Worker         0.0f, 0.0f, 0.0f, 1.0f, 0.5f, 1.0f, 0.5f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
423*35238bceSAndroid Build Coastguard Worker 
424*35238bceSAndroid Build Coastguard Worker         0.0f, 0.0f, 1.0f, 1.0f, // blue
425*35238bceSAndroid Build Coastguard Worker         0.0f, 0.0f, 1.0f, 1.0f, // blue
426*35238bceSAndroid Build Coastguard Worker         0.0f, 0.0f, 1.0f, 1.0f, // blue
427*35238bceSAndroid Build Coastguard Worker         0.0f, 0.0f, 1.0f, 1.0f, // blue
428*35238bceSAndroid Build Coastguard Worker     };
429*35238bceSAndroid Build Coastguard Worker 
430*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, viewport(0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT));
431*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clearColor(1.0f, 1.0f, 1.0f, 1.0f)); // white
432*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, clear(GL_COLOR_BUFFER_BIT));
433*35238bceSAndroid Build Coastguard Worker 
434*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, uniform4fv(colorLocation, DE_LENGTH_OF_ARRAY(colors), &colors[0]));
435*35238bceSAndroid Build Coastguard Worker 
436*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bindBuffer(GL_ARRAY_BUFFER, m_coordinatesBuffer));
437*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, bufferData(GL_ARRAY_BUFFER, (GLsizeiptr)sizeof(coords), coords, GL_STATIC_DRAW));
438*35238bceSAndroid Build Coastguard Worker 
439*35238bceSAndroid Build Coastguard Worker     if (m_vao)
440*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, bindVertexArray(m_vao));
441*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, enableVertexAttribArray(coordLocation));
442*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_GLW_CALL(m_gl, vertexAttribPointer(coordLocation, 2, GL_FLOAT, GL_FALSE, 0, DE_NULL));
443*35238bceSAndroid Build Coastguard Worker 
444*35238bceSAndroid Build Coastguard Worker     if (m_iterNdx == 0)
445*35238bceSAndroid Build Coastguard Worker     {
446*35238bceSAndroid Build Coastguard Worker         tcu::ScopedLogSection logSection(m_testCtx.getLog(), "Iter0", "Indices in client-side array");
447*35238bceSAndroid Build Coastguard Worker         draw(GL_TRIANGLES, drawCount, GL_UNSIGNED_SHORT, (GLvoid *)indices, baseVertex);
448*35238bceSAndroid Build Coastguard Worker     }
449*35238bceSAndroid Build Coastguard Worker 
450*35238bceSAndroid Build Coastguard Worker     if (m_iterNdx == 1)
451*35238bceSAndroid Build Coastguard Worker     {
452*35238bceSAndroid Build Coastguard Worker         tcu::ScopedLogSection logSection(m_testCtx.getLog(), "Iter1", "Indices in element array buffer");
453*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(m_gl, bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementsBuffer));
454*35238bceSAndroid Build Coastguard Worker         GLU_CHECK_GLW_CALL(
455*35238bceSAndroid Build Coastguard Worker             m_gl, bufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)sizeof(indices), &indices[0], GL_STATIC_DRAW));
456*35238bceSAndroid Build Coastguard Worker         draw(GL_TRIANGLES, drawCount, GL_UNSIGNED_SHORT, DE_NULL, baseVertex);
457*35238bceSAndroid Build Coastguard Worker     }
458*35238bceSAndroid Build Coastguard Worker 
459*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_context.getRenderContext(), 0, 0, surface.getAccess());
460*35238bceSAndroid Build Coastguard Worker     verifyImage(surface);
461*35238bceSAndroid Build Coastguard Worker 
462*35238bceSAndroid Build Coastguard Worker     m_iterNdx += 1;
463*35238bceSAndroid Build Coastguard Worker 
464*35238bceSAndroid Build Coastguard Worker     return (m_iterNdx < 2) ? CONTINUE : STOP;
465*35238bceSAndroid Build Coastguard Worker }
466*35238bceSAndroid Build Coastguard Worker 
467*35238bceSAndroid Build Coastguard Worker class BuiltInVariableGroup : public TestCaseGroup
468*35238bceSAndroid Build Coastguard Worker {
469*35238bceSAndroid Build Coastguard Worker public:
470*35238bceSAndroid Build Coastguard Worker     BuiltInVariableGroup(Context &context, const char *name, const char *descr,
471*35238bceSAndroid Build Coastguard Worker                          gls::DrawTestSpec::DrawMethod drawMethod);
472*35238bceSAndroid Build Coastguard Worker     ~BuiltInVariableGroup(void);
473*35238bceSAndroid Build Coastguard Worker 
474*35238bceSAndroid Build Coastguard Worker     void init(void);
475*35238bceSAndroid Build Coastguard Worker 
476*35238bceSAndroid Build Coastguard Worker private:
477*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
478*35238bceSAndroid Build Coastguard Worker };
479*35238bceSAndroid Build Coastguard Worker 
BuiltInVariableGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)480*35238bceSAndroid Build Coastguard Worker BuiltInVariableGroup::BuiltInVariableGroup(Context &context, const char *name, const char *descr,
481*35238bceSAndroid Build Coastguard Worker                                            gls::DrawTestSpec::DrawMethod drawMethod)
482*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
483*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
484*35238bceSAndroid Build Coastguard Worker {
485*35238bceSAndroid Build Coastguard Worker }
486*35238bceSAndroid Build Coastguard Worker 
~BuiltInVariableGroup(void)487*35238bceSAndroid Build Coastguard Worker BuiltInVariableGroup::~BuiltInVariableGroup(void)
488*35238bceSAndroid Build Coastguard Worker {
489*35238bceSAndroid Build Coastguard Worker }
490*35238bceSAndroid Build Coastguard Worker 
init(void)491*35238bceSAndroid Build Coastguard Worker void BuiltInVariableGroup::init(void)
492*35238bceSAndroid Build Coastguard Worker {
493*35238bceSAndroid Build Coastguard Worker     addChild(new VertexIDCase(m_context, m_method));
494*35238bceSAndroid Build Coastguard Worker }
495*35238bceSAndroid Build Coastguard Worker 
496*35238bceSAndroid Build Coastguard Worker class IndexGroup : public TestCaseGroup
497*35238bceSAndroid Build Coastguard Worker {
498*35238bceSAndroid Build Coastguard Worker public:
499*35238bceSAndroid Build Coastguard Worker     IndexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
500*35238bceSAndroid Build Coastguard Worker     ~IndexGroup(void);
501*35238bceSAndroid Build Coastguard Worker 
502*35238bceSAndroid Build Coastguard Worker     void init(void);
503*35238bceSAndroid Build Coastguard Worker 
504*35238bceSAndroid Build Coastguard Worker private:
505*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
506*35238bceSAndroid Build Coastguard Worker };
507*35238bceSAndroid Build Coastguard Worker 
IndexGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)508*35238bceSAndroid Build Coastguard Worker IndexGroup::IndexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod)
509*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
510*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
511*35238bceSAndroid Build Coastguard Worker {
512*35238bceSAndroid Build Coastguard Worker }
513*35238bceSAndroid Build Coastguard Worker 
~IndexGroup(void)514*35238bceSAndroid Build Coastguard Worker IndexGroup::~IndexGroup(void)
515*35238bceSAndroid Build Coastguard Worker {
516*35238bceSAndroid Build Coastguard Worker }
517*35238bceSAndroid Build Coastguard Worker 
init(void)518*35238bceSAndroid Build Coastguard Worker void IndexGroup::init(void)
519*35238bceSAndroid Build Coastguard Worker {
520*35238bceSAndroid Build Coastguard Worker     struct IndexTest
521*35238bceSAndroid Build Coastguard Worker     {
522*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::IndexType type;
523*35238bceSAndroid Build Coastguard Worker         int offsets[3];
524*35238bceSAndroid Build Coastguard Worker     };
525*35238bceSAndroid Build Coastguard Worker 
526*35238bceSAndroid Build Coastguard Worker     const IndexTest tests[] = {
527*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::INDEXTYPE_BYTE, {0, 1, -1}},
528*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::INDEXTYPE_SHORT, {0, 2, -1}},
529*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::INDEXTYPE_INT, {0, 4, -1}},
530*35238bceSAndroid Build Coastguard Worker     };
531*35238bceSAndroid Build Coastguard Worker 
532*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec spec;
533*35238bceSAndroid Build Coastguard Worker     glu::ContextType contextType = m_context.getRenderContext().getType();
534*35238bceSAndroid Build Coastguard Worker     genBasicSpec(spec, contextType, m_method);
535*35238bceSAndroid Build Coastguard Worker 
536*35238bceSAndroid Build Coastguard Worker     spec.indexStorage = gls::DrawTestSpec::STORAGE_BUFFER;
537*35238bceSAndroid Build Coastguard Worker 
538*35238bceSAndroid Build Coastguard Worker     for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx)
539*35238bceSAndroid Build Coastguard Worker     {
540*35238bceSAndroid Build Coastguard Worker         const IndexTest &indexTest = tests[testNdx];
541*35238bceSAndroid Build Coastguard Worker 
542*35238bceSAndroid Build Coastguard Worker         const std::string name = std::string("index_") + gls::DrawTestSpec::indexTypeToString(indexTest.type);
543*35238bceSAndroid Build Coastguard Worker         const std::string desc = std::string("index ") + gls::DrawTestSpec::indexTypeToString(indexTest.type);
544*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test    = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str());
545*35238bceSAndroid Build Coastguard Worker 
546*35238bceSAndroid Build Coastguard Worker         spec.indexType = indexTest.type;
547*35238bceSAndroid Build Coastguard Worker 
548*35238bceSAndroid Build Coastguard Worker         for (int iterationNdx = 0;
549*35238bceSAndroid Build Coastguard Worker              iterationNdx < DE_LENGTH_OF_ARRAY(indexTest.offsets) && indexTest.offsets[iterationNdx] != -1;
550*35238bceSAndroid Build Coastguard Worker              ++iterationNdx)
551*35238bceSAndroid Build Coastguard Worker         {
552*35238bceSAndroid Build Coastguard Worker             const std::string iterationDesc =
553*35238bceSAndroid Build Coastguard Worker                 std::string("first vertex ") +
554*35238bceSAndroid Build Coastguard Worker                 de::toString(indexTest.offsets[iterationNdx] / gls::DrawTestSpec::indexTypeSize(indexTest.type));
555*35238bceSAndroid Build Coastguard Worker             spec.indexPointerOffset = indexTest.offsets[iterationNdx];
556*35238bceSAndroid Build Coastguard Worker             test->addIteration(spec, iterationDesc.c_str());
557*35238bceSAndroid Build Coastguard Worker         }
558*35238bceSAndroid Build Coastguard Worker 
559*35238bceSAndroid Build Coastguard Worker         addChild(test);
560*35238bceSAndroid Build Coastguard Worker     }
561*35238bceSAndroid Build Coastguard Worker }
562*35238bceSAndroid Build Coastguard Worker 
563*35238bceSAndroid Build Coastguard Worker class BaseVertexGroup : public TestCaseGroup
564*35238bceSAndroid Build Coastguard Worker {
565*35238bceSAndroid Build Coastguard Worker public:
566*35238bceSAndroid Build Coastguard Worker     BaseVertexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
567*35238bceSAndroid Build Coastguard Worker     ~BaseVertexGroup(void);
568*35238bceSAndroid Build Coastguard Worker 
569*35238bceSAndroid Build Coastguard Worker     void init(void);
570*35238bceSAndroid Build Coastguard Worker 
571*35238bceSAndroid Build Coastguard Worker private:
572*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
573*35238bceSAndroid Build Coastguard Worker };
574*35238bceSAndroid Build Coastguard Worker 
BaseVertexGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)575*35238bceSAndroid Build Coastguard Worker BaseVertexGroup::BaseVertexGroup(Context &context, const char *name, const char *descr,
576*35238bceSAndroid Build Coastguard Worker                                  gls::DrawTestSpec::DrawMethod drawMethod)
577*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
578*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
579*35238bceSAndroid Build Coastguard Worker {
580*35238bceSAndroid Build Coastguard Worker }
581*35238bceSAndroid Build Coastguard Worker 
~BaseVertexGroup(void)582*35238bceSAndroid Build Coastguard Worker BaseVertexGroup::~BaseVertexGroup(void)
583*35238bceSAndroid Build Coastguard Worker {
584*35238bceSAndroid Build Coastguard Worker }
585*35238bceSAndroid Build Coastguard Worker 
init(void)586*35238bceSAndroid Build Coastguard Worker void BaseVertexGroup::init(void)
587*35238bceSAndroid Build Coastguard Worker {
588*35238bceSAndroid Build Coastguard Worker     struct IndexTest
589*35238bceSAndroid Build Coastguard Worker     {
590*35238bceSAndroid Build Coastguard Worker         bool positiveBase;
591*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::IndexType type;
592*35238bceSAndroid Build Coastguard Worker         int baseVertex[2];
593*35238bceSAndroid Build Coastguard Worker     };
594*35238bceSAndroid Build Coastguard Worker 
595*35238bceSAndroid Build Coastguard Worker     const IndexTest tests[] = {
596*35238bceSAndroid Build Coastguard Worker         {true, gls::DrawTestSpec::INDEXTYPE_BYTE, {1, 2}},     {true, gls::DrawTestSpec::INDEXTYPE_SHORT, {1, 2}},
597*35238bceSAndroid Build Coastguard Worker         {true, gls::DrawTestSpec::INDEXTYPE_INT, {1, 2}},      {false, gls::DrawTestSpec::INDEXTYPE_BYTE, {-1, -2}},
598*35238bceSAndroid Build Coastguard Worker         {false, gls::DrawTestSpec::INDEXTYPE_SHORT, {-1, -2}}, {false, gls::DrawTestSpec::INDEXTYPE_INT, {-1, -2}},
599*35238bceSAndroid Build Coastguard Worker     };
600*35238bceSAndroid Build Coastguard Worker 
601*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec spec;
602*35238bceSAndroid Build Coastguard Worker     glu::ContextType contextType = m_context.getRenderContext().getType();
603*35238bceSAndroid Build Coastguard Worker     genBasicSpec(spec, contextType, m_method);
604*35238bceSAndroid Build Coastguard Worker 
605*35238bceSAndroid Build Coastguard Worker     spec.indexStorage = gls::DrawTestSpec::STORAGE_BUFFER;
606*35238bceSAndroid Build Coastguard Worker 
607*35238bceSAndroid Build Coastguard Worker     for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx)
608*35238bceSAndroid Build Coastguard Worker     {
609*35238bceSAndroid Build Coastguard Worker         const IndexTest &indexTest = tests[testNdx];
610*35238bceSAndroid Build Coastguard Worker 
611*35238bceSAndroid Build Coastguard Worker         const std::string name = std::string("index_") + (indexTest.positiveBase ? "" : "neg_") +
612*35238bceSAndroid Build Coastguard Worker                                  gls::DrawTestSpec::indexTypeToString(indexTest.type);
613*35238bceSAndroid Build Coastguard Worker         const std::string desc = std::string("index ") + gls::DrawTestSpec::indexTypeToString(indexTest.type);
614*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test    = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str());
615*35238bceSAndroid Build Coastguard Worker 
616*35238bceSAndroid Build Coastguard Worker         spec.indexType = indexTest.type;
617*35238bceSAndroid Build Coastguard Worker 
618*35238bceSAndroid Build Coastguard Worker         for (int iterationNdx = 0; iterationNdx < DE_LENGTH_OF_ARRAY(indexTest.baseVertex); ++iterationNdx)
619*35238bceSAndroid Build Coastguard Worker         {
620*35238bceSAndroid Build Coastguard Worker             const std::string iterationDesc =
621*35238bceSAndroid Build Coastguard Worker                 std::string("base vertex ") + de::toString(indexTest.baseVertex[iterationNdx]);
622*35238bceSAndroid Build Coastguard Worker             spec.baseVertex = indexTest.baseVertex[iterationNdx];
623*35238bceSAndroid Build Coastguard Worker             // spec.indexMin + spec.baseVertex can not be a negative value
624*35238bceSAndroid Build Coastguard Worker             if (spec.indexMin + spec.baseVertex < 0)
625*35238bceSAndroid Build Coastguard Worker             {
626*35238bceSAndroid Build Coastguard Worker                 spec.indexMax -= (spec.indexMin + spec.baseVertex);
627*35238bceSAndroid Build Coastguard Worker                 spec.indexMin -= (spec.indexMin + spec.baseVertex);
628*35238bceSAndroid Build Coastguard Worker             }
629*35238bceSAndroid Build Coastguard Worker             test->addIteration(spec, iterationDesc.c_str());
630*35238bceSAndroid Build Coastguard Worker         }
631*35238bceSAndroid Build Coastguard Worker 
632*35238bceSAndroid Build Coastguard Worker         addChild(test);
633*35238bceSAndroid Build Coastguard Worker     }
634*35238bceSAndroid Build Coastguard Worker }
635*35238bceSAndroid Build Coastguard Worker 
636*35238bceSAndroid Build Coastguard Worker class AttributeGroup : public TestCaseGroup
637*35238bceSAndroid Build Coastguard Worker {
638*35238bceSAndroid Build Coastguard Worker public:
639*35238bceSAndroid Build Coastguard Worker     AttributeGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod,
640*35238bceSAndroid Build Coastguard Worker                    gls::DrawTestSpec::Primitive primitive, gls::DrawTestSpec::IndexType indexType,
641*35238bceSAndroid Build Coastguard Worker                    gls::DrawTestSpec::Storage indexStorage);
642*35238bceSAndroid Build Coastguard Worker     ~AttributeGroup(void);
643*35238bceSAndroid Build Coastguard Worker 
644*35238bceSAndroid Build Coastguard Worker     void init(void);
645*35238bceSAndroid Build Coastguard Worker 
646*35238bceSAndroid Build Coastguard Worker private:
647*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
648*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::Primitive m_primitive;
649*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::IndexType m_indexType;
650*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::Storage m_indexStorage;
651*35238bceSAndroid Build Coastguard Worker };
652*35238bceSAndroid Build Coastguard Worker 
AttributeGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod,gls::DrawTestSpec::Primitive primitive,gls::DrawTestSpec::IndexType indexType,gls::DrawTestSpec::Storage indexStorage)653*35238bceSAndroid Build Coastguard Worker AttributeGroup::AttributeGroup(Context &context, const char *name, const char *descr,
654*35238bceSAndroid Build Coastguard Worker                                gls::DrawTestSpec::DrawMethod drawMethod, gls::DrawTestSpec::Primitive primitive,
655*35238bceSAndroid Build Coastguard Worker                                gls::DrawTestSpec::IndexType indexType, gls::DrawTestSpec::Storage indexStorage)
656*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
657*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
658*35238bceSAndroid Build Coastguard Worker     , m_primitive(primitive)
659*35238bceSAndroid Build Coastguard Worker     , m_indexType(indexType)
660*35238bceSAndroid Build Coastguard Worker     , m_indexStorage(indexStorage)
661*35238bceSAndroid Build Coastguard Worker {
662*35238bceSAndroid Build Coastguard Worker }
663*35238bceSAndroid Build Coastguard Worker 
~AttributeGroup(void)664*35238bceSAndroid Build Coastguard Worker AttributeGroup::~AttributeGroup(void)
665*35238bceSAndroid Build Coastguard Worker {
666*35238bceSAndroid Build Coastguard Worker }
667*35238bceSAndroid Build Coastguard Worker 
init(void)668*35238bceSAndroid Build Coastguard Worker void AttributeGroup::init(void)
669*35238bceSAndroid Build Coastguard Worker {
670*35238bceSAndroid Build Coastguard Worker     // Single attribute
671*35238bceSAndroid Build Coastguard Worker     {
672*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test =
673*35238bceSAndroid Build Coastguard Worker             new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "single_attribute", "Single attribute array.");
674*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
675*35238bceSAndroid Build Coastguard Worker         glu::ContextType contextType = m_context.getRenderContext().getType();
676*35238bceSAndroid Build Coastguard Worker 
677*35238bceSAndroid Build Coastguard Worker         spec.apiType            = glu::isContextTypeES(contextType) ? glu::ApiType::es(3, 1) : contextType.getAPI();
678*35238bceSAndroid Build Coastguard Worker         spec.primitive          = m_primitive;
679*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount     = 5;
680*35238bceSAndroid Build Coastguard Worker         spec.drawMethod         = m_method;
681*35238bceSAndroid Build Coastguard Worker         spec.indexType          = m_indexType;
682*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = 0;
683*35238bceSAndroid Build Coastguard Worker         spec.indexStorage       = m_indexStorage;
684*35238bceSAndroid Build Coastguard Worker         spec.first              = 0;
685*35238bceSAndroid Build Coastguard Worker         spec.indexMin           = 0;
686*35238bceSAndroid Build Coastguard Worker         spec.indexMax           = 0;
687*35238bceSAndroid Build Coastguard Worker         spec.instanceCount      = 1;
688*35238bceSAndroid Build Coastguard Worker         spec.indirectOffset     = 0;
689*35238bceSAndroid Build Coastguard Worker 
690*35238bceSAndroid Build Coastguard Worker         spec.attribs.resize(1);
691*35238bceSAndroid Build Coastguard Worker 
692*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
693*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
694*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
695*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
696*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].componentCount      = 2;
697*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].offset              = 0;
698*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].stride              = 0;
699*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].normalize           = false;
700*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].instanceDivisor     = 0;
701*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].useDefaultAttribute = false;
702*35238bceSAndroid Build Coastguard Worker 
703*35238bceSAndroid Build Coastguard Worker         addTestIterations(test, spec, TYPE_DRAW_COUNT);
704*35238bceSAndroid Build Coastguard Worker 
705*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
706*35238bceSAndroid Build Coastguard Worker     }
707*35238bceSAndroid Build Coastguard Worker 
708*35238bceSAndroid Build Coastguard Worker     // Multiple attribute
709*35238bceSAndroid Build Coastguard Worker     {
710*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "multiple_attributes",
711*35238bceSAndroid Build Coastguard Worker                                                 "Multiple attribute arrays.");
712*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
713*35238bceSAndroid Build Coastguard Worker         glu::ContextType contextType = m_context.getRenderContext().getType();
714*35238bceSAndroid Build Coastguard Worker 
715*35238bceSAndroid Build Coastguard Worker         spec.apiType            = glu::isContextTypeES(contextType) ? glu::ApiType::es(3, 1) : contextType.getAPI();
716*35238bceSAndroid Build Coastguard Worker         spec.primitive          = m_primitive;
717*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount     = 5;
718*35238bceSAndroid Build Coastguard Worker         spec.drawMethod         = m_method;
719*35238bceSAndroid Build Coastguard Worker         spec.indexType          = m_indexType;
720*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = 0;
721*35238bceSAndroid Build Coastguard Worker         spec.indexStorage       = m_indexStorage;
722*35238bceSAndroid Build Coastguard Worker         spec.first              = 0;
723*35238bceSAndroid Build Coastguard Worker         spec.indexMin           = 0;
724*35238bceSAndroid Build Coastguard Worker         spec.indexMax           = 0;
725*35238bceSAndroid Build Coastguard Worker         spec.instanceCount      = 1;
726*35238bceSAndroid Build Coastguard Worker         spec.indirectOffset     = 0;
727*35238bceSAndroid Build Coastguard Worker 
728*35238bceSAndroid Build Coastguard Worker         spec.attribs.resize(2);
729*35238bceSAndroid Build Coastguard Worker 
730*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
731*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
732*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
733*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
734*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].componentCount      = 4;
735*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].offset              = 0;
736*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].stride              = 0;
737*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].normalize           = false;
738*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].instanceDivisor     = 0;
739*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].useDefaultAttribute = false;
740*35238bceSAndroid Build Coastguard Worker 
741*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
742*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
743*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
744*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
745*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].componentCount      = 2;
746*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].offset              = 0;
747*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].stride              = 0;
748*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].normalize           = false;
749*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].instanceDivisor     = 0;
750*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].useDefaultAttribute = false;
751*35238bceSAndroid Build Coastguard Worker 
752*35238bceSAndroid Build Coastguard Worker         addTestIterations(test, spec, TYPE_DRAW_COUNT);
753*35238bceSAndroid Build Coastguard Worker 
754*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
755*35238bceSAndroid Build Coastguard Worker     }
756*35238bceSAndroid Build Coastguard Worker 
757*35238bceSAndroid Build Coastguard Worker     // Multiple attribute, second one divided
758*35238bceSAndroid Build Coastguard Worker     {
759*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "instanced_attributes",
760*35238bceSAndroid Build Coastguard Worker                                                 "Instanced attribute array.");
761*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
762*35238bceSAndroid Build Coastguard Worker         glu::ContextType contextType = m_context.getRenderContext().getType();
763*35238bceSAndroid Build Coastguard Worker 
764*35238bceSAndroid Build Coastguard Worker         spec.apiType            = glu::isContextTypeES(contextType) ? glu::ApiType::es(3, 1) : contextType.getAPI();
765*35238bceSAndroid Build Coastguard Worker         spec.primitive          = m_primitive;
766*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount     = 5;
767*35238bceSAndroid Build Coastguard Worker         spec.drawMethod         = m_method;
768*35238bceSAndroid Build Coastguard Worker         spec.indexType          = m_indexType;
769*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = 0;
770*35238bceSAndroid Build Coastguard Worker         spec.indexStorage       = m_indexStorage;
771*35238bceSAndroid Build Coastguard Worker         spec.first              = 0;
772*35238bceSAndroid Build Coastguard Worker         spec.indexMin           = 0;
773*35238bceSAndroid Build Coastguard Worker         spec.indexMax           = 0;
774*35238bceSAndroid Build Coastguard Worker         spec.instanceCount      = 1;
775*35238bceSAndroid Build Coastguard Worker         spec.indirectOffset     = 0;
776*35238bceSAndroid Build Coastguard Worker 
777*35238bceSAndroid Build Coastguard Worker         spec.attribs.resize(3);
778*35238bceSAndroid Build Coastguard Worker 
779*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
780*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
781*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
782*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
783*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].componentCount      = 4;
784*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].offset              = 0;
785*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].stride              = 0;
786*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].normalize           = false;
787*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].instanceDivisor     = 0;
788*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].useDefaultAttribute = false;
789*35238bceSAndroid Build Coastguard Worker 
790*35238bceSAndroid Build Coastguard Worker         // Add another position component so the instances wont be drawn on each other
791*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].inputType                   = gls::DrawTestSpec::INPUTTYPE_FLOAT;
792*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].outputType                  = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
793*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].storage                     = gls::DrawTestSpec::STORAGE_BUFFER;
794*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].usage                       = gls::DrawTestSpec::USAGE_STATIC_DRAW;
795*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].componentCount              = 2;
796*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].offset                      = 0;
797*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].stride                      = 0;
798*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].normalize                   = false;
799*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].instanceDivisor             = 1;
800*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].useDefaultAttribute         = false;
801*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].additionalPositionAttribute = true;
802*35238bceSAndroid Build Coastguard Worker 
803*35238bceSAndroid Build Coastguard Worker         // Instanced color
804*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
805*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
806*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
807*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
808*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].componentCount      = 3;
809*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].offset              = 0;
810*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].stride              = 0;
811*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].normalize           = false;
812*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].instanceDivisor     = 1;
813*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].useDefaultAttribute = false;
814*35238bceSAndroid Build Coastguard Worker 
815*35238bceSAndroid Build Coastguard Worker         addTestIterations(test, spec, TYPE_INSTANCE_COUNT);
816*35238bceSAndroid Build Coastguard Worker 
817*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
818*35238bceSAndroid Build Coastguard Worker     }
819*35238bceSAndroid Build Coastguard Worker 
820*35238bceSAndroid Build Coastguard Worker     // Multiple attribute, second one default
821*35238bceSAndroid Build Coastguard Worker     {
822*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "default_attribute",
823*35238bceSAndroid Build Coastguard Worker                                                 "Attribute specified with glVertexAttrib*.");
824*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
825*35238bceSAndroid Build Coastguard Worker         glu::ContextType contextType = m_context.getRenderContext().getType();
826*35238bceSAndroid Build Coastguard Worker 
827*35238bceSAndroid Build Coastguard Worker         spec.apiType            = glu::isContextTypeES(contextType) ? glu::ApiType::es(3, 1) : contextType.getAPI();
828*35238bceSAndroid Build Coastguard Worker         spec.primitive          = m_primitive;
829*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount     = 5;
830*35238bceSAndroid Build Coastguard Worker         spec.drawMethod         = m_method;
831*35238bceSAndroid Build Coastguard Worker         spec.indexType          = m_indexType;
832*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = 0;
833*35238bceSAndroid Build Coastguard Worker         spec.indexStorage       = m_indexStorage;
834*35238bceSAndroid Build Coastguard Worker         spec.first              = 0;
835*35238bceSAndroid Build Coastguard Worker         spec.indexMin           = 0;
836*35238bceSAndroid Build Coastguard Worker         spec.indexMax           = 0;
837*35238bceSAndroid Build Coastguard Worker         spec.instanceCount      = 1;
838*35238bceSAndroid Build Coastguard Worker         spec.indirectOffset     = 0;
839*35238bceSAndroid Build Coastguard Worker 
840*35238bceSAndroid Build Coastguard Worker         spec.attribs.resize(2);
841*35238bceSAndroid Build Coastguard Worker 
842*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
843*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
844*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
845*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
846*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].componentCount      = 2;
847*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].offset              = 0;
848*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].stride              = 0;
849*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].normalize           = false;
850*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].instanceDivisor     = 0;
851*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].useDefaultAttribute = false;
852*35238bceSAndroid Build Coastguard Worker 
853*35238bceSAndroid Build Coastguard Worker         struct IOPair
854*35238bceSAndroid Build Coastguard Worker         {
855*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::InputType input;
856*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::OutputType output;
857*35238bceSAndroid Build Coastguard Worker             int componentCount;
858*35238bceSAndroid Build Coastguard Worker         } iopairs[] = {
859*35238bceSAndroid Build Coastguard Worker             {gls::DrawTestSpec::INPUTTYPE_FLOAT, gls::DrawTestSpec::OUTPUTTYPE_VEC2, 4},
860*35238bceSAndroid Build Coastguard Worker             {gls::DrawTestSpec::INPUTTYPE_FLOAT, gls::DrawTestSpec::OUTPUTTYPE_VEC4, 2},
861*35238bceSAndroid Build Coastguard Worker             {gls::DrawTestSpec::INPUTTYPE_INT, gls::DrawTestSpec::OUTPUTTYPE_IVEC3, 4},
862*35238bceSAndroid Build Coastguard Worker             {gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT, gls::DrawTestSpec::OUTPUTTYPE_UVEC2, 4},
863*35238bceSAndroid Build Coastguard Worker         };
864*35238bceSAndroid Build Coastguard Worker 
865*35238bceSAndroid Build Coastguard Worker         for (int ioNdx = 0; ioNdx < DE_LENGTH_OF_ARRAY(iopairs); ++ioNdx)
866*35238bceSAndroid Build Coastguard Worker         {
867*35238bceSAndroid Build Coastguard Worker             const std::string desc = gls::DrawTestSpec::inputTypeToString(iopairs[ioNdx].input) +
868*35238bceSAndroid Build Coastguard Worker                                      de::toString(iopairs[ioNdx].componentCount) + " to " +
869*35238bceSAndroid Build Coastguard Worker                                      gls::DrawTestSpec::outputTypeToString(iopairs[ioNdx].output);
870*35238bceSAndroid Build Coastguard Worker 
871*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].inputType           = iopairs[ioNdx].input;
872*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].outputType          = iopairs[ioNdx].output;
873*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
874*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
875*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].componentCount      = iopairs[ioNdx].componentCount;
876*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].offset              = 0;
877*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].stride              = 0;
878*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].normalize           = false;
879*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].instanceDivisor     = 0;
880*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].useDefaultAttribute = true;
881*35238bceSAndroid Build Coastguard Worker 
882*35238bceSAndroid Build Coastguard Worker             test->addIteration(spec, desc.c_str());
883*35238bceSAndroid Build Coastguard Worker         }
884*35238bceSAndroid Build Coastguard Worker 
885*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
886*35238bceSAndroid Build Coastguard Worker     }
887*35238bceSAndroid Build Coastguard Worker }
888*35238bceSAndroid Build Coastguard Worker 
889*35238bceSAndroid Build Coastguard Worker class MethodGroup : public TestCaseGroup
890*35238bceSAndroid Build Coastguard Worker {
891*35238bceSAndroid Build Coastguard Worker public:
892*35238bceSAndroid Build Coastguard Worker     MethodGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
893*35238bceSAndroid Build Coastguard Worker     ~MethodGroup(void);
894*35238bceSAndroid Build Coastguard Worker 
895*35238bceSAndroid Build Coastguard Worker     void init(void);
896*35238bceSAndroid Build Coastguard Worker 
897*35238bceSAndroid Build Coastguard Worker private:
898*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
899*35238bceSAndroid Build Coastguard Worker };
900*35238bceSAndroid Build Coastguard Worker 
MethodGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)901*35238bceSAndroid Build Coastguard Worker MethodGroup::MethodGroup(Context &context, const char *name, const char *descr,
902*35238bceSAndroid Build Coastguard Worker                          gls::DrawTestSpec::DrawMethod drawMethod)
903*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
904*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
905*35238bceSAndroid Build Coastguard Worker {
906*35238bceSAndroid Build Coastguard Worker }
907*35238bceSAndroid Build Coastguard Worker 
~MethodGroup(void)908*35238bceSAndroid Build Coastguard Worker MethodGroup::~MethodGroup(void)
909*35238bceSAndroid Build Coastguard Worker {
910*35238bceSAndroid Build Coastguard Worker }
911*35238bceSAndroid Build Coastguard Worker 
init(void)912*35238bceSAndroid Build Coastguard Worker void MethodGroup::init(void)
913*35238bceSAndroid Build Coastguard Worker {
914*35238bceSAndroid Build Coastguard Worker     const bool indexed = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_BASEVERTEX) ||
915*35238bceSAndroid Build Coastguard Worker                          (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED_BASEVERTEX) ||
916*35238bceSAndroid Build Coastguard Worker                          (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED_BASEVERTEX);
917*35238bceSAndroid Build Coastguard Worker 
918*35238bceSAndroid Build Coastguard Worker     const gls::DrawTestSpec::Primitive primitive[] = {
919*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_POINTS,       gls::DrawTestSpec::PRIMITIVE_TRIANGLES,
920*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN, gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP,
921*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_LINES,        gls::DrawTestSpec::PRIMITIVE_LINE_STRIP,
922*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_LINE_LOOP};
923*35238bceSAndroid Build Coastguard Worker 
924*35238bceSAndroid Build Coastguard Worker     if (indexed)
925*35238bceSAndroid Build Coastguard Worker     {
926*35238bceSAndroid Build Coastguard Worker         // Index-tests
927*35238bceSAndroid Build Coastguard Worker         this->addChild(new IndexGroup(m_context, "indices", "Index tests", m_method));
928*35238bceSAndroid Build Coastguard Worker         this->addChild(new BaseVertexGroup(m_context, "base_vertex", "Base vertex tests", m_method));
929*35238bceSAndroid Build Coastguard Worker         this->addChild(
930*35238bceSAndroid Build Coastguard Worker             new BuiltInVariableGroup(m_context, "builtin_variable", "Built in shader variable tests", m_method));
931*35238bceSAndroid Build Coastguard Worker     }
932*35238bceSAndroid Build Coastguard Worker 
933*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(primitive); ++ndx)
934*35238bceSAndroid Build Coastguard Worker     {
935*35238bceSAndroid Build Coastguard Worker         const std::string name = gls::DrawTestSpec::primitiveToString(primitive[ndx]);
936*35238bceSAndroid Build Coastguard Worker         const std::string desc = gls::DrawTestSpec::primitiveToString(primitive[ndx]);
937*35238bceSAndroid Build Coastguard Worker 
938*35238bceSAndroid Build Coastguard Worker         this->addChild(new AttributeGroup(m_context, name.c_str(), desc.c_str(), m_method, primitive[ndx],
939*35238bceSAndroid Build Coastguard Worker                                           gls::DrawTestSpec::INDEXTYPE_SHORT, gls::DrawTestSpec::STORAGE_BUFFER));
940*35238bceSAndroid Build Coastguard Worker     }
941*35238bceSAndroid Build Coastguard Worker }
942*35238bceSAndroid Build Coastguard Worker 
943*35238bceSAndroid Build Coastguard Worker } // namespace
944*35238bceSAndroid Build Coastguard Worker 
DrawElementsBaseVertexTests(Context & context)945*35238bceSAndroid Build Coastguard Worker DrawElementsBaseVertexTests::DrawElementsBaseVertexTests(Context &context)
946*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "draw_base_vertex", "Base vertex extension drawing tests")
947*35238bceSAndroid Build Coastguard Worker {
948*35238bceSAndroid Build Coastguard Worker }
949*35238bceSAndroid Build Coastguard Worker 
~DrawElementsBaseVertexTests(void)950*35238bceSAndroid Build Coastguard Worker DrawElementsBaseVertexTests::~DrawElementsBaseVertexTests(void)
951*35238bceSAndroid Build Coastguard Worker {
952*35238bceSAndroid Build Coastguard Worker }
953*35238bceSAndroid Build Coastguard Worker 
init(void)954*35238bceSAndroid Build Coastguard Worker void DrawElementsBaseVertexTests::init(void)
955*35238bceSAndroid Build Coastguard Worker {
956*35238bceSAndroid Build Coastguard Worker     const gls::DrawTestSpec::DrawMethod basicMethods[] = {
957*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_BASEVERTEX,
958*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED_BASEVERTEX,
959*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED_BASEVERTEX,
960*35238bceSAndroid Build Coastguard Worker     };
961*35238bceSAndroid Build Coastguard Worker 
962*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(basicMethods); ++ndx)
963*35238bceSAndroid Build Coastguard Worker     {
964*35238bceSAndroid Build Coastguard Worker         const std::string name = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]);
965*35238bceSAndroid Build Coastguard Worker         const std::string desc = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]);
966*35238bceSAndroid Build Coastguard Worker 
967*35238bceSAndroid Build Coastguard Worker         this->addChild(new MethodGroup(m_context, name.c_str(), desc.c_str(), basicMethods[ndx]));
968*35238bceSAndroid Build Coastguard Worker     }
969*35238bceSAndroid Build Coastguard Worker }
970*35238bceSAndroid Build Coastguard Worker 
971*35238bceSAndroid Build Coastguard Worker } // namespace Functional
972*35238bceSAndroid Build Coastguard Worker } // namespace gles31
973*35238bceSAndroid Build Coastguard Worker } // namespace deqp
974