本文整理汇总了C++中GrGLSLVaryingHandler::addVarying方法的典型用法代码示例。如果您正苦于以下问题:C++ GrGLSLVaryingHandler::addVarying方法的具体用法?C++ GrGLSLVaryingHandler::addVarying怎么用?C++ GrGLSLVaryingHandler::addVarying使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrGLSLVaryingHandler
的用法示例。
在下文中一共展示了GrGLSLVaryingHandler::addVarying方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onEmitCode
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const auto& proc = args.fGP.cast<Processor>();
bool useHWDerivatives = (proc.fFlags & Flags::kUseHWDerivatives);
SkASSERT(proc.vertexStride() == sizeof(CoverageVertex));
GrGLSLVaryingHandler* varyings = args.fVaryingHandler;
varyings->emitAttributes(proc);
varyings->addPassThroughAttribute(*proc.fColorAttrib, args.fOutputColor,
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
// Emit the vertex shader.
GrGLSLVertexBuilder* v = args.fVertBuilder;
// Unpack vertex attribs.
v->codeAppend("float2 corner = corner_and_radius_outsets.xy;");
v->codeAppend("float2 radius_outset = corner_and_radius_outsets.zw;");
v->codeAppend("float2 aa_bloat_direction = aa_bloat_and_coverage.xy;");
v->codeAppend("float coverage = aa_bloat_and_coverage.z;");
v->codeAppend("float is_linear_coverage = aa_bloat_and_coverage.w;");
// Find the amount to bloat each edge for AA (in source space).
v->codeAppend("float2 pixellength = inversesqrt("
"float2(dot(skew.xz, skew.xz), dot(skew.yw, skew.yw)));");
v->codeAppend("float4 normalized_axis_dirs = skew * pixellength.xyxy;");
v->codeAppend("float2 axiswidths = (abs(normalized_axis_dirs.xy) + "
"abs(normalized_axis_dirs.zw));");
v->codeAppend("float2 aa_bloatradius = axiswidths * pixellength * .5;");
// Identify our radii.
v->codeAppend("float4 radii_and_neighbors = radii_selector"
"* float4x4(radii_x, radii_y, radii_x.yxwz, radii_y.wzyx);");
v->codeAppend("float2 radii = radii_and_neighbors.xy;");
v->codeAppend("float2 neighbor_radii = radii_and_neighbors.zw;");
v->codeAppend("if (any(greaterThan(aa_bloatradius, float2(1)))) {");
// The rrect is more narrow than an AA coverage ramp. We can't draw as-is
// or else opposite AA borders will overlap. Instead, fudge the size up to
// the width of a coverage ramp, and then reduce total coverage to make
// the rect appear more thin.
v->codeAppend( "corner = max(abs(corner), aa_bloatradius) * sign(corner);");
v->codeAppend( "coverage /= max(aa_bloatradius.x, 1) * max(aa_bloatradius.y, 1);");
// Set radii to zero to ensure we take the "linear coverage" codepath.
// (The "coverage" variable only has effect in the linear codepath.)
v->codeAppend( "radii = float2(0);");
v->codeAppend("}");
v->codeAppend("if (any(lessThan(radii, aa_bloatradius * 1.25))) {");
// The radii are very small. Demote this arc to a sharp 90 degree corner.
v->codeAppend( "radii = aa_bloatradius;");
// Snap octagon vertices to the corner of the bounding box.
v->codeAppend( "radius_outset = floor(abs(radius_outset)) * radius_outset;");
v->codeAppend( "is_linear_coverage = 1;");
v->codeAppend("} else {");
// Don't let radii get smaller than a pixel.
v->codeAppend( "radii = clamp(radii, pixellength, 2 - pixellength);");
v->codeAppend( "neighbor_radii = clamp(neighbor_radii, pixellength, 2 - pixellength);");
// Don't let neighboring radii get closer together than 1/16 pixel.
v->codeAppend( "float2 spacing = 2 - radii - neighbor_radii;");
v->codeAppend( "float2 extra_pad = max(pixellength * .0625 - spacing, float2(0));");
v->codeAppend( "radii -= extra_pad * .5;");
v->codeAppend("}");
// Find our vertex position, adjusted for radii and bloated for AA. Our rect is drawn in
// normalized [-1,-1,+1,+1] space.
v->codeAppend("float2 aa_outset = aa_bloat_direction.xy * aa_bloatradius;");
v->codeAppend("float2 vertexpos = corner + radius_outset * radii + aa_outset;");
// Emit transforms.
GrShaderVar localCoord("", kFloat2_GrSLType);
if (proc.fFlags & Flags::kHasLocalCoords) {
v->codeAppend("float2 localcoord = (local_rect.xy * (1 - vertexpos) + "
"local_rect.zw * (1 + vertexpos)) * .5;");
localCoord.set(kFloat2_GrSLType, "localcoord");
}
this->emitTransforms(v, varyings, args.fUniformHandler, localCoord,
args.fFPCoordTransformHandler);
// Transform to device space.
SkASSERT(!(proc.fFlags & Flags::kHasPerspective));
v->codeAppend("float2x2 skewmatrix = float2x2(skew.xy, skew.zw);");
v->codeAppend("float2 devcoord = vertexpos * skewmatrix + translate;");
gpArgs->fPositionVar.set(kFloat2_GrSLType, "devcoord");
// Setup interpolants for coverage.
GrGLSLVarying arcCoord(useHWDerivatives ? kFloat2_GrSLType : kFloat4_GrSLType);
varyings->addVarying("arccoord", &arcCoord);
v->codeAppend("if (0 != is_linear_coverage) {");
// We are a non-corner piece: Set x=0 to indicate built-in coverage, and
// interpolate linear coverage across y.
v->codeAppendf( "%s.xy = float2(0, coverage);", arcCoord.vsOut());
v->codeAppend("} else {");
// Find the normalized arc coordinates for our corner ellipse.
// (i.e., the coordinate system where x^2 + y^2 == 1).
v->codeAppend( "float2 arccoord = 1 - abs(radius_outset) + aa_outset/radii * corner;");
// We are a corner piece: Interpolate the arc coordinates for coverage.
// Emit x+1 to ensure no pixel in the arc has a x value of 0 (since x=0
// instructs the fragment shader to use linear coverage).
v->codeAppendf( "%s.xy = float2(arccoord.x+1, arccoord.y);", arcCoord.vsOut());
if (!useHWDerivatives) {
//.........这里部分代码省略.........