Add multitexture support to text and path shaders, take 3.
This does not add additional textures to the atlases, just adds the
ability to access those textures in the shaders.
Bug: skia:3550
Change-Id: I4c1da2bc374a76131f5f4ad946543e03e0ab3126
Reviewed-on: https://skia-review.googlesource.com/44841
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index c2cf8eb..8013d2e 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -7,6 +7,7 @@
#include "GrBitmapTextGeoProc.h"
+#include "GrAtlasedShaderHelpers.h"
#include "GrTexture.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
@@ -36,12 +37,10 @@
"AtlasSizeInv",
&atlasSizeInvName);
- GrGLSLVertToFrag v(kVec2f_GrSLType);
- varyingHandler->addVarying("TextureCoords", &v, kHigh_GrSLPrecision);
- vertBuilder->codeAppendf("%s = float2(%s.x, %s.y) * %s;", v.vsOut(),
- btgp.inTextureCoords()->fName,
- btgp.inTextureCoords()->fName,
- atlasSizeInvName);
+ GrGLSLVertToFrag uv(kVec2f_GrSLType);
+ GrGLSLVertToFrag texIdx(kFloat_GrSLType);
+ append_index_uv_varyings(args, btgp.inTextureCoords()->fName, atlasSizeInvName,
+ &uv, &texIdx, nullptr);
GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
@@ -64,18 +63,16 @@
btgp.localMatrix(),
args.fFPCoordTransformHandler);
+ fragBuilder->codeAppend("float4 texColor;");
+ append_multitexture_lookup(args, btgp.numTextureSamplers(),
+ texIdx, uv.fsIn(), "texColor");
+
if (btgp.maskFormat() == kARGB_GrMaskFormat) {
- fragBuilder->codeAppendf("%s = ", args.fOutputColor);
- fragBuilder->appendTextureLookupAndModulate(args.fOutputColor,
- args.fTexSamplers[0],
- v.fsIn(),
- kVec2f_GrSLType);
- fragBuilder->codeAppend(";");
+ // modulate by color
+ fragBuilder->codeAppendf("%s = %s * texColor;", args.fOutputColor, args.fOutputColor);
fragBuilder->codeAppendf("%s = float4(1);", args.fOutputCoverage);
} else {
- fragBuilder->codeAppendf("%s = ", args.fOutputCoverage);
- fragBuilder->appendTextureLookup(args.fTexSamplers[0], v.fsIn(), kVec2f_GrSLType);
- fragBuilder->codeAppend(";");
+ fragBuilder->codeAppendf("%s = texColor;", args.fOutputCoverage);
}
}
@@ -89,7 +86,7 @@
fColor = btgp.color();
}
- SkASSERT(btgp.numTextureSamplers() == 1);
+ SkASSERT(btgp.numTextureSamplers() >= 1);
GrTexture* atlas = btgp.textureSampler(0).peekTexture();
SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()));
@@ -108,6 +105,7 @@
key |= (btgp.usesLocalCoords() && btgp.localMatrix().hasPerspective()) ? 0x1 : 0x0;
key |= btgp.maskFormat() << 1;
b->add32(key);
+ b->add32(btgp.numTextureSamplers());
}
private: