blob: aa65611fc8555a03bb3c3c36eef5d8b5806f1d0d [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// 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 COMPILER_OUTPUTHLSL_H_
8#define COMPILER_OUTPUTHLSL_H_
9
10#include "intermediate.h"
11#include "ParseHelper.h"
12
13namespace sh
14{
daniel@transgaming.comb5875982010-04-15 20:44:53 +000015class UnfoldSelect;
16
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000017class OutputHLSL : public TIntermTraverser
18{
19 public:
daniel@transgaming.comb5875982010-04-15 20:44:53 +000020 explicit OutputHLSL(TParseContext &context);
21 ~OutputHLSL();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022
daniel@transgaming.com950f9932010-04-13 03:26:14 +000023 void output();
24
daniel@transgaming.comb5875982010-04-15 20:44:53 +000025 TInfoSinkBase &getBodyStream();
26
27 static TString argumentString(const TIntermSymbol *symbol);
28 static TString qualifierString(TQualifier qualifier);
29 static TString typeString(const TType &type);
30 static TString arrayString(const TType &type);
31 static TString initializer(const TType &type);
32 static TString decorate(const TString &string); // Prepend an underscore to avoid naming clashes
33
daniel@transgaming.com950f9932010-04-13 03:26:14 +000034 protected:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000035 void header();
daniel@transgaming.come78c0c92010-03-28 19:36:06 +000036 void footer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000037
daniel@transgaming.com950f9932010-04-13 03:26:14 +000038 // Visit AST nodes and output their code to the body stream
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039 void visitSymbol(TIntermSymbol*);
40 void visitConstantUnion(TIntermConstantUnion*);
41 bool visitBinary(Visit visit, TIntermBinary*);
42 bool visitUnary(Visit visit, TIntermUnary*);
43 bool visitSelection(Visit visit, TIntermSelection*);
44 bool visitAggregate(Visit visit, TIntermAggregate*);
45 bool visitLoop(Visit visit, TIntermLoop*);
46 bool visitBranch(Visit visit, TIntermBranch*);
47
daniel@transgaming.comb5875982010-04-15 20:44:53 +000048 bool isSingleStatement(TIntermNode *node);
daniel@transgaming.com4a35ef22010-04-08 03:51:06 +000049 bool handleExcessiveLoop(TIntermLoop *node);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000050 void outputTriplet(Visit visit, const char *preString, const char *inString, const char *postString);
51
daniel@transgaming.com950f9932010-04-13 03:26:14 +000052 TParseContext &mContext;
daniel@transgaming.comb5875982010-04-15 20:44:53 +000053 UnfoldSelect *mUnfoldSelect;
daniel@transgaming.com950f9932010-04-13 03:26:14 +000054
55 // Output streams
56 TInfoSinkBase mHeader;
57 TInfoSinkBase mBody;
58 TInfoSinkBase mFooter;
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +000059
60 // Parameters determining what goes in the header output
61 bool mUsesEqualMat2;
62 bool mUsesEqualMat3;
63 bool mUsesEqualMat4;
64 bool mUsesEqualVec2;
65 bool mUsesEqualVec3;
66 bool mUsesEqualVec4;
67 bool mUsesEqualIVec2;
68 bool mUsesEqualIVec3;
69 bool mUsesEqualIVec4;
70 bool mUsesEqualBVec2;
71 bool mUsesEqualBVec3;
72 bool mUsesEqualBVec4;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000073};
74}
75
76#endif // COMPILER_OUTPUTHLSL_H_