blob: 1f751e282667e7f64ef5376f2581216c8a92ad34 [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{
18public:
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000019 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,
22 NameMap& nameMap,
Jamie Madill02f20dd2013-09-12 12:07:42 -040023 TSymbolTable& symbolTable,
24 int shaderVersion);
zmo@google.com5601ea02011-06-10 18:23:25 +000025
26protected:
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);
30 virtual bool writeVariablePrecision(TPrecision precision) = 0;
31 void writeFunctionParameters(const TIntermSequence& args);
32 const ConstantUnion* writeConstantUnion(const TType& type, const ConstantUnion* pConstUnion);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000033 TString getTypeName(const TType& type);
zmo@google.com5601ea02011-06-10 18:23:25 +000034
35 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);
43
44 void visitCodeBlock(TIntermNode* node);
45
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000046
47 // Return the original name if hash function pointer is NULL;
48 // otherwise return the hashed name.
49 TString hashName(const TString& name);
50 // Same as hashName(), but without hashing built-in variables.
51 TString hashVariableName(const TString& name);
52 // Same as hashName(), but without hashing built-in functions.
53 TString hashFunctionName(const TString& mangled_name);
Nicolas Capens46485082014-04-15 13:12:50 -040054 // Used to translate function names for differences between ESSL and GLSL
55 virtual TString translateTextureFunction(TString& name) { return name; }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000056
zmo@google.com5601ea02011-06-10 18:23:25 +000057private:
Jamie Madill98493dd2013-07-08 14:39:03 -040058 bool structDeclared(const TStructure* structure) const;
59 void declareStruct(const TStructure* structure);
Zhenyao Mo904a9162014-05-09 14:07:45 -070060 void pushDeclaredStructsScope();
61 void popDeclaredStructsScope();
Jamie Madill98493dd2013-07-08 14:39:03 -040062
zmo@google.com5601ea02011-06-10 18:23:25 +000063 TInfoSinkBase& mObjSink;
64 bool mDeclaringVariables;
65
Zhenyao Mo904a9162014-05-09 14:07:45 -070066 // Structs are declared as the tree is traversed. This list contains all
67 // the structs already declared within a scope. It is maintained so that
68 // a struct is declared only once within a scope.
69 typedef std::vector<TStructure *> ScopedDeclaredStructs;
70 // This vector contains all the structs from the global scope to the
71 // current scope. When the traverser exits a scope, the scope is discarded.
72 typedef std::vector<ScopedDeclaredStructs> DeclaredStructs;
zmo@google.com5601ea02011-06-10 18:23:25 +000073 DeclaredStructs mDeclaredStructs;
74
Zhenyao Mo550c6002014-02-26 15:40:48 -080075 // Stack of loops that need to be unrolled.
76 TLoopStack mLoopUnrollStack;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000077
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000078 ShArrayIndexClampingStrategy mClampingStrategy;
79
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000080 // name hashing.
81 ShHashFunction64 mHashFunction;
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000082
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000083 NameMap& mNameMap;
84
85 TSymbolTable& mSymbolTable;
Jamie Madill02f20dd2013-09-12 12:07:42 -040086
87 const int mShaderVersion;
zmo@google.com5601ea02011-06-10 18:23:25 +000088};
89
90#endif // CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_