本文整理汇总了C++中GrGLSLFragmentBuilder::codeAppendf方法的典型用法代码示例。如果您正苦于以下问题:C++ GrGLSLFragmentBuilder::codeAppendf方法的具体用法?C++ GrGLSLFragmentBuilder::codeAppendf怎么用?C++ GrGLSLFragmentBuilder::codeAppendf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrGLSLFragmentBuilder
的用法示例。
在下文中一共展示了GrGLSLFragmentBuilder::codeAppendf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitCode
void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
const char *edgeArrayName;
fEdgeUniform = args.fUniformHandler->addUniformArray(GrGLSLUniformHandler::kFragment_Visibility,
kVec3f_GrSLType,
kDefault_GrSLPrecision,
"edges",
cpe.getEdgeCount(),
&edgeArrayName);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppend("\t\tfloat alpha = 1.0;\n");
fragBuilder->codeAppend("\t\tfloat edge;\n");
const char* fragmentPos = fragBuilder->fragmentPosition();
for (int i = 0; i < cpe.getEdgeCount(); ++i) {
fragBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n",
edgeArrayName, i, fragmentPos, fragmentPos);
if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) {
fragBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n");
} else {
fragBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n");
}
fragBuilder->codeAppend("\t\talpha *= edge;\n");
}
if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) {
fragBuilder->codeAppend("\talpha = 1.0 - alpha;\n");
}
fragBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,
(GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
}
示例2: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const char* colorUni;
fColorUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec4f_GrSLType, kMedium_GrSLPrecision,
"constantColor",
&colorUni);
GrConstColorProcessor::InputMode mode = args.fFp.cast<GrConstColorProcessor>().inputMode();
if (!args.fInputColor) {
mode = GrConstColorProcessor::kIgnore_InputMode;
}
switch (mode) {
case GrConstColorProcessor::kIgnore_InputMode:
fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, colorUni);
break;
case GrConstColorProcessor::kModulateRGBA_InputMode:
fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, args.fInputColor,
colorUni);
break;
case GrConstColorProcessor::kModulateA_InputMode:
fragBuilder->codeAppendf("%s = %s.a * %s;", args.fOutputColor, args.fInputColor,
colorUni);
break;
}
}
示例3: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fMatrixHandle = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kMat44f_GrSLType, kDefault_GrSLPrecision,
"ColorMatrix");
fVectorHandle = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"ColorMatrixVector");
if (nullptr == args.fInputColor) {
// could optimize this case, but we aren't for now.
args.fInputColor = "vec4(1)";
}
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// The max() is to guard against 0 / 0 during unpremul when the incoming color is
// transparent black.
fragBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n",
args.fInputColor);
fragBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha) + %s;\n",
args.fOutputColor,
uniformHandler->getUniformCStr(fMatrixHandle),
args.fInputColor,
uniformHandler->getUniformCStr(fVectorHandle));
fragBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n",
args.fOutputColor, args.fOutputColor);
fragBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fOutputColor);
}
示例4: emitCode
virtual void emitCode(EmitArgs& args) override {
// pass through
GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
if (args.fInputColor) {
fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor);
} else {
fsBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor);
}
}
示例5: emitCode
void emitCode(EmitArgs& args) override {
// pass through
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
if (args.fInputColor) {
fragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor);
} else {
fragBuilder->codeAppendf("%s = vec4(1.0);\n", args.fOutputColor);
}
}
示例6: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("vec2 c = %s;",
fragBuilder->ensureFSCoords2D(args.fCoords, 0).c_str());
fragBuilder->codeAppend("vec2 r = mod(c, vec2(20.0));");
fragBuilder->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5,"
"0.5*cos((c.x + c.y) / 15.0) + 0.5,"
"(r.x + r.y) / 20.0,"
"distance(r, vec2(15.0)) / 20.0 + 0.2);");
fragBuilder->codeAppendf("color.rgb *= color.a;"
"%s = color * %s;",
args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_str());
}
示例7: onEmitCode
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>();
GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
// emit attributes
varyingHandler->emitAttributes(qe);
GrGLSLVertToFrag v(kVec4f_GrSLType);
varyingHandler->addVarying("QuadEdge", &v);
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.inQuadEdge()->fName);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
if (!qe.colorIgnored()) {
this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
}
// Setup position
this->setupPosition(pb, vertBuilder, gpArgs, qe.inPosition()->fName);
// emit transforms
this->emitTransforms(args.fPB,
vertBuilder,
varyingHandler,
gpArgs->fPositionVar,
qe.inPosition()->fName,
qe.localMatrix(),
args.fTransformsIn,
args.fTransformsOut);
SkAssertResult(fragBuilder->enableFeature(
GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
fragBuilder->codeAppendf("float edgeAlpha;");
// keep the derivative instructions outside the conditional
fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn());
fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn());
fragBuilder->codeAppendf("if (%s.z > 0.0 && %s.w > 0.0) {", v.fsIn(), v.fsIn());
// today we know z and w are in device space. We could use derivatives
fragBuilder->codeAppendf("edgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);", v.fsIn(),
v.fsIn());
fragBuilder->codeAppendf ("} else {");
fragBuilder->codeAppendf("vec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,"
" 2.0*%s.x*duvdy.x - duvdy.y);",
v.fsIn(), v.fsIn());
fragBuilder->codeAppendf("edgeAlpha = (%s.x*%s.x - %s.y);", v.fsIn(), v.fsIn(),
v.fsIn());
fragBuilder->codeAppendf("edgeAlpha = "
"clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);}");
fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
示例8: emitCode
void emitCode(EmitArgs& args) override {
if (nullptr == args.fInputColor) {
args.fInputColor = "vec4(1)";
}
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb);\n",
SK_ITU_BT709_LUM_COEFF_R,
SK_ITU_BT709_LUM_COEFF_G,
SK_ITU_BT709_LUM_COEFF_B,
args.fInputColor);
fragBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n",
args.fOutputColor);
}
示例9: emitCode
void GLDitherEffect::emitCode(EmitArgs& args) {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Generate a random number based on the fragment position. For this
// random number generator, we use the "GLSL rand" function
// that seems to be floating around on the internet. It works under
// the assumption that sin(<big number>) oscillates with high frequency
// and sampling it will generate "randomness". Since we're using this
// for rendering and not cryptography it should be OK.
// For each channel c, add the random offset to the pixel to either bump
// it up or let it remain constant during quantization.
fragBuilder->codeAppendf("\t\tfloat r = "
"fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758.5453);\n",
fragBuilder->fragmentPosition());
fragBuilder->codeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n",
args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_str());
}
示例10: emitChild
void GrGLSLFragmentProcessor::emitChild(int childIndex, const char* inputColor,
SkString* outputColor, EmitArgs& args) {
SkASSERT(outputColor);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
outputColor->append(fragBuilder->getMangleString());
fragBuilder->codeAppendf("vec4 %s;", outputColor->c_str());
this->internalEmitChild(childIndex, inputColor, outputColor->c_str(), args);
}
示例11: emitCode
virtual void emitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("\t%s = ", args.fOutputColor);
fragBuilder->appendTextureLookupAndModulate(args.fInputColor,
args.fSamplers[0],
args.fCoords[0].c_str(),
args.fCoords[0].getType());
fragBuilder->codeAppend(";\n");
}
示例12: onEmitCode
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const PLSFinishEffect& fe = args.fGP.cast<PLSFinishEffect>();
GrGLSLVertexBuilder* vsBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fUseEvenOdd = uniformHandler->addUniform(kFragment_GrShaderFlag,
kFloat_GrSLType, kLow_GrSLPrecision,
"useEvenOdd");
const char* useEvenOdd = uniformHandler->getUniformCStr(fUseEvenOdd);
varyingHandler->emitAttributes(fe);
this->setupPosition(vsBuilder, gpArgs, fe.inPosition()->fName);
this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpArgs->fPositionVar,
fe.inPosition()->fName, fe.localMatrix(), args.fTransformsIn,
args.fTransformsOut);
GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
SkAssertResult(fsBuilder->enableFeature(
GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLFeature));
fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL);
fsBuilder->codeAppend("float coverage;");
fsBuilder->codeAppendf("if (%s != 0.0) {", useEvenOdd);
fsBuilder->codeAppend("coverage = float(abs(pls.windings[0]) % 2) * 0.25;");
fsBuilder->codeAppend("coverage += float(abs(pls.windings[1]) % 2) * 0.25;");
fsBuilder->codeAppend("coverage += float(abs(pls.windings[2]) % 2) * 0.25;");
fsBuilder->codeAppend("coverage += float(abs(pls.windings[3]) % 2) * 0.25;");
fsBuilder->codeAppend("} else {");
fsBuilder->codeAppend("coverage = pls.windings[0] != 0 ? 0.25 : 0.0;");
fsBuilder->codeAppend("coverage += pls.windings[1] != 0 ? 0.25 : 0.0;");
fsBuilder->codeAppend("coverage += pls.windings[2] != 0 ? 0.25 : 0.0;");
fsBuilder->codeAppend("coverage += pls.windings[3] != 0 ? 0.25 : 0.0;");
fsBuilder->codeAppend("}");
if (!fe.colorIgnored()) {
this->setupUniformColor(fsBuilder, uniformHandler, args.fOutputColor,
&fColorUniform);
}
fsBuilder->codeAppendf("%s = vec4(coverage);", args.fOutputCoverage);
fsBuilder->codeAppendf("%s = vec4(1.0, 0.0, 1.0, 1.0);", args.fOutputColor);
}
示例13: emitCode
void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
const GrConvolutionEffect& ce = args.fFp.cast<GrConvolutionEffect>();
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fImageIncrementUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"ImageIncrement");
if (ce.useBounds()) {
fBoundsUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"Bounds");
}
int width = Gr1DKernelEffect::WidthFromRadius(ce.radius());
fKernelUni = uniformHandler->addUniformArray(GrGLSLUniformHandler::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"Kernel", width);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
fragBuilder->codeAppendf("%s = vec4(0, 0, 0, 0);", args.fOutputColor);
const GrGLSLShaderVar& kernel = uniformHandler->getUniformVariable(fKernelUni);
const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
fragBuilder->codeAppendf("vec2 coord = %s - %d.0 * %s;", coords2D.c_str(), ce.radius(), imgInc);
// Manually unroll loop because some drivers don't; yields 20-30% speedup.
for (int i = 0; i < width; i++) {
SkString index;
SkString kernelIndex;
index.appendS32(i);
kernel.appendArrayAccess(index.c_str(), &kernelIndex);
if (ce.useBounds()) {
// We used to compute a bool indicating whether we're in bounds or not, cast it to a
// float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems
// to have a bug that caused corruption.
const char* bounds = uniformHandler->getUniformCStr(fBoundsUni);
const char* component = ce.direction() == Gr1DKernelEffect::kY_Direction ? "y" : "x";
fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {",
component, bounds, component, bounds);
}
fragBuilder->codeAppendf("\t\t%s += ", args.fOutputColor);
fragBuilder->appendTextureLookup(args.fSamplers[0], "coord");
fragBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str());
if (ce.useBounds()) {
fragBuilder->codeAppend("}");
}
fragBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc);
}
SkString modulate;
GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
fragBuilder->codeAppend(modulate.c_str());
}
示例14: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>();
// emit transforms
this->emitTransforms(args.fVaryingHandler, args.fTransformsIn, args.fTransformsOut);
// Setup uniform color
if (pathProc.overrides().readsColor()) {
const char* stagedLocalVarName;
fColorUniform = args.fUniformHandler->addUniform(
GrGLSLUniformHandler::kFragment_Visibility,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"Color",
&stagedLocalVarName);
fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalVarName);
}
// setup constant solid coverage
if (pathProc.overrides().readsCoverage()) {
fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
}
}
示例15: emitCode
void GrGLMagnifierEffect::emitCode(EmitArgs& args) {
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fOffsetVar = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"Offset");
fInvZoomVar = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"InvZoom");
fInvInsetVar = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"InvInset");
fBoundsVar = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"Bounds");
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
fragBuilder->codeAppendf("\t\tvec2 zoom_coord = %s + %s * %s;\n",
uniformHandler->getUniformCStr(fOffsetVar),
coords2D.c_str(),
uniformHandler->getUniformCStr(fInvZoomVar));
const char* bounds = uniformHandler->getUniformCStr(fBoundsVar);
fragBuilder->codeAppendf("\t\tvec2 delta = (coord - %s.xy) * %s.zw;\n", bounds, bounds);
fragBuilder->codeAppendf("\t\tdelta = min(delta, vec2(1.0, 1.0) - delta);\n");
fragBuilder->codeAppendf("\t\tdelta = delta * %s;\n",
uniformHandler->getUniformCStr(fInvInsetVar));
fragBuilder->codeAppend("\t\tfloat weight = 0.0;\n");
fragBuilder->codeAppend("\t\tif (delta.s < 2.0 && delta.t < 2.0) {\n");
fragBuilder->codeAppend("\t\t\tdelta = vec2(2.0, 2.0) - delta;\n");
fragBuilder->codeAppend("\t\t\tfloat dist = length(delta);\n");
fragBuilder->codeAppend("\t\t\tdist = max(2.0 - dist, 0.0);\n");
fragBuilder->codeAppend("\t\t\tweight = min(dist * dist, 1.0);\n");
fragBuilder->codeAppend("\t\t} else {\n");
fragBuilder->codeAppend("\t\t\tvec2 delta_squared = delta * delta;\n");
fragBuilder->codeAppend("\t\t\tweight = min(min(delta_squared.x, delta_squared.y), 1.0);\n");
fragBuilder->codeAppend("\t\t}\n");
fragBuilder->codeAppend("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n");
fragBuilder->codeAppend("\t\tvec4 output_color = ");
fragBuilder->appendTextureLookup(args.fSamplers[0], "mix_coord");
fragBuilder->codeAppend(";\n");
fragBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor);
SkString modulate;
GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
fragBuilder->codeAppend(modulate.c_str());
}