13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _RSGVARIABLETYPE_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _RSGVARIABLETYPE_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Random Shader Generator 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Variable Type class. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace rsg 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TokenStream; 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass VariableType 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum Type 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_VOID = 0, 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_FLOAT, 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_INT, 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_BOOL, 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_STRUCT, 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_ARRAY, 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_SAMPLER_2D, 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_SAMPLER_CUBE, 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_LAST 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum Precision 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PRECISION_NONE = 0, 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PRECISION_LOW, 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PRECISION_MEDIUM, 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PRECISION_HIGH, 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PRECISION_LAST 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry class Member 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public: 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Member (void) 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type(DE_NULL) 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_name() 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Member (const VariableType& type, const char* name) 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type(new VariableType(type)) 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_name(name) 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Member (void) 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_type; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Member (const Member& other) 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type(DE_NULL) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_name(other.m_name) 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (other.m_type) 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_type = new VariableType(*other.m_type); 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Member& operator= (const Member& other) 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (this == &other) 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *this; 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_type; 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_type = DE_NULL; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_name = other.m_name; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (other.m_type) 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_type = new VariableType(*other.m_type); 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *this; 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator!= (const Member& other) const 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_name != other.m_name) 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!!m_type != !!other.m_type) 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_type && *m_type != *other.m_type) 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator== (const Member& other) const 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return !(*this != other); 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const VariableType& getType (void) const { return *m_type; } 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getName (void) const { return m_name.c_str(); } 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private: 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType* m_type; 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string m_name; 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType (void); 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType (Type baseType, int numElements = 0); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType (Type baseType, const VariableType& elementType, int numElements); 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType (Type baseType, const char* typeName); 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~VariableType (void); 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Type getBaseType (void) const { return m_baseType; } 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Precision getPrecision (void) const { return m_precision; } 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getTypeName (void) const { return m_typeName.c_str(); } 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getNumElements (void) const { return m_numElements; } 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const VariableType& getElementType (void) const; 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::vector<Member>& getMembers (void) const { return m_members; } 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Member>& getMembers (void) { return m_members; } 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getScalarSize (void) const; 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getElementScalarOffset (int elementNdx) const; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getMemberScalarOffset (int memberNdx) const; 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator!= (const VariableType& other) const; 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator== (const VariableType& other) const; 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType& operator= (const VariableType& other); 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType (const VariableType& other); 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void tokenizeShortType (TokenStream& str) const; 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isStruct (void) const { return m_baseType == TYPE_STRUCT; } 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isArray (void) const { return m_baseType == TYPE_ARRAY; } 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isFloatOrVec (void) const { return m_baseType == TYPE_FLOAT; } 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isIntOrVec (void) const { return m_baseType == TYPE_INT; } 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isBoolOrVec (void) const { return m_baseType == TYPE_BOOL; } 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isSampler (void) const { return m_baseType == TYPE_SAMPLER_2D || m_baseType == TYPE_SAMPLER_CUBE; } 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isVoid (void) const { return m_baseType == TYPE_VOID; } 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const VariableType& getScalarType (Type baseType); 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Type m_baseType; 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Precision m_precision; 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string m_typeName; 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_numElements; 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType* m_elementType; 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Member> m_members; 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline VariableType::VariableType (void) 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_baseType (TYPE_VOID) 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_precision (PRECISION_NONE) 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_typeName () 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numElements (0) 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_elementType (DE_NULL) 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline VariableType::VariableType (Type baseType, int numElements) 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_baseType (baseType) 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_precision (PRECISION_NONE) 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_typeName () 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numElements (numElements) 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_elementType (DE_NULL) 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(baseType != TYPE_ARRAY && baseType != TYPE_STRUCT); 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline VariableType::VariableType (Type baseType, const VariableType& elementType, int numElements) 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_baseType (baseType) 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_precision (PRECISION_NONE) 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_typeName () 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numElements (numElements) 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_elementType (new VariableType(elementType)) 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(baseType == TYPE_ARRAY); 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline VariableType::VariableType (Type baseType, const char* typeName) 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_baseType (baseType) 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_precision (PRECISION_NONE) 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_typeName (typeName) 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numElements (0) 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_elementType (DE_NULL) 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(baseType == TYPE_STRUCT); 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline VariableType::~VariableType (void) 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_elementType; 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // rsg 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _RSGVARIABLETYPE_HPP 224