Line data Source code
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/ParseContext.h"
14 :
15 : namespace sh
16 : {
17 :
18 0 : class TOutputGLSLBase : public TIntermTraverser
19 : {
20 : public:
21 : TOutputGLSLBase(TInfoSinkBase &objSink,
22 : ShArrayIndexClampingStrategy clampingStrategy,
23 : ShHashFunction64 hashFunction,
24 : NameMap &nameMap,
25 : TSymbolTable &symbolTable,
26 : sh::GLenum shaderType,
27 : int shaderVersion,
28 : ShShaderOutput output,
29 : ShCompileOptions compileOptions);
30 :
31 0 : ShShaderOutput getShaderOutput() const
32 : {
33 0 : return mOutput;
34 : }
35 :
36 : protected:
37 0 : TInfoSinkBase &objSink() { return mObjSink; }
38 : void writeFloat(TInfoSinkBase &out, float f);
39 : void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr);
40 : void writeLayoutQualifier(const TType &type);
41 : void writeInvariantQualifier(const TType &type);
42 : void writeVariableType(const TType &type);
43 : virtual bool writeVariablePrecision(TPrecision precision) = 0;
44 : void writeFunctionParameters(const TIntermSequence &args);
45 : const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion);
46 : void writeConstructorTriplet(Visit visit, const TType &type);
47 : TString getTypeName(const TType &type);
48 :
49 : void visitSymbol(TIntermSymbol *node) override;
50 : void visitConstantUnion(TIntermConstantUnion *node) override;
51 : bool visitSwizzle(Visit visit, TIntermSwizzle *node) override;
52 : bool visitBinary(Visit visit, TIntermBinary *node) override;
53 : bool visitUnary(Visit visit, TIntermUnary *node) override;
54 : bool visitTernary(Visit visit, TIntermTernary *node) override;
55 : bool visitIfElse(Visit visit, TIntermIfElse *node) override;
56 : bool visitSwitch(Visit visit, TIntermSwitch *node) override;
57 : bool visitCase(Visit visit, TIntermCase *node) override;
58 : bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override;
59 : bool visitAggregate(Visit visit, TIntermAggregate *node) override;
60 : bool visitBlock(Visit visit, TIntermBlock *node) override;
61 : bool visitDeclaration(Visit visit, TIntermDeclaration *node) override;
62 : bool visitLoop(Visit visit, TIntermLoop *node) override;
63 : bool visitBranch(Visit visit, TIntermBranch *node) override;
64 :
65 : void visitCodeBlock(TIntermBlock *node);
66 :
67 : // Return the original name if hash function pointer is NULL;
68 : // otherwise return the hashed name.
69 : TString hashName(const TName &name);
70 : // Same as hashName(), but without hashing built-in variables.
71 : TString hashVariableName(const TName &name);
72 : // Same as hashName(), but without hashing built-in functions and with unmangling.
73 : TString hashFunctionNameIfNeeded(const TName &mangledName);
74 : // Used to translate function names for differences between ESSL and GLSL
75 0 : virtual TString translateTextureFunction(TString &name) { return name; }
76 :
77 : private:
78 : bool structDeclared(const TStructure *structure) const;
79 : void declareStruct(const TStructure *structure);
80 :
81 : void declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock);
82 : void declareInterfaceBlock(const TInterfaceBlock *interfaceBlock);
83 :
84 : void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction);
85 :
86 : const char *mapQualifierToString(TQualifier qialifier);
87 :
88 : TInfoSinkBase &mObjSink;
89 : bool mDeclaringVariables;
90 :
91 : // This set contains all the ids of the structs from every scope.
92 : std::set<int> mDeclaredStructs;
93 :
94 : ShArrayIndexClampingStrategy mClampingStrategy;
95 :
96 : // name hashing.
97 : ShHashFunction64 mHashFunction;
98 :
99 : NameMap &mNameMap;
100 :
101 : TSymbolTable &mSymbolTable;
102 :
103 : sh::GLenum mShaderType;
104 :
105 : const int mShaderVersion;
106 :
107 : ShShaderOutput mOutput;
108 :
109 : ShCompileOptions mCompileOptions;
110 : };
111 :
112 : } // namespace sh
113 :
114 : #endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_
|