180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc.
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrGLSL.h"
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrGLShaderVar.h"
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkString.h"
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGrGLSLGeneration GrGetGLSLGeneration(GrGLBinding binding,
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                   const GrGLInterface* gl) {
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrGLSLVersion ver = GrGLGetGLSLVersion(gl);
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    switch (binding) {
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case kDesktop_GrGLBinding:
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            GrAssert(ver >= GR_GLSL_VER(1,10));
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (ver >= GR_GLSL_VER(1,50)) {
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return k150_GrGLSLGeneration;
20363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger            } else if (ver >= GR_GLSL_VER(1,40)) {
21363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                return k140_GrGLSLGeneration;
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            } else if (ver >= GR_GLSL_VER(1,30)) {
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return k130_GrGLSLGeneration;
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            } else {
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return k110_GrGLSLGeneration;
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case kES2_GrGLBinding:
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            // version 1.00 of ES GLSL based on ver 1.20 of desktop GLSL
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            GrAssert(ver >= GR_GL_VER(1,00));
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return k110_GrGLSLGeneration;
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        default:
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            GrCrash("Unknown GL Binding");
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return k110_GrGLSLGeneration; // suppress warning
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* GrGetGLSLVersionDecl(GrGLBinding binding,
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                   GrGLSLGeneration gen) {
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    switch (gen) {
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case k110_GrGLSLGeneration:
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (kES2_GrGLBinding == binding) {
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                // ES2s shader language is based on version 1.20 but is version
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                // 1.00 of the ES language.
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return "#version 100\n";
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            } else {
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                GrAssert(kDesktop_GrGLBinding == binding);
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return "#version 110\n";
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case k130_GrGLSLGeneration:
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            GrAssert(kDesktop_GrGLBinding == binding);
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return "#version 130\n";
52363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        case k140_GrGLSLGeneration:
53363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger            GrAssert(kDesktop_GrGLBinding == binding);
54363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger            return "#version 140\n";
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        case k150_GrGLSLGeneration:
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            GrAssert(kDesktop_GrGLBinding == binding);
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return "#version 150\n";
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        default:
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            GrCrash("Unknown GL version.");
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return ""; // suppress warning
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool GrGLSLSetupFSColorOuput(GrGLSLGeneration gen,
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                             const char* nameIfDeclared,
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                             GrGLShaderVar* var) {
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool declaredOutput = k110_GrGLSLGeneration != gen;
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    var->set(kVec4f_GrSLType,
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru             GrGLShaderVar::kOut_TypeModifier,
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru             declaredOutput ? nameIfDeclared : "gl_FragColor");
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return declaredOutput;
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGrSLType GrSLFloatVectorType (int count) {
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GR_STATIC_ASSERT(kFloat_GrSLType == 1);
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(count > 0 && count <= 4);
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return (GrSLType)(count);
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* GrGLSLVectorHomogCoord(int count) {
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static const char* HOMOGS[] = {"ERROR", "", ".y", ".z", ".w"};
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(HOMOGS));
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return HOMOGS[count];
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* GrGLSLVectorHomogCoord(GrSLType type) {
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return GrGLSLVectorHomogCoord(GrSLTypeToVecLength(type));
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* GrGLSLVectorNonhomogCoords(int count) {
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static const char* NONHOMOGS[] = {"ERROR", "", ".x", ".xy", ".xyz"};
9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(NONHOMOGS));
9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return NONHOMOGS[count];
9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* GrGLSLVectorNonhomogCoords(GrSLType type) {
10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return GrGLSLVectorNonhomogCoords(GrSLTypeToVecLength(type));
10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGrSLConstantVec GrGLSLModulate4f(SkString* outAppend,
10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 const char* in0,
10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 const char* in1,
10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 GrSLConstantVec default0,
10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 GrSLConstantVec default1) {
10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(NULL != outAppend);
10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool has0 = NULL != in0 && '\0' != *in0;
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool has1 = NULL != in1 && '\0' != *in1;
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(has0 || kNone_GrSLConstantVec != default0);
11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(has1 || kNone_GrSLConstantVec != default1);
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (!has0 && !has1) {
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0);
11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1);
11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (kZeros_GrSLConstantVec == default0 || kZeros_GrSLConstantVec == default1) {
12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            outAppend->append(GrGLSLZerosVecf(4));
12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return kZeros_GrSLConstantVec;
12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        } else {
12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            // both inputs are ones vectors
12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            outAppend->append(GrGLSLOnesVecf(4));
12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return kOnes_GrSLConstantVec;
12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    } else if (!has0) {
12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0);
12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (kZeros_GrSLConstantVec == default0) {
13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            outAppend->append(GrGLSLZerosVecf(4));
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return kZeros_GrSLConstantVec;
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        } else {
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            outAppend->appendf("vec4(%s)", in1);
13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return kNone_GrSLConstantVec;
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    } else if (!has1) {
13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1);
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (kZeros_GrSLConstantVec == default1) {
13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            outAppend->append(GrGLSLZerosVecf(4));
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return kZeros_GrSLConstantVec;
14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        } else {
14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            outAppend->appendf("vec4(%s)", in0);
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return kNone_GrSLConstantVec;
14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    } else {
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        outAppend->appendf("vec4(%s * %s)", in0, in1);
14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return kNone_GrSLConstantVec;
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querunamespace {
15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid append_tabs(SkString* outAppend, int tabCnt) {
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static const char kTabs[] = "\t\t\t\t\t\t\t\t";
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    while (tabCnt) {
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt);
15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        outAppend->append(kTabs, cnt);
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        tabCnt -= cnt;
15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend,
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 int tabCnt,
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 const char* vec4VarName,
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 const char* mulFactor,
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 GrSLConstantVec mulFactorDefault) {
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool haveFactor = NULL != mulFactor && '\0' != *mulFactor;
16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(NULL != outAppend);
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(NULL != vec4VarName);
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(kNone_GrSLConstantVec != mulFactorDefault || haveFactor);
17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (!haveFactor) {
17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        if (kOnes_GrSLConstantVec == mulFactorDefault) {
17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return kNone_GrSLConstantVec;
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        } else {
17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            GrAssert(kZeros_GrSLConstantVec == mulFactorDefault);
17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            append_tabs(outAppend, tabCnt);
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            outAppend->appendf("%s = vec4(0, 0, 0, 0);\n", vec4VarName);
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            return kZeros_GrSLConstantVec;
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    append_tabs(outAppend, tabCnt);
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor);
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return kNone_GrSLConstantVec;
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGrSLConstantVec GrGLSLAdd4f(SkString* outAppend,
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            const char* in0,
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            const char* in1,
19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            GrSLConstantVec default0,
19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            GrSLConstantVec default1) {
19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAssert(NULL != outAppend);
19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool has0 = NULL != in0 && '\0' != *in0;
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool has1 = NULL != in1 && '\0' != *in1;
19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (!has0 && !has1) {
19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert(kZeros_GrSLConstantVec == default0);
20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert(kZeros_GrSLConstantVec == default1);
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        outAppend->append(GrGLSLZerosVecf(4));
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return kZeros_GrSLConstantVec;
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    } else if (!has0) {
20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert(kZeros_GrSLConstantVec == default0);
20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        outAppend->appendf("vec4(%s)", in1);
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return kNone_GrSLConstantVec;
20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    } else if (!has1) {
20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert(kZeros_GrSLConstantVec == default1);
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        outAppend->appendf("vec4(%s)", in0);
21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return kNone_GrSLConstantVec;
21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    } else {
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        outAppend->appendf("(vec4(%s) + vec4(%s))", in0, in1);
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return kNone_GrSLConstantVec;
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
216