Rename ShaderType enum to ShaderVisibility

Renames ShaderType in GrGLShaderBuilder to ShaderVisibility. It is now
used solely as a bitfield. Methods that previously accepted a single
ShaderType value are split into separate calls:

 - getShader -> vsGetShader, gsGetShader, fsGetShader
 - emiitFunction -> fsEmitFunction
 - appendTextureLookup -> fsAppendTextureLookup

No change in functionality. This is a refactoring to allow us to
separate the vertex/geometry and fragment parts of GrGLShaderBuilder.

R=bsalomon@google.com

Author: cdalton@nvidia.com

Review URL: https://chromiumcodereview.appspot.com/23826002

git-svn-id: http://skia.googlecode.com/svn/trunk@11044 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-08-30 19:43:59 +00:00
parent 3628ad9f13
commit 74a3a2135c
23 changed files with 267 additions and 361 deletions

View File

@ -952,10 +952,7 @@ public:
GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCoords, NULL, "BG");
dstColor = "bgColor";
builder->fsCodeAppendf("\t\tvec4 %s = ", dstColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
bgCoords.c_str(),
bgCoordsType);
builder->fsAppendTextureLookup(samplers[0], bgCoords.c_str(), bgCoordsType);
builder->fsCodeAppendf(";\n");
} else {
dstColor = builder->dstColor();
@ -1225,8 +1222,7 @@ public:
GrGLShaderVar("color", kVec3f_GrSLType),
};
SkString getLumBody("\treturn dot(vec3(0.3, 0.59, 0.11), color);\n");
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType,
builder->fsEmitFunction(kFloat_GrSLType,
"luminance",
SK_ARRAY_COUNT(getLumArgs), getLumArgs,
getLumBody.c_str(),
@ -1251,8 +1247,7 @@ public:
"\t\toutColor = outLum + ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / (maxComp - outLum);\n"
"\t}\n"
"\treturn outColor;\n");
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType,
builder->fsEmitFunction(kVec3f_GrSLType,
"set_luminance",
SK_ARRAY_COUNT(setLumArgs), setLumArgs,
setLumBody.c_str(),
@ -1269,8 +1264,7 @@ public:
SkString getSatBody;
getSatBody.printf("\treturn max(max(color.r, color.g), color.b) - "
"min(min(color.r, color.g), color.b);\n");
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType,
builder->fsEmitFunction(kFloat_GrSLType,
"saturation",
SK_ARRAY_COUNT(getSatArgs), getSatArgs,
getSatBody.c_str(),
@ -1296,8 +1290,7 @@ public:
"\t} else {\n"
"\t\treturn vec3(0, 0, 0);\n"
"\t}\n";
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType,
builder->fsEmitFunction(kVec3f_GrSLType,
"set_saturation_helper",
SK_ARRAY_COUNT(helperArgs), helperArgs,
kHelperBody,
@ -1328,8 +1321,7 @@ public:
"\treturn hueLumColor;\n",
getFunction.c_str(), helpFunc, helpFunc, helpFunc, helpFunc,
helpFunc, helpFunc);
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType,
builder->fsEmitFunction(kVec3f_GrSLType,
"set_saturation",
SK_ARRAY_COUNT(setSatArgs), setSatArgs,
setSatBody.c_str(),

View File

@ -354,10 +354,7 @@ void GrGLArithmeticEffect::emitCode(GrGLShaderBuilder* builder,
SkString bgCoords;
GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCoords, NULL, "BG");
builder->fsCodeAppend("\t\tvec4 bgColor = ");
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
bgCoords.c_str(),
bgCoordsType);
builder->fsAppendTextureLookup(samplers[0], bgCoords.c_str(), bgCoordsType);
builder->fsCodeAppendf(";\n");
dstColor = "bgColor";
} else {
@ -365,7 +362,7 @@ void GrGLArithmeticEffect::emitCode(GrGLShaderBuilder* builder,
}
SkASSERT(NULL != dstColor);
fKUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fKUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType, "k");
const char* kUni = builder->getUniformCStr(fKUni);

View File

@ -226,9 +226,9 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
const TextureSamplerArray& samplers) {
SkString coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kMat44f_GrSLType, "Coefficients");
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "ImageIncrement");
const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
@ -244,8 +244,7 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
GrGLShaderVar("c2", kVec4f_GrSLType),
GrGLShaderVar("c3", kVec4f_GrSLType),
};
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec4f_GrSLType,
builder->fsEmitFunction(kVec4f_GrSLType,
"cubicBlend",
SK_ARRAY_COUNT(gCubicBlendArgs),
gCubicBlendArgs,
@ -260,9 +259,7 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
SkString coord;
coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1);
builder->fsCodeAppendf("\tvec4 s%d%d = ", x, y);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
coord.c_str());
builder->fsAppendTextureLookup(samplers[0], coord.c_str());
builder->fsCodeAppend(";\n");
}
builder->fsCodeAppendf("\tvec4 s%d = %s(%s, f.x, s0%d, s1%d, s2%d, s3%d);\n", y, cubicBlendName.c_str(), coeff, y, y, y, y);

View File

@ -400,10 +400,10 @@ public:
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE {
fMatrixHandle = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fMatrixHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kMat44f_GrSLType,
"ColorMatrix");
fVectorHandle = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fVectorHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType,
"ColorMatrixVector");

View File

@ -409,7 +409,7 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
const TextureSamplerArray& samplers) {
sk_ignore_unused_variable(inputColor);
fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "Scale");
const char* scaleUni = builder->getUniformCStr(fScaleUni);
@ -428,10 +428,7 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
// leave room for 32-bit float GPU rounding errors.
builder->fsCodeAppendf("\t\tvec4 %s = ", dColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
dCoordsIn.c_str(),
dCoordsType);
builder->fsAppendTextureLookup(samplers[0], dCoordsIn.c_str(), dCoordsType);
builder->fsCodeAppend(";\n");
// Unpremultiply the displacement
@ -484,10 +481,7 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
"bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0);\t\t",
outOfBounds, cCoords, cCoords, cCoords, cCoords);
builder->fsCodeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[1],
cCoords,
cCoordsType);
builder->fsAppendTextureLookup(samplers[1], cCoords, cCoordsType);
builder->fsCodeAppend(";\n");
}

View File

@ -1207,10 +1207,10 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
SkString coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType,
"ImageIncrement");
fSurfaceScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fSurfaceScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType,
"SurfaceScale");
fLight->emitLightColorUniform(builder);
@ -1226,8 +1226,7 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
GrGLShaderVar("scale", kFloat_GrSLType),
};
SkString sobelFuncName;
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType,
builder->fsEmitFunction(kFloat_GrSLType,
"sobel",
SK_ARRAY_COUNT(gSobelArgs),
gSobelArgs,
@ -1239,8 +1238,7 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
GrGLShaderVar("scale", kFloat_GrSLType),
};
SkString pointToNormalName;
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType,
builder->fsEmitFunction(kVec3f_GrSLType,
"pointToNormal",
SK_ARRAY_COUNT(gPointToNormalArgs),
gPointToNormalArgs,
@ -1259,8 +1257,7 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
sobelFuncName.c_str(),
sobelFuncName.c_str());
SkString interiorNormalName;
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType,
builder->fsEmitFunction(kVec3f_GrSLType,
"interiorNormal",
SK_ARRAY_COUNT(gInteriorNormalArgs),
gInteriorNormalArgs,
@ -1279,9 +1276,7 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
SkString texCoords;
texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc);
builder->fsCodeAppendf("\t\tm[%d] = ", index++);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
texCoords.c_str());
builder->fsAppendTextureLookup(samplers[0], texCoords.c_str());
builder->fsCodeAppend(".a;\n");
}
}
@ -1337,7 +1332,7 @@ GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactor
void GrGLDiffuseLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkString* funcName) {
const char* kd;
fKDUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fKDUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType,
"KD",
&kd);
@ -1350,8 +1345,7 @@ void GrGLDiffuseLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStri
SkString lightBody;
lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n", kd);
lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1.0);\n");
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec4f_GrSLType,
builder->fsEmitFunction(kVec4f_GrSLType,
"light",
SK_ARRAY_COUNT(gLightArgs),
gLightArgs,
@ -1419,9 +1413,9 @@ void GrGLSpecularLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStr
const char* ks;
const char* shininess;
fKSUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fKSUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "KS", &ks);
fShininessUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fShininessUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "Shininess", &shininess);
static const GrGLShaderVar gLightArgs[] = {
@ -1434,8 +1428,7 @@ void GrGLSpecularLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStr
lightBody.appendf("\tfloat colorScale = %s * pow(dot(normal, halfDir), %s);\n", ks, shininess);
lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\n");
lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b));\n");
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec4f_GrSLType,
builder->fsEmitFunction(kVec4f_GrSLType,
"light",
SK_ARRAY_COUNT(gLightArgs),
gLightArgs,
@ -1453,7 +1446,7 @@ void GrGLSpecularLightingEffect::setData(const GrGLUniformManager& uman,
///////////////////////////////////////////////////////////////////////////////
void GrGLLight::emitLightColorUniform(GrGLShaderBuilder* builder) {
fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec3f_GrSLType, "LightColor");
}
@ -1479,7 +1472,7 @@ void GrGLDistantLight::setData(const GrGLUniformManager& uman,
void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z) {
const char* dir;
fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec3f_GrSLType,
"LightDirection", &dir);
builder->fsCodeAppend(dir);
}
@ -1496,7 +1489,7 @@ void GrGLPointLight::setData(const GrGLUniformManager& uman,
void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z) {
const char* loc;
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec3f_GrSLType,
"LightLocation", &loc);
builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->fragmentPosition(), z);
}
@ -1518,7 +1511,7 @@ void GrGLSpotLight::setData(const GrGLUniformManager& uman,
void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z) {
const char* location;
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec3f_GrSLType, "LightLocation", &location);
builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))",
location, builder->fragmentPosition(), z);
@ -1534,15 +1527,15 @@ void GrGLSpotLight::emitLightColor(GrGLShaderBuilder* builder,
const char* cosOuter;
const char* coneScale;
const char* s;
fExponentUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fExponentUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "Exponent", &exponent);
fCosInnerConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fCosInnerConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "CosInnerConeAngle", &cosInner);
fCosOuterConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fCosOuterConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "CosOuterConeAngle", &cosOuter);
fConeScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fConeScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "ConeScale", &coneScale);
fSUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fSUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec3f_GrSLType, "S", &s);
static const GrGLShaderVar gLightColorArgs[] = {
@ -1559,8 +1552,7 @@ void GrGLSpotLight::emitLightColor(GrGLShaderBuilder* builder,
color, cosOuter, coneScale);
lightColorBody.appendf("\t}\n");
lightColorBody.appendf("\treturn %s;\n", color);
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType,
builder->fsEmitFunction(kVec3f_GrSLType,
"lightColor",
SK_ARRAY_COUNT(gLightColorArgs),
gLightColorArgs,

View File

@ -130,16 +130,16 @@ void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
SkString coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fOffsetVar = builder->addUniform(
GrGLShaderBuilder::kFragment_ShaderType |
GrGLShaderBuilder::kVertex_ShaderType,
GrGLShaderBuilder::kFragment_Visibility |
GrGLShaderBuilder::kVertex_Visibility,
kVec2f_GrSLType, "uOffset");
fZoomVar = builder->addUniform(
GrGLShaderBuilder::kFragment_ShaderType |
GrGLShaderBuilder::kVertex_ShaderType,
GrGLShaderBuilder::kFragment_Visibility |
GrGLShaderBuilder::kVertex_Visibility,
kVec2f_GrSLType, "uZoom");
fInsetVar = builder->addUniform(
GrGLShaderBuilder::kFragment_ShaderType |
GrGLShaderBuilder::kVertex_ShaderType,
GrGLShaderBuilder::kFragment_Visibility |
GrGLShaderBuilder::kVertex_Visibility,
kVec2f_GrSLType, "uInset");
builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str());
@ -165,7 +165,7 @@ void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppend("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n");
builder->fsCodeAppend("\t\tvec4 output_color = ");
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "mix_coord");
builder->fsAppendTextureLookup(samplers[0], "mix_coord");
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\t\t%s = output_color;", outputColor);

View File

@ -376,7 +376,7 @@ static void appendTextureLookup(GrGLShaderBuilder* builder,
builder->fsCodeAppendf("clamp(%s, 0.0, 1.0) != %s ? vec4(0, 0, 0, 0) : ", coord, coord);
break;
}
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sampler, coord);
builder->fsAppendTextureLookup(sampler, coord);
}
void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
@ -387,15 +387,15 @@ void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
const TextureSamplerArray& samplers) {
SkString coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "ImageIncrement");
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "Kernel", fKernelSize.width() * fKernelSize.height());
fTargetUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fTargetUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "Target");
fGainUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fGainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "Gain");
fBiasUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fBiasUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "Bias");
const char* target = builder->getUniformCStr(fTargetUni);

View File

@ -326,7 +326,7 @@ void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
const TextureSamplerArray& samplers) {
SkString coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "ImageIncrement");
const char* func;
@ -349,7 +349,7 @@ void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords.c_str(), fRadius, imgInc);
builder->fsCodeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width());
builder->fsCodeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "coord");
builder->fsAppendTextureLookup(samplers[0], "coord");
builder->fsCodeAppend(");\n");
builder->fsCodeAppendf("\t\t\tcoord += %s;\n", imgInc);
builder->fsCodeAppend("\t\t}\n");

View File

@ -752,16 +752,16 @@ void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder,
SkString vCoords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
fSeedUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fSeedUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "seed");
const char* seedUni = builder->getUniformCStr(fSeedUni);
fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kMat33f_GrSLType, "invMatrix");
const char* invMatrixUni = builder->getUniformCStr(fInvMatrixUni);
fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "baseFrequency");
const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni);
fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "alpha");
const char* alphaUni = builder->getUniformCStr(fAlphaUni);
@ -771,7 +771,7 @@ void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder,
};
SkString mod289_3_funcName;
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
builder->fsEmitFunction(kVec3f_GrSLType,
"mod289", SK_ARRAY_COUNT(gVec3Args), gVec3Args,
"const vec2 C = vec2(1.0 / 289.0, 289.0);\n"
"return x - floor(x * C.xxx) * C.yyy;", &mod289_3_funcName);
@ -782,7 +782,7 @@ void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder,
};
SkString mod289_4_funcName;
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kVec4f_GrSLType,
builder->fsEmitFunction(kVec4f_GrSLType,
"mod289", SK_ARRAY_COUNT(gVec4Args), gVec4Args,
"const vec2 C = vec2(1.0 / 289.0, 289.0);\n"
"return x - floor(x * C.xxxx) * C.yyyy;", &mod289_4_funcName);
@ -792,13 +792,13 @@ void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder,
permuteCode.appendf("const vec2 C = vec2(34.0, 1.0);\n"
"return %s(((x * C.xxxx) + C.yyyy) * x);", mod289_4_funcName.c_str());
SkString permuteFuncName;
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kVec4f_GrSLType,
builder->fsEmitFunction(kVec4f_GrSLType,
"permute", SK_ARRAY_COUNT(gVec4Args), gVec4Args,
permuteCode.c_str(), &permuteFuncName);
// Add vec4 taylorInvSqrt function
SkString taylorInvSqrtFuncName;
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kVec4f_GrSLType,
builder->fsEmitFunction(kVec4f_GrSLType,
"taylorInvSqrt", SK_ARRAY_COUNT(gVec4Args), gVec4Args,
"const vec2 C = vec2(-0.85373472095314, 1.79284291400159);\n"
"return x * C.xxxx + C.yyyy;", &taylorInvSqrtFuncName);
@ -886,7 +886,7 @@ void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder,
taylorInvSqrtFuncName.c_str());
SkString noiseFuncName;
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kFloat_GrSLType,
builder->fsEmitFunction(kFloat_GrSLType,
"snoise", SK_ARRAY_COUNT(gNoiseVec3Args), gNoiseVec3Args,
noiseCode.c_str(), &noiseFuncName);
@ -968,19 +968,19 @@ void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder,
SkString vCoords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kMat33f_GrSLType, "invMatrix");
const char* invMatrixUni = builder->getUniformCStr(fInvMatrixUni);
fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "baseFrequency");
const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni);
fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "alpha");
const char* alphaUni = builder->getUniformCStr(fAlphaUni);
const char* stitchDataUni = NULL;
if (fStitchTiles) {
fStitchDataUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fStitchDataUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "stitchData");
stitchDataUni = builder->getUniformCStr(fStitchDataUni);
}
@ -1137,11 +1137,11 @@ void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder,
SkString noiseFuncName;
if (fStitchTiles) {
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kFloat_GrSLType,
builder->fsEmitFunction(kFloat_GrSLType,
"perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitchArgs),
gPerlinNoiseStitchArgs, noiseCode.c_str(), &noiseFuncName);
} else {
builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kFloat_GrSLType,
builder->fsEmitFunction(kFloat_GrSLType,
"perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs),
gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncName);
}

View File

@ -312,19 +312,19 @@ void GLColorTableEffect::emitCode(GrGLShaderBuilder* builder,
}
builder->fsCodeAppendf("\t\t%s.a = ", outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "vec2(coord.a, 0.125)");
builder->fsAppendTextureLookup(samplers[0], "vec2(coord.a, 0.125)");
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\t\t%s.r = ", outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "vec2(coord.r, 0.375)");
builder->fsAppendTextureLookup(samplers[0], "vec2(coord.r, 0.375)");
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\t\t%s.g = ", outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "vec2(coord.g, 0.625)");
builder->fsAppendTextureLookup(samplers[0], "vec2(coord.g, 0.625)");
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\t\t%s.b = ", outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "vec2(coord.b, 0.875)");
builder->fsAppendTextureLookup(samplers[0], "vec2(coord.b, 0.875)");
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);

View File

@ -832,7 +832,7 @@ GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
GrGLGradientEffect::~GrGLGradientEffect() { }
void GrGLGradientEffect::emitYCoordUniform(GrGLShaderBuilder* builder) {
fFSYUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fFSYUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "GradientYCoordFS");
}
@ -877,10 +877,7 @@ void GrGLGradientEffect::emitColorLookup(GrGLShaderBuilder* builder,
gradientTValue,
builder->getUniformVariable(fFSYUni).c_str());
builder->fsCodeAppendf("\t%s = ", outputColor);
builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
inputColor,
sampler,
"coord");
builder->fsAppendTextureLookupAndModulate(inputColor, sampler, "coord");
builder->fsCodeAppend(";\n");
}

View File

@ -499,9 +499,9 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
// in test apps, but need to keep an eye on it.
fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType,
fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_Visibility,
kFloat_GrSLType, "Conical2VSParams", 6);
fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "Conical2FSParams", 6);
// For radial gradients without perspective we can pass the linear

View File

@ -541,9 +541,9 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
// in test apps, but need to keep an eye on it.
fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType,
fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_Visibility,
kFloat_GrSLType, "Radial2VSParams", 6);
fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "Radial2FSParams", 6);
// For radial gradients without perspective we can pass the linear

View File

@ -33,10 +33,7 @@ public:
SkString coords;
GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords);
builder->fsCodeAppendf("\t\t%s = ", outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
coords.c_str(),
coordsType);
builder->fsAppendTextureLookup(samplers[0], coords.c_str(), coordsType);
builder->fsCodeAppend(";\n");
if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) {
SkASSERT(fSwapRedAndBlue);

View File

@ -64,13 +64,13 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
const TextureSamplerArray& samplers) {
SkString coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "ImageIncrement");
if (this->useBounds()) {
fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "Bounds");
}
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "Kernel", this->width());
builder->fsCodeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor);
@ -88,7 +88,7 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
index.appendS32(i);
kernel.appendArrayAccess(index.c_str(), &kernelIndex);
builder->fsCodeAppendf("\t\t%s += ", outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "coord");
builder->fsAppendTextureLookup(samplers[0], "coord");
if (this->useBounds()) {
const char* bounds = builder->getUniformCStr(fBoundsUni);
const char* component = this->direction() == Gr1DKernelEffect::kY_Direction ? "y" : "x";

View File

@ -48,8 +48,7 @@ public:
fsCoordSLType = fEffectMatrix.get()->emitCode(builder, key, &fsCoordName);
}
builder->fsCodeAppendf("\t%s = ", outputColor);
builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
inputColor,
builder->fsAppendTextureLookupAndModulate(inputColor,
samplers[0],
fsCoordName.c_str(),
fsCoordSLType);

View File

@ -53,7 +53,7 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
SkString coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
const char* domain;
fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType, "TexDom", &domain);
if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) {
@ -61,10 +61,7 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
coords.c_str(), domain, domain);
builder->fsCodeAppendf("\t%s = ", outputColor);
builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
inputColor,
samplers[0],
"clampCoord");
builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], "clampCoord");
builder->fsCodeAppend(";\n");
} else {
SkASSERT(GrTextureDomainEffect::kDecal_WrapMode == texDom.wrapMode());
@ -78,10 +75,7 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
// result=white;" code fails to compile.
builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n");
builder->fsCodeAppend("\tvec4 inside = ");
builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
inputColor,
samplers[0],
coords.c_str());
builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords.c_str());
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n",
@ -95,10 +89,7 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coords.c_str(), domain);
builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", coords.c_str(), domain);
builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", outputColor);
builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
inputColor,
samplers[0],
coords.c_str());
builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords.c_str());
builder->fsCodeAppend(";\n");
}
}

View File

@ -81,7 +81,7 @@ GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
uniName = suffixedUniName.c_str();
}
if (kVoid_GrSLType != fUniType) {
fUni = builder->addUniform(GrGLShaderBuilder::kVertex_ShaderType,
fUni = builder->addUniform(GrGLShaderBuilder::kVertex_Visibility,
fUniType,
uniName,
&uniName);

View File

@ -231,7 +231,7 @@ GrSLConstantVec GrGLProgram::genInputColor(GrGLShaderBuilder* builder, SkString*
}
case GrGLProgramDesc::kUniform_ColorInput: {
const char* name;
fUniformHandles.fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fUniformHandles.fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType, "Color", &name);
*inColor = name;
return kNone_GrSLConstantVec;
@ -261,7 +261,7 @@ GrSLConstantVec GrGLProgram::genInputCoverage(GrGLShaderBuilder* builder, SkStri
case GrGLProgramDesc::kUniform_ColorInput: {
const char* name;
fUniformHandles.fCoverageUni =
builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType, "Coverage", &name);
*inCoverage = name;
return kNone_GrSLConstantVec;
@ -399,7 +399,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) {
SkString shader;
builder.getShader(GrGLShaderBuilder::kVertex_ShaderType, &shader);
builder.vsGetShader(&shader);
if (c_PrintShaders) {
GrPrintf(shader.c_str());
GrPrintf("\n");
@ -412,7 +412,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) {
fGShaderID = 0;
#if GR_GL_EXPERIMENTAL_GS
if (fDesc.getHeader().fExperimentalGS) {
builder.getShader(GrGLShaderBuilder::kGeometry_ShaderType, &shader);
builder.gsGetShader(&shader);
if (c_PrintShaders) {
GrPrintf(shader.c_str());
GrPrintf("\n");
@ -423,7 +423,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) {
}
#endif
builder.getShader(GrGLShaderBuilder::kFragment_ShaderType, &shader);
builder.fsGetShader(&shader);
if (c_PrintShaders) {
GrPrintf(shader.c_str());
GrPrintf("\n");
@ -456,7 +456,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
}
const char* viewMName;
fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::kVertex_ShaderType,
fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::kVertex_Visibility,
kMat33f_GrSLType, "ViewM", &viewMName);
@ -514,7 +514,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
// Insert the color filter. This will soon be replaced by a color effect.
if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) {
const char* colorFilterColorUniName = NULL;
fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType, "FilterColor",
&colorFilterColorUniName);

View File

@ -138,11 +138,11 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
}
fDstCopySampler.init(this, configMask, "rgba", 0);
fDstCopyTopLeftUniform = this->addUniform(kFragment_ShaderType,
fDstCopyTopLeftUniform = this->addUniform(kFragment_Visibility,
kVec2f_GrSLType,
"DstCopyUpperLeft",
&dstCopyTopLeftName);
fDstCopyScaleUniform = this->addUniform(kFragment_ShaderType,
fDstCopyScaleUniform = this->addUniform(kFragment_Visibility,
kVec2f_GrSLType,
"DstCopyCoordScale",
&dstCopyCoordScaleName);
@ -154,7 +154,7 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
this->fsCodeAppend("\t_dstTexCoord.y = 1.0 - _dstTexCoord.y;\n");
}
this->fsCodeAppendf("\tvec4 %s = ", kDstCopyColorName);
this->appendTextureLookup(kFragment_ShaderType, fDstCopySampler, "_dstTexCoord");
this->fsAppendTextureLookup(fDstCopySampler, "_dstTexCoord");
this->fsCodeAppend(";\n\n");
}
}
@ -253,42 +253,6 @@ const char* GrGLShaderBuilder::dstColor() {
}
}
void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_list args) {
SkString* string = NULL;
switch (type) {
case kVertex_ShaderType:
string = &fVSCode;
break;
case kGeometry_ShaderType:
string = &fGSCode;
break;
case kFragment_ShaderType:
string = &fFSCode;
break;
default:
GrCrash("Invalid shader type");
}
string->appendf(format, args);
}
void GrGLShaderBuilder::codeAppend(ShaderType type, const char* str) {
SkString* string = NULL;
switch (type) {
case kVertex_ShaderType:
string = &fVSCode;
break;
case kGeometry_ShaderType:
string = &fGSCode;
break;
case kFragment_ShaderType:
string = &fFSCode;
break;
default:
GrCrash("Invalid shader type");
}
string->append(str);
}
void GrGLShaderBuilder::appendTextureLookup(SkString* out,
const GrGLShaderBuilder::TextureSampler& sampler,
const char* coordName,
@ -302,21 +266,17 @@ void GrGLShaderBuilder::appendTextureLookup(SkString* out,
append_swizzle(out, sampler, *fCtxInfo.caps());
}
void GrGLShaderBuilder::appendTextureLookup(ShaderType type,
const GrGLShaderBuilder::TextureSampler& sampler,
void GrGLShaderBuilder::fsAppendTextureLookup(const GrGLShaderBuilder::TextureSampler& sampler,
const char* coordName,
GrSLType varyingType) {
SkASSERT(kFragment_ShaderType == type);
this->appendTextureLookup(&fFSCode, sampler, coordName, varyingType);
}
void GrGLShaderBuilder::appendTextureLookupAndModulate(
ShaderType type,
void GrGLShaderBuilder::fsAppendTextureLookupAndModulate(
const char* modulation,
const GrGLShaderBuilder::TextureSampler& sampler,
const char* coordName,
GrSLType varyingType) {
SkASSERT(kFragment_ShaderType == type);
SkString lookup;
this->appendTextureLookup(&lookup, sampler, coordName, varyingType);
GrGLSLModulatef<4>(&fFSCode, modulation, lookup.c_str());
@ -383,7 +343,7 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t vi
int count,
const char** outName) {
SkASSERT(name && strlen(name));
SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_ShaderType | kFragment_ShaderType);
SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_Visibility | kFragment_Visibility);
SkASSERT(0 == (~kVisibilityMask & visibility));
SkASSERT(0 != visibility);
@ -403,7 +363,7 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t vi
// If it is visible in both the VS and FS, the precision must match.
// We declare a default FS precision, but not a default VS. So set the var
// to use the default FS precision.
if ((kVertex_ShaderType | kFragment_ShaderType) == visibility) {
if ((kVertex_Visibility | kFragment_Visibility) == visibility) {
// the fragment and vertex precisions must match
uni.fVariable.setPrecision(kDefaultFragmentPrecision);
}
@ -508,7 +468,7 @@ const char* GrGLShaderBuilder::fragmentPosition() {
SkASSERT(!fRTHeightUniform.isValid());
const char* rtHeightName;
fRTHeightUniform = this->addUniform(kFragment_ShaderType,
fRTHeightUniform = this->addUniform(kFragment_Visibility,
kFloat_GrSLType,
"RTHeight",
&rtHeightName);
@ -523,14 +483,12 @@ const char* GrGLShaderBuilder::fragmentPosition() {
}
void GrGLShaderBuilder::emitFunction(ShaderType shader,
GrSLType returnType,
void GrGLShaderBuilder::fsEmitFunction(GrSLType returnType,
const char* name,
int argCnt,
const GrGLShaderVar* args,
const char* body,
SkString* outName) {
SkASSERT(kFragment_ShaderType == shader);
fFSFunctions.append(GrGLSLTypeString(returnType));
this->nameVariable(outName, '\0', name);
fFSFunctions.appendf(" %s", outName->c_str());
@ -579,48 +537,48 @@ void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
}
}
void GrGLShaderBuilder::appendUniformDecls(ShaderType stype, SkString* out) const {
void GrGLShaderBuilder::appendUniformDecls(ShaderVisibility visibility,
SkString* out) const {
for (int i = 0; i < fUniforms.count(); ++i) {
if (fUniforms[i].fVisibility & stype) {
if (fUniforms[i].fVisibility & visibility) {
fUniforms[i].fVariable.appendDecl(fCtxInfo, out);
out->append(";\n");
}
}
}
void GrGLShaderBuilder::getShader(ShaderType type, SkString* shaderStr) const {
const char* version = GrGetGLSLVersionDecl(fCtxInfo);
switch (type) {
case kVertex_ShaderType:
*shaderStr = version;
this->appendUniformDecls(kVertex_ShaderType, shaderStr);
void GrGLShaderBuilder::vsGetShader(SkString* shaderStr) const {
*shaderStr = GrGetGLSLVersionDecl(fCtxInfo);
this->appendUniformDecls(kVertex_Visibility, shaderStr);
this->appendDecls(fVSAttrs, shaderStr);
this->appendDecls(fVSOutputs, shaderStr);
shaderStr->append("void main() {\n");
shaderStr->append(fVSCode);
shaderStr->append("}\n");
break;
case kGeometry_ShaderType:
if (fUsesGS) {
*shaderStr = version;
}
void GrGLShaderBuilder::gsGetShader(SkString* shaderStr) const {
if (!fUsesGS) {
shaderStr->reset();
return;
}
*shaderStr = GrGetGLSLVersionDecl(fCtxInfo);
shaderStr->append(fGSHeader);
this->appendDecls(fGSInputs, shaderStr);
this->appendDecls(fGSOutputs, shaderStr);
shaderStr->append("void main() {\n");
shaderStr->append(fGSCode);
shaderStr->append("}\n");
} else {
shaderStr->reset();
}
break;
case kFragment_ShaderType:
*shaderStr = version;
}
void GrGLShaderBuilder::fsGetShader(SkString* shaderStr) const {
*shaderStr = GrGetGLSLVersionDecl(fCtxInfo);
shaderStr->append(fFSExtensions);
append_default_precision_qualifier(kDefaultFragmentPrecision,
fCtxInfo.binding(),
shaderStr);
this->appendUniformDecls(kFragment_ShaderType, shaderStr);
this->appendUniformDecls(kFragment_Visibility, shaderStr);
this->appendDecls(fFSInputs, shaderStr);
// We shouldn't have declared outputs on 1.10
SkASSERT(k110_GrGLSLGeneration != fCtxInfo.glslGeneration() || fFSOutputs.empty());
@ -629,9 +587,7 @@ void GrGLShaderBuilder::getShader(ShaderType type, SkString* shaderStr) const {
shaderStr->append("void main() {\n");
shaderStr->append(fFSCode);
shaderStr->append("}\n");
break;
}
}
}
void GrGLShaderBuilder::finished(GrGLuint programID) {
fUniformManager.getUniformLocations(programID, fUniforms);

View File

@ -71,7 +71,7 @@ public:
SkASSERT(NULL != builder);
SkString name;
name.printf("Sampler%d", idx);
fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kSampler2D_GrSLType,
name.c_str());
SkASSERT(fSamplerUniform.isValid());
@ -97,10 +97,10 @@ public:
typedef SkTArray<TextureSampler> TextureSamplerArray;
enum ShaderType {
kVertex_ShaderType = 0x1,
kGeometry_ShaderType = 0x2,
kFragment_ShaderType = 0x4,
enum ShaderVisibility {
kVertex_Visibility = 0x1,
kGeometry_Visibility = 0x2,
kFragment_Visibility = 0x4,
};
GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&, const GrGLProgramDesc&);
@ -127,27 +127,27 @@ public:
void vsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
va_list args;
va_start(args, format);
this->codeAppendf(kVertex_ShaderType, format, args);
fVSCode.appendf(format, args);
va_end(args);
}
void gsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
va_list args;
va_start(args, format);
this->codeAppendf(kGeometry_ShaderType, format, args);
fGSCode.appendf(format, args);
va_end(args);
}
void fsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
va_list args;
va_start(args, format);
this->codeAppendf(kFragment_ShaderType, format, args);
fFSCode.appendf(format, args);
va_end(args);
}
void vsCodeAppend(const char* str) { this->codeAppend(kVertex_ShaderType, str); }
void gsCodeAppend(const char* str) { this->codeAppend(kGeometry_ShaderType, str); }
void fsCodeAppend(const char* str) { this->codeAppend(kFragment_ShaderType, str); }
void vsCodeAppend(const char* str) { fVSCode.append(str); }
void gsCodeAppend(const char* str) { fGSCode.append(str); }
void fsCodeAppend(const char* str) { fFSCode.append(str); }
/** Appends a 2D texture sample with projection if necessary. coordType must either be Vec2f or
Vec3f. The latter is interpreted as projective texture coords. The vec length and swizzle
@ -157,10 +157,8 @@ public:
const char* coordName,
GrSLType coordType = kVec2f_GrSLType) const;
/** Version of above that appends the result to the shader code rather than an SkString.
Currently the shader type must be kFragment */
void appendTextureLookup(ShaderType,
const TextureSampler&,
/** Version of above that appends the result to the fragment shader code instead.*/
void fsAppendTextureLookup(const TextureSampler&,
const char* coordName,
GrSLType coordType = kVec2f_GrSLType);
@ -169,16 +167,13 @@ public:
always a vec4. modulation and the swizzle specified by TextureSampler must both be vec4 or
float. If modulation is "" or NULL it this function acts as though appendTextureLookup were
called. */
void appendTextureLookupAndModulate(ShaderType,
const char* modulation,
void fsAppendTextureLookupAndModulate(const char* modulation,
const TextureSampler&,
const char* coordName,
GrSLType coordType = kVec2f_GrSLType);
/** Emits a helper function outside of main(). Currently ShaderType must be
kFragment_ShaderType. */
void emitFunction(ShaderType shader,
GrSLType returnType,
/** Emits a helper function outside of main() in the fragment shader. */
void fsEmitFunction(GrSLType returnType,
const char* name,
int argCnt,
const GrGLShaderVar* args,
@ -209,8 +204,8 @@ public:
static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCaps& caps);
/** Add a uniform variable to the current program, that has visibility in one or more shaders.
visibility is a bitfield of ShaderType values indicating from which shaders the uniform
should be accessible. At least one bit must be set. Geometry shader uniforms are not
visibility is a bitfield of ShaderVisibility values indicating from which shaders the
uniform should be accessible. At least one bit must be set. Geometry shader uniforms are not
supported at this time. The actual uniform name will be mangled. If outName is not NULL then
it will refer to the final uniform name after return. Use the addUniformArray variant to add
an array of uniforms.
@ -280,7 +275,9 @@ public:
*/
/** Called after building is complete to get the final shader string. */
void getShader(ShaderType, SkString*) const;
void vsGetShader(SkString*) const;
void gsGetShader(SkString*) const;
void fsGetShader(SkString*) const;
/**
* Adds code for effects. effectStages contains the effects to add. effectKeys[i] is the key
@ -330,13 +327,10 @@ public:
const GrGLContextInfo& ctxInfo() const { return fCtxInfo; }
private:
void codeAppendf(ShaderType type, const char format[], va_list args);
void codeAppend(ShaderType type, const char* str);
typedef GrTAllocator<GrGLShaderVar> VarArray;
void appendDecls(const VarArray&, SkString*) const;
void appendUniformDecls(ShaderType, SkString*) const;
void appendUniformDecls(ShaderVisibility, SkString*) const;
typedef GrGLUniformManager::BuilderUniform BuilderUniform;
GrGLUniformManager::BuilderUniformArray fUniforms;
@ -414,8 +408,8 @@ private:
};
bool enablePrivateFeature(GLSLPrivateFeature);
// If we ever have VS/GS features we can expand this to take a bitmask of ShaderType and track
// the enables separately for each shader.
// If we ever have VS/GS features we can expand this to take a bitmask of ShaderVisibility and
// track the enables separately for each shader.
void addFSFeature(uint32_t featureBit, const char* extensionName);
// Generates a name for a variable. The generated string will be name prefixed by the prefix

View File

@ -259,10 +259,10 @@ void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUn
// TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
GR_GL_CALL_RET(fContext.interface(), location,
GetUniformLocation(programID, uniforms[i].fVariable.c_str()));
if (GrGLShaderBuilder::kVertex_ShaderType & uniforms[i].fVisibility) {
if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) {
fUniforms[i].fVSLocation = location;
}
if (GrGLShaderBuilder::kFragment_ShaderType & uniforms[i].fVisibility) {
if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) {
fUniforms[i].fFSLocation = location;
}
}