| 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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  698         GL_CALL(BindFragDataLocation(fProgramID, 0, declared_color_output_name()
     )); |  698         GL_CALL(BindFragDataLocation(fProgramID, 0, declared_color_output_name()
     )); | 
|  699     } |  699     } | 
|  700     if (bindDualSrcOut) { |  700     if (bindDualSrcOut) { | 
|  701         GL_CALL(BindFragDataLocationIndexed(fProgramID, 0, 1, dual_source_output
     _name())); |  701         GL_CALL(BindFragDataLocationIndexed(fProgramID, 0, 1, dual_source_output
     _name())); | 
|  702     } |  702     } | 
|  703  |  703  | 
|  704     // Bind the attrib locations to same values for all shaders |  704     // Bind the attrib locations to same values for all shaders | 
|  705     GL_CALL(BindAttribLocation(fProgramID, |  705     GL_CALL(BindAttribLocation(fProgramID, | 
|  706                                fDesc.fPositionAttributeIndex, |  706                                fDesc.fPositionAttributeIndex, | 
|  707                                builder.positionAttribute().c_str())); |  707                                builder.positionAttribute().c_str())); | 
|  708     GL_CALL(BindAttribLocation(fProgramID, fDesc.fColorAttributeIndex, COL_ATTR_
     NAME)); |  708     if (-1 != fDesc.fLocalCoordAttributeIndex) { | 
|  709     GL_CALL(BindAttribLocation(fProgramID, fDesc.fCoverageAttributeIndex, COV_AT
     TR_NAME)); |  | 
|  710  |  | 
|  711     if (fDesc.fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { |  | 
|  712         GL_CALL(BindAttribLocation(fProgramID, |  709         GL_CALL(BindAttribLocation(fProgramID, | 
|  713                                    fDesc.fLocalCoordsAttributeIndex, |  710                                    fDesc.fLocalCoordAttributeIndex, | 
|  714                                    builder.localCoordsAttribute().c_str())); |  711                                    builder.localCoordsAttribute().c_str())); | 
|  715     } |  712     } | 
 |  713     if (-1 != fDesc.fColorAttributeIndex) { | 
 |  714         GL_CALL(BindAttribLocation(fProgramID, fDesc.fColorAttributeIndex, COL_A
     TTR_NAME)); | 
 |  715     } | 
 |  716     if (-1 != fDesc.fCoverageAttributeIndex) { | 
 |  717         GL_CALL(BindAttribLocation(fProgramID, fDesc.fCoverageAttributeIndex, CO
     V_ATTR_NAME)); | 
 |  718     } | 
|  716  |  719  | 
|  717     const GrGLShaderBuilder::AttributePair* attribEnd = builder.getEffectAttribu
     tes().end(); |  720     const GrGLShaderBuilder::AttributePair* attribEnd = builder.getEffectAttribu
     tes().end(); | 
|  718     for (const GrGLShaderBuilder::AttributePair* attrib = builder.getEffectAttri
     butes().begin(); |  721     for (const GrGLShaderBuilder::AttributePair* attrib = builder.getEffectAttri
     butes().begin(); | 
|  719          attrib != attribEnd; |  722          attrib != attribEnd; | 
|  720          ++attrib) { |  723          ++attrib) { | 
|  721          GL_CALL(BindAttribLocation(fProgramID, attrib->fIndex, attrib->fName.c_
     str())); |  724          GL_CALL(BindAttribLocation(fProgramID, attrib->fIndex, attrib->fName.c_
     str())); | 
|  722     } |  725     } | 
|  723  |  726  | 
|  724     GL_CALL(LinkProgram(fProgramID)); |  727     GL_CALL(LinkProgram(fProgramID)); | 
|  725  |  728  | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  819         GrAssert(GrGLUniformManager::kInvalidUniformHandle == |  822         GrAssert(GrGLUniformManager::kInvalidUniformHandle == | 
|  820                     fUniformHandles.fDstCopyScaleUni); |  823                     fUniformHandles.fDstCopyScaleUni); | 
|  821         GrAssert(GrGLUniformManager::kInvalidUniformHandle == |  824         GrAssert(GrGLUniformManager::kInvalidUniformHandle == | 
|  822                     fUniformHandles.fDstCopySamplerUni); |  825                     fUniformHandles.fDstCopySamplerUni); | 
|  823     } |  826     } | 
|  824     for (int s = 0; s < GrDrawState::kNumStages; ++s) { |  827     for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 
|  825         if (NULL != fEffects[s]) { |  828         if (NULL != fEffects[s]) { | 
|  826             const GrEffectStage& stage = drawState.getStage(s); |  829             const GrEffectStage& stage = drawState.getStage(s); | 
|  827             GrAssert(NULL != stage.getEffect()); |  830             GrAssert(NULL != stage.getEffect()); | 
|  828  |  831  | 
|  829             bool explicitLocalCoords = |  832             bool explicitLocalCoords = -1 != fDesc.fLocalCoordAttributeIndex; | 
|  830                 (fDesc.fAttribBindings & GrDrawState::kLocalCoords_AttribBinding
     sBit); |  | 
|  831             GrDrawEffect drawEffect(stage, explicitLocalCoords); |  833             GrDrawEffect drawEffect(stage, explicitLocalCoords); | 
|  832             fEffects[s]->setData(fUniformManager, drawEffect); |  834             fEffects[s]->setData(fUniformManager, drawEffect); | 
|  833             int numSamplers = fUniformHandles.fEffectSamplerUnis[s].count(); |  835             int numSamplers = fUniformHandles.fEffectSamplerUnis[s].count(); | 
|  834             for (int u = 0; u < numSamplers; ++u) { |  836             for (int u = 0; u < numSamplers; ++u) { | 
|  835                 UniformHandle handle = fUniformHandles.fEffectSamplerUnis[s][u]; |  837                 UniformHandle handle = fUniformHandles.fEffectSamplerUnis[s][u]; | 
|  836                 if (GrGLUniformManager::kInvalidUniformHandle != handle) { |  838                 if (GrGLUniformManager::kInvalidUniformHandle != handle) { | 
|  837                     const GrTextureAccess& access = (*stage.getEffect())->textur
     eAccess(u); |  839                     const GrTextureAccess& access = (*stage.getEffect())->textur
     eAccess(u); | 
|  838                     GrGLTexture* texture = static_cast<GrGLTexture*>(access.getT
     exture()); |  840                     GrGLTexture* texture = static_cast<GrGLTexture*>(access.getT
     exture()); | 
|  839                     gpu->bindTexture(texUnitIdx, access.getParams(), texture); |  841                     gpu->bindTexture(texUnitIdx, access.getParams(), texture); | 
|  840                     ++texUnitIdx; |  842                     ++texUnitIdx; | 
|  841                 } |  843                 } | 
|  842             } |  844             } | 
|  843         } |  845         } | 
|  844     } |  846     } | 
|  845 } |  847 } | 
|  846  |  848  | 
|  847 void GrGLProgram::setColor(const GrDrawState& drawState, |  849 void GrGLProgram::setColor(const GrDrawState& drawState, | 
|  848                            GrColor color, |  850                            GrColor color, | 
|  849                            SharedGLState* sharedState) { |  851                            SharedGLState* sharedState) { | 
|  850     if (!(drawState.getAttribBindings() & GrDrawState::kColor_AttribBindingsBit)
     ) { |  852     if (!drawState.hasColorVertexAttribute()) { | 
|  851         switch (fDesc.fColorInput) { |  853         switch (fDesc.fColorInput) { | 
|  852             case GrGLProgramDesc::kAttribute_ColorInput: |  854             case GrGLProgramDesc::kAttribute_ColorInput: | 
|  853                 if (sharedState->fConstAttribColor != color) { |  855                 GrAssert(-1 != fDesc.fColorAttributeIndex); | 
 |  856                 if (sharedState->fConstAttribColor != color || | 
 |  857                     sharedState->fConstAttribColorIndex != fDesc.fColorAttribute
     Index) { | 
|  854                     // OpenGL ES only supports the float varieties of glVertexAt
     trib |  858                     // OpenGL ES only supports the float varieties of glVertexAt
     trib | 
|  855                     GrGLfloat c[4]; |  859                     GrGLfloat c[4]; | 
|  856                     GrColorToRGBAFloat(color, c); |  860                     GrColorToRGBAFloat(color, c); | 
|  857                     GL_CALL(VertexAttrib4fv(fDesc.fColorAttributeIndex, c)); |  861                     GL_CALL(VertexAttrib4fv(fDesc.fColorAttributeIndex, c)); | 
|  858                     sharedState->fConstAttribColor = color; |  862                     sharedState->fConstAttribColor = color; | 
 |  863                     sharedState->fConstAttribColorIndex = fDesc.fColorAttributeI
     ndex; | 
|  859                 } |  864                 } | 
|  860                 break; |  865                 break; | 
|  861             case GrGLProgramDesc::kUniform_ColorInput: |  866             case GrGLProgramDesc::kUniform_ColorInput: | 
|  862                 if (fColor != color) { |  867                 if (fColor != color) { | 
|  863                     // OpenGL ES doesn't support unsigned byte varieties of glUn
     iform |  868                     // OpenGL ES doesn't support unsigned byte varieties of glUn
     iform | 
|  864                     GrGLfloat c[4]; |  869                     GrGLfloat c[4]; | 
|  865                     GrColorToRGBAFloat(color, c); |  870                     GrColorToRGBAFloat(color, c); | 
|  866                     GrAssert(GrGLUniformManager::kInvalidUniformHandle != |  871                     GrAssert(GrGLUniformManager::kInvalidUniformHandle != | 
|  867                              fUniformHandles.fColorUni); |  872                              fUniformHandles.fColorUni); | 
|  868                     fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); |  873                     fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); | 
|  869                     fColor = color; |  874                     fColor = color; | 
|  870                 } |  875                 } | 
 |  876                 sharedState->fConstAttribColorIndex = -1; | 
|  871                 break; |  877                 break; | 
|  872             case GrGLProgramDesc::kSolidWhite_ColorInput: |  878             case GrGLProgramDesc::kSolidWhite_ColorInput: | 
|  873             case GrGLProgramDesc::kTransBlack_ColorInput: |  879             case GrGLProgramDesc::kTransBlack_ColorInput: | 
 |  880                 sharedState->fConstAttribColorIndex = -1; | 
|  874                 break; |  881                 break; | 
|  875             default: |  882             default: | 
|  876                 GrCrash("Unknown color type."); |  883                 GrCrash("Unknown color type."); | 
|  877         } |  884         } | 
 |  885     } else { | 
 |  886         sharedState->fConstAttribColorIndex = -1; | 
|  878     } |  887     } | 
|  879 } |  888 } | 
|  880  |  889  | 
|  881 void GrGLProgram::setCoverage(const GrDrawState& drawState, |  890 void GrGLProgram::setCoverage(const GrDrawState& drawState, | 
|  882                               GrColor coverage, |  891                               GrColor coverage, | 
|  883                               SharedGLState* sharedState) { |  892                               SharedGLState* sharedState) { | 
|  884     if (!(drawState.getAttribBindings() & GrDrawState::kCoverage_AttribBindingsB
     it)) { |  893     if (!drawState.hasCoverageVertexAttribute()) { | 
|  885         switch (fDesc.fCoverageInput) { |  894         switch (fDesc.fCoverageInput) { | 
|  886             case GrGLProgramDesc::kAttribute_ColorInput: |  895             case GrGLProgramDesc::kAttribute_ColorInput: | 
|  887                 if (sharedState->fConstAttribCoverage != coverage) { |  896                 if (sharedState->fConstAttribCoverage != coverage || | 
 |  897                     sharedState->fConstAttribCoverageIndex != fDesc.fCoverageAtt
     ributeIndex) { | 
|  888                     // OpenGL ES only supports the float varieties of  glVertexA
     ttrib |  898                     // OpenGL ES only supports the float varieties of  glVertexA
     ttrib | 
|  889                     GrGLfloat c[4]; |  899                     GrGLfloat c[4]; | 
|  890                     GrColorToRGBAFloat(coverage, c); |  900                     GrColorToRGBAFloat(coverage, c); | 
|  891                     GL_CALL(VertexAttrib4fv(fDesc.fCoverageAttributeIndex, c)); |  901                     GL_CALL(VertexAttrib4fv(fDesc.fCoverageAttributeIndex, c)); | 
|  892                     sharedState->fConstAttribCoverage = coverage; |  902                     sharedState->fConstAttribCoverage = coverage; | 
 |  903                     sharedState->fConstAttribCoverageIndex = fDesc.fCoverageAttr
     ibuteIndex; | 
|  893                 } |  904                 } | 
|  894                 break; |  905                 break; | 
|  895             case GrGLProgramDesc::kUniform_ColorInput: |  906             case GrGLProgramDesc::kUniform_ColorInput: | 
|  896                 if (fCoverage != coverage) { |  907                 if (fCoverage != coverage) { | 
|  897                     // OpenGL ES doesn't support unsigned byte varieties of glUn
     iform |  908                     // OpenGL ES doesn't support unsigned byte varieties of glUn
     iform | 
|  898                     GrGLfloat c[4]; |  909                     GrGLfloat c[4]; | 
|  899                     GrColorToRGBAFloat(coverage, c); |  910                     GrColorToRGBAFloat(coverage, c); | 
|  900                     GrAssert(GrGLUniformManager::kInvalidUniformHandle != |  911                     GrAssert(GrGLUniformManager::kInvalidUniformHandle != | 
|  901                              fUniformHandles.fCoverageUni); |  912                              fUniformHandles.fCoverageUni); | 
|  902                     fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
     ); |  913                     fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
     ); | 
|  903                     fCoverage = coverage; |  914                     fCoverage = coverage; | 
|  904                 } |  915                 } | 
 |  916                 sharedState->fConstAttribCoverageIndex = -1; | 
|  905                 break; |  917                 break; | 
|  906             case GrGLProgramDesc::kSolidWhite_ColorInput: |  918             case GrGLProgramDesc::kSolidWhite_ColorInput: | 
|  907             case GrGLProgramDesc::kTransBlack_ColorInput: |  919             case GrGLProgramDesc::kTransBlack_ColorInput: | 
 |  920                 sharedState->fConstAttribCoverageIndex = -1; | 
|  908                 break; |  921                 break; | 
|  909             default: |  922             default: | 
|  910                 GrCrash("Unknown coverage type."); |  923                 GrCrash("Unknown coverage type."); | 
|  911         } |  924         } | 
 |  925     } else { | 
 |  926         sharedState->fConstAttribCoverageIndex = -1; | 
|  912     } |  927     } | 
|  913 } |  928 } | 
|  914  |  929  | 
|  915 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { |  930 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { | 
|  916     const GrRenderTarget* rt = drawState.getRenderTarget(); |  931     const GrRenderTarget* rt = drawState.getRenderTarget(); | 
|  917     SkISize size; |  932     SkISize size; | 
|  918     size.set(rt->width(), rt->height()); |  933     size.set(rt->width(), rt->height()); | 
|  919  |  934  | 
|  920     // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |  935     // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 
|  921     if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fRTHeightUn
     i && |  936     if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fRTHeightUn
     i && | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|  951             SkScalarToFloat(m[SkMatrix::kMTransX]), |  966             SkScalarToFloat(m[SkMatrix::kMTransX]), | 
|  952             SkScalarToFloat(m[SkMatrix::kMTransY]), |  967             SkScalarToFloat(m[SkMatrix::kMTransY]), | 
|  953             SkScalarToFloat(m[SkMatrix::kMPersp2]) |  968             SkScalarToFloat(m[SkMatrix::kMPersp2]) | 
|  954         }; |  969         }; | 
|  955         fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); |  970         fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 
|  956         fMatrixState.fViewMatrix = drawState.getViewMatrix(); |  971         fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 
|  957         fMatrixState.fRenderTargetSize = size; |  972         fMatrixState.fRenderTargetSize = size; | 
|  958         fMatrixState.fRenderTargetOrigin = rt->origin(); |  973         fMatrixState.fRenderTargetOrigin = rt->origin(); | 
|  959     } |  974     } | 
|  960 } |  975 } | 
| OLD | NEW |