Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / compiler / translator / BuiltInFunctionEmulator.h
1 //
2 // Copyright (c) 2011 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 COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_
8 #define COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_
9
10 #include "compiler/translator/InfoSink.h"
11 #include "compiler/translator/IntermNode.h"
12
13 //
14 // This class decides which built-in functions need to be replaced with the
15 // emulated ones.
16 // It's only a workaround for OpenGL driver bugs, and isn't needed in general.
17 //
18 class BuiltInFunctionEmulator {
19 public:
20     BuiltInFunctionEmulator(sh::GLenum shaderType);
21     // Records that a function is called by the shader and might needs to be
22     // emulated.  If the function's group is not in mFunctionGroupFilter, this
23     // becomes an no-op.
24     // Returns true if the function call needs to be replaced with an emulated
25     // one.
26     bool SetFunctionCalled(TOperator op, const TType& param);
27     bool SetFunctionCalled(
28         TOperator op, const TType& param1, const TType& param2);
29
30     // Output function emulation definition.  This should be before any other
31     // shader source.
32     void OutputEmulatedFunctionDefinition(TInfoSinkBase& out, bool withPrecision) const;
33
34     void MarkBuiltInFunctionsForEmulation(TIntermNode* root);
35
36     void Cleanup();
37
38     // "name(" becomes "webgl_name_emu(".
39     static TString GetEmulatedFunctionName(const TString& name);
40
41 private:
42     //
43     // Built-in functions.
44     //
45     enum TBuiltInFunction {
46         TFunctionCos1 = 0,  // float cos(float);
47         TFunctionCos2,  // vec2 cos(vec2);
48         TFunctionCos3,  // vec3 cos(vec3);
49         TFunctionCos4,  // vec4 cos(vec4);
50
51         TFunctionDistance1_1,  // float distance(float, float);
52         TFunctionDistance2_2,  // vec2 distance(vec2, vec2);
53         TFunctionDistance3_3,  // vec3 distance(vec3, vec3);
54         TFunctionDistance4_4,  // vec4 distance(vec4, vec4);
55
56         TFunctionDot1_1,  // float dot(float, float);
57         TFunctionDot2_2,  // vec2 dot(vec2, vec2);
58         TFunctionDot3_3,  // vec3 dot(vec3, vec3);
59         TFunctionDot4_4,  // vec4 dot(vec4, vec4);
60
61         TFunctionLength1,  // float length(float);
62         TFunctionLength2,  // float length(vec2);
63         TFunctionLength3,  // float length(vec3);
64         TFunctionLength4,  // float length(vec4);
65
66         TFunctionNormalize1,  // float normalize(float);
67         TFunctionNormalize2,  // vec2 normalize(vec2);
68         TFunctionNormalize3,  // vec3 normalize(vec3);
69         TFunctionNormalize4,  // vec4 normalize(vec4);
70
71         TFunctionReflect1_1,  // float reflect(float, float);
72         TFunctionReflect2_2,  // vec2 reflect(vec2, vec2);
73         TFunctionReflect3_3,  // vec3 reflect(vec3, vec3);
74         TFunctionReflect4_4,  // vec4 reflect(vec4, vec4);
75
76         TFunctionUnknown
77     };
78
79     TBuiltInFunction IdentifyFunction(TOperator op, const TType& param);
80     TBuiltInFunction IdentifyFunction(
81         TOperator op, const TType& param1, const TType& param2);
82
83     bool SetFunctionCalled(TBuiltInFunction function);
84
85     std::vector<TBuiltInFunction> mFunctions;
86
87     const bool* mFunctionMask;  // a boolean flag for each function.
88     const char** mFunctionSource;
89 };
90
91 #endif  // COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_