| 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader)))
{ | 410 if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader)))
{ |
| 411 return false; | 411 return false; |
| 412 } | 412 } |
| 413 | 413 |
| 414 return true; | 414 return true; |
| 415 } | 415 } |
| 416 | 416 |
| 417 bool GrGLProgram::genProgram(const GrEffectStage* stages[]) { | 417 bool GrGLProgram::genProgram(const GrEffectStage* stages[]) { |
| 418 GrAssert(0 == fProgramID); | 418 GrAssert(0 == fProgramID); |
| 419 | 419 |
| 420 const GrAttribBindings& attribBindings = fDesc.fAttribBindings; | 420 bool hasExplicitLocalCoords = -1 != fDesc.fLocalCoordAttributeIndex; |
| 421 bool hasExplicitLocalCoords = | |
| 422 SkToBool(attribBindings & GrDrawState::kLocalCoords_AttribBindingsBit); | |
| 423 GrGLShaderBuilder builder(fContext.info(), fUniformManager, hasExplicitLocal
Coords); | 421 GrGLShaderBuilder builder(fContext.info(), fUniformManager, hasExplicitLocal
Coords); |
| 424 | 422 |
| 425 #if GR_GL_EXPERIMENTAL_GS | 423 #if GR_GL_EXPERIMENTAL_GS |
| 426 builder.fUsesGS = fDesc.fExperimentalGS; | 424 builder.fUsesGS = fDesc.fExperimentalGS; |
| 427 #endif | 425 #endif |
| 428 | 426 |
| 429 SkXfermode::Coeff colorCoeff, uniformCoeff; | 427 SkXfermode::Coeff colorCoeff, uniformCoeff; |
| 430 // The rest of transfer mode color filters have not been implemented | 428 // The rest of transfer mode color filters have not been implemented |
| 431 if (fDesc.fColorFilterXfermode < SkXfermode::kCoeffModesCnt) { | 429 if (fDesc.fColorFilterXfermode < SkXfermode::kCoeffModesCnt) { |
| 432 GR_DEBUGCODE(bool success =) | 430 GR_DEBUGCODE(bool success =) |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 GL_CALL(BindFragDataLocation(fProgramID, 0, declared_color_output_name()
)); | 696 GL_CALL(BindFragDataLocation(fProgramID, 0, declared_color_output_name()
)); |
| 699 } | 697 } |
| 700 if (bindDualSrcOut) { | 698 if (bindDualSrcOut) { |
| 701 GL_CALL(BindFragDataLocationIndexed(fProgramID, 0, 1, dual_source_output
_name())); | 699 GL_CALL(BindFragDataLocationIndexed(fProgramID, 0, 1, dual_source_output
_name())); |
| 702 } | 700 } |
| 703 | 701 |
| 704 // Bind the attrib locations to same values for all shaders | 702 // Bind the attrib locations to same values for all shaders |
| 705 GL_CALL(BindAttribLocation(fProgramID, | 703 GL_CALL(BindAttribLocation(fProgramID, |
| 706 fDesc.fPositionAttributeIndex, | 704 fDesc.fPositionAttributeIndex, |
| 707 builder.positionAttribute().c_str())); | 705 builder.positionAttribute().c_str())); |
| 708 GL_CALL(BindAttribLocation(fProgramID, fDesc.fColorAttributeIndex, COL_ATTR_
NAME)); | 706 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, | 707 GL_CALL(BindAttribLocation(fProgramID, |
| 713 fDesc.fLocalCoordsAttributeIndex, | 708 fDesc.fLocalCoordAttributeIndex, |
| 714 builder.localCoordsAttribute().c_str())); | 709 builder.localCoordsAttribute().c_str())); |
| 715 } | 710 } |
| 711 if (-1 != fDesc.fColorAttributeIndex) { |
| 712 GL_CALL(BindAttribLocation(fProgramID, fDesc.fColorAttributeIndex, COL_A
TTR_NAME)); |
| 713 } |
| 714 if (-1 != fDesc.fCoverageAttributeIndex) { |
| 715 GL_CALL(BindAttribLocation(fProgramID, fDesc.fCoverageAttributeIndex, CO
V_ATTR_NAME)); |
| 716 } |
| 716 | 717 |
| 717 const GrGLShaderBuilder::AttributePair* attribEnd = builder.getEffectAttribu
tes().end(); | 718 const GrGLShaderBuilder::AttributePair* attribEnd = builder.getEffectAttribu
tes().end(); |
| 718 for (const GrGLShaderBuilder::AttributePair* attrib = builder.getEffectAttri
butes().begin(); | 719 for (const GrGLShaderBuilder::AttributePair* attrib = builder.getEffectAttri
butes().begin(); |
| 719 attrib != attribEnd; | 720 attrib != attribEnd; |
| 720 ++attrib) { | 721 ++attrib) { |
| 721 GL_CALL(BindAttribLocation(fProgramID, attrib->fIndex, attrib->fName.c_
str())); | 722 GL_CALL(BindAttribLocation(fProgramID, attrib->fIndex, attrib->fName.c_
str())); |
| 722 } | 723 } |
| 723 | 724 |
| 724 GL_CALL(LinkProgram(fProgramID)); | 725 GL_CALL(LinkProgram(fProgramID)); |
| 725 | 726 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 fUniformManager.set4fv(fUniformHandles.fColorFilterUni, 0, 1, c); | 785 fUniformManager.set4fv(fUniformHandles.fColorFilterUni, 0, 1, c); |
| 785 fColorFilterColor = drawState.getColorFilterColor(); | 786 fColorFilterColor = drawState.getColorFilterColor(); |
| 786 } | 787 } |
| 787 | 788 |
| 788 GrGLint texUnitIdx = 0; | 789 GrGLint texUnitIdx = 0; |
| 789 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 790 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 790 if (NULL != fEffects[s]) { | 791 if (NULL != fEffects[s]) { |
| 791 const GrEffectStage& stage = drawState.getStage(s); | 792 const GrEffectStage& stage = drawState.getStage(s); |
| 792 GrAssert(NULL != stage.getEffect()); | 793 GrAssert(NULL != stage.getEffect()); |
| 793 | 794 |
| 794 bool explicitLocalCoords = | 795 bool explicitLocalCoords = -1 != fDesc.fLocalCoordAttributeIndex; |
| 795 (fDesc.fAttribBindings & GrDrawState::kLocalCoords_AttribBinding
sBit); | |
| 796 GrDrawEffect drawEffect(stage, explicitLocalCoords); | 796 GrDrawEffect drawEffect(stage, explicitLocalCoords); |
| 797 fEffects[s]->setData(fUniformManager, drawEffect); | 797 fEffects[s]->setData(fUniformManager, drawEffect); |
| 798 int numSamplers = fUniformHandles.fSamplerUnis[s].count(); | 798 int numSamplers = fUniformHandles.fSamplerUnis[s].count(); |
| 799 for (int u = 0; u < numSamplers; ++u) { | 799 for (int u = 0; u < numSamplers; ++u) { |
| 800 UniformHandle handle = fUniformHandles.fSamplerUnis[s][u]; | 800 UniformHandle handle = fUniformHandles.fSamplerUnis[s][u]; |
| 801 if (GrGLUniformManager::kInvalidUniformHandle != handle) { | 801 if (GrGLUniformManager::kInvalidUniformHandle != handle) { |
| 802 const GrTextureAccess& access = (*stage.getEffect())->textur
eAccess(u); | 802 const GrTextureAccess& access = (*stage.getEffect())->textur
eAccess(u); |
| 803 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getT
exture()); | 803 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getT
exture()); |
| 804 gpu->bindTexture(texUnitIdx, access.getParams(), texture); | 804 gpu->bindTexture(texUnitIdx, access.getParams(), texture); |
| 805 ++texUnitIdx; | 805 ++texUnitIdx; |
| 806 } | 806 } |
| 807 } | 807 } |
| 808 } | 808 } |
| 809 } | 809 } |
| 810 } | 810 } |
| 811 | 811 |
| 812 void GrGLProgram::setColor(const GrDrawState& drawState, | 812 void GrGLProgram::setColor(const GrDrawState& drawState, |
| 813 GrColor color, | 813 GrColor color, |
| 814 SharedGLState* sharedState) { | 814 SharedGLState* sharedState) { |
| 815 if (!(drawState.getAttribBindings() & GrDrawState::kColor_AttribBindingsBit)
) { | 815 if (!drawState.hasColorVertexAttribute()) { |
| 816 switch (fDesc.fColorInput) { | 816 switch (fDesc.fColorInput) { |
| 817 case GrGLProgramDesc::kAttribute_ColorInput: | 817 case GrGLProgramDesc::kAttribute_ColorInput: |
| 818 if (sharedState->fConstAttribColor != color) { | 818 GrAssert(-1 != fDesc.fColorAttributeIndex); |
| 819 if (sharedState->fConstAttribColor != color || |
| 820 sharedState->fConstAttribColorIndex != fDesc.fColorAttribute
Index) { |
| 819 // OpenGL ES only supports the float varieties of glVertexAt
trib | 821 // OpenGL ES only supports the float varieties of glVertexAt
trib |
| 820 GrGLfloat c[4]; | 822 GrGLfloat c[4]; |
| 821 GrColorToRGBAFloat(color, c); | 823 GrColorToRGBAFloat(color, c); |
| 822 GL_CALL(VertexAttrib4fv(fDesc.fColorAttributeIndex, c)); | 824 GL_CALL(VertexAttrib4fv(fDesc.fColorAttributeIndex, c)); |
| 823 sharedState->fConstAttribColor = color; | 825 sharedState->fConstAttribColor = color; |
| 826 sharedState->fConstAttribColorIndex = fDesc.fColorAttributeI
ndex; |
| 827 // Reset const coverage if it previously had the same index
as us |
| 828 if (sharedState->fConstAttribColorIndex == |
| 829 sharedState->fConstAttribCoverageIndex) { |
| 830 sharedState->fConstAttribCoverageIndex = -1; |
| 831 } |
| 824 } | 832 } |
| 825 break; | 833 break; |
| 826 case GrGLProgramDesc::kUniform_ColorInput: | 834 case GrGLProgramDesc::kUniform_ColorInput: |
| 827 if (fColor != color) { | 835 if (fColor != color) { |
| 828 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 836 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
| 829 GrGLfloat c[4]; | 837 GrGLfloat c[4]; |
| 830 GrColorToRGBAFloat(color, c); | 838 GrColorToRGBAFloat(color, c); |
| 831 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | 839 GrAssert(GrGLUniformManager::kInvalidUniformHandle != |
| 832 fUniformHandles.fColorUni); | 840 fUniformHandles.fColorUni); |
| 833 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); | 841 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); |
| 834 fColor = color; | 842 fColor = color; |
| 835 } | 843 } |
| 836 break; | 844 break; |
| 837 case GrGLProgramDesc::kSolidWhite_ColorInput: | 845 case GrGLProgramDesc::kSolidWhite_ColorInput: |
| 838 case GrGLProgramDesc::kTransBlack_ColorInput: | 846 case GrGLProgramDesc::kTransBlack_ColorInput: |
| 839 break; | 847 break; |
| 840 default: | 848 default: |
| 841 GrCrash("Unknown color type."); | 849 GrCrash("Unknown color type."); |
| 842 } | 850 } |
| 843 } | 851 } |
| 844 } | 852 } |
| 845 | 853 |
| 846 void GrGLProgram::setCoverage(const GrDrawState& drawState, | 854 void GrGLProgram::setCoverage(const GrDrawState& drawState, |
| 847 GrColor coverage, | 855 GrColor coverage, |
| 848 SharedGLState* sharedState) { | 856 SharedGLState* sharedState) { |
| 849 if (!(drawState.getAttribBindings() & GrDrawState::kCoverage_AttribBindingsB
it)) { | 857 if (!drawState.hasCoverageVertexAttribute()) { |
| 850 switch (fDesc.fCoverageInput) { | 858 switch (fDesc.fCoverageInput) { |
| 851 case GrGLProgramDesc::kAttribute_ColorInput: | 859 case GrGLProgramDesc::kAttribute_ColorInput: |
| 852 if (sharedState->fConstAttribCoverage != coverage) { | 860 if (sharedState->fConstAttribCoverage != coverage || |
| 861 sharedState->fConstAttribCoverageIndex != fDesc.fCoverageAtt
ributeIndex) { |
| 853 // OpenGL ES only supports the float varieties of glVertexA
ttrib | 862 // OpenGL ES only supports the float varieties of glVertexA
ttrib |
| 854 GrGLfloat c[4]; | 863 GrGLfloat c[4]; |
| 855 GrColorToRGBAFloat(coverage, c); | 864 GrColorToRGBAFloat(coverage, c); |
| 856 GL_CALL(VertexAttrib4fv(fDesc.fCoverageAttributeIndex, c)); | 865 GL_CALL(VertexAttrib4fv(fDesc.fCoverageAttributeIndex, c)); |
| 857 sharedState->fConstAttribCoverage = coverage; | 866 sharedState->fConstAttribCoverage = coverage; |
| 867 sharedState->fConstAttribCoverageIndex = fDesc.fCoverageAttr
ibuteIndex; |
| 868 // Reset const color if it previously had the same index as
us |
| 869 if (sharedState->fConstAttribCoverageIndex == |
| 870 sharedState->fConstAttribColorIndex) { |
| 871 sharedState->fConstAttribColorIndex = -1; |
| 872 } |
| 858 } | 873 } |
| 859 break; | 874 break; |
| 860 case GrGLProgramDesc::kUniform_ColorInput: | 875 case GrGLProgramDesc::kUniform_ColorInput: |
| 861 if (fCoverage != coverage) { | 876 if (fCoverage != coverage) { |
| 862 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 877 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
| 863 GrGLfloat c[4]; | 878 GrGLfloat c[4]; |
| 864 GrColorToRGBAFloat(coverage, c); | 879 GrColorToRGBAFloat(coverage, c); |
| 865 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | 880 GrAssert(GrGLUniformManager::kInvalidUniformHandle != |
| 866 fUniformHandles.fCoverageUni); | 881 fUniformHandles.fCoverageUni); |
| 867 fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
); | 882 fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 SkScalarToFloat(m[SkMatrix::kMTransX]), | 931 SkScalarToFloat(m[SkMatrix::kMTransX]), |
| 917 SkScalarToFloat(m[SkMatrix::kMTransY]), | 932 SkScalarToFloat(m[SkMatrix::kMTransY]), |
| 918 SkScalarToFloat(m[SkMatrix::kMPersp2]) | 933 SkScalarToFloat(m[SkMatrix::kMPersp2]) |
| 919 }; | 934 }; |
| 920 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 935 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); |
| 921 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 936 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
| 922 fMatrixState.fRenderTargetSize = size; | 937 fMatrixState.fRenderTargetSize = size; |
| 923 fMatrixState.fRenderTargetOrigin = rt->origin(); | 938 fMatrixState.fRenderTargetOrigin = rt->origin(); |
| 924 } | 939 } |
| 925 } | 940 } |
| OLD | NEW |