1 #ifndef _RSGGENERATORSTATE_HPP 2 #define _RSGGENERATORSTATE_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Random Shader Generator 5 * ---------------------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Generator state. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "rsgDefs.hpp" 27 #include "rsgParameters.hpp" 28 #include "deRandom.hpp" 29 #include "rsgNameAllocator.hpp" 30 31 #include <vector> 32 33 namespace rsg 34 { 35 36 class Shader; 37 class VariableManager; 38 class VariableType; 39 class Statement; 40 41 enum ExpressionFlags 42 { 43 CONST_EXPR = (1<<0), 44 NO_VAR_ALLOCATION = (1<<1) 45 }; 46 47 enum 48 { 49 PRECEDENCE_MAX = 100 50 }; 51 52 class GeneratorState 53 { 54 public: 55 GeneratorState (const ProgramParameters& programParams, de::Random& random); 56 ~GeneratorState (void); 57 58 const ProgramParameters& getProgramParameters (void) const { return m_programParams; } 59 de::Random& getRandom (void) { return m_random; } 60 61 const ShaderParameters& getShaderParameters (void) const { return *m_shaderParams; } 62 Shader& getShader (void) { return *m_shader; } 63 64 void setShader (const ShaderParameters& params, Shader& shader); 65 66 NameAllocator& getNameAllocator (void) { return m_nameAllocator; } 67 VariableManager& getVariableManager (void) { return *m_varManager; } 68 const VariableManager& getVariableManager (void) const { return *m_varManager; } 69 void setVariableManager (VariableManager& varManager) { m_varManager = &varManager; } 70 71 // \todo [2011-06-10 pyry] Could we not expose whole statement stack to everyone? 72 int getStatementDepth (void) const { return (int)m_statementStack->size(); } 73 void setStatementStack (std::vector<Statement*>& stack) { m_statementStack = &stack; } 74 const Statement* getStatementStackEntry (int ndx) const { return m_statementStack->at(ndx); } 75 76 int getExpressionDepth (void) const { return m_expressionDepth; } 77 void setExpressionDepth (int depth) { m_expressionDepth = depth; } 78 79 // \todo [2011-03-21 pyry] A bit of a hack... Move to ValueRange? 80 deUint32 getExpressionFlags (void) const { return m_exprFlagStack.back(); } 81 void pushExpressionFlags (deUint32 flags) { m_exprFlagStack.push_back(flags); } 82 void popExpressionFlags (void) { m_exprFlagStack.pop_back(); } 83 84 int getPrecedence (void) const { return m_precedenceStack.back(); } 85 void pushPrecedence (int precedence) { m_precedenceStack.push_back(precedence); } 86 void popPrecedence (void) { m_precedenceStack.pop_back(); } 87 88 private: 89 const ProgramParameters& m_programParams; 90 de::Random& m_random; 91 92 const ShaderParameters* m_shaderParams; 93 Shader* m_shader; 94 95 NameAllocator m_nameAllocator; 96 VariableManager* m_varManager; 97 98 std::vector<Statement*>* m_statementStack; 99 int m_expressionDepth; 100 std::vector<deUint32> m_exprFlagStack; 101 std::vector<int> m_precedenceStack; 102 }; 103 104 } // rsg 105 106 #endif // _RSGGENERATORSTATE_HPP 107