blob: 7c6d09c1bb94442231cb447386f501554c4de368 [file] [log] [blame]
Zhenyao Mocd68fe72014-07-11 10:45:44 -07001//
2// Copyright (c) 2002-2014 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_TRANSLATOR_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS_H_
8#define COMPILER_TRANSLATOR_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS_H_
9
Jamie Madillb1a85f42014-08-19 15:23:24 -040010#include "compiler/translator/IntermNode.h"
Zhenyao Mocd68fe72014-07-11 10:45:44 -070011
12class ScalarizeVecAndMatConstructorArgs : public TIntermTraverser
13{
14 public:
Zhenyao Modaf56572014-08-06 16:18:30 -070015 ScalarizeVecAndMatConstructorArgs(sh::GLenum shaderType,
16 bool fragmentPrecisionHigh)
17 : mTempVarCount(0),
18 mShaderType(shaderType),
19 mFragmentPrecisionHigh(fragmentPrecisionHigh) {}
Zhenyao Mocd68fe72014-07-11 10:45:44 -070020
21 protected:
22 virtual bool visitAggregate(Visit visit, TIntermAggregate *node);
23
24 private:
25 void scalarizeArgs(TIntermAggregate *aggregate,
26 bool scalarizeVector, bool scalarizeMatrix);
27
28 // If we have the following code:
29 // mat4 m(0);
30 // vec4 v(1, m);
31 // We will rewrite to:
32 // mat4 m(0);
33 // mat4 _webgl_tmp_mat_0 = m;
34 // vec4 v(1, _webgl_tmp_mat_0[0][0], _webgl_tmp_mat_0[0][1], _webgl_tmp_mat_0[0][2]);
35 // This function is to create nodes for "mat4 _webgl_tmp_mat_0 = m;" and insert it to
36 // the code sequence.
37 // Return the temporary variable name.
38 TString createTempVariable(TIntermTyped *original);
39
40 std::vector<TIntermSequence> mSequenceStack;
41 int mTempVarCount;
Zhenyao Modaf56572014-08-06 16:18:30 -070042
43 sh::GLenum mShaderType;
44 bool mFragmentPrecisionHigh;
Zhenyao Mocd68fe72014-07-11 10:45:44 -070045};
46
47#endif // COMPILER_TRANSLATOR_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS_H_