Index: src/gpu/gl/GrGLProgram.cpp |
=================================================================== |
--- src/gpu/gl/GrGLProgram.cpp (revision 7952) |
+++ src/gpu/gl/GrGLProgram.cpp (working copy) |
@@ -125,6 +125,7 @@ |
desc->fDiscardIfOutsideEdge = false; |
} |
+ desc->fEffectAttributes.reset(); |
for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bool skip = s < drawState.getFirstCoverageStage() ? skipColor : skipCoverage; |
@@ -133,6 +134,14 @@ |
const GrEffectRef& effect = *drawState.getStage(s).getEffect(); |
const GrBackendEffectFactory& factory = effect->getFactory(); |
desc->fEffectKeys[s] = factory.glEffectKey(drawState.getStage(s), gpu->glCaps()); |
+ int attrCount = drawState.getStage(s).getVertexAttribIndexCount(); |
+ GrAssert(attrCount == effect.get()->numVertexAttribs()); |
+ for (int i = 0; i < attrCount; ++i) { |
+ Desc::AttribPair pair; |
+ pair.fIndex = drawState.getStage(s).getVertexAttribIndices()[i]; |
+ pair.fName = effect.get()->vertexAttribName(i); |
+ desc->fEffectAttributes.push_back(pair); |
+ } |
} else { |
desc->fEffectKeys[s] = 0; |
} |
@@ -462,13 +471,6 @@ |
builder->fFSCode.appendf("\tfloat innerAlpha = %s.w == 0.0 ? 1.0 : smoothstep(%s.w - 0.5, %s.w + 0.5, d);\n", fsName, fsName, fsName); |
builder->fFSCode.append("\tedgeAlpha = outerAlpha * innerAlpha;\n"); |
break; |
- case GrDrawState::kEllipse_EdgeType: |
- builder->fFSCode.append("\tfloat edgeAlpha;\n"); |
- builder->fFSCode.appendf("\tvec2 offset = (%s.xy - %s.xy);\n", builder->fragmentPosition(), fsName); |
- builder->fFSCode.appendf("\toffset.y *= %s.w;\n", fsName); |
- builder->fFSCode.append("\tfloat d = length(offset);\n"); |
- builder->fFSCode.appendf("\tedgeAlpha = smoothstep(d - 0.5, d + 0.5, %s.z);\n", fsName); |
- break; |
default: |
GrCrash("Unknown Edge Type!"); |
break; |
@@ -914,6 +916,11 @@ |
inCoverage = outCoverage; |
} |
} |
+ |
+ // discard if coverage is zero |
+ if (fDesc.fDiscardIfOutsideEdge && !outCoverage.isEmpty()) { |
+ builder.fFSCode.appendf("\tif (all(lessThan(%s, vec4(0.0))) {\n\t\tdiscard;\n\t}\n", outCoverage.c_str()); |
+ } |
} |
if (Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) { |
@@ -1023,6 +1030,13 @@ |
GL_CALL(BindAttribLocation(fProgramID, fDesc.fTexCoordAttributeIndex, TEX_ATTR_NAME)); |
} |
+ const Desc::AttribPair* attribEnd = fDesc.fEffectAttributes.end(); |
+ for (const Desc::AttribPair* attrib = fDesc.fEffectAttributes.begin(); |
+ attrib != attribEnd; |
+ ++attrib) { |
+ GL_CALL(BindAttribLocation(fProgramID, attrib->fIndex, attrib->fName)); |
+ } |
+ |
GL_CALL(LinkProgram(fProgramID)); |
GrGLint linked = GR_GL_INIT_ZERO; |