Edit

kc3-lang/angle/src/compiler/translator/BuiltInFunctionEmulatorGLSL.cpp

Branch :

  • Show log

    Commit

  • Author : Olli Etuaho
    Date : 2015-03-05 19:40:42
    Hash : 51585037
    Message : Remove unnecessary ifdef APPLE from built-in emulation The emulation is already toggled by a compilation flag, so having it behind an ifdef only adds unnecessary complexity, particularly when testing changes to the emulation code. BUG=angleproject:865 Change-Id: Idf7854c2b5323609880b527ed806440dcc8ac091 Reviewed-on: https://chromium-review.googlesource.com/256365 Tested-by: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Zhenyao Mo <zmo@chromium.org>

  • src/compiler/translator/BuiltInFunctionEmulatorGLSL.cpp
  • //
    // Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    #include "angle_gl.h"
    #include "compiler/translator/BuiltInFunctionEmulator.h"
    #include "compiler/translator/BuiltInFunctionEmulatorGLSL.h"
    #include "compiler/translator/SymbolTable.h"
    
    void InitBuiltInFunctionEmulatorForGLSL(BuiltInFunctionEmulator *emu, sh::GLenum shaderType)
    {
        // we use macros here instead of function definitions to work around more GLSL
        // compiler bugs, in particular on NVIDIA hardware on Mac OSX. Macros are
        // problematic because if the argument has side-effects they will be repeatedly
        // evaluated. This is unlikely to show up in real shaders, but is something to
        // consider.
    
        TType float1(EbtFloat);
        TType float2(EbtFloat, 2);
        TType float3(EbtFloat, 3);
        TType float4(EbtFloat, 4);
    
        if (shaderType == GL_FRAGMENT_SHADER)
        {
            emu->addEmulatedFunction(EOpCos, float1, "webgl_emu_precision float webgl_cos_emu(webgl_emu_precision float a) { return cos(a); }");
            emu->addEmulatedFunction(EOpCos, float2, "webgl_emu_precision vec2 webgl_cos_emu(webgl_emu_precision vec2 a) { return cos(a); }");
            emu->addEmulatedFunction(EOpCos, float3, "webgl_emu_precision vec3 webgl_cos_emu(webgl_emu_precision vec3 a) { return cos(a); }");
            emu->addEmulatedFunction(EOpCos, float4, "webgl_emu_precision vec4 webgl_cos_emu(webgl_emu_precision vec4 a) { return cos(a); }");
        }
        emu->addEmulatedFunction(EOpDistance, float1, float1, "#define webgl_distance_emu(x, y) ((x) >= (y) ? (x) - (y) : (y) - (x))");
        emu->addEmulatedFunction(EOpDot, float1, float1, "#define webgl_dot_emu(x, y) ((x) * (y))");
        emu->addEmulatedFunction(EOpLength, float1, "#define webgl_length_emu(x) ((x) >= 0.0 ? (x) : -(x))");
        emu->addEmulatedFunction(EOpNormalize, float1, "#define webgl_normalize_emu(x) ((x) == 0.0 ? 0.0 : ((x) > 0.0 ? 1.0 : -1.0))");
        emu->addEmulatedFunction(EOpReflect, float1, float1, "#define webgl_reflect_emu(I, N) ((I) - 2.0 * (N) * (I) * (N))");
    }