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 COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ |
8 | #define COMPILER_TRANSLATOR_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 | |
16 | class 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 | ShShaderOutput output); |
26 | |
27 | ShShaderOutput getShaderOutput() const |
28 | { |
29 | return mOutput; |
30 | } |
31 | |
32 | protected: |
33 | TInfoSinkBase &objSink() { return mObjSink; } |
34 | void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr); |
35 | void writeVariableType(const TType &type); |
36 | virtual bool writeVariablePrecision(TPrecision precision) = 0; |
37 | void writeFunctionParameters(const TIntermSequence &args); |
38 | const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion); |
39 | void writeConstructorTriplet(Visit visit, const TType &type, const char *constructorBaseType); |
40 | TString getTypeName(const TType &type); |
41 | |
42 | virtual void visitSymbol(TIntermSymbol *node); |
43 | virtual void visitConstantUnion(TIntermConstantUnion *node); |
44 | virtual bool visitBinary(Visit visit, TIntermBinary *node); |
45 | virtual bool visitUnary(Visit visit, TIntermUnary *node); |
46 | virtual bool visitSelection(Visit visit, TIntermSelection *node); |
47 | virtual bool visitSwitch(Visit visit, TIntermSwitch *node); |
48 | virtual bool visitCase(Visit visit, TIntermCase *node); |
49 | virtual bool visitAggregate(Visit visit, TIntermAggregate *node); |
50 | virtual bool visitLoop(Visit visit, TIntermLoop *node); |
51 | virtual bool visitBranch(Visit visit, TIntermBranch *node); |
52 | |
53 | void visitCodeBlock(TIntermNode *node); |
54 | |
55 | // Return the original name if hash function pointer is NULL; |
56 | // otherwise return the hashed name. |
57 | TString hashName(const TString &name); |
58 | // Same as hashName(), but without hashing built-in variables. |
59 | TString hashVariableName(const TString &name); |
60 | // Same as hashName(), but without hashing built-in functions. |
61 | TString hashFunctionName(const TString &mangled_name); |
62 | // Used to translate function names for differences between ESSL and GLSL |
63 | virtual TString translateTextureFunction(TString &name) { return name; } |
64 | |
65 | private: |
66 | bool structDeclared(const TStructure *structure) const; |
67 | void declareStruct(const TStructure *structure); |
68 | |
69 | void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction); |
70 | |
71 | TInfoSinkBase &mObjSink; |
72 | bool mDeclaringVariables; |
73 | |
74 | // This set contains all the ids of the structs from every scope. |
75 | std::set<int> mDeclaredStructs; |
76 | |
77 | // Stack of loops that need to be unrolled. |
78 | TLoopStack mLoopUnrollStack; |
79 | |
80 | ShArrayIndexClampingStrategy mClampingStrategy; |
81 | |
82 | // name hashing. |
83 | ShHashFunction64 mHashFunction; |
84 | |
85 | NameMap &mNameMap; |
86 | |
87 | TSymbolTable &mSymbolTable; |
88 | |
89 | const int mShaderVersion; |
90 | |
91 | ShShaderOutput mOutput; |
92 | }; |
93 | |
94 | #endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ |
95 | |