1// 2// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. 3// Use of this source code is governed by a BSD-style license that can be 4// found in the LICENSE file. 5// 6 7#ifndef CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_ 8#define CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_ 9 10#include <set> 11 12#include "compiler/translator/IntermNode.h" 13#include "compiler/translator/LoopInfo.h" 14#include "compiler/translator/ParseContext.h" 15 16class TOutputGLSLBase : public TIntermTraverser 17{ 18 public: 19 TOutputGLSLBase(TInfoSinkBase &objSink, 20 ShArrayIndexClampingStrategy clampingStrategy, 21 ShHashFunction64 hashFunction, 22 NameMap &nameMap, 23 TSymbolTable& symbolTable, 24 int shaderVersion); 25 26 protected: 27 TInfoSinkBase &objSink() { return mObjSink; } 28 void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr); 29 void writeVariableType(const TType &type); 30 virtual bool writeVariablePrecision(TPrecision precision) = 0; 31 void writeFunctionParameters(const TIntermSequence &args); 32 const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *pConstUnion); 33 TString getTypeName(const TType &type); 34 35 virtual void visitSymbol(TIntermSymbol *node); 36 virtual void visitConstantUnion(TIntermConstantUnion *node); 37 virtual bool visitBinary(Visit visit, TIntermBinary *node); 38 virtual bool visitUnary(Visit visit, TIntermUnary *node); 39 virtual bool visitSelection(Visit visit, TIntermSelection *node); 40 virtual bool visitAggregate(Visit visit, TIntermAggregate *node); 41 virtual bool visitLoop(Visit visit, TIntermLoop *node); 42 virtual bool visitBranch(Visit visit, TIntermBranch *node); 43 44 void visitCodeBlock(TIntermNode *node); 45 46 // Return the original name if hash function pointer is NULL; 47 // otherwise return the hashed name. 48 TString hashName(const TString &name); 49 // Same as hashName(), but without hashing built-in variables. 50 TString hashVariableName(const TString &name); 51 // Same as hashName(), but without hashing built-in functions. 52 TString hashFunctionName(const TString &mangled_name); 53 // Used to translate function names for differences between ESSL and GLSL 54 virtual TString translateTextureFunction(TString &name) { return name; } 55 56 private: 57 bool structDeclared(const TStructure *structure) const; 58 void declareStruct(const TStructure *structure); 59 60 void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction); 61 62 TInfoSinkBase &mObjSink; 63 bool mDeclaringVariables; 64 65 // This set contains all the ids of the structs from every scope. 66 std::set<int> mDeclaredStructs; 67 68 // Stack of loops that need to be unrolled. 69 TLoopStack mLoopUnrollStack; 70 71 ShArrayIndexClampingStrategy mClampingStrategy; 72 73 // name hashing. 74 ShHashFunction64 mHashFunction; 75 76 NameMap &mNameMap; 77 78 TSymbolTable &mSymbolTable; 79 80 const int mShaderVersion; 81}; 82 83#endif // CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_ 84