本文整理汇总了C++中GrGLSLVertexBuilder::codeAppend方法的典型用法代码示例。如果您正苦于以下问题:C++ GrGLSLVertexBuilder::codeAppend方法的具体用法?C++ GrGLSLVertexBuilder::codeAppend怎么用?C++ GrGLSLVertexBuilder::codeAppend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrGLSLVertexBuilder
的用法示例。
在下文中一共展示了GrGLSLVertexBuilder::codeAppend方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onEmitCode
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(gp);
// Setup pass through color
if (gp.hasVertexColor()) {
GrGLSLVarying varying(kHalf4_GrSLType);
varyingHandler->addVarying("color", &varying);
// There are several optional steps to process the color. Start with the attribute:
vertBuilder->codeAppendf("half4 color = %s;", gp.inColor()->fName);
// Linearize
if (gp.linearizeColor()) {
SkString srgbFuncName;
static const GrShaderVar gSrgbArgs[] = {
GrShaderVar("x", kHalf_GrSLType),
};
vertBuilder->emitFunction(kHalf_GrSLType,
"srgb_to_linear",
SK_ARRAY_COUNT(gSrgbArgs),
gSrgbArgs,
"return (x <= 0.04045) ? (x / 12.92) "
": pow((x + 0.055) / 1.055, 2.4);",
&srgbFuncName);
vertBuilder->codeAppendf("color = half4(%s(%s.r), %s(%s.g), %s(%s.b), %s.a);",
srgbFuncName.c_str(), gp.inColor()->fName,
srgbFuncName.c_str(), gp.inColor()->fName,
srgbFuncName.c_str(), gp.inColor()->fName,
gp.inColor()->fName);
}
// For SkColor, do a red/blue swap and premul
if (gp.fFlags & kColorAttributeIsSkColor_GPFlag) {
vertBuilder->codeAppend("color = half4(color.a * color.bgr, color.a);");
}
// Do color-correction to destination gamut
if (gp.linearizeColor()) {
fColorSpaceHelper.emitCode(uniformHandler, gp.fColorSpaceXform.get(),
kVertex_GrShaderFlag);
if (fColorSpaceHelper.isValid()) {
SkString xformedColor;
vertBuilder->appendColorGamutXform(&xformedColor, "color",
&fColorSpaceHelper);
vertBuilder->codeAppendf("color = %s;", xformedColor.c_str());
}
}
vertBuilder->codeAppendf("%s = color;\n", varying.vsOut());
fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn());
} else {
this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
&fColorUniform);
}
// Setup position
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.viewMatrix(),
&fViewMatrixUniform);
if (gp.hasExplicitLocalCoords()) {
// emit transforms with explicit local coords
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gp.inLocalCoords()->asShaderVar(),
gp.localMatrix(),
args.fFPCoordTransformHandler);
} else {
// emit transforms with position
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
gp.inPosition()->asShaderVar(),
gp.localMatrix(),
args.fFPCoordTransformHandler);
}
// Setup coverage as pass through
if (gp.hasVertexCoverage()) {
fragBuilder->codeAppendf("half alpha = 1.0;");
varyingHandler->addPassThroughAttribute(gp.inCoverage(), "alpha");
fragBuilder->codeAppendf("%s = half4(alpha);", args.fOutputCoverage);
} else if (gp.coverage() == 0xff) {
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
} else {
const char* fragCoverage;
fCoverageUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
kHalf_GrSLType,
"Coverage",
&fragCoverage);
//.........这里部分代码省略.........
示例2: onEmitCode
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const auto& proc = args.fGP.cast<Processor>();
bool useHWDerivatives = (proc.fFlags & Flags::kUseHWDerivatives);
bool hasPerspective = (proc.fFlags & Flags::kHasPerspective);
bool hasLocalCoords = (proc.fFlags & Flags::kHasLocalCoords);
SkASSERT(useHWDerivatives == hasPerspective);
SkASSERT(proc.vertexStride() == sizeof(MSAAVertex));
// Emit the vertex shader.
GrGLSLVertexBuilder* v = args.fVertBuilder;
GrGLSLVaryingHandler* varyings = args.fVaryingHandler;
varyings->emitAttributes(proc);
varyings->addPassThroughAttribute(*proc.fColorAttrib, args.fOutputColor,
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
// Unpack vertex attribs.
v->codeAppendf("float2 corner = corner_and_radius_outsets.xy;");
v->codeAppendf("float2 radius_outset = corner_and_radius_outsets.zw;");
// Identify our radii.
v->codeAppend("float2 radii;");
v->codeAppend("radii.x = dot(radii_selector, radii_x);");
v->codeAppend("radii.y = dot(radii_selector, radii_y);");
v->codeAppendf("bool is_arc_section = (radii.x > 0);");
v->codeAppendf("radii = abs(radii);");
// Find our vertex position, adjusted for radii. Our rect is drawn in normalized
// [-1,-1,+1,+1] space.
v->codeAppend("float2 vertexpos = corner + radius_outset * radii;");
// Emit transforms.
GrShaderVar localCoord("", kFloat2_GrSLType);
if (hasLocalCoords) {
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.
if (!hasPerspective) {
v->codeAppend("float2x2 skewmatrix = float2x2(skew.xy, skew.zw);");
v->codeAppend("float2 devcoord = vertexpos * skewmatrix + translate;");
gpArgs->fPositionVar.set(kFloat2_GrSLType, "devcoord");
} else {
v->codeAppend("float3x3 persp_matrix = float3x3(persp_x, persp_y, persp_z);");
v->codeAppend("float3 devcoord = float3(vertexpos, 1) * persp_matrix;");
gpArgs->fPositionVar.set(kFloat3_GrSLType, "devcoord");
}
// Determine normalized arc coordinates for the implicit function.
GrGLSLVarying arcCoord((useHWDerivatives) ? kFloat2_GrSLType : kFloat4_GrSLType);
varyings->addVarying("arccoord", &arcCoord);
v->codeAppendf("if (is_arc_section) {");
v->codeAppendf( "%s.xy = 1 - abs(radius_outset);", arcCoord.vsOut());
if (!useHWDerivatives) {
// The gradient is order-1: Interpolate it across arccoord.zw.
// This doesn't work with perspective.
SkASSERT(!hasPerspective);
v->codeAppendf("float2x2 derivatives = inverse(skewmatrix);");
v->codeAppendf("%s.zw = derivatives * (%s.xy/radii * corner * 2);",
arcCoord.vsOut(), arcCoord.vsOut());
}
v->codeAppendf("} else {");
if (useHWDerivatives) {
v->codeAppendf("%s = float2(0);", arcCoord.vsOut());
} else {
v->codeAppendf("%s = float4(0);", arcCoord.vsOut());
}
v->codeAppendf("}");
// Emit the fragment shader.
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;
f->codeAppendf("%s = half4(1);", args.fOutputCoverage);
// If x,y == 0, then we are drawing a triangle that does not track an arc.
f->codeAppendf("if (float2(0) != %s.xy) {", arcCoord.fsIn());
f->codeAppendf( "float fn = dot(%s.xy, %s.xy) - 1;", arcCoord.fsIn(), arcCoord.fsIn());
if (GrAAType::kMSAA == proc.fAAType) {
using ScopeFlags = GrGLSLFPFragmentBuilder::ScopeFlags;
if (!useHWDerivatives) {
f->codeAppendf("float2 grad = %s.zw;", arcCoord.fsIn());
f->applyFnToMultisampleMask("fn", "grad", ScopeFlags::kInsidePerPrimitiveBranch);
} else {
f->applyFnToMultisampleMask("fn", nullptr, ScopeFlags::kInsidePerPrimitiveBranch);
}
} else {
f->codeAppendf("if (fn > 0) {");
f->codeAppendf( "%s = half4(0);", args.fOutputCoverage);
f->codeAppendf("}");
}
f->codeAppendf("}");
}
示例3: onEmitCode
void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
using InstanceAttribs = GrCCPRPathProcessor::InstanceAttribs;
const GrCCPRPathProcessor& proc = args.fGP.cast<GrCCPRPathProcessor>();
GrGLSLUniformHandler* uniHandler = args.fUniformHandler;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
const char* atlasAdjust;
fAtlasAdjustUniform = uniHandler->addUniform(
kVertex_GrShaderFlag,
kVec2f_GrSLType, kHigh_GrSLPrecision, "atlas_adjust", &atlasAdjust);
varyingHandler->emitAttributes(proc);
GrGLSLVertToFrag texcoord(kVec2f_GrSLType);
GrGLSLVertToFrag color(kVec4f_GrSLType);
varyingHandler->addVarying("texcoord", &texcoord, kHigh_GrSLPrecision);
varyingHandler->addFlatPassThroughAttribute(&proc.getInstanceAttrib(InstanceAttribs::kColor),
args.fOutputColor, kLow_GrSLPrecision);
// Vertex shader.
GrGLSLVertexBuilder* v = args.fVertBuilder;
// Find the intersections of (bloated) devBounds and devBounds45 in order to come up with an
// octagon that circumscribes the (bloated) path. A vertex is the intersection of two lines:
// one edge from the path's bounding box and one edge from its 45-degree bounding box.
v->codeAppendf("highp mat2 N = mat2(%s);", proc.getEdgeNormsAttrib().fName);
// N[0] is the normal for the edge we are intersecting from the regular bounding box, pointing
// out of the octagon.
v->codeAppendf("highp vec2 refpt = (min(N[0].x, N[0].y) < 0) ? %s.xy : %s.zw;",
proc.getInstanceAttrib(InstanceAttribs::kDevBounds).fName,
proc.getInstanceAttrib(InstanceAttribs::kDevBounds).fName);
v->codeAppendf("refpt += N[0] * %f;", kAABloatRadius); // bloat for AA.
// N[1] is the normal for the edge we are intersecting from the 45-degree bounding box, pointing
// out of the octagon.
v->codeAppendf("highp vec2 refpt45 = (N[1].x < 0) ? %s.xy : %s.zw;",
proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).fName,
proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).fName);
v->codeAppendf("refpt45 *= mat2(.5,.5,-.5,.5);"); // transform back to device space.
v->codeAppendf("refpt45 += N[1] * %f;", kAABloatRadius); // bloat for AA.
v->codeAppend ("highp vec2 K = vec2(dot(N[0], refpt), dot(N[1], refpt45));");
v->codeAppendf("highp vec2 octocoord = K * inverse(N);");
gpArgs->fPositionVar.set(kVec2f_GrSLType, "octocoord");
// Convert to atlas coordinates in order to do our texture lookup.
v->codeAppendf("highp vec2 atlascoord = octocoord + vec2(%s);",
proc.getInstanceAttrib(InstanceAttribs::kAtlasOffset).fName);
if (kTopLeft_GrSurfaceOrigin == proc.atlas()->origin()) {
v->codeAppendf("%s = atlascoord * %s;", texcoord.vsOut(), atlasAdjust);
} else {
SkASSERT(kBottomLeft_GrSurfaceOrigin == proc.atlas()->origin());
v->codeAppendf("%s = vec2(atlascoord.x * %s.x, 1 - atlascoord.y * %s.y);",
texcoord.vsOut(), atlasAdjust, atlasAdjust);
}
// Convert to (local) path cordinates.
v->codeAppendf("highp vec2 pathcoord = inverse(mat2(%s)) * (octocoord - %s);",
proc.getInstanceAttrib(InstanceAttribs::kViewMatrix).fName,
proc.getInstanceAttrib(InstanceAttribs::kViewTranslate).fName);
this->emitTransforms(v, varyingHandler, uniHandler, gpArgs->fPositionVar, "pathcoord",
args.fFPCoordTransformHandler);
// Fragment shader.
GrGLSLPPFragmentBuilder* f = args.fFragBuilder;
f->codeAppend ("mediump float coverage_count = ");
f->appendTextureLookup(args.fTexSamplers[0], texcoord.fsIn(), kVec2f_GrSLType);
f->codeAppend (".a;");
if (SkPath::kWinding_FillType == proc.fillType()) {
f->codeAppendf("%s = vec4(min(abs(coverage_count), 1));", args.fOutputCoverage);
} else {
SkASSERT(SkPath::kEvenOdd_FillType == proc.fillType());
f->codeAppend ("mediump float t = mod(abs(coverage_count), 2);");
f->codeAppendf("%s = vec4(1 - abs(t - 1));", args.fOutputCoverage);
}
}