michael@0: // michael@0: // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #ifndef COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_ michael@0: #define COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_ michael@0: michael@0: #include "GLSLANG/ShaderLang.h" michael@0: michael@0: #include "compiler/InfoSink.h" michael@0: #include "compiler/intermediate.h" michael@0: michael@0: // michael@0: // This class decides which built-in functions need to be replaced with the michael@0: // emulated ones. michael@0: // It's only a workaround for OpenGL driver bugs, and isn't needed in general. michael@0: // michael@0: class BuiltInFunctionEmulator { michael@0: public: michael@0: BuiltInFunctionEmulator(ShShaderType shaderType); michael@0: // Records that a function is called by the shader and might needs to be michael@0: // emulated. If the function's group is not in mFunctionGroupFilter, this michael@0: // becomes an no-op. michael@0: // Returns true if the function call needs to be replaced with an emulated michael@0: // one. michael@0: bool SetFunctionCalled(TOperator op, const TType& param); michael@0: bool SetFunctionCalled( michael@0: TOperator op, const TType& param1, const TType& param2); michael@0: bool SetFunctionCalled( michael@0: TOperator op, const TType& param1, const TType& param2, const TType& param3); michael@0: michael@0: // Output function emulation definition. This should be before any other michael@0: // shader source. michael@0: void OutputEmulatedFunctionDefinition(TInfoSinkBase& out, bool withPrecision) const; michael@0: michael@0: void MarkBuiltInFunctionsForEmulation(TIntermNode* root); michael@0: michael@0: void Cleanup(); michael@0: michael@0: // "name(" becomes "webgl_name_emu(". michael@0: static TString GetEmulatedFunctionName(const TString& name); michael@0: michael@0: private: michael@0: // michael@0: // Built-in functions. michael@0: // michael@0: enum TBuiltInFunction { michael@0: TFunctionCos1 = 0, // float cos(float); michael@0: TFunctionCos2, // vec2 cos(vec2); michael@0: TFunctionCos3, // vec3 cos(vec3); michael@0: TFunctionCos4, // vec4 cos(vec4); michael@0: michael@0: TFunctionDistance1_1, // float distance(float, float); michael@0: TFunctionDistance2_2, // vec2 distance(vec2, vec2); michael@0: TFunctionDistance3_3, // vec3 distance(vec3, vec3); michael@0: TFunctionDistance4_4, // vec4 distance(vec4, vec4); michael@0: michael@0: TFunctionDot1_1, // float dot(float, float); michael@0: TFunctionDot2_2, // vec2 dot(vec2, vec2); michael@0: TFunctionDot3_3, // vec3 dot(vec3, vec3); michael@0: TFunctionDot4_4, // vec4 dot(vec4, vec4); michael@0: michael@0: TFunctionFaceForward1_1_1, // float faceforward(float, float, float); michael@0: TFunctionFaceForward2_2_2, // vec2 faceforward(vec2, vec2, vec2); michael@0: TFunctionFaceForward3_3_3, // vec3 faceforward(vec3, vec3, vec3); michael@0: TFunctionFaceForward4_4_4, // vec4 faceforward(vec4, vec4, vec4); michael@0: michael@0: TFunctionLength1, // float length(float); michael@0: TFunctionLength2, // float length(vec2); michael@0: TFunctionLength3, // float length(vec3); michael@0: TFunctionLength4, // float length(vec4); michael@0: michael@0: TFunctionNormalize1, // float normalize(float); michael@0: TFunctionNormalize2, // vec2 normalize(vec2); michael@0: TFunctionNormalize3, // vec3 normalize(vec3); michael@0: TFunctionNormalize4, // vec4 normalize(vec4); michael@0: michael@0: TFunctionReflect1_1, // float reflect(float, float); michael@0: TFunctionReflect2_2, // vec2 reflect(vec2, vec2); michael@0: TFunctionReflect3_3, // vec3 reflect(vec3, vec3); michael@0: TFunctionReflect4_4, // vec4 reflect(vec4, vec4); michael@0: michael@0: TFunctionUnknown michael@0: }; michael@0: michael@0: TBuiltInFunction IdentifyFunction(TOperator op, const TType& param); michael@0: TBuiltInFunction IdentifyFunction( michael@0: TOperator op, const TType& param1, const TType& param2); michael@0: TBuiltInFunction IdentifyFunction( michael@0: TOperator op, const TType& param1, const TType& param2, const TType& param3); michael@0: michael@0: bool SetFunctionCalled(TBuiltInFunction function); michael@0: michael@0: std::vector mFunctions; michael@0: michael@0: const bool* mFunctionMask; // a boolean flag for each function. michael@0: const char** mFunctionSource; michael@0: }; michael@0: michael@0: #endif // COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_