blob: 1f3558eeeb38096a1ae1d8092356bdfed360556a [file] [log] [blame]
zmo@google.com5601ea02011-06-10 18:23:25 +00001//
Jamie Madill02f20dd2013-09-12 12:07:42 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
zmo@google.com5601ea02011-06-10 18:23:25 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_
8#define COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_
zmo@google.com5601ea02011-06-10 18:23:25 +00009
Jamie Madill01f85ac2014-06-06 11:55:04 -040010#include <set>
zmo@google.com5601ea02011-06-10 18:23:25 +000011
Jamie Madillb1a85f42014-08-19 15:23:24 -040012#include "compiler/translator/IntermNode.h"
Zhenyao Mo550c6002014-02-26 15:40:48 -080013#include "compiler/translator/LoopInfo.h"
Jamie Madill6b9cb252013-10-17 10:45:47 -040014#include "compiler/translator/ParseContext.h"
zmo@google.com5601ea02011-06-10 18:23:25 +000015
16class TOutputGLSLBase : public TIntermTraverser
17{
Zhenyao Mo9eedea02014-05-12 16:02:35 -070018 public:
19 TOutputGLSLBase(TInfoSinkBase &objSink,
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000020 ShArrayIndexClampingStrategy clampingStrategy,
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000021 ShHashFunction64 hashFunction,
Zhenyao Mo9eedea02014-05-12 16:02:35 -070022 NameMap &nameMap,
Jamie Madill02f20dd2013-09-12 12:07:42 -040023 TSymbolTable& symbolTable,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080024 int shaderVersion,
25 ShShaderOutput output);
26
27 ShShaderOutput getShaderOutput() const
28 {
29 return mOutput;
30 }
zmo@google.com5601ea02011-06-10 18:23:25 +000031
Zhenyao Mo9eedea02014-05-12 16:02:35 -070032 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.com5601ea02011-06-10 18:23:25 +000036 virtual bool writeVariablePrecision(TPrecision precision) = 0;
Zhenyao Mo9eedea02014-05-12 16:02:35 -070037 void writeFunctionParameters(const TIntermSequence &args);
Jamie Madill6ba6ead2015-05-04 14:21:21 -040038 const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion);
Olli Etuahof40319e2015-03-10 14:33:00 +020039 void writeConstructorTriplet(Visit visit, const TType &type, const char *constructorBaseType);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070040 TString getTypeName(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000041
Zhenyao Mo9eedea02014-05-12 16:02:35 -070042 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 Etuaho3c1dfb52015-02-20 11:34:03 +020047 virtual bool visitSwitch(Visit visit, TIntermSwitch *node);
48 virtual bool visitCase(Visit visit, TIntermCase *node);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070049 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.com5601ea02011-06-10 18:23:25 +000052
Zhenyao Mo9eedea02014-05-12 16:02:35 -070053 void visitCodeBlock(TIntermNode *node);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000054
55 // Return the original name if hash function pointer is NULL;
56 // otherwise return the hashed name.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070057 TString hashName(const TString &name);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000058 // Same as hashName(), but without hashing built-in variables.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070059 TString hashVariableName(const TString &name);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000060 // Same as hashName(), but without hashing built-in functions.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070061 TString hashFunctionName(const TString &mangled_name);
Nicolas Capens46485082014-04-15 13:12:50 -040062 // Used to translate function names for differences between ESSL and GLSL
Zhenyao Mo9eedea02014-05-12 16:02:35 -070063 virtual TString translateTextureFunction(TString &name) { return name; }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000064
Zhenyao Mo9eedea02014-05-12 16:02:35 -070065 private:
66 bool structDeclared(const TStructure *structure) const;
67 void declareStruct(const TStructure *structure);
Jamie Madill98493dd2013-07-08 14:39:03 -040068
Zhenyao Mo9eedea02014-05-12 16:02:35 -070069 void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction);
70
71 TInfoSinkBase &mObjSink;
zmo@google.com5601ea02011-06-10 18:23:25 +000072 bool mDeclaringVariables;
73
Jamie Madill01f85ac2014-06-06 11:55:04 -040074 // This set contains all the ids of the structs from every scope.
75 std::set<int> mDeclaredStructs;
zmo@google.com5601ea02011-06-10 18:23:25 +000076
Zhenyao Mo550c6002014-02-26 15:40:48 -080077 // Stack of loops that need to be unrolled.
78 TLoopStack mLoopUnrollStack;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000079
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000080 ShArrayIndexClampingStrategy mClampingStrategy;
81
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000082 // name hashing.
83 ShHashFunction64 mHashFunction;
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000084
Zhenyao Mo9eedea02014-05-12 16:02:35 -070085 NameMap &mNameMap;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000086
Zhenyao Mo9eedea02014-05-12 16:02:35 -070087 TSymbolTable &mSymbolTable;
Jamie Madill02f20dd2013-09-12 12:07:42 -040088
89 const int mShaderVersion;
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080090
91 ShShaderOutput mOutput;
zmo@google.com5601ea02011-06-10 18:23:25 +000092};
93
Geoff Lang0a73dd82014-11-19 16:18:08 -050094#endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_