diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/effects/SkBlendImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkLightingImageFilter.cpp | 7 | ||||
-rw-r--r-- | src/effects/SkMagnifierImageFilter.cpp | 5 | ||||
-rw-r--r-- | src/effects/SkMorphologyImageFilter.cpp | 10 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShader.cpp | 15 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShaderPriv.h | 7 | ||||
-rw-r--r-- | src/effects/gradients/SkLinearGradient.cpp | 2 | ||||
-rw-r--r-- | src/effects/gradients/SkRadialGradient.cpp | 2 | ||||
-rw-r--r-- | src/effects/gradients/SkSweepGradient.cpp | 2 | ||||
-rw-r--r-- | src/effects/gradients/SkTwoPointConicalGradient.cpp | 6 | ||||
-rw-r--r-- | src/effects/gradients/SkTwoPointRadialGradient.cpp | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrConfigConversionEffect.cpp | 24 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.cpp | 8 | ||||
-rw-r--r-- | src/gpu/effects/GrSingleTextureEffect.cpp | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureDomainEffect.cpp | 4 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 1 | ||||
-rw-r--r-- | src/gpu/gl/GrGLSL.cpp | 38 | ||||
-rw-r--r-- | src/gpu/gl/GrGLSL.h | 13 | ||||
-rw-r--r-- | src/gpu/gl/GrGLShaderBuilder.cpp | 34 | ||||
-rw-r--r-- | src/gpu/gl/GrGLShaderBuilder.h | 27 |
20 files changed, 78 insertions, 137 deletions
diff --git a/src/effects/SkBlendImageFilter.cpp b/src/effects/SkBlendImageFilter.cpp index 825767783d..f4ef9def7f 100644 --- a/src/effects/SkBlendImageFilter.cpp +++ b/src/effects/SkBlendImageFilter.cpp @@ -263,8 +263,8 @@ void GrGLBlendEffect::emitFS(GrGLShaderBuilder* builder, const char* bgColor = inputColor; const char* fgColor = "fgColor"; code->appendf("\t\tvec4 %s = ", fgColor); - builder->appendTextureLookup(code, samplerName); - code->append(";\n"); + builder->emitTextureLookup(samplerName); + code->appendf(";\n"); code->appendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.b);\n", outputColor, bgColor, fgColor); switch (fMode) { case SkBlendImageFilter::kNormal_Mode: diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 8eb28bb3c5..408e7021ff 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -1160,7 +1160,7 @@ void GrGLLightingEffect::emitFS(GrGLShaderBuilder* builder, SkString texCoords; texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc); code->appendf("\t\tm[%d] = ", index++); - builder->appendTextureLookup(code, samplerName, texCoords.c_str()); + builder->emitTextureLookup(samplerName, texCoords.c_str()); code->appendf(".a;\n"); } } @@ -1168,12 +1168,11 @@ void GrGLLightingEffect::emitFS(GrGLShaderBuilder* builder, SkString arg; arg.appendf("%s * m[4]", surfScale); fLight->emitSurfaceToLight(builder, code, arg.c_str()); - code->append(";\n"); + code->appendf(";\n"); code->appendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", outputColor, lightFunc.c_str(), interiorNormalName.c_str(), surfScale); fLight->emitLightColor(builder, "surfaceToLight"); - code->append(");\n"); - GrGLSLMulVarBy4f(code, 2, outputColor, inputColor); + code->appendf(")%s;\n", builder->fModulate.c_str()); } GrGLProgramStage::StageKey GrGLLightingEffect::GenKey(const GrCustomStage& s, diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index 6b8324a7ab..3145321816 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -159,11 +159,10 @@ void GrGLMagnifierEffect::emitFS(GrGLShaderBuilder* state, code->appendf("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n"); code->appendf("\t\tvec4 output_color = "); - state->appendTextureLookup(code, samplerName, "mix_coord"); - code->append(";\n"); + state->emitTextureLookup(samplerName, "mix_coord"); + code->appendf(";\n"); code->appendf("\t\t%s = output_color;", outputColor); - GrGLSLMulVarBy4f(code, 2, outputColor, inputColor); } void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman, diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 04dc2270c6..eb121a72da 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -319,11 +319,11 @@ void GrGLMorphologyEffect::emitFS(GrGLShaderBuilder* builder, const char* func; switch (fType) { case GrMorphologyEffect::kErode_MorphologyType: - code->appendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor); + code->appendf("\t\tvec4 value = vec4(1, 1, 1, 1);\n"); func = "min"; break; case GrMorphologyEffect::kDilate_MorphologyType: - code->appendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); + code->appendf("\t\tvec4 value = vec4(0, 0, 0, 0);\n"); func = "max"; break; default: @@ -336,12 +336,12 @@ void GrGLMorphologyEffect::emitFS(GrGLShaderBuilder* builder, code->appendf("\t\tvec2 coord = %s - %d.0 * %s;\n", builder->defaultTexCoordsName(), fRadius, imgInc); code->appendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width()); - code->appendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor); - builder->appendTextureLookup(&builder->fFSCode, samplerName, "coord"); + code->appendf("\t\t\tvalue = %s(value, ", func); + builder->emitTextureLookup(samplerName, "coord"); code->appendf(");\n"); code->appendf("\t\t\tcoord += %s;\n", imgInc); code->appendf("\t\t}\n"); - GrGLSLMulVarBy4f(code, 2, outputColor, inputColor); + code->appendf("\t\t%s = value%s;\n", outputColor, builder->fModulate.c_str()); } GrGLProgramStage::StageKey GrGLMorphologyEffect::GenKey(const GrCustomStage& s, diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 3d989b7611..891b1cdf9b 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -699,19 +699,14 @@ void GrGLGradientStage::setData(const GrGLUniformManager& uman, } void GrGLGradientStage::emitColorLookup(GrGLShaderBuilder* builder, - const char* gradientTValue, + const char* tName, const char* outputColor, - const char* inputColor, const char* samplerName) { - SkString* code = &builder->fFSCode; - code->appendf("\tvec2 coord = vec2(%s, %s);\n", - gradientTValue, - builder->getUniformVariable(fFSYUni).c_str()); - GrGLSLMulVarBy4f(code, 1, outputColor, inputColor); - code->appendf("\t%s = ", outputColor); - builder->appendTextureLookupAndModulate(code, inputColor, samplerName, "coord"); - code->append(";\n"); + builder->fFSCode.appendf("\tvec2 coord = vec2(%s, %s);\n", + tName, + builder->getUniformVariable(fFSYUni).c_str()); + builder->emitTextureLookupAndModulate(outputColor, samplerName, "coord"); } ///////////////////////////////////////////////////////////////////// diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h index 2b584f30b6..37959678a2 100644 --- a/src/effects/gradients/SkGradientShaderPriv.h +++ b/src/effects/gradients/SkGradientShaderPriv.h @@ -287,11 +287,8 @@ public: // emit code that gets a fragment's color from an expression for t; for now // this always uses the texture, but for simpler cases we'll be able to lerp - void emitColorLookup(GrGLShaderBuilder* builder, - const char* gradientTValue, - const char* outputColor, - const char* inputColor, - const char* samplerName); + void emitColorLookup(GrGLShaderBuilder* builder, const char* t, + const char* outputColor, const char* samplerName); private: diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index 6415927c72..78d2f24a04 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -553,7 +553,7 @@ void GrGLLinearGradient::emitFS(GrGLShaderBuilder* builder, const char* samplerName) { SkString t; t.printf("%s.x", builder->defaultTexCoordsName()); - this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplerName); + this->emitColorLookup(builder, t.c_str(), outputColor, samplerName); } ///////////////////////////////////////////////////////////////////// diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp index 98433e28ef..317ab68b47 100644 --- a/src/effects/gradients/SkRadialGradient.cpp +++ b/src/effects/gradients/SkRadialGradient.cpp @@ -553,7 +553,7 @@ void GrGLRadialGradient::emitFS(GrGLShaderBuilder* builder, const char* samplerName) { SkString t; t.printf("length(%s.xy)", builder->defaultTexCoordsName()); - this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplerName); + this->emitColorLookup(builder, t.c_str(), outputColor, samplerName); } ///////////////////////////////////////////////////////////////////// diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index 22b211871c..15547de6d4 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -459,7 +459,7 @@ void GrGLSweepGradient::emitFS(GrGLShaderBuilder* builder, SkString t; t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", builder->defaultTexCoordsName(), builder->defaultTexCoordsName()); - this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplerName); + this->emitColorLookup(builder, t.c_str(), outputColor, samplerName); } ///////////////////////////////////////////////////////////////////// diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index c84989b67f..8b32ab6bb7 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -593,7 +593,7 @@ void GrGLConical2Gradient::emitFS(GrGLShaderBuilder* builder, p5.c_str(), p3.c_str()); code->appendf("\t\t"); - this->emitColorLookup(builder, tName.c_str(), outputColor, inputColor, samplerName); + this->emitColorLookup(builder, tName.c_str(), outputColor, samplerName); // otherwise, if r(t) for the larger root was <= 0, try the other root code->appendf("\t\t} else {\n"); @@ -605,7 +605,7 @@ void GrGLConical2Gradient::emitFS(GrGLShaderBuilder* builder, tName.c_str(), p5.c_str(), p3.c_str()); code->appendf("\t\t\t"); - this->emitColorLookup(builder, tName.c_str(), outputColor, inputColor, samplerName); + this->emitColorLookup(builder, tName.c_str(), outputColor, samplerName); // end if (r(t) > 0) for smaller root code->appendf("\t\t\t}\n"); @@ -623,7 +623,7 @@ void GrGLConical2Gradient::emitFS(GrGLShaderBuilder* builder, code->appendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(), p5.c_str(), p3.c_str()); code->appendf("\t"); - this->emitColorLookup(builder, tName.c_str(), outputColor, inputColor, samplerName); + this->emitColorLookup(builder, tName.c_str(), outputColor, samplerName); code->appendf("\t}\n"); } } diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp index 2192707cc4..693dc32b0a 100644 --- a/src/effects/gradients/SkTwoPointRadialGradient.cpp +++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp @@ -601,7 +601,7 @@ void GrGLRadial2Gradient::emitFS(GrGLShaderBuilder* builder, t.printf("-%s / %s", cName.c_str(), bVar.c_str()); } - this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplerName); + this->emitColorLookup(builder, t.c_str(), outputColor, samplerName); } void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index 318c03e653..fbf5a4090a 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -23,39 +23,37 @@ public: const char* outputColor, const char* inputColor, const char* samplerName) SK_OVERRIDE { - builder->fFSCode.appendf("\t\t%s = ", outputColor); - builder->appendTextureLookup(&builder->fFSCode, samplerName); - builder->fFSCode.appendf("%s;\n", builder->fSwizzle.c_str()); + builder->fFSCode.append("\tvec4 tempColor;\n"); + builder->emitTextureLookupAndModulate("tempColor", samplerName); if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { GrAssert(fSwapRedAndBlue); - builder->fFSCode.appendf("\t%s = %s.bgra;\n", outputColor, outputColor); + builder->fFSCode.appendf("\t%s = tempColor.bgra;\n", outputColor); } else { const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; switch (fPMConversion) { case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: builder->fFSCode.appendf( - "\t\t%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);\n", - outputColor, outputColor, swiz, outputColor, outputColor); + "\t%s = vec4(ceil(tempColor.%s*tempColor.a*255.0)/255.0, tempColor.a);\n", + outputColor, swiz); break; case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversion: builder->fFSCode.appendf( - "\t\t%s = vec4(floor(%s.%s * %s.a * 255.0) / 255.0, %s.a);\n", - outputColor, outputColor, swiz, outputColor, outputColor); + "\t%s = vec4(floor(tempColor.%s*tempColor.a*255.0)/255.0, tempColor.a);\n", + outputColor, swiz); break; case GrConfigConversionEffect::kDivByAlpha_RoundUp_PMConversion: - builder->fFSCode.appendf("\t\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(%s.%s / %s.a * 255.0) / 255.0, %s.a);\n", - outputColor, outputColor, outputColor, swiz, outputColor, outputColor); + builder->fFSCode.appendf("\t%s = tempColor.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(tempColor.%s / tempColor.a * 255.0)/255.0, tempColor.a);\n", + outputColor, swiz); break; case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversion: - builder->fFSCode.appendf("\t\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / %s.a * 255.0) / 255.0, %s.a);\n", - outputColor, outputColor, outputColor, swiz, outputColor, outputColor); + builder->fFSCode.appendf("\t%s = tempColor.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(tempColor.%s / tempColor.a * 255.0)/255.0, tempColor.a);\n", + outputColor, swiz); break; default: GrCrash("Unknown conversion op."); break; } } - GrGLSLMulVarBy4f(&builder->fFSCode, 2, outputColor, inputColor); } static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps&) { diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index 635064fef7..162a0cc4c8 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -84,11 +84,15 @@ void GrGLConvolutionEffect::emitFS(GrGLShaderBuilder* builder, index.appendS32(i); kernel.appendArrayAccess(index.c_str(), &kernelIndex); code->appendf("\t\t%s += ", outputColor); - builder->appendTextureLookup(&builder->fFSCode, samplerName, "coord"); + builder->emitTextureLookup(samplerName, "coord"); code->appendf(" * %s;\n", kernelIndex.c_str()); code->appendf("\t\tcoord += %s;\n", imgInc); } - GrGLSLMulVarBy4f(&builder->fFSCode, 2, outputColor, inputColor); + + if (builder->fModulate.size()) { + code->appendf("\t\t%s = %s%s;\n", outputColor, outputColor, + builder->fModulate.c_str()); + } } void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp index dc91a68c20..42a8bf9501 100644 --- a/src/gpu/effects/GrSingleTextureEffect.cpp +++ b/src/gpu/effects/GrSingleTextureEffect.cpp @@ -23,9 +23,7 @@ public: const char* outputColor, const char* inputColor, const char* samplerName) SK_OVERRIDE { - builder->fFSCode.appendf("\t%s = ", outputColor); - builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplerName); - builder->fFSCode.append(";\n"); + builder->emitTextureLookupAndModulate(outputColor, samplerName); } static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&) { return 0; } diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp index f5306c7b01..a67dd49afd 100644 --- a/src/gpu/effects/GrTextureDomainEffect.cpp +++ b/src/gpu/effects/GrTextureDomainEffect.cpp @@ -55,9 +55,7 @@ void GrGLTextureDomainEffect::emitFS(GrGLShaderBuilder* builder, builder->getUniformCStr(fNameUni), builder->getUniformCStr(fNameUni)); - builder->fFSCode.appendf("\t%s = ", outputColor); - builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplerName, "clampCoord"); - builder->fFSCode.append(";\n"); + builder->emitTextureLookupAndModulate(outputColor, samplerName, "clampCoord"); } void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index ff29bd4028..50e839b77c 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -987,6 +987,7 @@ void GrGLProgram::genStageCode(int stageNum, builder->fVSCode.appendf("\t}\n"); builder->computeSwizzle(desc.fInConfigFlags); + builder->computeModulate(fsInColor); // Enclose custom code in a block to avoid namespace conflicts builder->fFSCode.appendf("\t{ // stage %d %s \n", diff --git a/src/gpu/gl/GrGLSL.cpp b/src/gpu/gl/GrGLSL.cpp index 079c08232f..c995a34652 100644 --- a/src/gpu/gl/GrGLSL.cpp +++ b/src/gpu/gl/GrGLSL.cpp @@ -115,7 +115,6 @@ GrSLConstantVec GrGLSLModulate4f(SkString* outAppend, outAppend->append(GrGLSLZerosVecf(4)); return kZeros_GrSLConstantVec; } else { - // both inputs are ones vectors outAppend->append(GrGLSLOnesVecf(4)); return kOnes_GrSLConstantVec; } @@ -143,43 +142,6 @@ GrSLConstantVec GrGLSLModulate4f(SkString* outAppend, } } -namespace { -void append_tabs(SkString* outAppend, int tabCnt) { - static const char kTabs[] = "\t\t\t\t\t\t\t\t"; - while (tabCnt) { - int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt); - outAppend->append(kTabs, cnt); - tabCnt -= cnt; - } -} -} - -GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend, - int tabCnt, - const char* vec4VarName, - const char* mulFactor, - GrSLConstantVec mulFactorDefault) { - bool haveFactor = NULL != mulFactor && '\0' != *mulFactor; - - GrAssert(NULL != outAppend); - GrAssert(NULL != vec4VarName); - GrAssert(kNone_GrSLConstantVec != mulFactorDefault || haveFactor); - - if (!haveFactor) { - if (kOnes_GrSLConstantVec == mulFactorDefault) { - return kNone_GrSLConstantVec; - } else { - GrAssert(kZeros_GrSLConstantVec == mulFactorDefault); - append_tabs(outAppend, tabCnt); - outAppend->appendf("%s = vec4(0, 0, 0, 0);\n", vec4VarName); - return kZeros_GrSLConstantVec; - } - } - append_tabs(outAppend, tabCnt); - outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor); - return kNone_GrSLConstantVec; -} - GrSLConstantVec GrGLSLAdd4f(SkString* outAppend, const char* in0, const char* in1, diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/gl/GrGLSL.h index cbff273382..6595608615 100644 --- a/src/gpu/gl/GrGLSL.h +++ b/src/gpu/gl/GrGLSL.h @@ -144,19 +144,6 @@ GrSLConstantVec GrGLSLModulate4f(SkString* outAppend, GrSLConstantVec default0 = kOnes_GrSLConstantVec, GrSLConstantVec default1 = kOnes_GrSLConstantVec); -/** - * Does an inplace mul, *=, of vec4VarName by mulFactor. If mulFactorDefault is not kNone then - * mulFactor may be either "" or NULL. In this case either nothing will be appened (kOnes) or an - * assignment of vec(0,0,0,0) will be appended (kZeros). The assignment is prepended by tabCnt tabs. - * A semicolon and newline are added after the assignment. (TODO: Remove tabCnt when we auto-insert - * tabs to custom stage-generated lines.) If a zeros vec is assigned then the return value is - * kZeros, otherwise kNone. - */ -GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend, - int tabCnt, - const char* vec4VarName, - const char* mulFactor, - GrSLConstantVec mulFactorDefault = kOnes_GrSLConstantVec); /** * Produces a string that is the result of adding two inputs. The inputs must be vec4 or float. diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp index e899e416c3..c0614684be 100644 --- a/src/gpu/gl/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/GrGLShaderBuilder.cpp @@ -96,6 +96,14 @@ void GrGLShaderBuilder::computeSwizzle(uint32_t configFlags) { } } +void GrGLShaderBuilder::computeModulate(const char* fsInColor) { + if (NULL != fsInColor) { + fModulate.printf(" * %s", fsInColor); + } else { + fModulate.reset(); + } +} + void GrGLShaderBuilder::setupTextureAccess(const char* varyingFSName, GrSLType varyingType) { // FIXME: We don't know how the custom stage will manipulate the coords. So we give up on using // projective texturing and always give the stage 2D coords. This will be fixed when custom @@ -122,27 +130,23 @@ void GrGLShaderBuilder::setupTextureAccess(const char* varyingFSName, GrSLType v } } -void GrGLShaderBuilder::appendTextureLookup(SkString* out, - const char* samplerName, - const char* coordName, - GrSLType varyingType) const { +void GrGLShaderBuilder::emitTextureLookup(const char* samplerName, + const char* coordName, + GrSLType varyingType) { if (NULL == coordName) { coordName = fDefaultTexCoordsName.c_str(); varyingType = kVec2f_GrSLType; } - out->appendf("%s(%s, %s)", sample_function_name(varyingType), samplerName, coordName); + fFSCode.appendf("%s(%s, %s)", sample_function_name(varyingType), samplerName, coordName); } -void GrGLShaderBuilder::appendTextureLookupAndModulate(SkString* out, - const char* modulation, - const char* samplerName, - const char* coordName, - GrSLType varyingType) const { - GrAssert(NULL != out); - SkString lookup; - this->appendTextureLookup(&lookup, samplerName, coordName, varyingType); - GrGLSLModulate4f(out, modulation, lookup.c_str()); - out->append(fSwizzle.c_str()); +void GrGLShaderBuilder::emitTextureLookupAndModulate(const char* outColor, + const char* samplerName, + const char* coordName, + GrSLType varyingType) { + fFSCode.appendf("\t%s = ", outColor); + this->emitTextureLookup(samplerName, coordName, varyingType); + fFSCode.appendf("%s%s;\n", fSwizzle.c_str(), fModulate.c_str()); } void GrGLShaderBuilder::emitCustomTextureLookup(const GrTextureAccess& textureAccess, diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h index bc108923f9..66de5abdcc 100644 --- a/src/gpu/gl/GrGLShaderBuilder.h +++ b/src/gpu/gl/GrGLShaderBuilder.h @@ -32,6 +32,7 @@ public: GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&); void computeSwizzle(uint32_t configFlags); + void computeModulate(const char* fsInColor); /** Determines whether we should use texture2D() or texture2Dproj(), and if an explicit divide is required for the sample coordinates, creates the new variable and emits the code to @@ -41,20 +42,17 @@ public: /** texture2D(samplerName, coordName), with projection if necessary; if coordName is not specified, uses fSampleCoords. coordType must either be Vec2f or Vec3f. The latter is interpreted as projective texture coords. */ - void appendTextureLookup(SkString* out, - const char* samplerName, - const char* coordName = NULL, - GrSLType coordType = kVec2f_GrSLType) const; - - /** appends a texture lookup, with swizzle as necessary. If coordName is NULL then it as if - defaultTexCoordsName() was passed. coordType must be either kVec2f or kVec3f. If modulateVar - is not NULL or "" then the texture lookup will be modulated by it. modulation must refer to - be expression that evaluates to a float or vec4. */ - void appendTextureLookupAndModulate(SkString* out, - const char* modulation, - const char* samplerName, - const char* coordName = NULL, - GrSLType varyingType = kVec2f_GrSLType) const; + void emitTextureLookup(const char* samplerName, + const char* coordName = NULL, + GrSLType coordType = kVec2f_GrSLType); + + /** sets outColor to results of texture lookup, with swizzle, and/or modulate as necessary. If + coordName is NULL then it as if defaultTexCoordsName() was passed. coordType must be either + kVec2f or kVec3f. */ + void emitTextureLookupAndModulate(const char* outColor, + const char* samplerName, + const char* coordName = NULL, + GrSLType coordType = kVec2f_GrSLType); /** Gets the name of the default texture coords which are always kVec2f */ const char* defaultTexCoordsName() const { return fDefaultTexCoordsName.c_str(); } @@ -173,6 +171,7 @@ public: //@{ SkString fSwizzle; + SkString fModulate; //@} |