本文整理汇总了C++中GrGLSLFPFragmentBuilder类的典型用法代码示例。如果您正苦于以下问题:C++ GrGLSLFPFragmentBuilder类的具体用法?C++ GrGLSLFPFragmentBuilder怎么用?C++ GrGLSLFPFragmentBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GrGLSLFPFragmentBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrCircleEffect& _outer = args.fFp.cast<GrCircleEffect>();
(void)_outer;
auto edgeType = _outer.edgeType;
(void)edgeType;
auto center = _outer.center;
(void)center;
auto radius = _outer.radius;
(void)radius;
prevRadius = -1.0;
circleVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat4_GrSLType,
"circle");
fragBuilder->codeAppendf(
"float2 prevCenter;\nfloat prevRadius = %f;\nhalf d;\[email protected] (%d == 2 || %d == 3) {\n "
" d = half((length((%s.xy - sk_FragCoord.xy) * %s.w) - 1.0) * %s.z);\n} else {\n "
" d = half((1.0 - length((%s.xy - sk_FragCoord.xy) * %s.w)) * %s.z);\n}\[email protected] "
"((%d == 1 || %d == 3) || %d == 4) {\n %s = %s * clamp(d, 0.0, 1.0);\n} else "
"{\n %s = d > 0.5 ? %s : half4(0.0);\n}\n",
prevRadius, (int)_outer.edgeType, (int)_outer.edgeType,
args.fUniformHandler->getUniformCStr(circleVar),
args.fUniformHandler->getUniformCStr(circleVar),
args.fUniformHandler->getUniformCStr(circleVar),
args.fUniformHandler->getUniformCStr(circleVar),
args.fUniformHandler->getUniformCStr(circleVar),
args.fUniformHandler->getUniformCStr(circleVar), (int)_outer.edgeType,
(int)_outer.edgeType, (int)_outer.edgeType, args.fOutputColor, args.fInputColor,
args.fOutputColor, args.fInputColor);
}
示例2: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
(void)_outer;
auto mirror = _outer.mirror;
(void)mirror;
auto makePremul = _outer.makePremul;
(void)makePremul;
auto colorsAreOpaque = _outer.colorsAreOpaque;
(void)colorsAreOpaque;
SkString _child1("_child1");
this->emitChild(_outer.gradLayout_index, &_child1, args);
fragBuilder->codeAppendf(
"half4 t = %s;\nif (!%s && t.y < 0.0) {\n %s = half4(0.0);\n} else {\n @if "
"(%s) {\n half t_1 = t.x - 1.0;\n half tiled_t = (t_1 - 2.0 * "
"floor(t_1 * 0.5)) - 1.0;\n if (sk_Caps.mustDoOpBetweenFloorAndAbs) {\n "
" tiled_t = clamp(tiled_t, -1.0, 1.0);\n }\n t.x = "
"abs(tiled_t);\n } else {\n t.x = fract(t.x);\n }",
_child1.c_str(),
(_outer.childProcessor(_outer.gradLayout_index).preservesOpaqueInput() ? "true"
: "false"),
args.fOutputColor, (_outer.mirror ? "true" : "false"));
SkString _input0("t");
SkString _child0("_child0");
this->emitChild(_outer.colorizer_index, _input0.c_str(), &_child0, args);
fragBuilder->codeAppendf("\n %s = %s;\n}\[email protected] (%s) {\n %s.xyz *= %s.w;\n}\n",
args.fOutputColor, _child0.c_str(),
(_outer.makePremul ? "true" : "false"), args.fOutputColor,
args.fOutputColor);
}
示例3: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
this->emitChild(0, args);
fragBuilder->codeAppendf("%s.rgb *= %s.rgb;", args.fOutputColor,
args.fInputColor);
fragBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputColor);
}
示例4: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrCircleBlurFragmentProcessor& _outer =
args.fFp.cast<GrCircleBlurFragmentProcessor>();
(void)_outer;
auto circleRect = _outer.circleRect();
(void)circleRect;
auto textureRadius = _outer.textureRadius();
(void)textureRadius;
auto solidRadius = _outer.solidRadius();
(void)solidRadius;
fCircleDataVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf4_GrSLType,
kDefault_GrSLPrecision, "circleData");
fragBuilder->codeAppendf(
"half2 vec = half2(half((sk_FragCoord.x - float(%s.x)) * float(%s.w)), "
"half((sk_FragCoord.y - float(%s.y)) * float(%s.w)));\nhalf dist = "
"float(length(vec)) + (0.5 - float(%s.z)) * float(%s.w);\n%s = %s * texture(%s, "
"float2(half2(dist, 0.5))).%s.w;\n",
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fUniformHandler->getUniformCStr(fCircleDataVar),
args.fUniformHandler->getUniformCStr(fCircleDataVar), args.fOutputColor,
args.fInputColor ? args.fInputColor : "half4(1)",
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
}
示例5: emitCode
void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
const char *edgeArrayName;
fEdgeUniform = args.fUniformHandler->addUniformArray(kFragment_GrShaderFlag,
kVec3f_GrSLType,
kDefault_GrSLPrecision,
"edges",
cpe.getEdgeCount(),
&edgeArrayName);
GrGLSLFPFragmentBuilder* 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());
}
示例6: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("%s = ", args.fOutputColor);
fragBuilder->appendTextureLookupAndModulate(args.fInputColor,
args.fSamplers[0],
args.fCoords[0].c_str(),
args.fCoords[0].getType());
fragBuilder->codeAppend(";");
}
示例7: SkASSERT
void GrGLSLFragmentProcessor::emitChild(int childIndex, const char* inputColor,
SkString* outputColor, EmitArgs& args) {
SkASSERT(outputColor);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
outputColor->append(fragBuilder->getMangleString());
fragBuilder->codeAppendf("vec4 %s;", outputColor->c_str());
this->internalEmitChild(childIndex, inputColor, outputColor->c_str(), args);
}
示例8: length
void GrCircleBlurFragmentProcessor::GLSLProcessor::emitCode(EmitArgs& args) {
const char *dataName;
// The data is formatted as:
// x,y - the center of the circle
// z - inner radius that should map to 0th entry in the texture.
// w - the inverse of the distance over which the texture is stretched.
fDataUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"data",
&dataName);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
if (args.fInputColor) {
fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor);
} else {
fragBuilder->codeAppendf("vec4 src=vec4(1);");
}
// We just want to compute "(length(vec) - %s.z + 0.5) * %s.w" but need to rearrange
// for precision.
fragBuilder->codeAppendf("vec2 vec = vec2( (sk_FragCoord.x - %s.x) * %s.w, "
"(sk_FragCoord.y - %s.y) * %s.w );",
dataName, dataName, dataName, dataName);
fragBuilder->codeAppendf("float dist = length(vec) + (0.5 - %s.z) * %s.w;",
dataName, dataName);
fragBuilder->codeAppendf("float intensity = ");
fragBuilder->appendTextureLookup(args.fTexSamplers[0], "vec2(dist, 0.5)");
fragBuilder->codeAppend(".a;");
fragBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor );
}
示例9: onEmitCode
void onEmitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// add uniform
const char* xformUniName = nullptr;
fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat22f_GrSLType,
kDefault_GrSLPrecision, "Xform", &xformUniName);
SkString dstNormalColorName("dstNormalColor");
this->emitChild(0, nullptr, &dstNormalColorName, args);
fragBuilder->codeAppendf("vec3 normal = normalize(%s.rgb - vec3(0.5));",
dstNormalColorName.c_str());
// If there's no x & y components, return (0, 0, +/- 1) instead to avoid division by 0
fragBuilder->codeAppend( "if (abs(normal.z) > 0.999) {");
fragBuilder->codeAppendf(" %s = normalize(vec4(0.0, 0.0, normal.z, 0.0));",
args.fOutputColor);
// Else, Normalizing the transformed X and Y, while keeping constant both Z and the
// vector's angle in the XY plane. This maintains the "slope" for the surface while
// appropriately rotating the normal regardless of any anisotropic scaling that occurs.
// Here, we call 'scaling factor' the number that must divide the transformed X and Y so
// that the normal's length remains equal to 1.
fragBuilder->codeAppend( "} else {");
fragBuilder->codeAppendf(" vec2 transformed = %s * normal.xy;",
xformUniName);
fragBuilder->codeAppend( " float scalingFactorSquared = "
"( (transformed.x * transformed.x) "
"+ (transformed.y * transformed.y) )"
"/(1.0 - (normal.z * normal.z));");
fragBuilder->codeAppendf(" %s = vec4(transformed*inversesqrt(scalingFactorSquared),"
"normal.z, 0.0);",
args.fOutputColor);
fragBuilder->codeAppend( "}");
}
示例10: onEmitCode
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const GrBitmapTextGeoProc& btgp = args.fGP.cast<GrBitmapTextGeoProc>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(btgp);
const char* atlasSizeInvName;
fAtlasSizeInvUniform = uniformHandler->addUniform(kVertex_GrShaderFlag,
kFloat2_GrSLType,
kHigh_GrSLPrecision,
"AtlasSizeInv",
&atlasSizeInvName);
GrGLSLVarying uv(kFloat2_GrSLType);
GrSLType texIdxType = args.fShaderCaps->integerSupport() ? kInt_GrSLType : kFloat_GrSLType;
GrGLSLVarying texIdx(texIdxType);
append_index_uv_varyings(args, btgp.inTextureCoords().name(), atlasSizeInvName, &uv,
&texIdx, nullptr);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
if (btgp.hasVertexColor()) {
varyingHandler->addPassThroughAttribute(btgp.inColor(), args.fOutputColor);
} else {
this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
&fColorUniform);
}
// Setup position
gpArgs->fPositionVar = btgp.inPosition().asShaderVar();
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
btgp.inPosition().asShaderVar(),
btgp.localMatrix(),
args.fFPCoordTransformHandler);
fragBuilder->codeAppend("half4 texColor;");
append_multitexture_lookup(args, btgp.numTextureSamplers(),
texIdx, uv.fsIn(), "texColor");
if (btgp.maskFormat() == kARGB_GrMaskFormat) {
// modulate by color
fragBuilder->codeAppendf("%s = %s * texColor;", args.fOutputColor, args.fOutputColor);
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
} else {
fragBuilder->codeAppendf("%s = texColor;", args.fOutputCoverage);
}
}
示例11: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
(void)_outer;
auto matrix = _outer.matrix();
(void)matrix;
SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf(
"%s = %s * texture(%s, %s).%s;\n", args.fOutputColor,
args.fInputColor ? args.fInputColor : "half4(1)",
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
sk_TransformedCoords2D_0.c_str(),
fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
}
示例12: emitCode
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrBlurredEdgeFragmentProcessor& _outer =
args.fFp.cast<GrBlurredEdgeFragmentProcessor>();
(void)_outer;
auto mode = _outer.mode;
(void)mode;
fragBuilder->codeAppendf(
"half factor = 1.0 - %s.w;\[email protected] (%d) {\n case 0:\n factor = "
"exp((-factor * factor) * 4.0) - 0.017999999999999999;\n break;\n case "
"1:\n factor = smoothstep(1.0, 0.0, factor);\n break;\n}\n%s = "
"half4(factor);\n",
args.fInputColor, (int)_outer.mode, args.fOutputColor);
}
示例13: emitCode
void emitCode(EmitArgs& args) override {
const GrColorSpaceXformEffect& csxe = args.fFp.cast<GrColorSpaceXformEffect>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fColorSpaceHelper.emitCode(uniformHandler, csxe.colorXform());
SkString childColor("src_color");
this->emitChild(0, &childColor, args);
SkString xformedColor;
fragBuilder->appendColorGamutXform(&xformedColor, childColor.c_str(), &fColorSpaceHelper);
fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, xformedColor.c_str(),
args.fInputColor);
}
示例14: emitCode
void emitCode(EmitArgs& args) override {
if (nullptr == args.fInputColor) {
args.fInputColor = "vec4(1)";
}
GrGLSLFPFragmentBuilder* 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);
}
示例15: emitCode
void GLDitherEffect::emitCode(EmitArgs& args) {
GrGLSLFPFragmentBuilder* 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());
}