1*35238bceSAndroid Build Coastguard Worker /*------------------------------------------------------------------------- 2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program Random Shader Generator 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 Expression generator. 22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/ 23*35238bceSAndroid Build Coastguard Worker 24*35238bceSAndroid Build Coastguard Worker #include "rsgExpressionGenerator.hpp" 25*35238bceSAndroid Build Coastguard Worker 26*35238bceSAndroid Build Coastguard Worker namespace rsg 27*35238bceSAndroid Build Coastguard Worker { 28*35238bceSAndroid Build Coastguard Worker ExpressionGenerator(GeneratorState & state)29*35238bceSAndroid Build Coastguard WorkerExpressionGenerator::ExpressionGenerator(GeneratorState &state) : m_state(state) 30*35238bceSAndroid Build Coastguard Worker { 31*35238bceSAndroid Build Coastguard Worker } 32*35238bceSAndroid Build Coastguard Worker ~ExpressionGenerator(void)33*35238bceSAndroid Build Coastguard WorkerExpressionGenerator::~ExpressionGenerator(void) 34*35238bceSAndroid Build Coastguard Worker { 35*35238bceSAndroid Build Coastguard Worker } 36*35238bceSAndroid Build Coastguard Worker generate(const ValueRange & valueRange,int initialDepth)37*35238bceSAndroid Build Coastguard WorkerExpression *ExpressionGenerator::generate(const ValueRange &valueRange, int initialDepth) 38*35238bceSAndroid Build Coastguard Worker { 39*35238bceSAndroid Build Coastguard Worker // Create root 40*35238bceSAndroid Build Coastguard Worker m_state.setExpressionDepth(initialDepth); 41*35238bceSAndroid Build Coastguard Worker Expression *root = Expression::createRandom(m_state, valueRange); 42*35238bceSAndroid Build Coastguard Worker 43*35238bceSAndroid Build Coastguard Worker try 44*35238bceSAndroid Build Coastguard Worker { 45*35238bceSAndroid Build Coastguard Worker // Generate full expression 46*35238bceSAndroid Build Coastguard Worker generate(root); 47*35238bceSAndroid Build Coastguard Worker } 48*35238bceSAndroid Build Coastguard Worker catch (const std::exception &) 49*35238bceSAndroid Build Coastguard Worker { 50*35238bceSAndroid Build Coastguard Worker delete root; 51*35238bceSAndroid Build Coastguard Worker m_expressionStack.clear(); 52*35238bceSAndroid Build Coastguard Worker throw; 53*35238bceSAndroid Build Coastguard Worker } 54*35238bceSAndroid Build Coastguard Worker 55*35238bceSAndroid Build Coastguard Worker return root; 56*35238bceSAndroid Build Coastguard Worker } 57*35238bceSAndroid Build Coastguard Worker generate(Expression * root)58*35238bceSAndroid Build Coastguard Workervoid ExpressionGenerator::generate(Expression *root) 59*35238bceSAndroid Build Coastguard Worker { 60*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_expressionStack.empty()); 61*35238bceSAndroid Build Coastguard Worker 62*35238bceSAndroid Build Coastguard Worker // Initialize stack 63*35238bceSAndroid Build Coastguard Worker m_expressionStack.push_back(root); 64*35238bceSAndroid Build Coastguard Worker m_state.setExpressionDepth(m_state.getExpressionDepth() + 1); 65*35238bceSAndroid Build Coastguard Worker 66*35238bceSAndroid Build Coastguard Worker // Process until done 67*35238bceSAndroid Build Coastguard Worker while (!m_expressionStack.empty()) 68*35238bceSAndroid Build Coastguard Worker { 69*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_state.getExpressionDepth() <= m_state.getShaderParameters().maxExpressionDepth); 70*35238bceSAndroid Build Coastguard Worker 71*35238bceSAndroid Build Coastguard Worker Expression *curExpr = m_expressionStack[m_expressionStack.size() - 1]; 72*35238bceSAndroid Build Coastguard Worker Expression *child = curExpr->createNextChild(m_state); 73*35238bceSAndroid Build Coastguard Worker 74*35238bceSAndroid Build Coastguard Worker if (child) 75*35238bceSAndroid Build Coastguard Worker { 76*35238bceSAndroid Build Coastguard Worker m_expressionStack.push_back(child); 77*35238bceSAndroid Build Coastguard Worker m_state.setExpressionDepth(m_state.getExpressionDepth() + 1); 78*35238bceSAndroid Build Coastguard Worker } 79*35238bceSAndroid Build Coastguard Worker else 80*35238bceSAndroid Build Coastguard Worker { 81*35238bceSAndroid Build Coastguard Worker m_expressionStack.pop_back(); 82*35238bceSAndroid Build Coastguard Worker m_state.setExpressionDepth(m_state.getExpressionDepth() - 1); 83*35238bceSAndroid Build Coastguard Worker } 84*35238bceSAndroid Build Coastguard Worker } 85*35238bceSAndroid Build Coastguard Worker } 86*35238bceSAndroid Build Coastguard Worker 87*35238bceSAndroid Build Coastguard Worker } // namespace rsg 88