Index: src/gpu/gl/GrGLProgram.cpp |
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp |
index bfa5f3cbc155e7f18581e361933653d40bdaf357..2d9b569333a03c7ac11f13c9f8606074b9dcc677 100644 |
--- a/src/gpu/gl/GrGLProgram.cpp |
+++ b/src/gpu/gl/GrGLProgram.cpp |
@@ -129,12 +129,13 @@ |
void GrGLProgram::setData(const GrOptDrawState& optState, |
GrGpu::DrawType drawType, |
- const GrDeviceCoordTexture* dstCopy) { |
+ const GrDeviceCoordTexture* dstCopy, |
+ SharedGLState* sharedState) { |
GrColor color = optState.getColor(); |
GrColor coverage = optState.getCoverageColor(); |
- this->setColor(optState, color); |
- this->setCoverage(optState, coverage); |
+ this->setColor(optState, color, sharedState); |
+ this->setCoverage(optState, coverage, sharedState); |
this->setMatrixAndRenderTargetHeight(drawType, optState); |
if (dstCopy) { |
@@ -200,49 +201,80 @@ |
SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
} |
-void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) { |
+void GrGLProgram::setColor(const GrOptDrawState& optState, |
+ GrColor color, |
+ SharedGLState* sharedState) { |
const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
- switch (header.fColorInput) { |
- case GrGLProgramDesc::kAttribute_ColorInput: |
- // Attribute case is handled in GrGpuGL::setupGeometry |
- break; |
- case GrGLProgramDesc::kUniform_ColorInput: |
- if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { |
- // OpenGL ES doesn't support unsigned byte varieties of glUniform |
- GrGLfloat c[4]; |
- GrColorToRGBAFloat(color, c); |
- fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c); |
- fColor = color; |
- } |
- break; |
- case GrGLProgramDesc::kAllOnes_ColorInput: |
- // Handled by shader creation |
- break; |
- default: |
- SkFAIL("Unexpected color type."); |
- } |
-} |
- |
-void GrGLProgram::setCoverage(const GrOptDrawState& optState, GrColor coverage) { |
+ if (!optState.hasColorVertexAttribute()) { |
+ switch (header.fColorInput) { |
+ case GrGLProgramDesc::kAttribute_ColorInput: |
+ SkASSERT(-1 != header.fColorAttributeIndex); |
+ if (sharedState->fConstAttribColor != color || |
+ sharedState->fConstAttribColorIndex != header.fColorAttributeIndex) { |
+ // OpenGL ES only supports the float varieties of glVertexAttrib |
+ GrGLfloat c[4]; |
+ GrColorToRGBAFloat(color, c); |
+ GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
+ sharedState->fConstAttribColor = color; |
+ sharedState->fConstAttribColorIndex = header.fColorAttributeIndex; |
+ } |
+ break; |
+ case GrGLProgramDesc::kUniform_ColorInput: |
+ if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { |
+ // OpenGL ES doesn't support unsigned byte varieties of glUniform |
+ GrGLfloat c[4]; |
+ GrColorToRGBAFloat(color, c); |
+ fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c); |
+ fColor = color; |
+ } |
+ sharedState->fConstAttribColorIndex = -1; |
+ break; |
+ case GrGLProgramDesc::kAllOnes_ColorInput: |
+ sharedState->fConstAttribColorIndex = -1; |
+ break; |
+ default: |
+ SkFAIL("Unexpected color type."); |
+ } |
+ } else { |
+ sharedState->fConstAttribColorIndex = -1; |
+ } |
+} |
+ |
+void GrGLProgram::setCoverage(const GrOptDrawState& optState, |
+ GrColor coverage, |
+ SharedGLState* sharedState) { |
const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
- switch (header.fCoverageInput) { |
- case GrGLProgramDesc::kAttribute_ColorInput: |
- // Attribute case is handled in GrGpuGL::setupGeometry |
- break; |
- case GrGLProgramDesc::kUniform_ColorInput: |
- if (fCoverage != coverage) { |
- // OpenGL ES doesn't support unsigned byte varieties of glUniform |
- GrGLfloat c[4]; |
- GrColorToRGBAFloat(coverage, c); |
- fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni, 1, c); |
- fCoverage = coverage; |
- } |
- break; |
- case GrGLProgramDesc::kAllOnes_ColorInput: |
- // Handled by shader creation |
- break; |
- default: |
- SkFAIL("Unexpected coverage type."); |
+ if (!optState.hasCoverageVertexAttribute()) { |
+ switch (header.fCoverageInput) { |
+ case GrGLProgramDesc::kAttribute_ColorInput: |
+ if (sharedState->fConstAttribCoverage != coverage || |
+ sharedState->fConstAttribCoverageIndex != header.fCoverageAttributeIndex) { |
+ // OpenGL ES only supports the float varieties of glVertexAttrib |
+ GrGLfloat c[4]; |
+ GrColorToRGBAFloat(coverage, c); |
+ GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
+ sharedState->fConstAttribCoverage = coverage; |
+ sharedState->fConstAttribCoverageIndex = header.fCoverageAttributeIndex; |
+ } |
+ break; |
+ case GrGLProgramDesc::kUniform_ColorInput: |
+ if (fCoverage != coverage) { |
+ // OpenGL ES doesn't support unsigned byte varieties of glUniform |
+ GrGLfloat c[4]; |
+ GrColorToRGBAFloat(coverage, c); |
+ fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni, 1, c); |
+ fCoverage = coverage; |
+ } |
+ sharedState->fConstAttribCoverageIndex = -1; |
+ break; |
+ case GrGLProgramDesc::kAllOnes_ColorInput: |
+ sharedState->fConstAttribCoverageIndex = -1; |
+ break; |
+ default: |
+ SkFAIL("Unexpected coverage type."); |
+ } |
+ } else { |
+ sharedState->fConstAttribCoverageIndex = -1; |
} |
} |