blob: 79c2c72e561af19a8251c75490f099720be4b831 [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);
Olli Etuahoae69d7e2015-10-07 17:19:50 +030035 void writeLayoutQualifier(const TType &type);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070036 void writeVariableType(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000037 virtual bool writeVariablePrecision(TPrecision precision) = 0;
Zhenyao Mo9eedea02014-05-12 16:02:35 -070038 void writeFunctionParameters(const TIntermSequence &args);
Jamie Madill6ba6ead2015-05-04 14:21:21 -040039 const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion);
Olli Etuahoe92507b2016-07-04 11:20:10 +030040 void writeConstructorTriplet(Visit visit, const TType &type);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070041 TString getTypeName(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000042
Corentin Walleze5a1f272015-08-21 02:58:25 +020043 void visitSymbol(TIntermSymbol *node) override;
44 void visitConstantUnion(TIntermConstantUnion *node) override;
45 bool visitBinary(Visit visit, TIntermBinary *node) override;
46 bool visitUnary(Visit visit, TIntermUnary *node) override;
Olli Etuahod0bad2c2016-09-09 18:01:16 +030047 bool visitTernary(Visit visit, TIntermTernary *node) override;
Olli Etuaho57961272016-09-14 13:57:46 +030048 bool visitIfElse(Visit visit, TIntermIfElse *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020049 bool visitSwitch(Visit visit, TIntermSwitch *node) override;
50 bool visitCase(Visit visit, TIntermCase *node) override;
51 bool visitAggregate(Visit visit, TIntermAggregate *node) override;
52 bool visitLoop(Visit visit, TIntermLoop *node) override;
53 bool visitBranch(Visit visit, TIntermBranch *node) override;
zmo@google.com5601ea02011-06-10 18:23:25 +000054
Zhenyao Mo9eedea02014-05-12 16:02:35 -070055 void visitCodeBlock(TIntermNode *node);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000056
57 // Return the original name if hash function pointer is NULL;
58 // otherwise return the hashed name.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070059 TString hashName(const TString &name);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000060 // Same as hashName(), but without hashing built-in variables.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070061 TString hashVariableName(const TString &name);
Olli Etuaho59f9a642015-08-06 20:38:26 +030062 // Same as hashName(), but without hashing built-in functions and with unmangling.
63 TString hashFunctionNameIfNeeded(const TName &mangledName);
Nicolas Capens46485082014-04-15 13:12:50 -040064 // Used to translate function names for differences between ESSL and GLSL
Zhenyao Mo9eedea02014-05-12 16:02:35 -070065 virtual TString translateTextureFunction(TString &name) { return name; }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000066
Zhenyao Mo9eedea02014-05-12 16:02:35 -070067 private:
68 bool structDeclared(const TStructure *structure) const;
69 void declareStruct(const TStructure *structure);
Jamie Madill98493dd2013-07-08 14:39:03 -040070
Geoff Langbdcc54a2015-09-02 13:09:48 -040071 void declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock);
72 void declareInterfaceBlock(const TInterfaceBlock *interfaceBlock);
73
Zhenyao Mo9eedea02014-05-12 16:02:35 -070074 void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction);
75
76 TInfoSinkBase &mObjSink;
zmo@google.com5601ea02011-06-10 18:23:25 +000077 bool mDeclaringVariables;
78
Jamie Madill01f85ac2014-06-06 11:55:04 -040079 // This set contains all the ids of the structs from every scope.
80 std::set<int> mDeclaredStructs;
zmo@google.com5601ea02011-06-10 18:23:25 +000081
Zhenyao Mo550c6002014-02-26 15:40:48 -080082 // Stack of loops that need to be unrolled.
83 TLoopStack mLoopUnrollStack;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000084
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000085 ShArrayIndexClampingStrategy mClampingStrategy;
86
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000087 // name hashing.
88 ShHashFunction64 mHashFunction;
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000089
Zhenyao Mo9eedea02014-05-12 16:02:35 -070090 NameMap &mNameMap;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000091
Zhenyao Mo9eedea02014-05-12 16:02:35 -070092 TSymbolTable &mSymbolTable;
Jamie Madill02f20dd2013-09-12 12:07:42 -040093
94 const int mShaderVersion;
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080095
96 ShShaderOutput mOutput;
zmo@google.com5601ea02011-06-10 18:23:25 +000097};
98
Geoff Lang0a73dd82014-11-19 16:18:08 -050099#endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_