blob: ae40f85e0d5ef321483d31682bdfd3e836494fa4 [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
7#ifndef CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_
8#define CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_
9
Zhenyao Mo904a9162014-05-09 14:07:45 -070010#include <vector>
zmo@google.com5601ea02011-06-10 18:23:25 +000011
Geoff Lang17732822013-08-29 13:46:49 -040012#include "compiler/translator/intermediate.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,
24 int shaderVersion);
zmo@google.com5601ea02011-06-10 18:23:25 +000025
Zhenyao Mo9eedea02014-05-12 16:02:35 -070026 protected:
27 TInfoSinkBase &objSink() { return mObjSink; }
28 void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr);
29 void writeVariableType(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000030 virtual bool writeVariablePrecision(TPrecision precision) = 0;
Zhenyao Mo9eedea02014-05-12 16:02:35 -070031 void writeFunctionParameters(const TIntermSequence &args);
32 const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *pConstUnion);
33 TString getTypeName(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000034
Zhenyao Mo9eedea02014-05-12 16:02:35 -070035 virtual void visitSymbol(TIntermSymbol *node);
36 virtual void visitConstantUnion(TIntermConstantUnion *node);
37 virtual bool visitBinary(Visit visit, TIntermBinary *node);
38 virtual bool visitUnary(Visit visit, TIntermUnary *node);
39 virtual bool visitSelection(Visit visit, TIntermSelection *node);
40 virtual bool visitAggregate(Visit visit, TIntermAggregate *node);
41 virtual bool visitLoop(Visit visit, TIntermLoop *node);
42 virtual bool visitBranch(Visit visit, TIntermBranch *node);
zmo@google.com5601ea02011-06-10 18:23:25 +000043
Zhenyao Mo9eedea02014-05-12 16:02:35 -070044 void visitCodeBlock(TIntermNode *node);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000045
46 // Return the original name if hash function pointer is NULL;
47 // otherwise return the hashed name.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070048 TString hashName(const TString &name);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000049 // Same as hashName(), but without hashing built-in variables.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070050 TString hashVariableName(const TString &name);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000051 // Same as hashName(), but without hashing built-in functions.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070052 TString hashFunctionName(const TString &mangled_name);
Nicolas Capens46485082014-04-15 13:12:50 -040053 // Used to translate function names for differences between ESSL and GLSL
Zhenyao Mo9eedea02014-05-12 16:02:35 -070054 virtual TString translateTextureFunction(TString &name) { return name; }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000055
Zhenyao Mo9eedea02014-05-12 16:02:35 -070056 private:
57 bool structDeclared(const TStructure *structure) const;
58 void declareStruct(const TStructure *structure);
Zhenyao Mo904a9162014-05-09 14:07:45 -070059 void pushDeclaredStructsScope();
60 void popDeclaredStructsScope();
Jamie Madill98493dd2013-07-08 14:39:03 -040061
Zhenyao Mo9eedea02014-05-12 16:02:35 -070062 void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction);
63
64 TInfoSinkBase &mObjSink;
zmo@google.com5601ea02011-06-10 18:23:25 +000065 bool mDeclaringVariables;
66
Zhenyao Mo904a9162014-05-09 14:07:45 -070067 // Structs are declared as the tree is traversed. This list contains all
68 // the structs already declared within a scope. It is maintained so that
69 // a struct is declared only once within a scope.
70 typedef std::vector<TStructure *> ScopedDeclaredStructs;
71 // This vector contains all the structs from the global scope to the
72 // current scope. When the traverser exits a scope, the scope is discarded.
73 typedef std::vector<ScopedDeclaredStructs> DeclaredStructs;
zmo@google.com5601ea02011-06-10 18:23:25 +000074 DeclaredStructs mDeclaredStructs;
75
Zhenyao Mo550c6002014-02-26 15:40:48 -080076 // Stack of loops that need to be unrolled.
77 TLoopStack mLoopUnrollStack;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000078
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000079 ShArrayIndexClampingStrategy mClampingStrategy;
80
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000081 // name hashing.
82 ShHashFunction64 mHashFunction;
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000083
Zhenyao Mo9eedea02014-05-12 16:02:35 -070084 NameMap &mNameMap;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000085
Zhenyao Mo9eedea02014-05-12 16:02:35 -070086 TSymbolTable &mSymbolTable;
Jamie Madill02f20dd2013-09-12 12:07:42 -040087
88 const int mShaderVersion;
zmo@google.com5601ea02011-06-10 18:23:25 +000089};
90
91#endif // CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_