1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Random Shader Generator
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 Random Shader Generator Tester.
22 *//*--------------------------------------------------------------------*/
24 #include "rsgProgramGenerator.hpp"
25 #include "rsgProgramExecutor.hpp"
26 #include "tcuSurface.hpp"
27 #include "tcuImageIO.hpp"
28 #include "rsgUtils.hpp"
29 #include "deStringUtil.hpp"
37 void runTest (deUint32 seed)
39 printf("Seed: %d\n", seed);
41 // Generate test program
44 rsg::ProgramParameters programParams;
46 programParams.seed = seed;
47 programParams.fragmentParameters.randomize = true;
48 programParams.fragmentParameters.maxStatementDepth = 3;
50 rsg::Shader vertexShader(rsg::Shader::TYPE_VERTEX);
51 rsg::Shader fragmentShader(rsg::Shader::TYPE_FRAGMENT);
53 rsg::ProgramGenerator generator;
54 generator.generate(programParams, vertexShader, fragmentShader);
56 std::cout << "Vertex shader:\n--\n" << vertexShader.getSource() << "--\n";
57 std::cout << "Fragment shader:\n--\n" << fragmentShader.getSource() << "--\n";
60 std::vector<const rsg::ShaderInput*> uniforms;
61 std::vector<rsg::VariableValue> uniformValues;
63 rsg::computeUnifiedUniforms(vertexShader, fragmentShader, uniforms);
64 rsg::computeUniformValues(rnd, uniformValues, uniforms);
67 tcu::Surface surface(64, 64);
68 rsg::ProgramExecutor executor(surface.getAccess(), 3, 5);
70 executor.execute(vertexShader, fragmentShader, uniformValues);
72 string fileName = string("test-") + de::toString(seed) + ".png";
73 tcu::ImageIO::savePNG(surface.getAccess(), fileName.c_str());
74 std::cout << fileName << " written\n";
76 catch (const std::exception& e)
78 printf("Failed: %s\n", e.what());
82 int main (int argc, const char* const* argv)
84 DE_UNREF(argc && argv);
86 for (int seed = 0; seed < 10; seed++)