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 Shader built-in variable tests.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es3fShaderBuiltinVarTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsShaderRenderCase.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "glsShaderExecUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "deString.h"
29*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
30*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuTestCase.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "gluDrawUtil.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "rrRenderer.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "rrFragmentOperations.hpp"
42*35238bceSAndroid Build Coastguard Worker
43*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
45*35238bceSAndroid Build Coastguard Worker
46*35238bceSAndroid Build Coastguard Worker using std::string;
47*35238bceSAndroid Build Coastguard Worker using std::vector;
48*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
49*35238bceSAndroid Build Coastguard Worker
50*35238bceSAndroid Build Coastguard Worker namespace deqp
51*35238bceSAndroid Build Coastguard Worker {
52*35238bceSAndroid Build Coastguard Worker namespace gles3
53*35238bceSAndroid Build Coastguard Worker {
54*35238bceSAndroid Build Coastguard Worker namespace Functional
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker
getInteger(const glw::Functions & gl,uint32_t pname)57*35238bceSAndroid Build Coastguard Worker static int getInteger(const glw::Functions &gl, uint32_t pname)
58*35238bceSAndroid Build Coastguard Worker {
59*35238bceSAndroid Build Coastguard Worker int value = -1;
60*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(pname, &value);
61*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(),
62*35238bceSAndroid Build Coastguard Worker ("glGetIntegerv(" + glu::getGettableStateStr((int)pname).toString() + ")").c_str());
63*35238bceSAndroid Build Coastguard Worker return value;
64*35238bceSAndroid Build Coastguard Worker }
65*35238bceSAndroid Build Coastguard Worker
66*35238bceSAndroid Build Coastguard Worker template <uint32_t Pname>
getInteger(const glw::Functions & gl)67*35238bceSAndroid Build Coastguard Worker static int getInteger(const glw::Functions &gl)
68*35238bceSAndroid Build Coastguard Worker {
69*35238bceSAndroid Build Coastguard Worker return getInteger(gl, Pname);
70*35238bceSAndroid Build Coastguard Worker }
71*35238bceSAndroid Build Coastguard Worker
getVectorsFromComps(const glw::Functions & gl,uint32_t pname)72*35238bceSAndroid Build Coastguard Worker static int getVectorsFromComps(const glw::Functions &gl, uint32_t pname)
73*35238bceSAndroid Build Coastguard Worker {
74*35238bceSAndroid Build Coastguard Worker int value = -1;
75*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(pname, &value);
76*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(),
77*35238bceSAndroid Build Coastguard Worker ("glGetIntegerv(" + glu::getGettableStateStr((int)pname).toString() + ")").c_str());
78*35238bceSAndroid Build Coastguard Worker // Accept truncated division. According to the spec, the number of vectors is number of components divided by four, plain and simple.
79*35238bceSAndroid Build Coastguard Worker return value / 4;
80*35238bceSAndroid Build Coastguard Worker }
81*35238bceSAndroid Build Coastguard Worker
82*35238bceSAndroid Build Coastguard Worker template <uint32_t Pname>
getVectorsFromComps(const glw::Functions & gl)83*35238bceSAndroid Build Coastguard Worker static int getVectorsFromComps(const glw::Functions &gl)
84*35238bceSAndroid Build Coastguard Worker {
85*35238bceSAndroid Build Coastguard Worker return getVectorsFromComps(gl, Pname);
86*35238bceSAndroid Build Coastguard Worker }
87*35238bceSAndroid Build Coastguard Worker
88*35238bceSAndroid Build Coastguard Worker class ShaderBuiltinConstantCase : public TestCase
89*35238bceSAndroid Build Coastguard Worker {
90*35238bceSAndroid Build Coastguard Worker public:
91*35238bceSAndroid Build Coastguard Worker typedef int (*GetConstantValueFunc)(const glw::Functions &gl);
92*35238bceSAndroid Build Coastguard Worker
93*35238bceSAndroid Build Coastguard Worker ShaderBuiltinConstantCase(Context &context, const char *name, const char *desc, const char *varName,
94*35238bceSAndroid Build Coastguard Worker GetConstantValueFunc getValue, glu::ShaderType shaderType);
95*35238bceSAndroid Build Coastguard Worker ~ShaderBuiltinConstantCase(void);
96*35238bceSAndroid Build Coastguard Worker
97*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
98*35238bceSAndroid Build Coastguard Worker
99*35238bceSAndroid Build Coastguard Worker private:
100*35238bceSAndroid Build Coastguard Worker const std::string m_varName;
101*35238bceSAndroid Build Coastguard Worker const GetConstantValueFunc m_getValue;
102*35238bceSAndroid Build Coastguard Worker const glu::ShaderType m_shaderType;
103*35238bceSAndroid Build Coastguard Worker };
104*35238bceSAndroid Build Coastguard Worker
ShaderBuiltinConstantCase(Context & context,const char * name,const char * desc,const char * varName,GetConstantValueFunc getValue,glu::ShaderType shaderType)105*35238bceSAndroid Build Coastguard Worker ShaderBuiltinConstantCase::ShaderBuiltinConstantCase(Context &context, const char *name, const char *desc,
106*35238bceSAndroid Build Coastguard Worker const char *varName, GetConstantValueFunc getValue,
107*35238bceSAndroid Build Coastguard Worker glu::ShaderType shaderType)
108*35238bceSAndroid Build Coastguard Worker : TestCase(context, name, desc)
109*35238bceSAndroid Build Coastguard Worker , m_varName(varName)
110*35238bceSAndroid Build Coastguard Worker , m_getValue(getValue)
111*35238bceSAndroid Build Coastguard Worker , m_shaderType(shaderType)
112*35238bceSAndroid Build Coastguard Worker {
113*35238bceSAndroid Build Coastguard Worker }
114*35238bceSAndroid Build Coastguard Worker
~ShaderBuiltinConstantCase(void)115*35238bceSAndroid Build Coastguard Worker ShaderBuiltinConstantCase::~ShaderBuiltinConstantCase(void)
116*35238bceSAndroid Build Coastguard Worker {
117*35238bceSAndroid Build Coastguard Worker }
118*35238bceSAndroid Build Coastguard Worker
createGetConstantExecutor(const glu::RenderContext & renderCtx,glu::ShaderType shaderType,const std::string & varName)119*35238bceSAndroid Build Coastguard Worker static gls::ShaderExecUtil::ShaderExecutor *createGetConstantExecutor(const glu::RenderContext &renderCtx,
120*35238bceSAndroid Build Coastguard Worker glu::ShaderType shaderType,
121*35238bceSAndroid Build Coastguard Worker const std::string &varName)
122*35238bceSAndroid Build Coastguard Worker {
123*35238bceSAndroid Build Coastguard Worker using namespace gls::ShaderExecUtil;
124*35238bceSAndroid Build Coastguard Worker
125*35238bceSAndroid Build Coastguard Worker ShaderSpec shaderSpec;
126*35238bceSAndroid Build Coastguard Worker
127*35238bceSAndroid Build Coastguard Worker shaderSpec.version = glu::GLSL_VERSION_300_ES;
128*35238bceSAndroid Build Coastguard Worker shaderSpec.source = string("result = ") + varName + ";\n";
129*35238bceSAndroid Build Coastguard Worker shaderSpec.outputs.push_back(Symbol("result", glu::VarType(glu::TYPE_INT, glu::PRECISION_HIGHP)));
130*35238bceSAndroid Build Coastguard Worker
131*35238bceSAndroid Build Coastguard Worker return createExecutor(renderCtx, shaderType, shaderSpec);
132*35238bceSAndroid Build Coastguard Worker }
133*35238bceSAndroid Build Coastguard Worker
iterate(void)134*35238bceSAndroid Build Coastguard Worker ShaderBuiltinConstantCase::IterateResult ShaderBuiltinConstantCase::iterate(void)
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker using namespace gls::ShaderExecUtil;
137*35238bceSAndroid Build Coastguard Worker
138*35238bceSAndroid Build Coastguard Worker const de::UniquePtr<ShaderExecutor> shaderExecutor(
139*35238bceSAndroid Build Coastguard Worker createGetConstantExecutor(m_context.getRenderContext(), m_shaderType, m_varName));
140*35238bceSAndroid Build Coastguard Worker const int reference = m_getValue(m_context.getRenderContext().getFunctions());
141*35238bceSAndroid Build Coastguard Worker int result = -1;
142*35238bceSAndroid Build Coastguard Worker void *const outputs = &result;
143*35238bceSAndroid Build Coastguard Worker
144*35238bceSAndroid Build Coastguard Worker if (!shaderExecutor->isOk())
145*35238bceSAndroid Build Coastguard Worker {
146*35238bceSAndroid Build Coastguard Worker shaderExecutor->log(m_testCtx.getLog());
147*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Compile failed");
148*35238bceSAndroid Build Coastguard Worker }
149*35238bceSAndroid Build Coastguard Worker
150*35238bceSAndroid Build Coastguard Worker shaderExecutor->useProgram();
151*35238bceSAndroid Build Coastguard Worker shaderExecutor->execute(1, DE_NULL, &outputs);
152*35238bceSAndroid Build Coastguard Worker
153*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << TestLog::Integer(m_varName, m_varName, "", QP_KEY_TAG_NONE, result);
154*35238bceSAndroid Build Coastguard Worker
155*35238bceSAndroid Build Coastguard Worker if (result != reference)
156*35238bceSAndroid Build Coastguard Worker {
157*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << TestLog::Message << "ERROR: Expected " << m_varName << " = " << reference
158*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage << TestLog::Message << "Test shader:" << TestLog::EndMessage;
159*35238bceSAndroid Build Coastguard Worker shaderExecutor->log(m_testCtx.getLog());
160*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid builtin constant value");
161*35238bceSAndroid Build Coastguard Worker }
162*35238bceSAndroid Build Coastguard Worker else
163*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
164*35238bceSAndroid Build Coastguard Worker
165*35238bceSAndroid Build Coastguard Worker return STOP;
166*35238bceSAndroid Build Coastguard Worker }
167*35238bceSAndroid Build Coastguard Worker
168*35238bceSAndroid Build Coastguard Worker namespace
169*35238bceSAndroid Build Coastguard Worker {
170*35238bceSAndroid Build Coastguard Worker
171*35238bceSAndroid Build Coastguard Worker struct DepthRangeParams
172*35238bceSAndroid Build Coastguard Worker {
DepthRangeParamsdeqp::gles3::Functional::__anon39e231830111::DepthRangeParams173*35238bceSAndroid Build Coastguard Worker DepthRangeParams(void) : zNear(0.0f), zFar(1.0f)
174*35238bceSAndroid Build Coastguard Worker {
175*35238bceSAndroid Build Coastguard Worker }
176*35238bceSAndroid Build Coastguard Worker
DepthRangeParamsdeqp::gles3::Functional::__anon39e231830111::DepthRangeParams177*35238bceSAndroid Build Coastguard Worker DepthRangeParams(float zNear_, float zFar_) : zNear(zNear_), zFar(zFar_)
178*35238bceSAndroid Build Coastguard Worker {
179*35238bceSAndroid Build Coastguard Worker }
180*35238bceSAndroid Build Coastguard Worker
181*35238bceSAndroid Build Coastguard Worker float zNear;
182*35238bceSAndroid Build Coastguard Worker float zFar;
183*35238bceSAndroid Build Coastguard Worker };
184*35238bceSAndroid Build Coastguard Worker
185*35238bceSAndroid Build Coastguard Worker class DepthRangeEvaluator : public gls::ShaderEvaluator
186*35238bceSAndroid Build Coastguard Worker {
187*35238bceSAndroid Build Coastguard Worker public:
DepthRangeEvaluator(const DepthRangeParams & params)188*35238bceSAndroid Build Coastguard Worker DepthRangeEvaluator(const DepthRangeParams ¶ms) : m_params(params)
189*35238bceSAndroid Build Coastguard Worker {
190*35238bceSAndroid Build Coastguard Worker }
191*35238bceSAndroid Build Coastguard Worker
evaluate(gls::ShaderEvalContext & c)192*35238bceSAndroid Build Coastguard Worker void evaluate(gls::ShaderEvalContext &c)
193*35238bceSAndroid Build Coastguard Worker {
194*35238bceSAndroid Build Coastguard Worker float zNear = deFloatClamp(m_params.zNear, 0.0f, 1.0f);
195*35238bceSAndroid Build Coastguard Worker float zFar = deFloatClamp(m_params.zFar, 0.0f, 1.0f);
196*35238bceSAndroid Build Coastguard Worker float diff = zFar - zNear;
197*35238bceSAndroid Build Coastguard Worker c.color.xyz() = tcu::Vec3(zNear, zFar, diff * 0.5f + 0.5f);
198*35238bceSAndroid Build Coastguard Worker }
199*35238bceSAndroid Build Coastguard Worker
200*35238bceSAndroid Build Coastguard Worker private:
201*35238bceSAndroid Build Coastguard Worker const DepthRangeParams &m_params;
202*35238bceSAndroid Build Coastguard Worker };
203*35238bceSAndroid Build Coastguard Worker
204*35238bceSAndroid Build Coastguard Worker } // namespace
205*35238bceSAndroid Build Coastguard Worker
206*35238bceSAndroid Build Coastguard Worker class ShaderDepthRangeTest : public gls::ShaderRenderCase
207*35238bceSAndroid Build Coastguard Worker {
208*35238bceSAndroid Build Coastguard Worker public:
ShaderDepthRangeTest(Context & context,const char * name,const char * desc,bool isVertexCase)209*35238bceSAndroid Build Coastguard Worker ShaderDepthRangeTest(Context &context, const char *name, const char *desc, bool isVertexCase)
210*35238bceSAndroid Build Coastguard Worker : ShaderRenderCase(context.getTestContext(), context.getRenderContext(), context.getContextInfo(), name, desc,
211*35238bceSAndroid Build Coastguard Worker isVertexCase, m_evaluator)
212*35238bceSAndroid Build Coastguard Worker , m_evaluator(m_depthRange)
213*35238bceSAndroid Build Coastguard Worker , m_iterNdx(0)
214*35238bceSAndroid Build Coastguard Worker {
215*35238bceSAndroid Build Coastguard Worker }
216*35238bceSAndroid Build Coastguard Worker
init(void)217*35238bceSAndroid Build Coastguard Worker void init(void)
218*35238bceSAndroid Build Coastguard Worker {
219*35238bceSAndroid Build Coastguard Worker static const char *defaultVertSrc = "#version 300 es\n"
220*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
221*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
222*35238bceSAndroid Build Coastguard Worker "{\n"
223*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
224*35238bceSAndroid Build Coastguard Worker "}\n";
225*35238bceSAndroid Build Coastguard Worker static const char *defaultFragSrc = "#version 300 es\n"
226*35238bceSAndroid Build Coastguard Worker "in mediump vec4 v_color;\n"
227*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 o_color;\n\n"
228*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
229*35238bceSAndroid Build Coastguard Worker "{\n"
230*35238bceSAndroid Build Coastguard Worker " o_color = v_color;\n"
231*35238bceSAndroid Build Coastguard Worker "}\n";
232*35238bceSAndroid Build Coastguard Worker
233*35238bceSAndroid Build Coastguard Worker // Construct shader.
234*35238bceSAndroid Build Coastguard Worker std::ostringstream src;
235*35238bceSAndroid Build Coastguard Worker src << "#version 300 es\n";
236*35238bceSAndroid Build Coastguard Worker if (m_isVertexCase)
237*35238bceSAndroid Build Coastguard Worker src << "in highp vec4 a_position;\n"
238*35238bceSAndroid Build Coastguard Worker << "out mediump vec4 v_color;\n";
239*35238bceSAndroid Build Coastguard Worker else
240*35238bceSAndroid Build Coastguard Worker src << "layout(location = 0) out mediump vec4 o_color;\n";
241*35238bceSAndroid Build Coastguard Worker
242*35238bceSAndroid Build Coastguard Worker src << "void main (void)\n{\n";
243*35238bceSAndroid Build Coastguard Worker src << "\t" << (m_isVertexCase ? "v_color" : "o_color")
244*35238bceSAndroid Build Coastguard Worker << " = vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff*0.5 + 0.5, 1.0);\n";
245*35238bceSAndroid Build Coastguard Worker
246*35238bceSAndroid Build Coastguard Worker if (m_isVertexCase)
247*35238bceSAndroid Build Coastguard Worker src << "\tgl_Position = a_position;\n";
248*35238bceSAndroid Build Coastguard Worker
249*35238bceSAndroid Build Coastguard Worker src << "}\n";
250*35238bceSAndroid Build Coastguard Worker
251*35238bceSAndroid Build Coastguard Worker m_vertShaderSource = m_isVertexCase ? src.str() : defaultVertSrc;
252*35238bceSAndroid Build Coastguard Worker m_fragShaderSource = m_isVertexCase ? defaultFragSrc : src.str();
253*35238bceSAndroid Build Coastguard Worker
254*35238bceSAndroid Build Coastguard Worker gls::ShaderRenderCase::init();
255*35238bceSAndroid Build Coastguard Worker }
256*35238bceSAndroid Build Coastguard Worker
iterate(void)257*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void)
258*35238bceSAndroid Build Coastguard Worker {
259*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_renderCtx.getFunctions();
260*35238bceSAndroid Build Coastguard Worker
261*35238bceSAndroid Build Coastguard Worker const DepthRangeParams cases[] = {DepthRangeParams(0.0f, 1.0f), DepthRangeParams(1.5f, -1.0f),
262*35238bceSAndroid Build Coastguard Worker DepthRangeParams(0.7f, 0.3f)};
263*35238bceSAndroid Build Coastguard Worker
264*35238bceSAndroid Build Coastguard Worker m_depthRange = cases[m_iterNdx];
265*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "glDepthRangef(" << m_depthRange.zNear << ", "
266*35238bceSAndroid Build Coastguard Worker << m_depthRange.zFar << ")" << tcu::TestLog::EndMessage;
267*35238bceSAndroid Build Coastguard Worker gl.depthRangef(m_depthRange.zNear, m_depthRange.zFar);
268*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "glDepthRangef()");
269*35238bceSAndroid Build Coastguard Worker
270*35238bceSAndroid Build Coastguard Worker gls::ShaderRenderCase::iterate();
271*35238bceSAndroid Build Coastguard Worker m_iterNdx += 1;
272*35238bceSAndroid Build Coastguard Worker
273*35238bceSAndroid Build Coastguard Worker if (m_iterNdx == DE_LENGTH_OF_ARRAY(cases) || m_testCtx.getTestResult() != QP_TEST_RESULT_PASS)
274*35238bceSAndroid Build Coastguard Worker return STOP;
275*35238bceSAndroid Build Coastguard Worker else
276*35238bceSAndroid Build Coastguard Worker return CONTINUE;
277*35238bceSAndroid Build Coastguard Worker }
278*35238bceSAndroid Build Coastguard Worker
279*35238bceSAndroid Build Coastguard Worker private:
280*35238bceSAndroid Build Coastguard Worker DepthRangeParams m_depthRange;
281*35238bceSAndroid Build Coastguard Worker DepthRangeEvaluator m_evaluator;
282*35238bceSAndroid Build Coastguard Worker int m_iterNdx;
283*35238bceSAndroid Build Coastguard Worker };
284*35238bceSAndroid Build Coastguard Worker
285*35238bceSAndroid Build Coastguard Worker class FragCoordXYZCase : public TestCase
286*35238bceSAndroid Build Coastguard Worker {
287*35238bceSAndroid Build Coastguard Worker public:
FragCoordXYZCase(Context & context)288*35238bceSAndroid Build Coastguard Worker FragCoordXYZCase(Context &context) : TestCase(context, "fragcoord_xyz", "gl_FragCoord.xyz Test")
289*35238bceSAndroid Build Coastguard Worker {
290*35238bceSAndroid Build Coastguard Worker }
291*35238bceSAndroid Build Coastguard Worker
iterate(void)292*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void)
293*35238bceSAndroid Build Coastguard Worker {
294*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
295*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
296*35238bceSAndroid Build Coastguard Worker const int width = m_context.getRenderTarget().getWidth();
297*35238bceSAndroid Build Coastguard Worker const int height = m_context.getRenderTarget().getHeight();
298*35238bceSAndroid Build Coastguard Worker const tcu::RGBA threshold =
299*35238bceSAndroid Build Coastguard Worker tcu::RGBA(1, 1, 1, 1) + m_context.getRenderTarget().getPixelFormat().getColorThreshold();
300*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 scale(1.f / float(width), 1.f / float(height), 1.0f);
301*35238bceSAndroid Build Coastguard Worker
302*35238bceSAndroid Build Coastguard Worker tcu::Surface testImg(width, height);
303*35238bceSAndroid Build Coastguard Worker tcu::Surface refImg(width, height);
304*35238bceSAndroid Build Coastguard Worker
305*35238bceSAndroid Build Coastguard Worker const glu::ShaderProgram program(m_context.getRenderContext(),
306*35238bceSAndroid Build Coastguard Worker glu::makeVtxFragSources("#version 300 es\n"
307*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
308*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
309*35238bceSAndroid Build Coastguard Worker "{\n"
310*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
311*35238bceSAndroid Build Coastguard Worker "}\n",
312*35238bceSAndroid Build Coastguard Worker
313*35238bceSAndroid Build Coastguard Worker "#version 300 es\n"
314*35238bceSAndroid Build Coastguard Worker "uniform highp vec3 u_scale;\n"
315*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 o_color;\n"
316*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
317*35238bceSAndroid Build Coastguard Worker "{\n"
318*35238bceSAndroid Build Coastguard Worker " o_color = vec4(gl_FragCoord.xyz*u_scale, 1.0);\n"
319*35238bceSAndroid Build Coastguard Worker "}\n"));
320*35238bceSAndroid Build Coastguard Worker
321*35238bceSAndroid Build Coastguard Worker log << program;
322*35238bceSAndroid Build Coastguard Worker
323*35238bceSAndroid Build Coastguard Worker if (!program.isOk())
324*35238bceSAndroid Build Coastguard Worker throw tcu::TestError("Compile failed");
325*35238bceSAndroid Build Coastguard Worker
326*35238bceSAndroid Build Coastguard Worker // Draw with GL.
327*35238bceSAndroid Build Coastguard Worker {
328*35238bceSAndroid Build Coastguard Worker const float positions[] = {-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f,
329*35238bceSAndroid Build Coastguard Worker 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
330*35238bceSAndroid Build Coastguard Worker const uint16_t indices[] = {0, 1, 2, 2, 1, 3};
331*35238bceSAndroid Build Coastguard Worker
332*35238bceSAndroid Build Coastguard Worker const int scaleLoc = gl.getUniformLocation(program.getProgram(), "u_scale");
333*35238bceSAndroid Build Coastguard Worker glu::VertexArrayBinding posBinding = glu::va::Float("a_position", 4, 4, 0, &positions[0]);
334*35238bceSAndroid Build Coastguard Worker
335*35238bceSAndroid Build Coastguard Worker gl.useProgram(program.getProgram());
336*35238bceSAndroid Build Coastguard Worker gl.uniform3fv(scaleLoc, 1, scale.getPtr());
337*35238bceSAndroid Build Coastguard Worker
338*35238bceSAndroid Build Coastguard Worker glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding,
339*35238bceSAndroid Build Coastguard Worker glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indices), &indices[0]));
340*35238bceSAndroid Build Coastguard Worker
341*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), 0, 0, testImg.getAccess());
342*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
343*35238bceSAndroid Build Coastguard Worker }
344*35238bceSAndroid Build Coastguard Worker
345*35238bceSAndroid Build Coastguard Worker // Draw reference
346*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < refImg.getHeight(); y++)
347*35238bceSAndroid Build Coastguard Worker {
348*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < refImg.getWidth(); x++)
349*35238bceSAndroid Build Coastguard Worker {
350*35238bceSAndroid Build Coastguard Worker const float xf = (float(x) + .5f) / float(refImg.getWidth());
351*35238bceSAndroid Build Coastguard Worker const float yf = (float(refImg.getHeight() - y - 1) + .5f) / float(refImg.getHeight());
352*35238bceSAndroid Build Coastguard Worker const float z = (xf + yf) / 2.0f;
353*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 fragCoord(float(x) + .5f, float(y) + .5f, z);
354*35238bceSAndroid Build Coastguard Worker const tcu::Vec3 scaledFC = fragCoord * scale;
355*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color(scaledFC.x(), scaledFC.y(), scaledFC.z(), 1.0f);
356*35238bceSAndroid Build Coastguard Worker
357*35238bceSAndroid Build Coastguard Worker refImg.setPixel(x, y, tcu::RGBA(color));
358*35238bceSAndroid Build Coastguard Worker }
359*35238bceSAndroid Build Coastguard Worker }
360*35238bceSAndroid Build Coastguard Worker
361*35238bceSAndroid Build Coastguard Worker // Compare
362*35238bceSAndroid Build Coastguard Worker {
363*35238bceSAndroid Build Coastguard Worker bool isOk = tcu::pixelThresholdCompare(log, "Result", "Image comparison result", refImg, testImg, threshold,
364*35238bceSAndroid Build Coastguard Worker tcu::COMPARE_LOG_RESULT);
365*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
366*35238bceSAndroid Build Coastguard Worker isOk ? "Pass" : "Image comparison failed");
367*35238bceSAndroid Build Coastguard Worker }
368*35238bceSAndroid Build Coastguard Worker
369*35238bceSAndroid Build Coastguard Worker return STOP;
370*35238bceSAndroid Build Coastguard Worker }
371*35238bceSAndroid Build Coastguard Worker };
372*35238bceSAndroid Build Coastguard Worker
projectedTriInterpolate(const tcu::Vec3 & s,const tcu::Vec3 & w,float nx,float ny)373*35238bceSAndroid Build Coastguard Worker static inline float projectedTriInterpolate(const tcu::Vec3 &s, const tcu::Vec3 &w, float nx, float ny)
374*35238bceSAndroid Build Coastguard Worker {
375*35238bceSAndroid Build Coastguard Worker return (s[0] * (1.0f - nx - ny) / w[0] + s[1] * ny / w[1] + s[2] * nx / w[2]) /
376*35238bceSAndroid Build Coastguard Worker ((1.0f - nx - ny) / w[0] + ny / w[1] + nx / w[2]);
377*35238bceSAndroid Build Coastguard Worker }
378*35238bceSAndroid Build Coastguard Worker
379*35238bceSAndroid Build Coastguard Worker class FragCoordWCase : public TestCase
380*35238bceSAndroid Build Coastguard Worker {
381*35238bceSAndroid Build Coastguard Worker public:
FragCoordWCase(Context & context)382*35238bceSAndroid Build Coastguard Worker FragCoordWCase(Context &context) : TestCase(context, "fragcoord_w", "gl_FragCoord.w Test")
383*35238bceSAndroid Build Coastguard Worker {
384*35238bceSAndroid Build Coastguard Worker }
385*35238bceSAndroid Build Coastguard Worker
iterate(void)386*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void)
387*35238bceSAndroid Build Coastguard Worker {
388*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
389*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
390*35238bceSAndroid Build Coastguard Worker const int width = m_context.getRenderTarget().getWidth();
391*35238bceSAndroid Build Coastguard Worker const int height = m_context.getRenderTarget().getHeight();
392*35238bceSAndroid Build Coastguard Worker const tcu::RGBA threshold =
393*35238bceSAndroid Build Coastguard Worker tcu::RGBA(1, 1, 1, 1) + m_context.getRenderTarget().getPixelFormat().getColorThreshold();
394*35238bceSAndroid Build Coastguard Worker
395*35238bceSAndroid Build Coastguard Worker tcu::Surface testImg(width, height);
396*35238bceSAndroid Build Coastguard Worker tcu::Surface refImg(width, height);
397*35238bceSAndroid Build Coastguard Worker
398*35238bceSAndroid Build Coastguard Worker const float w[4] = {1.7f, 2.0f, 1.2f, 1.0f};
399*35238bceSAndroid Build Coastguard Worker
400*35238bceSAndroid Build Coastguard Worker const glu::ShaderProgram program(
401*35238bceSAndroid Build Coastguard Worker m_context.getRenderContext(),
402*35238bceSAndroid Build Coastguard Worker glu::makeVtxFragSources("#version 300 es\n"
403*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
404*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
405*35238bceSAndroid Build Coastguard Worker "{\n"
406*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
407*35238bceSAndroid Build Coastguard Worker "}\n",
408*35238bceSAndroid Build Coastguard Worker
409*35238bceSAndroid Build Coastguard Worker "#version 300 es\n"
410*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 o_color;\n"
411*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
412*35238bceSAndroid Build Coastguard Worker "{\n"
413*35238bceSAndroid Build Coastguard Worker " o_color = vec4(0.0, 1.0/gl_FragCoord.w - 1.0, 0.0, 1.0);\n"
414*35238bceSAndroid Build Coastguard Worker "}\n"));
415*35238bceSAndroid Build Coastguard Worker
416*35238bceSAndroid Build Coastguard Worker log << program;
417*35238bceSAndroid Build Coastguard Worker
418*35238bceSAndroid Build Coastguard Worker if (!program.isOk())
419*35238bceSAndroid Build Coastguard Worker throw tcu::TestError("Compile failed");
420*35238bceSAndroid Build Coastguard Worker
421*35238bceSAndroid Build Coastguard Worker // Draw with GL.
422*35238bceSAndroid Build Coastguard Worker {
423*35238bceSAndroid Build Coastguard Worker const float positions[] = {-w[0], w[0], 0.0f, w[0], -w[1], -w[1], 0.0f, w[1],
424*35238bceSAndroid Build Coastguard Worker w[2], w[2], 0.0f, w[2], w[3], -w[3], 0.0f, w[3]};
425*35238bceSAndroid Build Coastguard Worker const uint16_t indices[] = {0, 1, 2, 2, 1, 3};
426*35238bceSAndroid Build Coastguard Worker
427*35238bceSAndroid Build Coastguard Worker glu::VertexArrayBinding posBinding = glu::va::Float("a_position", 4, 4, 0, &positions[0]);
428*35238bceSAndroid Build Coastguard Worker
429*35238bceSAndroid Build Coastguard Worker gl.useProgram(program.getProgram());
430*35238bceSAndroid Build Coastguard Worker
431*35238bceSAndroid Build Coastguard Worker glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding,
432*35238bceSAndroid Build Coastguard Worker glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indices), &indices[0]));
433*35238bceSAndroid Build Coastguard Worker
434*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), 0, 0, testImg.getAccess());
435*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
436*35238bceSAndroid Build Coastguard Worker }
437*35238bceSAndroid Build Coastguard Worker
438*35238bceSAndroid Build Coastguard Worker // Draw reference
439*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < refImg.getHeight(); y++)
440*35238bceSAndroid Build Coastguard Worker {
441*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < refImg.getWidth(); x++)
442*35238bceSAndroid Build Coastguard Worker {
443*35238bceSAndroid Build Coastguard Worker const float xf = (float(x) + .5f) / float(refImg.getWidth());
444*35238bceSAndroid Build Coastguard Worker const float yf = (float(refImg.getHeight() - y - 1) + .5f) / float(refImg.getHeight());
445*35238bceSAndroid Build Coastguard Worker const float oow =
446*35238bceSAndroid Build Coastguard Worker ((xf + yf) < 1.0f) ?
447*35238bceSAndroid Build Coastguard Worker projectedTriInterpolate(tcu::Vec3(w[0], w[1], w[2]), tcu::Vec3(w[0], w[1], w[2]), xf, yf) :
448*35238bceSAndroid Build Coastguard Worker projectedTriInterpolate(tcu::Vec3(w[3], w[2], w[1]), tcu::Vec3(w[3], w[2], w[1]), 1.0f - xf,
449*35238bceSAndroid Build Coastguard Worker 1.0f - yf);
450*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color(0.0f, oow - 1.0f, 0.0f, 1.0f);
451*35238bceSAndroid Build Coastguard Worker
452*35238bceSAndroid Build Coastguard Worker refImg.setPixel(x, y, tcu::RGBA(color));
453*35238bceSAndroid Build Coastguard Worker }
454*35238bceSAndroid Build Coastguard Worker }
455*35238bceSAndroid Build Coastguard Worker
456*35238bceSAndroid Build Coastguard Worker // Compare
457*35238bceSAndroid Build Coastguard Worker {
458*35238bceSAndroid Build Coastguard Worker bool isOk = tcu::pixelThresholdCompare(log, "Result", "Image comparison result", refImg, testImg, threshold,
459*35238bceSAndroid Build Coastguard Worker tcu::COMPARE_LOG_RESULT);
460*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
461*35238bceSAndroid Build Coastguard Worker isOk ? "Pass" : "Image comparison failed");
462*35238bceSAndroid Build Coastguard Worker }
463*35238bceSAndroid Build Coastguard Worker
464*35238bceSAndroid Build Coastguard Worker return STOP;
465*35238bceSAndroid Build Coastguard Worker }
466*35238bceSAndroid Build Coastguard Worker };
467*35238bceSAndroid Build Coastguard Worker
468*35238bceSAndroid Build Coastguard Worker class PointCoordCase : public TestCase
469*35238bceSAndroid Build Coastguard Worker {
470*35238bceSAndroid Build Coastguard Worker public:
PointCoordCase(Context & context)471*35238bceSAndroid Build Coastguard Worker PointCoordCase(Context &context) : TestCase(context, "pointcoord", "gl_PointCoord Test")
472*35238bceSAndroid Build Coastguard Worker {
473*35238bceSAndroid Build Coastguard Worker }
474*35238bceSAndroid Build Coastguard Worker
iterate(void)475*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void)
476*35238bceSAndroid Build Coastguard Worker {
477*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
478*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
479*35238bceSAndroid Build Coastguard Worker const int width = de::min(256, m_context.getRenderTarget().getWidth());
480*35238bceSAndroid Build Coastguard Worker const int height = de::min(256, m_context.getRenderTarget().getHeight());
481*35238bceSAndroid Build Coastguard Worker const float threshold = 0.02f;
482*35238bceSAndroid Build Coastguard Worker
483*35238bceSAndroid Build Coastguard Worker const int numPoints = 8;
484*35238bceSAndroid Build Coastguard Worker
485*35238bceSAndroid Build Coastguard Worker vector<tcu::Vec3> coords(numPoints);
486*35238bceSAndroid Build Coastguard Worker float pointSizeRange[2] = {0.0f, 0.0f};
487*35238bceSAndroid Build Coastguard Worker
488*35238bceSAndroid Build Coastguard Worker de::Random rnd(0x145fa);
489*35238bceSAndroid Build Coastguard Worker tcu::Surface testImg(width, height);
490*35238bceSAndroid Build Coastguard Worker tcu::Surface refImg(width, height);
491*35238bceSAndroid Build Coastguard Worker
492*35238bceSAndroid Build Coastguard Worker gl.getFloatv(GL_ALIASED_POINT_SIZE_RANGE, &pointSizeRange[0]);
493*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE)");
494*35238bceSAndroid Build Coastguard Worker
495*35238bceSAndroid Build Coastguard Worker if (pointSizeRange[0] <= 0.0f || pointSizeRange[1] <= 0.0f || pointSizeRange[1] < pointSizeRange[0])
496*35238bceSAndroid Build Coastguard Worker throw tcu::TestError("Invalid GL_ALIASED_POINT_SIZE_RANGE");
497*35238bceSAndroid Build Coastguard Worker
498*35238bceSAndroid Build Coastguard Worker // Compute coordinates.
499*35238bceSAndroid Build Coastguard Worker {
500*35238bceSAndroid Build Coastguard Worker
501*35238bceSAndroid Build Coastguard Worker for (vector<tcu::Vec3>::iterator coord = coords.begin(); coord != coords.end(); ++coord)
502*35238bceSAndroid Build Coastguard Worker {
503*35238bceSAndroid Build Coastguard Worker coord->x() = rnd.getFloat(-0.9f, 0.9f);
504*35238bceSAndroid Build Coastguard Worker coord->y() = rnd.getFloat(-0.9f, 0.9f);
505*35238bceSAndroid Build Coastguard Worker coord->z() = rnd.getFloat(pointSizeRange[0], pointSizeRange[1]);
506*35238bceSAndroid Build Coastguard Worker }
507*35238bceSAndroid Build Coastguard Worker }
508*35238bceSAndroid Build Coastguard Worker
509*35238bceSAndroid Build Coastguard Worker const glu::ShaderProgram program(
510*35238bceSAndroid Build Coastguard Worker m_context.getRenderContext(),
511*35238bceSAndroid Build Coastguard Worker glu::makeVtxFragSources("#version 300 es\n"
512*35238bceSAndroid Build Coastguard Worker "in highp vec3 a_positionSize;\n"
513*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
514*35238bceSAndroid Build Coastguard Worker "{\n"
515*35238bceSAndroid Build Coastguard Worker " gl_Position = vec4(a_positionSize.xy, 0.0, 1.0);\n"
516*35238bceSAndroid Build Coastguard Worker " gl_PointSize = a_positionSize.z;\n"
517*35238bceSAndroid Build Coastguard Worker "}\n",
518*35238bceSAndroid Build Coastguard Worker
519*35238bceSAndroid Build Coastguard Worker "#version 300 es\n"
520*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 o_color;\n"
521*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
522*35238bceSAndroid Build Coastguard Worker "{\n"
523*35238bceSAndroid Build Coastguard Worker " o_color = vec4(gl_PointCoord, 0.0, 1.0);\n"
524*35238bceSAndroid Build Coastguard Worker "}\n"));
525*35238bceSAndroid Build Coastguard Worker
526*35238bceSAndroid Build Coastguard Worker log << program;
527*35238bceSAndroid Build Coastguard Worker
528*35238bceSAndroid Build Coastguard Worker if (!program.isOk())
529*35238bceSAndroid Build Coastguard Worker throw tcu::TestError("Compile failed");
530*35238bceSAndroid Build Coastguard Worker
531*35238bceSAndroid Build Coastguard Worker // Draw with GL.
532*35238bceSAndroid Build Coastguard Worker {
533*35238bceSAndroid Build Coastguard Worker glu::VertexArrayBinding posBinding =
534*35238bceSAndroid Build Coastguard Worker glu::va::Float("a_positionSize", 3, (int)coords.size(), 0, (const float *)&coords[0]);
535*35238bceSAndroid Build Coastguard Worker const int viewportX = rnd.getInt(0, m_context.getRenderTarget().getWidth() - width);
536*35238bceSAndroid Build Coastguard Worker const int viewportY = rnd.getInt(0, m_context.getRenderTarget().getHeight() - height);
537*35238bceSAndroid Build Coastguard Worker
538*35238bceSAndroid Build Coastguard Worker gl.viewport(viewportX, viewportY, width, height);
539*35238bceSAndroid Build Coastguard Worker gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
540*35238bceSAndroid Build Coastguard Worker gl.clear(GL_COLOR_BUFFER_BIT);
541*35238bceSAndroid Build Coastguard Worker
542*35238bceSAndroid Build Coastguard Worker gl.useProgram(program.getProgram());
543*35238bceSAndroid Build Coastguard Worker
544*35238bceSAndroid Build Coastguard Worker glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding,
545*35238bceSAndroid Build Coastguard Worker glu::pr::Points((int)coords.size()));
546*35238bceSAndroid Build Coastguard Worker
547*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, testImg.getAccess());
548*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
549*35238bceSAndroid Build Coastguard Worker }
550*35238bceSAndroid Build Coastguard Worker
551*35238bceSAndroid Build Coastguard Worker // Draw reference
552*35238bceSAndroid Build Coastguard Worker tcu::clear(refImg.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
553*35238bceSAndroid Build Coastguard Worker for (vector<tcu::Vec3>::const_iterator pointIter = coords.begin(); pointIter != coords.end(); ++pointIter)
554*35238bceSAndroid Build Coastguard Worker {
555*35238bceSAndroid Build Coastguard Worker const int x0 = deRoundFloatToInt32(float(width) * (pointIter->x() * 0.5f + 0.5f) - pointIter->z() * 0.5f);
556*35238bceSAndroid Build Coastguard Worker const int y0 = deRoundFloatToInt32(float(height) * (pointIter->y() * 0.5f + 0.5f) - pointIter->z() * 0.5f);
557*35238bceSAndroid Build Coastguard Worker const int x1 = deRoundFloatToInt32(float(width) * (pointIter->x() * 0.5f + 0.5f) + pointIter->z() * 0.5f);
558*35238bceSAndroid Build Coastguard Worker const int y1 = deRoundFloatToInt32(float(height) * (pointIter->y() * 0.5f + 0.5f) + pointIter->z() * 0.5f);
559*35238bceSAndroid Build Coastguard Worker const int w = x1 - x0;
560*35238bceSAndroid Build Coastguard Worker const int h = y1 - y0;
561*35238bceSAndroid Build Coastguard Worker
562*35238bceSAndroid Build Coastguard Worker for (int yo = 0; yo < h; yo++)
563*35238bceSAndroid Build Coastguard Worker {
564*35238bceSAndroid Build Coastguard Worker for (int xo = 0; xo < w; xo++)
565*35238bceSAndroid Build Coastguard Worker {
566*35238bceSAndroid Build Coastguard Worker const float xf = (float(xo) + 0.5f) / float(w);
567*35238bceSAndroid Build Coastguard Worker const float yf = (float(h - yo - 1) + 0.5f) / float(h);
568*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color(xf, yf, 0.0f, 1.0f);
569*35238bceSAndroid Build Coastguard Worker const int dx = x0 + xo;
570*35238bceSAndroid Build Coastguard Worker const int dy = y0 + yo;
571*35238bceSAndroid Build Coastguard Worker
572*35238bceSAndroid Build Coastguard Worker if (de::inBounds(dx, 0, refImg.getWidth()) && de::inBounds(dy, 0, refImg.getHeight()))
573*35238bceSAndroid Build Coastguard Worker refImg.setPixel(dx, dy, tcu::RGBA(color));
574*35238bceSAndroid Build Coastguard Worker }
575*35238bceSAndroid Build Coastguard Worker }
576*35238bceSAndroid Build Coastguard Worker }
577*35238bceSAndroid Build Coastguard Worker
578*35238bceSAndroid Build Coastguard Worker // Compare
579*35238bceSAndroid Build Coastguard Worker {
580*35238bceSAndroid Build Coastguard Worker bool isOk = tcu::fuzzyCompare(log, "Result", "Image comparison result", refImg, testImg, threshold,
581*35238bceSAndroid Build Coastguard Worker tcu::COMPARE_LOG_RESULT);
582*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
583*35238bceSAndroid Build Coastguard Worker isOk ? "Pass" : "Image comparison failed");
584*35238bceSAndroid Build Coastguard Worker }
585*35238bceSAndroid Build Coastguard Worker
586*35238bceSAndroid Build Coastguard Worker return STOP;
587*35238bceSAndroid Build Coastguard Worker }
588*35238bceSAndroid Build Coastguard Worker };
589*35238bceSAndroid Build Coastguard Worker
590*35238bceSAndroid Build Coastguard Worker class FrontFacingCase : public TestCase
591*35238bceSAndroid Build Coastguard Worker {
592*35238bceSAndroid Build Coastguard Worker public:
FrontFacingCase(Context & context)593*35238bceSAndroid Build Coastguard Worker FrontFacingCase(Context &context) : TestCase(context, "frontfacing", "gl_FrontFacing Test")
594*35238bceSAndroid Build Coastguard Worker {
595*35238bceSAndroid Build Coastguard Worker }
596*35238bceSAndroid Build Coastguard Worker
iterate(void)597*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void)
598*35238bceSAndroid Build Coastguard Worker {
599*35238bceSAndroid Build Coastguard Worker // Test case renders two adjecent quads, where left is has front-facing
600*35238bceSAndroid Build Coastguard Worker // triagles and right back-facing. Color is selected based on gl_FrontFacing
601*35238bceSAndroid Build Coastguard Worker // value.
602*35238bceSAndroid Build Coastguard Worker
603*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
604*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
605*35238bceSAndroid Build Coastguard Worker de::Random rnd(0x89f2c);
606*35238bceSAndroid Build Coastguard Worker const int width = de::min(64, m_context.getRenderTarget().getWidth());
607*35238bceSAndroid Build Coastguard Worker const int height = de::min(64, m_context.getRenderTarget().getHeight());
608*35238bceSAndroid Build Coastguard Worker const int viewportX = rnd.getInt(0, m_context.getRenderTarget().getWidth() - width);
609*35238bceSAndroid Build Coastguard Worker const int viewportY = rnd.getInt(0, m_context.getRenderTarget().getHeight() - height);
610*35238bceSAndroid Build Coastguard Worker const tcu::RGBA threshold =
611*35238bceSAndroid Build Coastguard Worker tcu::RGBA(1, 1, 1, 1) + m_context.getRenderTarget().getPixelFormat().getColorThreshold();
612*35238bceSAndroid Build Coastguard Worker
613*35238bceSAndroid Build Coastguard Worker tcu::Surface testImg(width, height);
614*35238bceSAndroid Build Coastguard Worker tcu::Surface refImg(width, height);
615*35238bceSAndroid Build Coastguard Worker
616*35238bceSAndroid Build Coastguard Worker const glu::ShaderProgram program(m_context.getRenderContext(),
617*35238bceSAndroid Build Coastguard Worker glu::makeVtxFragSources("#version 300 es\n"
618*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
619*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
620*35238bceSAndroid Build Coastguard Worker "{\n"
621*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
622*35238bceSAndroid Build Coastguard Worker "}\n",
623*35238bceSAndroid Build Coastguard Worker
624*35238bceSAndroid Build Coastguard Worker "#version 300 es\n"
625*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 o_color;\n"
626*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
627*35238bceSAndroid Build Coastguard Worker "{\n"
628*35238bceSAndroid Build Coastguard Worker " if (gl_FrontFacing)\n"
629*35238bceSAndroid Build Coastguard Worker " o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
630*35238bceSAndroid Build Coastguard Worker " else\n"
631*35238bceSAndroid Build Coastguard Worker " o_color = vec4(0.0, 0.0, 1.0, 1.0);\n"
632*35238bceSAndroid Build Coastguard Worker "}\n"));
633*35238bceSAndroid Build Coastguard Worker
634*35238bceSAndroid Build Coastguard Worker log << program;
635*35238bceSAndroid Build Coastguard Worker
636*35238bceSAndroid Build Coastguard Worker if (!program.isOk())
637*35238bceSAndroid Build Coastguard Worker throw tcu::TestError("Compile failed");
638*35238bceSAndroid Build Coastguard Worker
639*35238bceSAndroid Build Coastguard Worker // Draw with GL.
640*35238bceSAndroid Build Coastguard Worker {
641*35238bceSAndroid Build Coastguard Worker const float positions[] = {-1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f,
642*35238bceSAndroid Build Coastguard Worker 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f};
643*35238bceSAndroid Build Coastguard Worker const uint16_t indicesCCW[] = {0, 1, 2, 2, 1, 3};
644*35238bceSAndroid Build Coastguard Worker const uint16_t indicesCW[] = {2, 1, 0, 3, 1, 2};
645*35238bceSAndroid Build Coastguard Worker
646*35238bceSAndroid Build Coastguard Worker glu::VertexArrayBinding posBinding = glu::va::Float("a_position", 4, 4, 0, &positions[0]);
647*35238bceSAndroid Build Coastguard Worker
648*35238bceSAndroid Build Coastguard Worker gl.useProgram(program.getProgram());
649*35238bceSAndroid Build Coastguard Worker
650*35238bceSAndroid Build Coastguard Worker gl.frontFace(GL_CCW);
651*35238bceSAndroid Build Coastguard Worker
652*35238bceSAndroid Build Coastguard Worker gl.viewport(viewportX, viewportY, width / 2, height / 2);
653*35238bceSAndroid Build Coastguard Worker glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding,
654*35238bceSAndroid Build Coastguard Worker glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indicesCCW), &indicesCCW[0]));
655*35238bceSAndroid Build Coastguard Worker
656*35238bceSAndroid Build Coastguard Worker gl.viewport(viewportX + width / 2, viewportY, width - width / 2, height / 2);
657*35238bceSAndroid Build Coastguard Worker glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding,
658*35238bceSAndroid Build Coastguard Worker glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indicesCW), &indicesCW[0]));
659*35238bceSAndroid Build Coastguard Worker
660*35238bceSAndroid Build Coastguard Worker gl.frontFace(GL_CW);
661*35238bceSAndroid Build Coastguard Worker
662*35238bceSAndroid Build Coastguard Worker gl.viewport(viewportX, viewportY + height / 2, width / 2, height - height / 2);
663*35238bceSAndroid Build Coastguard Worker glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding,
664*35238bceSAndroid Build Coastguard Worker glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indicesCCW), &indicesCCW[0]));
665*35238bceSAndroid Build Coastguard Worker
666*35238bceSAndroid Build Coastguard Worker gl.viewport(viewportX + width / 2, viewportY + height / 2, width - width / 2, height - height / 2);
667*35238bceSAndroid Build Coastguard Worker glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding,
668*35238bceSAndroid Build Coastguard Worker glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indicesCW), &indicesCW[0]));
669*35238bceSAndroid Build Coastguard Worker
670*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, testImg.getAccess());
671*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
672*35238bceSAndroid Build Coastguard Worker }
673*35238bceSAndroid Build Coastguard Worker
674*35238bceSAndroid Build Coastguard Worker // Draw reference
675*35238bceSAndroid Build Coastguard Worker {
676*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < refImg.getHeight() / 2; y++)
677*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < refImg.getWidth() / 2; x++)
678*35238bceSAndroid Build Coastguard Worker refImg.setPixel(x, y, tcu::RGBA::green());
679*35238bceSAndroid Build Coastguard Worker
680*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < refImg.getHeight() / 2; y++)
681*35238bceSAndroid Build Coastguard Worker for (int x = refImg.getWidth() / 2; x < refImg.getWidth(); x++)
682*35238bceSAndroid Build Coastguard Worker refImg.setPixel(x, y, tcu::RGBA::blue());
683*35238bceSAndroid Build Coastguard Worker
684*35238bceSAndroid Build Coastguard Worker for (int y = refImg.getHeight() / 2; y < refImg.getHeight(); y++)
685*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < refImg.getWidth() / 2; x++)
686*35238bceSAndroid Build Coastguard Worker refImg.setPixel(x, y, tcu::RGBA::blue());
687*35238bceSAndroid Build Coastguard Worker
688*35238bceSAndroid Build Coastguard Worker for (int y = refImg.getHeight() / 2; y < refImg.getHeight(); y++)
689*35238bceSAndroid Build Coastguard Worker for (int x = refImg.getWidth() / 2; x < refImg.getWidth(); x++)
690*35238bceSAndroid Build Coastguard Worker refImg.setPixel(x, y, tcu::RGBA::green());
691*35238bceSAndroid Build Coastguard Worker }
692*35238bceSAndroid Build Coastguard Worker
693*35238bceSAndroid Build Coastguard Worker // Compare
694*35238bceSAndroid Build Coastguard Worker {
695*35238bceSAndroid Build Coastguard Worker bool isOk = tcu::pixelThresholdCompare(log, "Result", "Image comparison result", refImg, testImg, threshold,
696*35238bceSAndroid Build Coastguard Worker tcu::COMPARE_LOG_RESULT);
697*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
698*35238bceSAndroid Build Coastguard Worker isOk ? "Pass" : "Image comparison failed");
699*35238bceSAndroid Build Coastguard Worker }
700*35238bceSAndroid Build Coastguard Worker
701*35238bceSAndroid Build Coastguard Worker return STOP;
702*35238bceSAndroid Build Coastguard Worker }
703*35238bceSAndroid Build Coastguard Worker };
704*35238bceSAndroid Build Coastguard Worker
705*35238bceSAndroid Build Coastguard Worker // VertexIDCase
706*35238bceSAndroid Build Coastguard Worker
707*35238bceSAndroid Build Coastguard Worker class VertexIDCase : public TestCase
708*35238bceSAndroid Build Coastguard Worker {
709*35238bceSAndroid Build Coastguard Worker public:
710*35238bceSAndroid Build Coastguard Worker VertexIDCase(Context &context);
711*35238bceSAndroid Build Coastguard Worker ~VertexIDCase(void);
712*35238bceSAndroid Build Coastguard Worker
713*35238bceSAndroid Build Coastguard Worker void init(void);
714*35238bceSAndroid Build Coastguard Worker void deinit(void);
715*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
716*35238bceSAndroid Build Coastguard Worker
717*35238bceSAndroid Build Coastguard Worker private:
718*35238bceSAndroid Build Coastguard Worker enum
719*35238bceSAndroid Build Coastguard Worker {
720*35238bceSAndroid Build Coastguard Worker MAX_VERTICES = 8 * 3 //!< 8 triangles, totals 24 vertices
721*35238bceSAndroid Build Coastguard Worker };
722*35238bceSAndroid Build Coastguard Worker
723*35238bceSAndroid Build Coastguard Worker void renderReference(const tcu::PixelBufferAccess &dst, const int numVertices, const uint16_t *const indices,
724*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 *const positions, const tcu::Vec4 *const colors, const int subpixelBits);
725*35238bceSAndroid Build Coastguard Worker
726*35238bceSAndroid Build Coastguard Worker glu::ShaderProgram *m_program;
727*35238bceSAndroid Build Coastguard Worker uint32_t m_positionBuffer;
728*35238bceSAndroid Build Coastguard Worker uint32_t m_elementBuffer;
729*35238bceSAndroid Build Coastguard Worker
730*35238bceSAndroid Build Coastguard Worker vector<tcu::Vec4> m_positions;
731*35238bceSAndroid Build Coastguard Worker vector<tcu::Vec4> m_colors;
732*35238bceSAndroid Build Coastguard Worker int m_viewportW;
733*35238bceSAndroid Build Coastguard Worker int m_viewportH;
734*35238bceSAndroid Build Coastguard Worker
735*35238bceSAndroid Build Coastguard Worker int m_iterNdx;
736*35238bceSAndroid Build Coastguard Worker };
737*35238bceSAndroid Build Coastguard Worker
VertexIDCase(Context & context)738*35238bceSAndroid Build Coastguard Worker VertexIDCase::VertexIDCase(Context &context)
739*35238bceSAndroid Build Coastguard Worker : TestCase(context, "vertex_id", "gl_VertexID Test")
740*35238bceSAndroid Build Coastguard Worker , m_program(DE_NULL)
741*35238bceSAndroid Build Coastguard Worker , m_positionBuffer(0)
742*35238bceSAndroid Build Coastguard Worker , m_elementBuffer(0)
743*35238bceSAndroid Build Coastguard Worker , m_viewportW(0)
744*35238bceSAndroid Build Coastguard Worker , m_viewportH(0)
745*35238bceSAndroid Build Coastguard Worker , m_iterNdx(0)
746*35238bceSAndroid Build Coastguard Worker {
747*35238bceSAndroid Build Coastguard Worker }
748*35238bceSAndroid Build Coastguard Worker
~VertexIDCase(void)749*35238bceSAndroid Build Coastguard Worker VertexIDCase::~VertexIDCase(void)
750*35238bceSAndroid Build Coastguard Worker {
751*35238bceSAndroid Build Coastguard Worker VertexIDCase::deinit();
752*35238bceSAndroid Build Coastguard Worker }
753*35238bceSAndroid Build Coastguard Worker
init(void)754*35238bceSAndroid Build Coastguard Worker void VertexIDCase::init(void)
755*35238bceSAndroid Build Coastguard Worker {
756*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
757*35238bceSAndroid Build Coastguard Worker const int width = m_context.getRenderTarget().getWidth();
758*35238bceSAndroid Build Coastguard Worker const int height = m_context.getRenderTarget().getHeight();
759*35238bceSAndroid Build Coastguard Worker
760*35238bceSAndroid Build Coastguard Worker const int quadWidth = 32;
761*35238bceSAndroid Build Coastguard Worker const int quadHeight = 32;
762*35238bceSAndroid Build Coastguard Worker
763*35238bceSAndroid Build Coastguard Worker if (width < quadWidth)
764*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError("Too small render target");
765*35238bceSAndroid Build Coastguard Worker
766*35238bceSAndroid Build Coastguard Worker const int maxQuadsX = width / quadWidth;
767*35238bceSAndroid Build Coastguard Worker const int numVertices = MAX_VERTICES;
768*35238bceSAndroid Build Coastguard Worker
769*35238bceSAndroid Build Coastguard Worker const int numQuads = numVertices / 6 + (numVertices % 6 != 0 ? 1 : 0);
770*35238bceSAndroid Build Coastguard Worker const int viewportW = de::min(numQuads, maxQuadsX) * quadWidth;
771*35238bceSAndroid Build Coastguard Worker const int viewportH = (numQuads / maxQuadsX + (numQuads % maxQuadsX != 0 ? 1 : 0)) * quadHeight;
772*35238bceSAndroid Build Coastguard Worker
773*35238bceSAndroid Build Coastguard Worker if (viewportH > height)
774*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError("Too small render target");
775*35238bceSAndroid Build Coastguard Worker
776*35238bceSAndroid Build Coastguard Worker DE_ASSERT(viewportW <= width && viewportH <= height);
777*35238bceSAndroid Build Coastguard Worker
778*35238bceSAndroid Build Coastguard Worker DE_ASSERT(!m_program);
779*35238bceSAndroid Build Coastguard Worker m_program = new glu::ShaderProgram(m_context.getRenderContext(),
780*35238bceSAndroid Build Coastguard Worker glu::makeVtxFragSources("#version 300 es\n"
781*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
782*35238bceSAndroid Build Coastguard Worker "out mediump vec4 v_color;\n"
783*35238bceSAndroid Build Coastguard Worker "uniform highp vec4 u_colors[24];\n"
784*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
785*35238bceSAndroid Build Coastguard Worker "{\n"
786*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
787*35238bceSAndroid Build Coastguard Worker " v_color = u_colors[gl_VertexID];\n"
788*35238bceSAndroid Build Coastguard Worker "}\n",
789*35238bceSAndroid Build Coastguard Worker
790*35238bceSAndroid Build Coastguard Worker "#version 300 es\n"
791*35238bceSAndroid Build Coastguard Worker "in mediump vec4 v_color;\n"
792*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 o_color;\n"
793*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
794*35238bceSAndroid Build Coastguard Worker "{\n"
795*35238bceSAndroid Build Coastguard Worker " o_color = v_color;\n"
796*35238bceSAndroid Build Coastguard Worker "}\n"));
797*35238bceSAndroid Build Coastguard Worker
798*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << *m_program;
799*35238bceSAndroid Build Coastguard Worker
800*35238bceSAndroid Build Coastguard Worker if (!m_program->isOk())
801*35238bceSAndroid Build Coastguard Worker {
802*35238bceSAndroid Build Coastguard Worker delete m_program;
803*35238bceSAndroid Build Coastguard Worker m_program = DE_NULL;
804*35238bceSAndroid Build Coastguard Worker throw tcu::TestError("Compile failed");
805*35238bceSAndroid Build Coastguard Worker }
806*35238bceSAndroid Build Coastguard Worker
807*35238bceSAndroid Build Coastguard Worker gl.genBuffers(1, &m_positionBuffer);
808*35238bceSAndroid Build Coastguard Worker gl.genBuffers(1, &m_elementBuffer);
809*35238bceSAndroid Build Coastguard Worker
810*35238bceSAndroid Build Coastguard Worker // Set colors (in dynamic memory to save static data space).
811*35238bceSAndroid Build Coastguard Worker m_colors.resize(numVertices);
812*35238bceSAndroid Build Coastguard Worker m_colors[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
813*35238bceSAndroid Build Coastguard Worker m_colors[1] = tcu::Vec4(0.5f, 1.0f, 0.5f, 1.0f);
814*35238bceSAndroid Build Coastguard Worker m_colors[2] = tcu::Vec4(0.0f, 0.5f, 1.0f, 1.0f);
815*35238bceSAndroid Build Coastguard Worker m_colors[3] = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
816*35238bceSAndroid Build Coastguard Worker m_colors[4] = tcu::Vec4(0.0f, 1.0f, 1.0f, 1.0f);
817*35238bceSAndroid Build Coastguard Worker m_colors[5] = tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f);
818*35238bceSAndroid Build Coastguard Worker m_colors[6] = tcu::Vec4(0.5f, 0.0f, 1.0f, 1.0f);
819*35238bceSAndroid Build Coastguard Worker m_colors[7] = tcu::Vec4(0.5f, 0.0f, 0.5f, 1.0f);
820*35238bceSAndroid Build Coastguard Worker m_colors[8] = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
821*35238bceSAndroid Build Coastguard Worker m_colors[9] = tcu::Vec4(0.5f, 1.0f, 0.0f, 1.0f);
822*35238bceSAndroid Build Coastguard Worker m_colors[10] = tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f);
823*35238bceSAndroid Build Coastguard Worker m_colors[11] = tcu::Vec4(0.5f, 1.0f, 1.0f, 1.0f);
824*35238bceSAndroid Build Coastguard Worker m_colors[12] = tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f);
825*35238bceSAndroid Build Coastguard Worker m_colors[13] = tcu::Vec4(1.0f, 0.0f, 0.5f, 1.0f);
826*35238bceSAndroid Build Coastguard Worker m_colors[14] = tcu::Vec4(0.0f, 0.5f, 0.5f, 1.0f);
827*35238bceSAndroid Build Coastguard Worker m_colors[15] = tcu::Vec4(1.0f, 1.0f, 0.5f, 1.0f);
828*35238bceSAndroid Build Coastguard Worker m_colors[16] = tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f);
829*35238bceSAndroid Build Coastguard Worker m_colors[17] = tcu::Vec4(1.0f, 0.5f, 0.0f, 1.0f);
830*35238bceSAndroid Build Coastguard Worker m_colors[18] = tcu::Vec4(0.0f, 1.0f, 0.5f, 1.0f);
831*35238bceSAndroid Build Coastguard Worker m_colors[19] = tcu::Vec4(1.0f, 0.5f, 1.0f, 1.0f);
832*35238bceSAndroid Build Coastguard Worker m_colors[20] = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
833*35238bceSAndroid Build Coastguard Worker m_colors[21] = tcu::Vec4(1.0f, 0.5f, 0.5f, 1.0f);
834*35238bceSAndroid Build Coastguard Worker m_colors[22] = tcu::Vec4(0.0f, 0.0f, 0.5f, 1.0f);
835*35238bceSAndroid Build Coastguard Worker m_colors[23] = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
836*35238bceSAndroid Build Coastguard Worker
837*35238bceSAndroid Build Coastguard Worker // Compute positions.
838*35238bceSAndroid Build Coastguard Worker m_positions.resize(numVertices);
839*35238bceSAndroid Build Coastguard Worker DE_ASSERT(numVertices % 3 == 0);
840*35238bceSAndroid Build Coastguard Worker for (int vtxNdx = 0; vtxNdx < numVertices; vtxNdx += 3)
841*35238bceSAndroid Build Coastguard Worker {
842*35238bceSAndroid Build Coastguard Worker const float h = 2.0f * float(quadHeight) / float(viewportH);
843*35238bceSAndroid Build Coastguard Worker const float w = 2.0f * float(quadWidth) / float(viewportW);
844*35238bceSAndroid Build Coastguard Worker
845*35238bceSAndroid Build Coastguard Worker const int triNdx = vtxNdx / 3;
846*35238bceSAndroid Build Coastguard Worker const int quadNdx = triNdx / 2;
847*35238bceSAndroid Build Coastguard Worker const int quadY = quadNdx / maxQuadsX;
848*35238bceSAndroid Build Coastguard Worker const int quadX = quadNdx % maxQuadsX;
849*35238bceSAndroid Build Coastguard Worker
850*35238bceSAndroid Build Coastguard Worker const float x0 = -1.0f + float(quadX) * w;
851*35238bceSAndroid Build Coastguard Worker const float y0 = -1.0f + float(quadY) * h;
852*35238bceSAndroid Build Coastguard Worker
853*35238bceSAndroid Build Coastguard Worker if (triNdx % 2 == 0)
854*35238bceSAndroid Build Coastguard Worker {
855*35238bceSAndroid Build Coastguard Worker m_positions[vtxNdx + 0] = tcu::Vec4(x0, y0, 0.0f, 1.0f);
856*35238bceSAndroid Build Coastguard Worker m_positions[vtxNdx + 1] = tcu::Vec4(x0 + w, y0 + h, 0.0f, 1.0f);
857*35238bceSAndroid Build Coastguard Worker m_positions[vtxNdx + 2] = tcu::Vec4(x0, y0 + h, 0.0f, 1.0f);
858*35238bceSAndroid Build Coastguard Worker }
859*35238bceSAndroid Build Coastguard Worker else
860*35238bceSAndroid Build Coastguard Worker {
861*35238bceSAndroid Build Coastguard Worker m_positions[vtxNdx + 0] = tcu::Vec4(x0 + w, y0 + h, 0.0f, 1.0f);
862*35238bceSAndroid Build Coastguard Worker m_positions[vtxNdx + 1] = tcu::Vec4(x0, y0, 0.0f, 1.0f);
863*35238bceSAndroid Build Coastguard Worker m_positions[vtxNdx + 2] = tcu::Vec4(x0 + w, y0, 0.0f, 1.0f);
864*35238bceSAndroid Build Coastguard Worker }
865*35238bceSAndroid Build Coastguard Worker }
866*35238bceSAndroid Build Coastguard Worker
867*35238bceSAndroid Build Coastguard Worker m_viewportW = viewportW;
868*35238bceSAndroid Build Coastguard Worker m_viewportH = viewportH;
869*35238bceSAndroid Build Coastguard Worker m_iterNdx = 0;
870*35238bceSAndroid Build Coastguard Worker
871*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
872*35238bceSAndroid Build Coastguard Worker }
873*35238bceSAndroid Build Coastguard Worker
deinit(void)874*35238bceSAndroid Build Coastguard Worker void VertexIDCase::deinit(void)
875*35238bceSAndroid Build Coastguard Worker {
876*35238bceSAndroid Build Coastguard Worker delete m_program;
877*35238bceSAndroid Build Coastguard Worker m_program = DE_NULL;
878*35238bceSAndroid Build Coastguard Worker
879*35238bceSAndroid Build Coastguard Worker if (m_positionBuffer)
880*35238bceSAndroid Build Coastguard Worker {
881*35238bceSAndroid Build Coastguard Worker m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_positionBuffer);
882*35238bceSAndroid Build Coastguard Worker m_positionBuffer = 0;
883*35238bceSAndroid Build Coastguard Worker }
884*35238bceSAndroid Build Coastguard Worker
885*35238bceSAndroid Build Coastguard Worker if (m_elementBuffer)
886*35238bceSAndroid Build Coastguard Worker {
887*35238bceSAndroid Build Coastguard Worker m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_elementBuffer);
888*35238bceSAndroid Build Coastguard Worker m_elementBuffer = 0;
889*35238bceSAndroid Build Coastguard Worker }
890*35238bceSAndroid Build Coastguard Worker
891*35238bceSAndroid Build Coastguard Worker m_positions.clear();
892*35238bceSAndroid Build Coastguard Worker m_colors.clear();
893*35238bceSAndroid Build Coastguard Worker }
894*35238bceSAndroid Build Coastguard Worker
895*35238bceSAndroid Build Coastguard Worker class VertexIDReferenceShader : public rr::VertexShader, public rr::FragmentShader
896*35238bceSAndroid Build Coastguard Worker {
897*35238bceSAndroid Build Coastguard Worker public:
898*35238bceSAndroid Build Coastguard Worker enum
899*35238bceSAndroid Build Coastguard Worker {
900*35238bceSAndroid Build Coastguard Worker VARYINGLOC_COLOR = 0
901*35238bceSAndroid Build Coastguard Worker };
902*35238bceSAndroid Build Coastguard Worker
VertexIDReferenceShader()903*35238bceSAndroid Build Coastguard Worker VertexIDReferenceShader()
904*35238bceSAndroid Build Coastguard Worker : rr::VertexShader(2, 1) // color and pos in => color out
905*35238bceSAndroid Build Coastguard Worker , rr::FragmentShader(1, 1) // color in => color out
906*35238bceSAndroid Build Coastguard Worker {
907*35238bceSAndroid Build Coastguard Worker this->rr::VertexShader::m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
908*35238bceSAndroid Build Coastguard Worker this->rr::VertexShader::m_inputs[1].type = rr::GENERICVECTYPE_FLOAT;
909*35238bceSAndroid Build Coastguard Worker
910*35238bceSAndroid Build Coastguard Worker this->rr::VertexShader::m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
911*35238bceSAndroid Build Coastguard Worker this->rr::VertexShader::m_outputs[0].flatshade = false;
912*35238bceSAndroid Build Coastguard Worker
913*35238bceSAndroid Build Coastguard Worker this->rr::FragmentShader::m_inputs[0].type = rr::GENERICVECTYPE_FLOAT;
914*35238bceSAndroid Build Coastguard Worker this->rr::FragmentShader::m_inputs[0].flatshade = false;
915*35238bceSAndroid Build Coastguard Worker
916*35238bceSAndroid Build Coastguard Worker this->rr::FragmentShader::m_outputs[0].type = rr::GENERICVECTYPE_FLOAT;
917*35238bceSAndroid Build Coastguard Worker }
918*35238bceSAndroid Build Coastguard Worker
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const919*35238bceSAndroid Build Coastguard Worker void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const
920*35238bceSAndroid Build Coastguard Worker {
921*35238bceSAndroid Build Coastguard Worker for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
922*35238bceSAndroid Build Coastguard Worker {
923*35238bceSAndroid Build Coastguard Worker const int positionAttrLoc = 0;
924*35238bceSAndroid Build Coastguard Worker const int colorAttrLoc = 1;
925*35238bceSAndroid Build Coastguard Worker
926*35238bceSAndroid Build Coastguard Worker rr::VertexPacket &packet = *packets[packetNdx];
927*35238bceSAndroid Build Coastguard Worker
928*35238bceSAndroid Build Coastguard Worker // Transform to position
929*35238bceSAndroid Build Coastguard Worker packet.position = rr::readVertexAttribFloat(inputs[positionAttrLoc], packet.instanceNdx, packet.vertexNdx);
930*35238bceSAndroid Build Coastguard Worker
931*35238bceSAndroid Build Coastguard Worker // Pass color to FS
932*35238bceSAndroid Build Coastguard Worker packet.outputs[VARYINGLOC_COLOR] =
933*35238bceSAndroid Build Coastguard Worker rr::readVertexAttribFloat(inputs[colorAttrLoc], packet.instanceNdx, packet.vertexNdx);
934*35238bceSAndroid Build Coastguard Worker }
935*35238bceSAndroid Build Coastguard Worker }
936*35238bceSAndroid Build Coastguard Worker
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const937*35238bceSAndroid Build Coastguard Worker void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
938*35238bceSAndroid Build Coastguard Worker const rr::FragmentShadingContext &context) const
939*35238bceSAndroid Build Coastguard Worker {
940*35238bceSAndroid Build Coastguard Worker for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
941*35238bceSAndroid Build Coastguard Worker {
942*35238bceSAndroid Build Coastguard Worker rr::FragmentPacket &packet = packets[packetNdx];
943*35238bceSAndroid Build Coastguard Worker
944*35238bceSAndroid Build Coastguard Worker for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
945*35238bceSAndroid Build Coastguard Worker rr::writeFragmentOutput(context, packetNdx, fragNdx, 0,
946*35238bceSAndroid Build Coastguard Worker rr::readVarying<float>(packet, context, VARYINGLOC_COLOR, fragNdx));
947*35238bceSAndroid Build Coastguard Worker }
948*35238bceSAndroid Build Coastguard Worker }
949*35238bceSAndroid Build Coastguard Worker };
950*35238bceSAndroid Build Coastguard Worker
renderReference(const tcu::PixelBufferAccess & dst,const int numVertices,const uint16_t * const indices,const tcu::Vec4 * const positions,const tcu::Vec4 * const colors,const int subpixelBits)951*35238bceSAndroid Build Coastguard Worker void VertexIDCase::renderReference(const tcu::PixelBufferAccess &dst, const int numVertices,
952*35238bceSAndroid Build Coastguard Worker const uint16_t *const indices, const tcu::Vec4 *const positions,
953*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 *const colors, const int subpixelBits)
954*35238bceSAndroid Build Coastguard Worker {
955*35238bceSAndroid Build Coastguard Worker const rr::Renderer referenceRenderer;
956*35238bceSAndroid Build Coastguard Worker const rr::RenderState referenceState(
957*35238bceSAndroid Build Coastguard Worker (rr::ViewportState)(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(dst)), subpixelBits);
958*35238bceSAndroid Build Coastguard Worker const rr::RenderTarget referenceTarget(rr::MultisamplePixelBufferAccess::fromSinglesampleAccess(dst));
959*35238bceSAndroid Build Coastguard Worker const VertexIDReferenceShader referenceShader;
960*35238bceSAndroid Build Coastguard Worker rr::VertexAttrib attribs[2];
961*35238bceSAndroid Build Coastguard Worker
962*35238bceSAndroid Build Coastguard Worker attribs[0].type = rr::VERTEXATTRIBTYPE_FLOAT;
963*35238bceSAndroid Build Coastguard Worker attribs[0].size = 4;
964*35238bceSAndroid Build Coastguard Worker attribs[0].stride = 0;
965*35238bceSAndroid Build Coastguard Worker attribs[0].instanceDivisor = 0;
966*35238bceSAndroid Build Coastguard Worker attribs[0].pointer = positions;
967*35238bceSAndroid Build Coastguard Worker
968*35238bceSAndroid Build Coastguard Worker attribs[1].type = rr::VERTEXATTRIBTYPE_FLOAT;
969*35238bceSAndroid Build Coastguard Worker attribs[1].size = 4;
970*35238bceSAndroid Build Coastguard Worker attribs[1].stride = 0;
971*35238bceSAndroid Build Coastguard Worker attribs[1].instanceDivisor = 0;
972*35238bceSAndroid Build Coastguard Worker attribs[1].pointer = colors;
973*35238bceSAndroid Build Coastguard Worker
974*35238bceSAndroid Build Coastguard Worker referenceRenderer.draw(
975*35238bceSAndroid Build Coastguard Worker rr::DrawCommand(referenceState, referenceTarget, rr::Program(&referenceShader, &referenceShader), 2, attribs,
976*35238bceSAndroid Build Coastguard Worker rr::PrimitiveList(rr::PRIMITIVETYPE_TRIANGLES, numVertices, rr::DrawIndices(indices))));
977*35238bceSAndroid Build Coastguard Worker }
978*35238bceSAndroid Build Coastguard Worker
iterate(void)979*35238bceSAndroid Build Coastguard Worker VertexIDCase::IterateResult VertexIDCase::iterate(void)
980*35238bceSAndroid Build Coastguard Worker {
981*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
982*35238bceSAndroid Build Coastguard Worker const int width = m_context.getRenderTarget().getWidth();
983*35238bceSAndroid Build Coastguard Worker const int height = m_context.getRenderTarget().getHeight();
984*35238bceSAndroid Build Coastguard Worker const int viewportW = m_viewportW;
985*35238bceSAndroid Build Coastguard Worker const int viewportH = m_viewportH;
986*35238bceSAndroid Build Coastguard Worker
987*35238bceSAndroid Build Coastguard Worker const float threshold = 0.02f;
988*35238bceSAndroid Build Coastguard Worker
989*35238bceSAndroid Build Coastguard Worker de::Random rnd(0xcf23ab1 ^ deInt32Hash(m_iterNdx));
990*35238bceSAndroid Build Coastguard Worker tcu::Surface refImg(viewportW, viewportH);
991*35238bceSAndroid Build Coastguard Worker tcu::Surface testImg(viewportW, viewportH);
992*35238bceSAndroid Build Coastguard Worker
993*35238bceSAndroid Build Coastguard Worker const int viewportX = rnd.getInt(0, width - viewportW);
994*35238bceSAndroid Build Coastguard Worker const int viewportY = rnd.getInt(0, height - viewportH);
995*35238bceSAndroid Build Coastguard Worker
996*35238bceSAndroid Build Coastguard Worker const int posLoc = gl.getAttribLocation(m_program->getProgram(), "a_position");
997*35238bceSAndroid Build Coastguard Worker const int colorsLoc = gl.getUniformLocation(m_program->getProgram(), "u_colors[0]");
998*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 clearColor(0.0f, 0.0f, 0.0f, 1.0f);
999*35238bceSAndroid Build Coastguard Worker
1000*35238bceSAndroid Build Coastguard Worker // Setup common state.
1001*35238bceSAndroid Build Coastguard Worker gl.viewport(viewportX, viewportY, viewportW, viewportH);
1002*35238bceSAndroid Build Coastguard Worker gl.useProgram(m_program->getProgram());
1003*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_ARRAY_BUFFER, m_positionBuffer);
1004*35238bceSAndroid Build Coastguard Worker gl.enableVertexAttribArray(posLoc);
1005*35238bceSAndroid Build Coastguard Worker gl.vertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
1006*35238bceSAndroid Build Coastguard Worker gl.uniform4fv(colorsLoc, (int)m_colors.size(), (const float *)&m_colors[0]);
1007*35238bceSAndroid Build Coastguard Worker
1008*35238bceSAndroid Build Coastguard Worker // Clear render target to black.
1009*35238bceSAndroid Build Coastguard Worker gl.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
1010*35238bceSAndroid Build Coastguard Worker gl.clear(GL_COLOR_BUFFER_BIT);
1011*35238bceSAndroid Build Coastguard Worker
1012*35238bceSAndroid Build Coastguard Worker tcu::clear(refImg.getAccess(), clearColor);
1013*35238bceSAndroid Build Coastguard Worker
1014*35238bceSAndroid Build Coastguard Worker int subpixelBits = 0;
1015*35238bceSAndroid Build Coastguard Worker gl.getIntegerv(GL_SUBPIXEL_BITS, &subpixelBits);
1016*35238bceSAndroid Build Coastguard Worker
1017*35238bceSAndroid Build Coastguard Worker if (m_iterNdx == 0)
1018*35238bceSAndroid Build Coastguard Worker {
1019*35238bceSAndroid Build Coastguard Worker tcu::ScopedLogSection logSection(m_testCtx.getLog(), "Iter0", "glDrawArrays()");
1020*35238bceSAndroid Build Coastguard Worker vector<uint16_t> indices(m_positions.size());
1021*35238bceSAndroid Build Coastguard Worker
1022*35238bceSAndroid Build Coastguard Worker gl.bufferData(GL_ARRAY_BUFFER, (int)(m_positions.size() * sizeof(tcu::Vec4)), &m_positions[0], GL_DYNAMIC_DRAW);
1023*35238bceSAndroid Build Coastguard Worker gl.drawArrays(GL_TRIANGLES, 0, (int)m_positions.size());
1024*35238bceSAndroid Build Coastguard Worker
1025*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, testImg.getAccess());
1026*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
1027*35238bceSAndroid Build Coastguard Worker
1028*35238bceSAndroid Build Coastguard Worker // Reference indices
1029*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < (int)indices.size(); ndx++)
1030*35238bceSAndroid Build Coastguard Worker indices[ndx] = (uint16_t)ndx;
1031*35238bceSAndroid Build Coastguard Worker
1032*35238bceSAndroid Build Coastguard Worker renderReference(refImg.getAccess(), (int)m_positions.size(), &indices[0], &m_positions[0], &m_colors[0],
1033*35238bceSAndroid Build Coastguard Worker subpixelBits);
1034*35238bceSAndroid Build Coastguard Worker }
1035*35238bceSAndroid Build Coastguard Worker else if (m_iterNdx == 1)
1036*35238bceSAndroid Build Coastguard Worker {
1037*35238bceSAndroid Build Coastguard Worker tcu::ScopedLogSection logSection(m_testCtx.getLog(), "Iter1", "glDrawElements(), indices in client-side array");
1038*35238bceSAndroid Build Coastguard Worker vector<uint16_t> indices(m_positions.size());
1039*35238bceSAndroid Build Coastguard Worker vector<tcu::Vec4> mappedPos(m_positions.size());
1040*35238bceSAndroid Build Coastguard Worker
1041*35238bceSAndroid Build Coastguard Worker // Compute initial indices and suffle
1042*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < (int)indices.size(); ndx++)
1043*35238bceSAndroid Build Coastguard Worker indices[ndx] = (uint16_t)ndx;
1044*35238bceSAndroid Build Coastguard Worker rnd.shuffle(indices.begin(), indices.end());
1045*35238bceSAndroid Build Coastguard Worker
1046*35238bceSAndroid Build Coastguard Worker // Use indices to re-map positions.
1047*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < (int)indices.size(); ndx++)
1048*35238bceSAndroid Build Coastguard Worker mappedPos[indices[ndx]] = m_positions[ndx];
1049*35238bceSAndroid Build Coastguard Worker
1050*35238bceSAndroid Build Coastguard Worker gl.bufferData(GL_ARRAY_BUFFER, (int)(m_positions.size() * sizeof(tcu::Vec4)), &mappedPos[0], GL_DYNAMIC_DRAW);
1051*35238bceSAndroid Build Coastguard Worker gl.drawElements(GL_TRIANGLES, (int)indices.size(), GL_UNSIGNED_SHORT, &indices[0]);
1052*35238bceSAndroid Build Coastguard Worker
1053*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, testImg.getAccess());
1054*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
1055*35238bceSAndroid Build Coastguard Worker
1056*35238bceSAndroid Build Coastguard Worker renderReference(refImg.getAccess(), (int)indices.size(), &indices[0], &mappedPos[0], &m_colors[0],
1057*35238bceSAndroid Build Coastguard Worker subpixelBits);
1058*35238bceSAndroid Build Coastguard Worker }
1059*35238bceSAndroid Build Coastguard Worker else if (m_iterNdx == 2)
1060*35238bceSAndroid Build Coastguard Worker {
1061*35238bceSAndroid Build Coastguard Worker tcu::ScopedLogSection logSection(m_testCtx.getLog(), "Iter2", "glDrawElements(), indices in buffer");
1062*35238bceSAndroid Build Coastguard Worker vector<uint16_t> indices(m_positions.size());
1063*35238bceSAndroid Build Coastguard Worker vector<tcu::Vec4> mappedPos(m_positions.size());
1064*35238bceSAndroid Build Coastguard Worker
1065*35238bceSAndroid Build Coastguard Worker // Compute initial indices and suffle
1066*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < (int)indices.size(); ndx++)
1067*35238bceSAndroid Build Coastguard Worker indices[ndx] = (uint16_t)ndx;
1068*35238bceSAndroid Build Coastguard Worker rnd.shuffle(indices.begin(), indices.end());
1069*35238bceSAndroid Build Coastguard Worker
1070*35238bceSAndroid Build Coastguard Worker // Use indices to re-map positions.
1071*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < (int)indices.size(); ndx++)
1072*35238bceSAndroid Build Coastguard Worker mappedPos[indices[ndx]] = m_positions[ndx];
1073*35238bceSAndroid Build Coastguard Worker
1074*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuffer);
1075*35238bceSAndroid Build Coastguard Worker gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, (int)(indices.size() * sizeof(uint16_t)), &indices[0], GL_DYNAMIC_DRAW);
1076*35238bceSAndroid Build Coastguard Worker
1077*35238bceSAndroid Build Coastguard Worker gl.bufferData(GL_ARRAY_BUFFER, (int)(m_positions.size() * sizeof(tcu::Vec4)), &mappedPos[0], GL_DYNAMIC_DRAW);
1078*35238bceSAndroid Build Coastguard Worker gl.drawElements(GL_TRIANGLES, (int)indices.size(), GL_UNSIGNED_SHORT, DE_NULL);
1079*35238bceSAndroid Build Coastguard Worker
1080*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, testImg.getAccess());
1081*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
1082*35238bceSAndroid Build Coastguard Worker
1083*35238bceSAndroid Build Coastguard Worker tcu::clear(refImg.getAccess(), clearColor);
1084*35238bceSAndroid Build Coastguard Worker renderReference(refImg.getAccess(), (int)indices.size(), &indices[0], &mappedPos[0], &m_colors[0],
1085*35238bceSAndroid Build Coastguard Worker subpixelBits);
1086*35238bceSAndroid Build Coastguard Worker }
1087*35238bceSAndroid Build Coastguard Worker else
1088*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1089*35238bceSAndroid Build Coastguard Worker
1090*35238bceSAndroid Build Coastguard Worker if (!tcu::fuzzyCompare(m_testCtx.getLog(), "Result", "Image comparison result", refImg, testImg, threshold,
1091*35238bceSAndroid Build Coastguard Worker tcu::COMPARE_LOG_RESULT))
1092*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
1093*35238bceSAndroid Build Coastguard Worker
1094*35238bceSAndroid Build Coastguard Worker m_iterNdx += 1;
1095*35238bceSAndroid Build Coastguard Worker return (m_iterNdx < 3) ? CONTINUE : STOP;
1096*35238bceSAndroid Build Coastguard Worker }
1097*35238bceSAndroid Build Coastguard Worker
ShaderBuiltinVarTests(Context & context)1098*35238bceSAndroid Build Coastguard Worker ShaderBuiltinVarTests::ShaderBuiltinVarTests(Context &context)
1099*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(context, "builtin_variable", "Built-in Variable Tests")
1100*35238bceSAndroid Build Coastguard Worker {
1101*35238bceSAndroid Build Coastguard Worker }
1102*35238bceSAndroid Build Coastguard Worker
~ShaderBuiltinVarTests(void)1103*35238bceSAndroid Build Coastguard Worker ShaderBuiltinVarTests::~ShaderBuiltinVarTests(void)
1104*35238bceSAndroid Build Coastguard Worker {
1105*35238bceSAndroid Build Coastguard Worker }
1106*35238bceSAndroid Build Coastguard Worker
init(void)1107*35238bceSAndroid Build Coastguard Worker void ShaderBuiltinVarTests::init(void)
1108*35238bceSAndroid Build Coastguard Worker {
1109*35238bceSAndroid Build Coastguard Worker // Builtin constants.
1110*35238bceSAndroid Build Coastguard Worker
1111*35238bceSAndroid Build Coastguard Worker static const struct
1112*35238bceSAndroid Build Coastguard Worker {
1113*35238bceSAndroid Build Coastguard Worker const char *caseName;
1114*35238bceSAndroid Build Coastguard Worker const char *varName;
1115*35238bceSAndroid Build Coastguard Worker ShaderBuiltinConstantCase::GetConstantValueFunc getValue;
1116*35238bceSAndroid Build Coastguard Worker } builtinConstants[] = {
1117*35238bceSAndroid Build Coastguard Worker // GLES 2.
1118*35238bceSAndroid Build Coastguard Worker
1119*35238bceSAndroid Build Coastguard Worker {"max_vertex_attribs", "gl_MaxVertexAttribs", getInteger<GL_MAX_VERTEX_ATTRIBS>},
1120*35238bceSAndroid Build Coastguard Worker {"max_vertex_uniform_vectors", "gl_MaxVertexUniformVectors", getInteger<GL_MAX_VERTEX_UNIFORM_VECTORS>},
1121*35238bceSAndroid Build Coastguard Worker {"max_fragment_uniform_vectors", "gl_MaxFragmentUniformVectors", getInteger<GL_MAX_FRAGMENT_UNIFORM_VECTORS>},
1122*35238bceSAndroid Build Coastguard Worker {"max_texture_image_units", "gl_MaxTextureImageUnits", getInteger<GL_MAX_TEXTURE_IMAGE_UNITS>},
1123*35238bceSAndroid Build Coastguard Worker {"max_vertex_texture_image_units", "gl_MaxVertexTextureImageUnits",
1124*35238bceSAndroid Build Coastguard Worker getInteger<GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS>},
1125*35238bceSAndroid Build Coastguard Worker {"max_combined_texture_image_units", "gl_MaxCombinedTextureImageUnits",
1126*35238bceSAndroid Build Coastguard Worker getInteger<GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS>},
1127*35238bceSAndroid Build Coastguard Worker {"max_draw_buffers", "gl_MaxDrawBuffers", getInteger<GL_MAX_DRAW_BUFFERS>},
1128*35238bceSAndroid Build Coastguard Worker
1129*35238bceSAndroid Build Coastguard Worker // GLES 3.
1130*35238bceSAndroid Build Coastguard Worker
1131*35238bceSAndroid Build Coastguard Worker {"max_vertex_output_vectors", "gl_MaxVertexOutputVectors",
1132*35238bceSAndroid Build Coastguard Worker getVectorsFromComps<GL_MAX_VERTEX_OUTPUT_COMPONENTS>},
1133*35238bceSAndroid Build Coastguard Worker {"max_fragment_input_vectors", "gl_MaxFragmentInputVectors",
1134*35238bceSAndroid Build Coastguard Worker getVectorsFromComps<GL_MAX_FRAGMENT_INPUT_COMPONENTS>},
1135*35238bceSAndroid Build Coastguard Worker {"min_program_texel_offset", "gl_MinProgramTexelOffset", getInteger<GL_MIN_PROGRAM_TEXEL_OFFSET>},
1136*35238bceSAndroid Build Coastguard Worker {"max_program_texel_offset", "gl_MaxProgramTexelOffset", getInteger<GL_MAX_PROGRAM_TEXEL_OFFSET>}};
1137*35238bceSAndroid Build Coastguard Worker
1138*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(builtinConstants); ndx++)
1139*35238bceSAndroid Build Coastguard Worker {
1140*35238bceSAndroid Build Coastguard Worker const char *const caseName = builtinConstants[ndx].caseName;
1141*35238bceSAndroid Build Coastguard Worker const char *const varName = builtinConstants[ndx].varName;
1142*35238bceSAndroid Build Coastguard Worker const ShaderBuiltinConstantCase::GetConstantValueFunc getValue = builtinConstants[ndx].getValue;
1143*35238bceSAndroid Build Coastguard Worker
1144*35238bceSAndroid Build Coastguard Worker addChild(new ShaderBuiltinConstantCase(m_context, (string(caseName) + "_vertex").c_str(), varName, varName,
1145*35238bceSAndroid Build Coastguard Worker getValue, glu::SHADERTYPE_VERTEX));
1146*35238bceSAndroid Build Coastguard Worker addChild(new ShaderBuiltinConstantCase(m_context, (string(caseName) + "_fragment").c_str(), varName, varName,
1147*35238bceSAndroid Build Coastguard Worker getValue, glu::SHADERTYPE_FRAGMENT));
1148*35238bceSAndroid Build Coastguard Worker }
1149*35238bceSAndroid Build Coastguard Worker
1150*35238bceSAndroid Build Coastguard Worker addChild(new ShaderDepthRangeTest(m_context, "depth_range_vertex", "gl_DepthRange", true));
1151*35238bceSAndroid Build Coastguard Worker addChild(new ShaderDepthRangeTest(m_context, "depth_range_fragment", "gl_DepthRange", false));
1152*35238bceSAndroid Build Coastguard Worker
1153*35238bceSAndroid Build Coastguard Worker // Vertex shader builtin variables.
1154*35238bceSAndroid Build Coastguard Worker addChild(new VertexIDCase(m_context));
1155*35238bceSAndroid Build Coastguard Worker // \todo [2013-03-20 pyry] gl_InstanceID -- tested in instancing tests quite thoroughly.
1156*35238bceSAndroid Build Coastguard Worker
1157*35238bceSAndroid Build Coastguard Worker // Fragment shader builtin variables.
1158*35238bceSAndroid Build Coastguard Worker
1159*35238bceSAndroid Build Coastguard Worker addChild(new FragCoordXYZCase(m_context));
1160*35238bceSAndroid Build Coastguard Worker addChild(new FragCoordWCase(m_context));
1161*35238bceSAndroid Build Coastguard Worker addChild(new PointCoordCase(m_context));
1162*35238bceSAndroid Build Coastguard Worker addChild(new FrontFacingCase(m_context));
1163*35238bceSAndroid Build Coastguard Worker }
1164*35238bceSAndroid Build Coastguard Worker
1165*35238bceSAndroid Build Coastguard Worker } // namespace Functional
1166*35238bceSAndroid Build Coastguard Worker } // namespace gles3
1167*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1168