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 Variable class.
22 *//*--------------------------------------------------------------------*/
24 #include "rsgVariable.hpp"
25 #include "rsgGeneratorState.hpp"
26 #include "rsgShader.hpp"
31 Variable::Variable (const VariableType& type, Storage storage, const char* name)
35 , m_layoutLocation (-1)
39 Variable::~Variable (void)
43 void Variable::tokenizeDeclaration (GeneratorState& state, TokenStream& str) const
45 Version targetVersion = state.getProgramParameters().version;
47 // \todo [2011-03-10 pyry] Remove precision hacks once precision handling is implemented
50 case STORAGE_CONST: str << Token::CONST; break;
51 case STORAGE_PARAMETER_IN: str << Token::IN; break;
52 case STORAGE_PARAMETER_OUT: str << Token::OUT; break;
53 case STORAGE_PARAMETER_INOUT: str << Token::INOUT; break;
57 str << Token::UNIFORM;
58 if (m_type.isFloatOrVec() || m_type.isIntOrVec())
59 str << Token::MEDIUM_PRECISION;
63 case STORAGE_SHADER_IN:
65 if (targetVersion >= VERSION_300)
67 if (hasLayoutLocation())
68 str << Token::LAYOUT << Token::LEFT_PAREN << Token::LOCATION << Token::EQUAL << m_layoutLocation << Token::RIGHT_PAREN;
72 if (state.getShader().getType() == Shader::TYPE_FRAGMENT)
73 str << Token::MEDIUM_PRECISION;
77 DE_ASSERT(!hasLayoutLocation());
79 switch (state.getShader().getType())
81 case Shader::TYPE_VERTEX: str << Token::ATTRIBUTE; break;
82 case Shader::TYPE_FRAGMENT: str << Token::VARYING << Token::MEDIUM_PRECISION; break;
83 default: DE_ASSERT(DE_FALSE); break;
89 case STORAGE_SHADER_OUT:
91 if (targetVersion >= VERSION_300)
93 if (hasLayoutLocation())
94 str << Token::LAYOUT << Token::LEFT_PAREN << Token::LOCATION << Token::EQUAL << m_layoutLocation << Token::RIGHT_PAREN;
96 str << Token::OUT << Token::MEDIUM_PRECISION;
100 DE_ASSERT(!hasLayoutLocation());
102 if (state.getShader().getType() == Shader::TYPE_VERTEX)
103 str << Token::VARYING << Token::MEDIUM_PRECISION;
116 m_type.tokenizeShortType(str);
118 DE_ASSERT(m_name != "");
119 str << Token(m_name.c_str());