zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 1 | // |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 7 | #ifndef COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ |
| 8 | #define COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 9 | |
Jamie Madill | 01f85ac | 2014-06-06 11:55:04 -0400 | [diff] [blame] | 10 | #include <set> |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 11 | |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 12 | #include "compiler/translator/IntermNode.h" |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 13 | #include "compiler/translator/LoopInfo.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 14 | #include "compiler/translator/ParseContext.h" |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 15 | |
| 16 | class TOutputGLSLBase : public TIntermTraverser |
| 17 | { |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 18 | public: |
| 19 | TOutputGLSLBase(TInfoSinkBase &objSink, |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 20 | ShArrayIndexClampingStrategy clampingStrategy, |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 21 | ShHashFunction64 hashFunction, |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 22 | NameMap &nameMap, |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 23 | TSymbolTable& symbolTable, |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 24 | int shaderVersion, |
| 25 | ShShaderOutput output); |
| 26 | |
| 27 | ShShaderOutput getShaderOutput() const |
| 28 | { |
| 29 | return mOutput; |
| 30 | } |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 31 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 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); |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 36 | virtual bool writeVariablePrecision(TPrecision precision) = 0; |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 37 | void writeFunctionParameters(const TIntermSequence &args); |
Jamie Madill | 6ba6ead | 2015-05-04 14:21:21 -0400 | [diff] [blame^] | 38 | const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion); |
Olli Etuaho | f40319e | 2015-03-10 14:33:00 +0200 | [diff] [blame] | 39 | void writeConstructorTriplet(Visit visit, const TType &type, const char *constructorBaseType); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 40 | TString getTypeName(const TType &type); |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 41 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 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); |
Olli Etuaho | 3c1dfb5 | 2015-02-20 11:34:03 +0200 | [diff] [blame] | 47 | virtual bool visitSwitch(Visit visit, TIntermSwitch *node); |
| 48 | virtual bool visitCase(Visit visit, TIntermCase *node); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 49 | virtual bool visitAggregate(Visit visit, TIntermAggregate *node); |
| 50 | virtual bool visitLoop(Visit visit, TIntermLoop *node); |
| 51 | virtual bool visitBranch(Visit visit, TIntermBranch *node); |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 52 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 53 | void visitCodeBlock(TIntermNode *node); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 54 | |
| 55 | // Return the original name if hash function pointer is NULL; |
| 56 | // otherwise return the hashed name. |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 57 | TString hashName(const TString &name); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 58 | // Same as hashName(), but without hashing built-in variables. |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 59 | TString hashVariableName(const TString &name); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 60 | // Same as hashName(), but without hashing built-in functions. |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 61 | TString hashFunctionName(const TString &mangled_name); |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 62 | // Used to translate function names for differences between ESSL and GLSL |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 63 | virtual TString translateTextureFunction(TString &name) { return name; } |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 64 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 65 | private: |
| 66 | bool structDeclared(const TStructure *structure) const; |
| 67 | void declareStruct(const TStructure *structure); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 68 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 69 | void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction); |
| 70 | |
| 71 | TInfoSinkBase &mObjSink; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 72 | bool mDeclaringVariables; |
| 73 | |
Jamie Madill | 01f85ac | 2014-06-06 11:55:04 -0400 | [diff] [blame] | 74 | // This set contains all the ids of the structs from every scope. |
| 75 | std::set<int> mDeclaredStructs; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 76 | |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 77 | // Stack of loops that need to be unrolled. |
| 78 | TLoopStack mLoopUnrollStack; |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 79 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 80 | ShArrayIndexClampingStrategy mClampingStrategy; |
| 81 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 82 | // name hashing. |
| 83 | ShHashFunction64 mHashFunction; |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 84 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 85 | NameMap &mNameMap; |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 86 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 87 | TSymbolTable &mSymbolTable; |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 88 | |
| 89 | const int mShaderVersion; |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 90 | |
| 91 | ShShaderOutput mOutput; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 94 | #endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ |