1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL (ES) Module
3 * -----------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Utilities for tests with gls::LongStressCase.
22 *//*--------------------------------------------------------------------*/
24 #include "glsLongStressTestUtil.hpp"
25 #include "tcuStringTemplate.hpp"
26 #include "deStringUtil.hpp"
44 namespace LongStressTestUtil
48 static tcu::Matrix<float, Size, Size> translationMat (const float v)
50 tcu::Matrix<float, Size, Size> res(1.0f);
51 tcu::Vector<float, Size> col(v);
53 res.setColumn(Size-1, col);
57 // Specializes certain template patterns in templ for GLSL version m_glslVersion; params in additionalParams (optional) are also included in the substitution.
58 string ProgramLibrary::substitute (const string& templ, const map<string, string>& additionalParams) const
60 const bool isGLSL3 = m_glslVersion == glu::GLSL_VERSION_300_ES;
61 map<string, string> params;
63 params["FRAG_HEADER"] = isGLSL3 ? "#version 300 es\nlayout(location = 0) out mediump vec4 dEQP_FragColor;\n" : "";
64 params["VTX_HEADER"] = isGLSL3 ? "#version 300 es\n" : "";
65 params["VTX_IN"] = isGLSL3 ? "in" : "attribute";
66 params["VTX_OUT"] = isGLSL3 ? "out" : "varying";
67 params["FRAG_IN"] = isGLSL3 ? "in" : "varying";
68 params["FRAG_COLOR"] = isGLSL3 ? "dEQP_FragColor" : "gl_FragColor";
69 params["TEXTURE_2D_FUNC"] = isGLSL3 ? "texture" : "texture2D";
70 params["NS"] = "${NS}"; // \note Keep these as-is, they're handled by StressCase.
72 params.insert(additionalParams.begin(), additionalParams.end());
74 return tcu::StringTemplate(templ.c_str()).specialize(params);
77 string ProgramLibrary::substitute (const std::string& templ) const
79 return substitute(templ, map<string, string>());
82 ProgramLibrary::ProgramLibrary (const glu::GLSLVersion glslVersion)
83 : m_glslVersion (glslVersion)
85 DE_ASSERT(glslVersion == glu::GLSL_VERSION_100_ES || glslVersion == glu::GLSL_VERSION_300_ES);
88 gls::ProgramContext ProgramLibrary::generateBufferContext (const int numDummyAttributes) const
90 static const char* const vertexTemplate =
92 "${VTX_IN} highp vec3 a_position;\n"
94 "${VTX_OUT} mediump vec4 v_color;\n"
98 " gl_Position = vec4(a_position, 1.0);\n"
99 " v_color = ${VTX_COLOR_EXPRESSION};\n"
102 static const char* const fragmentTemplate =
104 "${FRAG_IN} mediump vec4 v_color;\n"
108 " ${FRAG_COLOR} = v_color;\n"
111 map<string, string> firstLevelParams;
114 string vtxDummyInputs;
116 for (int i = 0; i < numDummyAttributes; i++)
118 vtxDummyInputs += "${VTX_IN} mediump vec4 a_in" + toString(i) + ";\n";
119 vtxColorExpr += string() + (i > 0 ? " + " : "") + "a_in" + toString(i);
122 firstLevelParams["VTX_DUMMY_INPUTS"] = substitute(vtxDummyInputs);
123 firstLevelParams["VTX_COLOR_EXPRESSION"] = vtxColorExpr;
126 gls::ProgramContext context(substitute(vertexTemplate, firstLevelParams).c_str(), substitute(fragmentTemplate).c_str(), "a_position");
128 context.attributes.push_back(gls::VarSpec("a_position", Vec3(-0.1f), Vec3(0.1f)));
130 for (int i = 0; i < numDummyAttributes; i++)
131 context.attributes.push_back(gls::VarSpec("a_in" + de::toString(i), Vec4(0.0f), Vec4(1.0f / (float)numDummyAttributes)));
136 gls::ProgramContext ProgramLibrary::generateTextureContext (const int numTextures, const int texWid, const int texHei, const float positionFactor) const
138 static const char* const vertexTemplate =
140 "${VTX_IN} highp vec3 a_position;\n"
141 "${VTX_IN} mediump vec2 a_texCoord;\n"
142 "${VTX_OUT} mediump vec2 v_texCoord;\n"
143 "uniform mediump mat4 u_posTrans;\n"
147 " gl_Position = u_posTrans * vec4(a_position, 1.0);\n"
148 " v_texCoord = a_texCoord;\n"
151 static const char* const fragmentTemplate =
153 "${FRAG_IN} mediump vec2 v_texCoord;\n"
154 "uniform mediump sampler2D u_sampler;\n"
158 " ${FRAG_COLOR} = ${TEXTURE_2D_FUNC}(u_sampler, v_texCoord);\n"
161 gls::ProgramContext context(substitute(vertexTemplate).c_str(), substitute(fragmentTemplate).c_str(), "a_position");
163 context.attributes.push_back(gls::VarSpec("a_position", Vec3(-positionFactor), Vec3(positionFactor)));
164 context.attributes.push_back(gls::VarSpec("a_texCoord", Vec2(0.0f), Vec2(1.0f)));
166 context.uniforms.push_back(gls::VarSpec("u_sampler", 0));
167 context.uniforms.push_back(gls::VarSpec("u_posTrans", translationMat<4>(positionFactor-1.0f), translationMat<4>(1.0f-positionFactor)));
169 for (int i = 0; i < numTextures; i++)
170 context.textureSpecs.push_back(gls::TextureSpec(glu::TextureTestUtil::TEXTURETYPE_2D, 0,
171 texWid, texHei, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA, true,
172 GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT,
173 Vec4(0.0f), Vec4(1.0f)));
178 gls::ProgramContext ProgramLibrary::generateBufferAndTextureContext (const int numTextures, const int texWid, const int texHei) const
180 static const char* const vertexTemplate =
182 "${VTX_IN} highp vec3 a_position;\n"
183 "${VTX_TEX_COORD_INPUTS}"
184 "${VTX_TEX_COORD_OUTPUTS}"
188 " gl_Position = vec4(a_position, 1.0);\n"
189 "${VTX_TEX_COORD_WRITES}"
192 static const char* const fragmentTemplate =
194 "${FRAG_TEX_COORD_INPUTS}"
199 " ${FRAG_COLOR} =${FRAG_COLOR_EXPRESSION};\n"
202 map<string, string> firstLevelParams;
205 string vtxTexCoordInputs;
206 string vtxTexCoordOutputs;
207 string vtxTexCoordWrites;
208 string fragTexCoordInputs;
210 string fragColorExpression;
212 for (int i = 0; i < numTextures; i++)
214 vtxTexCoordInputs += "${VTX_IN} mediump vec2 a_texCoord" + toString(i) + ";\n";
215 vtxTexCoordOutputs += "${VTX_OUT} mediump vec2 v_texCoord" + toString(i) + ";\n";
216 vtxTexCoordWrites += "\tv_texCoord" + toString(i) + " = " + "a_texCoord" + toString(i) + ";\n";
217 fragTexCoordInputs += "${FRAG_IN} mediump vec2 v_texCoord" + toString(i) + ";\n";
218 fragSamplers += "uniform mediump sampler2D u_sampler" + toString(i) + ";\n";
219 fragColorExpression += string() + (i > 0 ? " +" : "") + "\n\t\t${TEXTURE_2D_FUNC}(u_sampler" + toString(i) + ", v_texCoord" + toString(i) + ")";
222 firstLevelParams["VTX_TEX_COORD_INPUTS"] = substitute(vtxTexCoordInputs);
223 firstLevelParams["VTX_TEX_COORD_OUTPUTS"] = substitute(vtxTexCoordOutputs);
224 firstLevelParams["VTX_TEX_COORD_WRITES"] = vtxTexCoordWrites;
225 firstLevelParams["FRAG_TEX_COORD_INPUTS"] = substitute(fragTexCoordInputs);
226 firstLevelParams["FRAG_SAMPLERS"] = fragSamplers;
227 firstLevelParams["FRAG_COLOR_EXPRESSION"] = substitute(fragColorExpression);
230 gls::ProgramContext context(substitute(vertexTemplate, firstLevelParams).c_str(), substitute(fragmentTemplate, firstLevelParams).c_str(), "a_position");
232 context.attributes.push_back(gls::VarSpec("a_position", Vec3(-0.1f), Vec3(0.1f)));
234 for (int i = 0; i < numTextures; i++)
236 context.attributes.push_back(gls::VarSpec("a_texCoord" + de::toString(i), Vec2(0.0f), Vec2(1.0f)));
237 context.uniforms.push_back(gls::VarSpec("u_sampler" + de::toString(i), i));
238 context.textureSpecs.push_back(gls::TextureSpec(glu::TextureTestUtil::TEXTURETYPE_2D, i,
239 texWid, texHei, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA, true,
240 GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT,
241 Vec4(0.0f), Vec4(1.0f / (float)numTextures)));
247 gls::ProgramContext ProgramLibrary::generateFragmentPointLightContext (const int texWid, const int texHei) const
249 static const char* const vertexTemplate =
253 " mediump vec3 ambientColor;\n"
254 " mediump vec4 diffuseColor;\n"
255 " mediump vec3 emissiveColor;\n"
256 " mediump vec3 specularColor;\n"
257 " mediump float shininess;\n"
262 " mediump vec3 color;\n"
263 " mediump vec4 position;\n"
264 " mediump vec3 direction;\n"
265 " mediump float constantAttenuation;\n"
266 " mediump float linearAttenuation;\n"
267 " mediump float quadraticAttenuation;\n"
270 "${VTX_IN} highp vec4 a_position${NS};\n"
271 "${VTX_IN} mediump vec3 a_normal${NS};\n"
272 "${VTX_IN} mediump vec3 a_color${NS};\n"
273 "${VTX_IN} mediump vec4 a_texCoord0${NS};\n"
275 "uniform Material u_material${NS};\n"
276 "uniform Light u_light${NS}[1];\n"
277 "uniform highp mat4 u_mvpMatrix${NS};\n"
278 "uniform mediump mat4 u_modelViewMatrix${NS};\n"
279 "uniform mediump mat3 u_normalMatrix${NS};\n"
280 "uniform mediump mat4 u_texCoordMatrix0${NS};\n"
282 "${VTX_OUT} mediump vec4 v_baseColor${NS};\n"
283 "${VTX_OUT} mediump vec2 v_texCoord0${NS};\n"
285 "${VTX_OUT} mediump vec3 v_eyeNormal${NS};\n"
286 "${VTX_OUT} mediump vec3 v_directionToLight${NS}[1];\n"
287 "${VTX_OUT} mediump float v_distanceToLight${NS}[1];\n"
289 "vec3 direction (vec4 from, vec4 to)\n"
291 " return vec3(to.xyz * from.w - from.xyz * to.w);\n"
296 " gl_Position = u_mvpMatrix${NS} * a_position${NS};\n"
297 " v_texCoord0${NS} = (u_texCoordMatrix0${NS} * a_texCoord0${NS}).xy;\n"
299 " mediump vec4 eyePosition = u_modelViewMatrix${NS} * a_position${NS};\n"
300 " mediump vec3 eyeNormal = normalize(u_normalMatrix${NS} * a_normal${NS});\n"
302 " vec4 color = vec4(0.0, 0.0, 0.0, 1.0);\n"
303 " color.rgb += u_material${NS}.emissiveColor;\n"
305 " color.a *= u_material${NS}.diffuseColor.a;\n"
307 " v_baseColor${NS} = color;\n"
309 " v_distanceToLight${NS}[0] = distance(eyePosition, u_light${NS}[0].position);\n"
310 " v_directionToLight${NS}[0] = normalize(direction(eyePosition, u_light${NS}[0].position));\n"
312 " v_eyeNormal${NS} = eyeNormal;\n"
315 static const char* const fragmentTemplate =
319 " mediump vec3 color;\n"
320 " mediump vec4 position;\n"
321 " mediump vec3 direction;\n"
322 " mediump float constantAttenuation;\n"
323 " mediump float linearAttenuation;\n"
324 " mediump float quadraticAttenuation;\n"
329 " mediump vec3 ambientColor;\n"
330 " mediump vec4 diffuseColor;\n"
331 " mediump vec3 emissiveColor;\n"
332 " mediump vec3 specularColor;\n"
333 " mediump float shininess;\n"
336 "uniform sampler2D u_sampler0${NS};\n"
337 "uniform Light u_light${NS}[1];\n"
338 "uniform Material u_material${NS};\n"
340 "${FRAG_IN} mediump vec4 v_baseColor${NS};\n"
341 "${FRAG_IN} mediump vec2 v_texCoord0${NS};\n"
343 "${FRAG_IN} mediump vec3 v_eyeNormal${NS};\n"
344 "${FRAG_IN} mediump vec3 v_directionToLight${NS}[1];\n"
345 "${FRAG_IN} mediump float v_distanceToLight${NS}[1];\n"
347 "mediump vec3 computeLighting (Light light, mediump vec3 directionToLight, mediump vec3 vertexEyeNormal)\n"
349 " mediump float normalDotDirection = max(dot(vertexEyeNormal, directionToLight), 0.0);\n"
350 " mediump vec3 color = normalDotDirection * u_material${NS}.diffuseColor.rgb * light.color;\n"
352 " if (normalDotDirection != 0.0)\n"
354 " mediump vec3 h = normalize(directionToLight + vec3(0.0, 0.0, 1.0));\n"
355 " color.rgb += pow(max(dot(vertexEyeNormal, h), 0.0), u_material${NS}.shininess) * u_material${NS}.specularColor * light.color;\n"
361 "mediump float computePointLightAttenuation (Light light, mediump float distanceToLight)\n"
363 " mediump float constantAttenuation = light.constantAttenuation;\n"
364 " mediump float linearAttenuation = light.linearAttenuation * distanceToLight;\n"
365 " mediump float quadraticAttenuation = light.quadraticAttenuation * distanceToLight * distanceToLight;\n"
367 " return 1.0 / (constantAttenuation + linearAttenuation + quadraticAttenuation);\n"
372 " mediump vec3 eyeNormal = normalize(v_eyeNormal${NS});\n"
373 " mediump vec4 color = v_baseColor${NS};\n"
375 " color.rgb += computePointLightAttenuation(u_light${NS}[0], v_distanceToLight${NS}[0]) * computeLighting(u_light${NS}[0], normalize(v_directionToLight${NS}[0]), eyeNormal);\n"
377 " color *= ${TEXTURE_2D_FUNC}(u_sampler0${NS}, v_texCoord0${NS});\n"
379 " ${FRAG_COLOR} = color;\n"
382 gls::ProgramContext context(substitute(vertexTemplate).c_str(), substitute(fragmentTemplate).c_str(), "a_position${NS}");
384 context.attributes.push_back(gls::VarSpec("a_position${NS}", Vec4(-1.0f), Vec4(1.0f)));
385 context.attributes.push_back(gls::VarSpec("a_normal${NS}", Vec3(-1.0f), Vec3(1.0f)));
386 context.attributes.push_back(gls::VarSpec("a_texCoord0${NS}", Vec4(-1.0f), Vec4(1.0f)));
388 context.uniforms.push_back(gls::VarSpec("u_material${NS}.ambientColor", Vec3(0.0f), Vec3(1.0f)));
389 context.uniforms.push_back(gls::VarSpec("u_material${NS}.diffuseColor", Vec4(0.0f), Vec4(1.0f)));
390 context.uniforms.push_back(gls::VarSpec("u_material${NS}.emissiveColor", Vec3(0.0f), Vec3(1.0f)));
391 context.uniforms.push_back(gls::VarSpec("u_material${NS}.specularColor", Vec3(0.0f), Vec3(1.0f)));
392 context.uniforms.push_back(gls::VarSpec("u_material${NS}.shininess", 0.0f, 1.0f));
394 context.uniforms.push_back(gls::VarSpec("u_light${NS}[0].color", Vec3(0.0f), Vec3(1.0f)));
395 context.uniforms.push_back(gls::VarSpec("u_light${NS}[0].position", Vec4(-1.0f), Vec4(1.0f)));
396 context.uniforms.push_back(gls::VarSpec("u_light${NS}[0].direction", Vec3(-1.0f), Vec3(1.0f)));
397 context.uniforms.push_back(gls::VarSpec("u_light${NS}[0].constantAttenuation", 0.1f, 1.0f));
398 context.uniforms.push_back(gls::VarSpec("u_light${NS}[0].linearAttenuation", 0.1f, 1.0f));
399 context.uniforms.push_back(gls::VarSpec("u_light${NS}[0].quadraticAttenuation", 0.1f, 1.0f));
401 context.uniforms.push_back(gls::VarSpec("u_mvpMatrix${NS}", translationMat<4>(-0.2f), translationMat<4>(0.2f)));
402 context.uniforms.push_back(gls::VarSpec("u_modelViewMatrix${NS}", translationMat<4>(-0.2f), translationMat<4>(0.2f)));
403 context.uniforms.push_back(gls::VarSpec("u_normalMatrix${NS}", translationMat<3>(-0.2f), translationMat<3>(0.2f)));
404 context.uniforms.push_back(gls::VarSpec("u_texCoordMatrix0${NS}", translationMat<4>(-0.2f), translationMat<4>(0.2f)));
406 context.uniforms.push_back(gls::VarSpec("u_sampler0${NS}", 0));
408 context.textureSpecs.push_back(gls::TextureSpec(glu::TextureTestUtil::TEXTURETYPE_2D, 0,
409 texWid, texHei, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA,
410 true, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT,
411 Vec4(0.0f), Vec4(1.0f)));
416 gls::ProgramContext ProgramLibrary::generateVertexUniformLoopLightContext (const int texWid, const int texHei) const
418 static const char* const vertexTemplate =
420 "struct Material {\n"
421 " mediump vec3 ambientColor;\n"
422 " mediump vec4 diffuseColor;\n"
423 " mediump vec3 emissiveColor;\n"
424 " mediump vec3 specularColor;\n"
425 " mediump float shininess;\n"
428 " mediump vec3 color;\n"
429 " mediump vec4 position;\n"
430 " mediump vec3 direction;\n"
431 " mediump float constantAttenuation;\n"
432 " mediump float linearAttenuation;\n"
433 " mediump float quadraticAttenuation;\n"
434 " mediump float spotExponent;\n"
435 " mediump float spotCutoff;\n"
437 "${VTX_IN} highp vec4 a_position${NS};\n"
438 "${VTX_IN} mediump vec3 a_normal${NS};\n"
439 "${VTX_IN} mediump vec4 a_texCoord0${NS};\n"
440 "uniform Material u_material${NS};\n"
441 "uniform Light u_directionalLight${NS}[1];\n"
442 "uniform mediump int u_directionalLightCount${NS};\n"
443 "uniform Light u_spotLight${NS}[4];\n"
444 "uniform mediump int u_spotLightCount${NS};\n"
445 "uniform highp mat4 u_mvpMatrix${NS};\n"
446 "uniform highp mat4 u_modelViewMatrix${NS};\n"
447 "uniform mediump mat3 u_normalMatrix${NS};\n"
448 "uniform mediump mat4 u_texCoordMatrix0${NS};\n"
449 "${VTX_OUT} mediump vec4 v_color${NS};\n"
450 "${VTX_OUT} mediump vec2 v_texCoord0${NS};\n"
451 "mediump vec3 direction (mediump vec4 from, mediump vec4 to)\n"
453 " return vec3(to.xyz * from.w - from.xyz * to.w);\n"
456 "mediump vec3 computeLighting (\n"
457 " mediump vec3 directionToLight,\n"
458 " mediump vec3 halfVector,\n"
459 " mediump vec3 normal,\n"
460 " mediump vec3 lightColor,\n"
461 " mediump vec3 diffuseColor,\n"
462 " mediump vec3 specularColor,\n"
463 " mediump float shininess)\n"
465 " mediump float normalDotDirection = max(dot(normal, directionToLight), 0.0);\n"
466 " mediump vec3 color = normalDotDirection * diffuseColor * lightColor;\n"
468 " if (normalDotDirection != 0.0)\n"
469 " color += pow(max(dot(normal, halfVector), 0.0), shininess) * specularColor * lightColor;\n"
474 "mediump float computeDistanceAttenuation (mediump float distToLight, mediump float constAtt, mediump float linearAtt, mediump float quadraticAtt)\n"
476 " return 1.0 / (constAtt + linearAtt * distToLight + quadraticAtt * distToLight * distToLight);\n"
479 "mediump float computeSpotAttenuation (\n"
480 " mediump vec3 directionToLight,\n"
481 " mediump vec3 lightDir,\n"
482 " mediump float spotExponent,\n"
483 " mediump float spotCutoff)\n"
485 " mediump float spotEffect = dot(lightDir, normalize(-directionToLight));\n"
487 " if (spotEffect < spotCutoff)\n"
488 " spotEffect = 0.0;\n"
490 " spotEffect = pow(spotEffect, spotExponent);\n"
491 " return spotEffect;\n"
496 " highp vec4 position = a_position${NS};\n"
497 " highp vec3 normal = a_normal${NS};\n"
498 " gl_Position = u_mvpMatrix${NS} * position;\n"
499 " v_texCoord0${NS} = (u_texCoordMatrix0${NS} * a_texCoord0${NS}).xy;\n"
500 " mediump vec4 color = vec4(u_material${NS}.emissiveColor, u_material${NS}.diffuseColor.a);\n"
502 " highp vec4 eyePosition = u_modelViewMatrix${NS} * position;\n"
503 " mediump vec3 eyeNormal = normalize(u_normalMatrix${NS} * normal);\n"
504 " for (int i = 0; i < u_directionalLightCount${NS}; i++)\n"
506 " mediump vec3 directionToLight = -u_directionalLight${NS}[i].direction;\n"
507 " mediump vec3 halfVector = normalize(directionToLight + vec3(0.0, 0.0, 1.0));\n"
508 " color.rgb += computeLighting(directionToLight, halfVector, eyeNormal, u_directionalLight${NS}[i].color, u_material${NS}.diffuseColor.rgb, u_material${NS}.specularColor, u_material${NS}.shininess);\n"
511 " for (int i = 0; i < u_spotLightCount${NS}; i++)\n"
513 " mediump float distanceToLight = distance(eyePosition, u_spotLight${NS}[i].position);\n"
514 " mediump vec3 directionToLight = normalize(direction(eyePosition, u_spotLight${NS}[i].position));\n"
515 " mediump vec3 halfVector = normalize(directionToLight + vec3(0.0, 0.0, 1.0));\n"
516 " color.rgb += computeLighting(directionToLight, halfVector, eyeNormal, u_spotLight${NS}[i].color, u_material${NS}.diffuseColor.rgb, u_material${NS}.specularColor, u_material${NS}.shininess) * computeDistanceAttenuation(distanceToLight, u_spotLight${NS}[i].constantAttenuation, u_spotLight${NS}[i].linearAttenuation, u_spotLight${NS}[i].quadraticAttenuation) * computeSpotAttenuation(directionToLight, u_spotLight${NS}[i].direction, u_spotLight${NS}[i].spotExponent, u_spotLight${NS}[i].spotCutoff);\n"
520 " v_color${NS} = color;\n"
523 static const char* const fragmentTemplate =
525 "uniform sampler2D u_sampler0${NS};\n"
526 "${FRAG_IN} mediump vec4 v_color${NS};\n"
527 "${FRAG_IN} mediump vec2 v_texCoord0${NS};\n"
530 " mediump vec2 texCoord0 = v_texCoord0${NS};\n"
531 " mediump vec4 color = v_color${NS};\n"
532 " color *= ${TEXTURE_2D_FUNC}(u_sampler0${NS}, texCoord0);\n"
533 " ${FRAG_COLOR} = color;\n"
536 gls::ProgramContext context(substitute(vertexTemplate).c_str(), substitute(fragmentTemplate).c_str(), "a_position${NS}");
538 context.attributes.push_back (gls::VarSpec("a_position${NS}", Vec4(-1.0f), Vec4(1.0f)));
539 context.attributes.push_back (gls::VarSpec("a_normal${NS}", Vec3(-1.0f), Vec3(1.0f)));
540 context.attributes.push_back (gls::VarSpec("a_texCoord0${NS}", Vec4(-1.0f), Vec4(1.0f)));
542 context.uniforms.push_back (gls::VarSpec("u_material${NS}.ambientColor", Vec3(0.0f), Vec3(1.0f)));
543 context.uniforms.push_back (gls::VarSpec("u_material${NS}.diffuseColor", Vec4(0.0f), Vec4(1.0f)));
544 context.uniforms.push_back (gls::VarSpec("u_material${NS}.emissiveColor", Vec3(0.0f), Vec3(1.0f)));
545 context.uniforms.push_back (gls::VarSpec("u_material${NS}.specularColor", Vec3(0.0f), Vec3(1.0f)));
546 context.uniforms.push_back (gls::VarSpec("u_material${NS}.shininess", 0.0f, 1.0f));
548 context.uniforms.push_back (gls::VarSpec("u_directionalLight${NS}[0].color", Vec3(0.0f), Vec3(1.0f)));
549 context.uniforms.push_back (gls::VarSpec("u_directionalLight${NS}[0].position", Vec4(-1.0f), Vec4(1.0f)));
550 context.uniforms.push_back (gls::VarSpec("u_directionalLight${NS}[0].direction", Vec3(-1.0f), Vec3(1.0f)));
551 context.uniforms.push_back (gls::VarSpec("u_directionalLight${NS}[0].constantAttenuation", 0.1f, 1.0f));
552 context.uniforms.push_back (gls::VarSpec("u_directionalLight${NS}[0].linearAttenuation", 0.1f, 1.0f));
553 context.uniforms.push_back (gls::VarSpec("u_directionalLight${NS}[0].quadraticAttenuation", 0.1f, 1.0f));
554 context.uniforms.push_back (gls::VarSpec("u_directionalLight${NS}[0].spotExponent", 0.1f, 1.0f));
555 context.uniforms.push_back (gls::VarSpec("u_directionalLight${NS}[0].spotCutoff", 0.1f, 1.0f));
557 context.uniforms.push_back (gls::VarSpec("u_directionalLightCount${NS}", 1));
559 for (int i = 0; i < 4; i++)
561 const std::string ndxStr = de::toString(i);
563 context.uniforms.push_back(gls::VarSpec("u_spotLight${NS}["+ndxStr+"].color", Vec3(0.0f), Vec3(1.0f)));
564 context.uniforms.push_back(gls::VarSpec("u_spotLight${NS}["+ndxStr+"].position", Vec4(-1.0f), Vec4(1.0f)));
565 context.uniforms.push_back(gls::VarSpec("u_spotLight${NS}["+ndxStr+"].direction", Vec3(-1.0f), Vec3(1.0f)));
566 context.uniforms.push_back(gls::VarSpec("u_spotLight${NS}["+ndxStr+"].constantAttenuation", 0.1f, 1.0f));
567 context.uniforms.push_back(gls::VarSpec("u_spotLight${NS}["+ndxStr+"].linearAttenuation", 0.1f, 1.0f));
568 context.uniforms.push_back(gls::VarSpec("u_spotLight${NS}["+ndxStr+"].quadraticAttenuation", 0.1f, 1.0f));
569 context.uniforms.push_back(gls::VarSpec("u_spotLight${NS}["+ndxStr+"].spotExponent", 0.1f, 1.0f));
570 context.uniforms.push_back(gls::VarSpec("u_spotLight${NS}["+ndxStr+"].spotCutoff", 0.1f, 1.0f));
573 context.uniforms.push_back (gls::VarSpec("u_spotLightCount${NS}", 4));
575 context.uniforms.push_back (gls::VarSpec("u_mvpMatrix${NS}", translationMat<4>(-0.2f), translationMat<4>(0.2f)));
576 context.uniforms.push_back (gls::VarSpec("u_modelViewMatrix${NS}", translationMat<4>(-0.2f), translationMat<4>(0.2f)));
577 context.uniforms.push_back (gls::VarSpec("u_normalMatrix${NS}", translationMat<3>(-0.2f), translationMat<3>(0.2f)));
578 context.uniforms.push_back (gls::VarSpec("u_texCoordMatrix0${NS}", translationMat<4>(-0.2f), translationMat<4>(0.2f)));
580 context.uniforms.push_back (gls::VarSpec("u_sampler0${NS}", 0));
582 context.textureSpecs.push_back (gls::TextureSpec(glu::TextureTestUtil::TEXTURETYPE_2D, 0,
583 texWid, texHei, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA,
584 true, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT,
585 Vec4(0.0f), Vec4(1.0f)));