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.
7 #ifndef COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_
8 #define COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_
10 #include "compiler/translator/InfoSink.h"
11 #include "compiler/translator/IntermNode.h"
14 // This class decides which built-in functions need to be replaced with the
16 // It's only a workaround for OpenGL driver bugs, and isn't needed in general.
18 class BuiltInFunctionEmulator {
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
24 // Returns true if the function call needs to be replaced with an emulated
26 bool SetFunctionCalled(TOperator op, const TType& param);
27 bool SetFunctionCalled(
28 TOperator op, const TType& param1, const TType& param2);
30 // Output function emulation definition. This should be before any other
32 void OutputEmulatedFunctionDefinition(TInfoSinkBase& out, bool withPrecision) const;
34 void MarkBuiltInFunctionsForEmulation(TIntermNode* root);
38 // "name(" becomes "webgl_name_emu(".
39 static TString GetEmulatedFunctionName(const TString& name);
43 // Built-in functions.
45 enum TBuiltInFunction {
46 TFunctionCos1 = 0, // float cos(float);
47 TFunctionCos2, // vec2 cos(vec2);
48 TFunctionCos3, // vec3 cos(vec3);
49 TFunctionCos4, // vec4 cos(vec4);
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);
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);
61 TFunctionLength1, // float length(float);
62 TFunctionLength2, // float length(vec2);
63 TFunctionLength3, // float length(vec3);
64 TFunctionLength4, // float length(vec4);
66 TFunctionNormalize1, // float normalize(float);
67 TFunctionNormalize2, // vec2 normalize(vec2);
68 TFunctionNormalize3, // vec3 normalize(vec3);
69 TFunctionNormalize4, // vec4 normalize(vec4);
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);
79 TBuiltInFunction IdentifyFunction(TOperator op, const TType& param);
80 TBuiltInFunction IdentifyFunction(
81 TOperator op, const TType& param1, const TType& param2);
83 bool SetFunctionCalled(TBuiltInFunction function);
85 std::vector<TBuiltInFunction> mFunctions;
87 const bool* mFunctionMask; // a boolean flag for each function.
88 const char** mFunctionSource;
91 #endif // COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_