blob: d5f6e5cc6103c688a9dd978f3d03e0084d48ff8e [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
10#include <set>
11
12#include "compiler/ForLoopUnroll.h"
13#include "compiler/intermediate.h"
14#include "compiler/ParseHelper.h"
15
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);
54
zmo@google.com5601ea02011-06-10 18:23:25 +000055private:
Jamie Madill98493dd2013-07-08 14:39:03 -040056 bool structDeclared(const TStructure* structure) const;
57 void declareStruct(const TStructure* structure);
58
zmo@google.com5601ea02011-06-10 18:23:25 +000059 TInfoSinkBase& mObjSink;
60 bool mDeclaringVariables;
61
62 // Structs are declared as the tree is traversed. This set contains all
63 // the structs already declared. It is maintained so that a struct is
64 // declared only once.
65 typedef std::set<TString> DeclaredStructs;
66 DeclaredStructs mDeclaredStructs;
67
68 ForLoopUnroll mLoopUnroll;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000069
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000070 ShArrayIndexClampingStrategy mClampingStrategy;
71
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000072 // name hashing.
73 ShHashFunction64 mHashFunction;
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000074
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000075 NameMap& mNameMap;
76
77 TSymbolTable& mSymbolTable;
Jamie Madill02f20dd2013-09-12 12:07:42 -040078
79 const int mShaderVersion;
zmo@google.com5601ea02011-06-10 18:23:25 +000080};
81
82#endif // CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_