| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
| 9 | 9 |
| 10 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 if (!skipCoverage && (desc->fAttribBindings & GrDrawState::kEdge_AttribBindi
ngsBit)) { | 119 if (!skipCoverage && (desc->fAttribBindings & GrDrawState::kEdge_AttribBindi
ngsBit)) { |
| 120 desc->fVertexEdgeType = drawState.getVertexEdgeType(); | 120 desc->fVertexEdgeType = drawState.getVertexEdgeType(); |
| 121 desc->fDiscardIfOutsideEdge = drawState.getStencil().doesWrite(); | 121 desc->fDiscardIfOutsideEdge = drawState.getStencil().doesWrite(); |
| 122 } else { | 122 } else { |
| 123 // Use canonical values when edge-aa is not enabled to avoid program cac
he misses. | 123 // Use canonical values when edge-aa is not enabled to avoid program cac
he misses. |
| 124 desc->fVertexEdgeType = GrDrawState::kHairLine_EdgeType; | 124 desc->fVertexEdgeType = GrDrawState::kHairLine_EdgeType; |
| 125 desc->fDiscardIfOutsideEdge = false; | 125 desc->fDiscardIfOutsideEdge = false; |
| 126 } | 126 } |
| 127 | 127 |
| 128 desc->fEffectAttributes.reset(); |
| 128 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 129 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 129 | 130 |
| 130 bool skip = s < drawState.getFirstCoverageStage() ? skipColor : skipCove
rage; | 131 bool skip = s < drawState.getFirstCoverageStage() ? skipColor : skipCove
rage; |
| 131 if (!skip && drawState.isStageEnabled(s)) { | 132 if (!skip && drawState.isStageEnabled(s)) { |
| 132 lastEnabledStage = s; | 133 lastEnabledStage = s; |
| 133 const GrEffectRef& effect = *drawState.getStage(s).getEffect(); | 134 const GrEffectRef& effect = *drawState.getStage(s).getEffect(); |
| 134 const GrBackendEffectFactory& factory = effect->getFactory(); | 135 const GrBackendEffectFactory& factory = effect->getFactory(); |
| 135 desc->fEffectKeys[s] = factory.glEffectKey(drawState.getStage(s), gp
u->glCaps()); | 136 desc->fEffectKeys[s] = factory.glEffectKey(drawState.getStage(s), gp
u->glCaps()); |
| 137 int attrCount = drawState.getStage(s).getVertexAttribIndexCount(); |
| 138 GrAssert(attrCount == effect.get()->numVertexAttribs()); |
| 139 for (int i = 0; i < attrCount; ++i) { |
| 140 Desc::AttribPair pair; |
| 141 pair.fIndex = drawState.getStage(s).getVertexAttribIndices()[i]; |
| 142 pair.fName = effect.get()->vertexAttribName(i); |
| 143 desc->fEffectAttributes.push_back(pair); |
| 144 } |
| 136 } else { | 145 } else { |
| 137 desc->fEffectKeys[s] = 0; | 146 desc->fEffectKeys[s] = 0; |
| 138 } | 147 } |
| 139 } | 148 } |
| 140 | 149 |
| 141 desc->fDualSrcOutput = Desc::kNone_DualSrcOutput; | 150 desc->fDualSrcOutput = Desc::kNone_DualSrcOutput; |
| 142 | 151 |
| 143 // Currently the experimental GS will only work with triangle prims (and it
doesn't do anything | 152 // Currently the experimental GS will only work with triangle prims (and it
doesn't do anything |
| 144 // other than pass through values from the VS to the FS anyway). | 153 // other than pass through values from the VS to the FS anyway). |
| 145 #if GR_GL_EXPERIMENTAL_GS | 154 #if GR_GL_EXPERIMENTAL_GS |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 builder->fHeader.printf("#extension GL_OES_standard_derivatives:
enable\n"); | 464 builder->fHeader.printf("#extension GL_OES_standard_derivatives:
enable\n"); |
| 456 } | 465 } |
| 457 break; | 466 break; |
| 458 case GrDrawState::kCircle_EdgeType: | 467 case GrDrawState::kCircle_EdgeType: |
| 459 builder->fFSCode.append("\tfloat edgeAlpha;\n"); | 468 builder->fFSCode.append("\tfloat edgeAlpha;\n"); |
| 460 builder->fFSCode.appendf("\tfloat d = distance(%s.xy, %s.xy);\n", bu
ilder->fragmentPosition(), fsName); | 469 builder->fFSCode.appendf("\tfloat d = distance(%s.xy, %s.xy);\n", bu
ilder->fragmentPosition(), fsName); |
| 461 builder->fFSCode.appendf("\tfloat outerAlpha = smoothstep(d - 0.5, d
+ 0.5, %s.z);\n", fsName); | 470 builder->fFSCode.appendf("\tfloat outerAlpha = smoothstep(d - 0.5, d
+ 0.5, %s.z);\n", fsName); |
| 462 builder->fFSCode.appendf("\tfloat innerAlpha = %s.w == 0.0 ? 1.0 : s
moothstep(%s.w - 0.5, %s.w + 0.5, d);\n", fsName, fsName, fsName); | 471 builder->fFSCode.appendf("\tfloat innerAlpha = %s.w == 0.0 ? 1.0 : s
moothstep(%s.w - 0.5, %s.w + 0.5, d);\n", fsName, fsName, fsName); |
| 463 builder->fFSCode.append("\tedgeAlpha = outerAlpha * innerAlpha;\n"); | 472 builder->fFSCode.append("\tedgeAlpha = outerAlpha * innerAlpha;\n"); |
| 464 break; | 473 break; |
| 465 case GrDrawState::kEllipse_EdgeType: | |
| 466 builder->fFSCode.append("\tfloat edgeAlpha;\n"); | |
| 467 builder->fFSCode.appendf("\tvec2 offset = (%s.xy - %s.xy);\n", build
er->fragmentPosition(), fsName); | |
| 468 builder->fFSCode.appendf("\toffset.y *= %s.w;\n", fsName); | |
| 469 builder->fFSCode.append("\tfloat d = length(offset);\n"); | |
| 470 builder->fFSCode.appendf("\tedgeAlpha = smoothstep(d - 0.5, d + 0.5,
%s.z);\n", fsName); | |
| 471 break; | |
| 472 default: | 474 default: |
| 473 GrCrash("Unknown Edge Type!"); | 475 GrCrash("Unknown Edge Type!"); |
| 474 break; | 476 break; |
| 475 } | 477 } |
| 476 if (fDesc.fDiscardIfOutsideEdge) { | 478 if (fDesc.fDiscardIfOutsideEdge) { |
| 477 builder->fFSCode.appendf("\tif (edgeAlpha <= 0.0) {\n\t\tdiscard;\n\
t}\n"); | 479 builder->fFSCode.appendf("\tif (edgeAlpha <= 0.0) {\n\t\tdiscard;\n\
t}\n"); |
| 478 } | 480 } |
| 479 *coverageVar = "edgeAlpha"; | 481 *coverageVar = "edgeAlpha"; |
| 480 return true; | 482 return true; |
| 481 } else { | 483 } else { |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 *stages[s], | 909 *stages[s], |
| 908 fDesc.fEffectKeys[s], | 910 fDesc.fEffectKeys[s], |
| 909 inCoverage.size() ? inCovera
ge.c_str() : NULL, | 911 inCoverage.size() ? inCovera
ge.c_str() : NULL, |
| 910 outCoverage.c_str(), | 912 outCoverage.c_str(), |
| 911 inCoords, | 913 inCoords, |
| 912 &fUniformHandles.fSamplerUni
s[s]); | 914 &fUniformHandles.fSamplerUni
s[s]); |
| 913 builder.setNonStage(); | 915 builder.setNonStage(); |
| 914 inCoverage = outCoverage; | 916 inCoverage = outCoverage; |
| 915 } | 917 } |
| 916 } | 918 } |
| 919 |
| 920 // discard if coverage is zero |
| 921 if (fDesc.fDiscardIfOutsideEdge && !outCoverage.isEmpty()) { |
| 922 builder.fFSCode.appendf("\tif (all(lessThan(%s, vec4(0.0))) {\n\
t\tdiscard;\n\t}\n", outCoverage.c_str()); |
| 923 } |
| 917 } | 924 } |
| 918 | 925 |
| 919 if (Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) { | 926 if (Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) { |
| 920 builder.fFSOutputs.push_back().set(kVec4f_GrSLType, | 927 builder.fFSOutputs.push_back().set(kVec4f_GrSLType, |
| 921 GrGLShaderVar::kOut_TypeModifier, | 928 GrGLShaderVar::kOut_TypeModifier, |
| 922 dual_source_output_name()); | 929 dual_source_output_name()); |
| 923 bool outputIsZero = coverageIsZero; | 930 bool outputIsZero = coverageIsZero; |
| 924 SkString coeff; | 931 SkString coeff; |
| 925 if (!outputIsZero && | 932 if (!outputIsZero && |
| 926 Desc::kCoverage_DualSrcOutput != fDesc.fDualSrcOutput && !wroteF
ragColorZero) { | 933 Desc::kCoverage_DualSrcOutput != fDesc.fDualSrcOutput && !wroteF
ragColorZero) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 GL_CALL(BindAttribLocation(fProgramID, fDesc.fColorAttributeIndex, COL_ATTR_
NAME)); | 1023 GL_CALL(BindAttribLocation(fProgramID, fDesc.fColorAttributeIndex, COL_ATTR_
NAME)); |
| 1017 GL_CALL(BindAttribLocation(fProgramID, fDesc.fCoverageAttributeIndex, COV_AT
TR_NAME)); | 1024 GL_CALL(BindAttribLocation(fProgramID, fDesc.fCoverageAttributeIndex, COV_AT
TR_NAME)); |
| 1018 | 1025 |
| 1019 if (fDesc.fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) { | 1026 if (fDesc.fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) { |
| 1020 GL_CALL(BindAttribLocation(fProgramID, fDesc.fEdgeAttributeIndex, EDGE_A
TTR_NAME)); | 1027 GL_CALL(BindAttribLocation(fProgramID, fDesc.fEdgeAttributeIndex, EDGE_A
TTR_NAME)); |
| 1021 } | 1028 } |
| 1022 if (GrDrawState::AttributesBindExplicitTexCoords(fDesc.fAttribBindings)) { | 1029 if (GrDrawState::AttributesBindExplicitTexCoords(fDesc.fAttribBindings)) { |
| 1023 GL_CALL(BindAttribLocation(fProgramID, fDesc.fTexCoordAttributeIndex, TE
X_ATTR_NAME)); | 1030 GL_CALL(BindAttribLocation(fProgramID, fDesc.fTexCoordAttributeIndex, TE
X_ATTR_NAME)); |
| 1024 } | 1031 } |
| 1025 | 1032 |
| 1033 const Desc::AttribPair* attribEnd = fDesc.fEffectAttributes.end(); |
| 1034 for (const Desc::AttribPair* attrib = fDesc.fEffectAttributes.begin(); |
| 1035 attrib != attribEnd; |
| 1036 ++attrib) { |
| 1037 GL_CALL(BindAttribLocation(fProgramID, attrib->fIndex, attrib->fName)); |
| 1038 } |
| 1039 |
| 1026 GL_CALL(LinkProgram(fProgramID)); | 1040 GL_CALL(LinkProgram(fProgramID)); |
| 1027 | 1041 |
| 1028 GrGLint linked = GR_GL_INIT_ZERO; | 1042 GrGLint linked = GR_GL_INIT_ZERO; |
| 1029 GL_CALL(GetProgramiv(fProgramID, GR_GL_LINK_STATUS, &linked)); | 1043 GL_CALL(GetProgramiv(fProgramID, GR_GL_LINK_STATUS, &linked)); |
| 1030 if (!linked) { | 1044 if (!linked) { |
| 1031 GrGLint infoLen = GR_GL_INIT_ZERO; | 1045 GrGLint infoLen = GR_GL_INIT_ZERO; |
| 1032 GL_CALL(GetProgramiv(fProgramID, GR_GL_INFO_LOG_LENGTH, &infoLen)); | 1046 GL_CALL(GetProgramiv(fProgramID, GR_GL_INFO_LOG_LENGTH, &infoLen)); |
| 1033 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger | 1047 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger |
| 1034 if (infoLen > 0) { | 1048 if (infoLen > 0) { |
| 1035 // retrieve length even though we don't need it to workaround | 1049 // retrieve length even though we don't need it to workaround |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 SkScalarToFloat(m[SkMatrix::kMTransX]), | 1228 SkScalarToFloat(m[SkMatrix::kMTransX]), |
| 1215 SkScalarToFloat(m[SkMatrix::kMTransY]), | 1229 SkScalarToFloat(m[SkMatrix::kMTransY]), |
| 1216 SkScalarToFloat(m[SkMatrix::kMPersp2]) | 1230 SkScalarToFloat(m[SkMatrix::kMPersp2]) |
| 1217 }; | 1231 }; |
| 1218 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 1232 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); |
| 1219 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 1233 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
| 1220 fMatrixState.fRenderTargetSize = size; | 1234 fMatrixState.fRenderTargetSize = size; |
| 1221 fMatrixState.fRenderTargetOrigin = rt->origin(); | 1235 fMatrixState.fRenderTargetOrigin = rt->origin(); |
| 1222 } | 1236 } |
| 1223 } | 1237 } |
| OLD | NEW |