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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 GL_CALL(DeleteProgram(fProgramID)); | 746 GL_CALL(DeleteProgram(fProgramID)); |
747 fProgramID = 0; | 747 fProgramID = 0; |
748 return false; | 748 return false; |
749 } | 749 } |
750 return true; | 750 return true; |
751 } | 751 } |
752 | 752 |
753 void GrGLProgram::initSamplerUniforms() { | 753 void GrGLProgram::initSamplerUniforms() { |
754 GL_CALL(UseProgram(fProgramID)); | 754 GL_CALL(UseProgram(fProgramID)); |
755 GrGLint texUnitIdx = 0; | 755 GrGLint texUnitIdx = 0; |
756 if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fDstCopySam
plerUni) { | 756 if (fUniformHandles.fDstCopySamplerUni.isValid()) { |
757 fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitId
x); | 757 fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitId
x); |
758 fDstCopyTexUnit = texUnitIdx++; | 758 fDstCopyTexUnit = texUnitIdx++; |
759 } | 759 } |
760 | 760 |
761 for (int e = 0; e < fColorEffects.count(); ++e) { | 761 for (int e = 0; e < fColorEffects.count(); ++e) { |
762 this->initEffectSamplerUniforms(&fColorEffects[e], &texUnitIdx); | 762 this->initEffectSamplerUniforms(&fColorEffects[e], &texUnitIdx); |
763 } | 763 } |
764 | 764 |
765 for (int e = 0; e < fCoverageEffects.count(); ++e) { | 765 for (int e = 0; e < fCoverageEffects.count(); ++e) { |
766 this->initEffectSamplerUniforms(&fCoverageEffects[e], &texUnitIdx); | 766 this->initEffectSamplerUniforms(&fCoverageEffects[e], &texUnitIdx); |
767 } | 767 } |
768 } | 768 } |
769 | 769 |
770 void GrGLProgram::initEffectSamplerUniforms(EffectAndSamplers* effect, int* texU
nitIdx) { | 770 void GrGLProgram::initEffectSamplerUniforms(EffectAndSamplers* effect, int* texU
nitIdx) { |
771 int numSamplers = effect->fSamplerUnis.count(); | 771 int numSamplers = effect->fSamplerUnis.count(); |
772 effect->fTextureUnits.reset(numSamplers); | 772 effect->fTextureUnits.reset(numSamplers); |
773 for (int s = 0; s < numSamplers; ++s) { | 773 for (int s = 0; s < numSamplers; ++s) { |
774 UniformHandle handle = effect->fSamplerUnis[s]; | 774 UniformHandle handle = effect->fSamplerUnis[s]; |
775 if (GrGLUniformManager::kInvalidUniformHandle != handle) { | 775 if (handle.isValid()) { |
776 fUniformManager.setSampler(handle, *texUnitIdx); | 776 fUniformManager.setSampler(handle, *texUnitIdx); |
777 effect->fTextureUnits[s] = (*texUnitIdx)++; | 777 effect->fTextureUnits[s] = (*texUnitIdx)++; |
778 } | 778 } |
779 } | 779 } |
780 } | 780 } |
781 | 781 |
782 /////////////////////////////////////////////////////////////////////////////// | 782 /////////////////////////////////////////////////////////////////////////////// |
783 | 783 |
784 void GrGLProgram::setEffectData(GrGpuGL* gpu, | 784 void GrGLProgram::setEffectData(GrGpuGL* gpu, |
785 const GrEffectStage& stage, | 785 const GrEffectStage& stage, |
786 const EffectAndSamplers& effect) { | 786 const EffectAndSamplers& effect) { |
787 | 787 |
788 // Let the GrGLEffect set its data. | 788 // Let the GrGLEffect set its data. |
789 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex
; | 789 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex
; |
790 GrDrawEffect drawEffect(stage, explicitLocalCoords); | 790 GrDrawEffect drawEffect(stage, explicitLocalCoords); |
791 effect.fGLEffect->setData(fUniformManager, drawEffect); | 791 effect.fGLEffect->setData(fUniformManager, drawEffect); |
792 | 792 |
793 // Bind the texures for the effect. | 793 // Bind the texures for the effect. |
794 int numSamplers = effect.fSamplerUnis.count(); | 794 int numSamplers = effect.fSamplerUnis.count(); |
795 GrAssert((*stage.getEffect())->numTextures() == numSamplers); | 795 GrAssert((*stage.getEffect())->numTextures() == numSamplers); |
796 for (int s = 0; s < numSamplers; ++s) { | 796 for (int s = 0; s < numSamplers; ++s) { |
797 UniformHandle handle = effect.fSamplerUnis[s]; | 797 UniformHandle handle = effect.fSamplerUnis[s]; |
798 if (GrGLUniformManager::kInvalidUniformHandle != handle) { | 798 if (handle.isValid()) { |
799 const GrTextureAccess& access = (*stage.getEffect())->textureAccess(
s); | 799 const GrTextureAccess& access = (*stage.getEffect())->textureAccess(
s); |
800 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()
); | 800 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()
); |
801 int unit = effect.fTextureUnits[s]; | 801 int unit = effect.fTextureUnits[s]; |
802 gpu->bindTexture(unit, access.getParams(), texture); | 802 gpu->bindTexture(unit, access.getParams(), texture); |
803 } | 803 } |
804 } | 804 } |
805 } | 805 } |
806 | 806 |
807 void GrGLProgram::setData(GrGpuGL* gpu, | 807 void GrGLProgram::setData(GrGpuGL* gpu, |
808 GrDrawState::BlendOptFlags blendOpts, | 808 GrDrawState::BlendOptFlags blendOpts, |
(...skipping 14 matching lines...) Expand all Loading... |
823 } else { | 823 } else { |
824 color = drawState.getColor(); | 824 color = drawState.getColor(); |
825 coverage = drawState.getCoverage(); | 825 coverage = drawState.getCoverage(); |
826 } | 826 } |
827 | 827 |
828 this->setColor(drawState, color, sharedState); | 828 this->setColor(drawState, color, sharedState); |
829 this->setCoverage(drawState, coverage, sharedState); | 829 this->setCoverage(drawState, coverage, sharedState); |
830 this->setMatrixAndRenderTargetHeight(drawState); | 830 this->setMatrixAndRenderTargetHeight(drawState); |
831 | 831 |
832 // Setup the SkXfermode::Mode-based colorfilter uniform if necessary | 832 // Setup the SkXfermode::Mode-based colorfilter uniform if necessary |
833 if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fColorFilte
rUni && | 833 if (fUniformHandles.fColorFilterUni.isValid() && |
834 fColorFilterColor != drawState.getColorFilterColor()) { | 834 fColorFilterColor != drawState.getColorFilterColor()) { |
835 GrGLfloat c[4]; | 835 GrGLfloat c[4]; |
836 GrColorToRGBAFloat(drawState.getColorFilterColor(), c); | 836 GrColorToRGBAFloat(drawState.getColorFilterColor(), c); |
837 fUniformManager.set4fv(fUniformHandles.fColorFilterUni, 0, 1, c); | 837 fUniformManager.set4fv(fUniformHandles.fColorFilterUni, 0, 1, c); |
838 fColorFilterColor = drawState.getColorFilterColor(); | 838 fColorFilterColor = drawState.getColorFilterColor(); |
839 } | 839 } |
840 | 840 |
841 if (NULL != dstCopy) { | 841 if (NULL != dstCopy) { |
842 if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fDstCop
yTopLeftUni) { | 842 if (fUniformHandles.fDstCopyTopLeftUni.isValid()) { |
843 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fUniformHandle
s.fDstCopyScaleUni); | |
844 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | |
845 fUniformHandles.fDstCopySamplerUni); | |
846 fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, | 843 fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, |
847 static_cast<GrGLfloat>(dstCopy->offset().fX), | 844 static_cast<GrGLfloat>(dstCopy->offset().fX), |
848 static_cast<GrGLfloat>(dstCopy->offset().fY)); | 845 static_cast<GrGLfloat>(dstCopy->offset().fY)); |
849 fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, | 846 fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, |
850 1.f / dstCopy->texture()->width(), | 847 1.f / dstCopy->texture()->width(), |
851 1.f / dstCopy->texture()->height()); | 848 1.f / dstCopy->texture()->height()); |
852 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; | 849 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; |
853 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. | 850 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. |
854 gpu->bindTexture(fDstCopyTexUnit, kParams, texture); | 851 gpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
855 } else { | 852 } else { |
856 GrAssert(GrGLUniformManager::kInvalidUniformHandle == | 853 GrAssert(!fUniformHandles.fDstCopyScaleUni.isValid()); |
857 fUniformHandles.fDstCopyScaleUni); | 854 GrAssert(!fUniformHandles.fDstCopySamplerUni.isValid()); |
858 GrAssert(GrGLUniformManager::kInvalidUniformHandle == | |
859 fUniformHandles.fDstCopySamplerUni); | |
860 } | 855 } |
861 } else { | 856 } else { |
862 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fD
stCopyTopLeftUni); | 857 GrAssert(!fUniformHandles.fDstCopyTopLeftUni.isValid()); |
863 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fD
stCopyScaleUni); | 858 GrAssert(!fUniformHandles.fDstCopyScaleUni.isValid()); |
864 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fD
stCopySamplerUni); | 859 GrAssert(!fUniformHandles.fDstCopySamplerUni.isValid()); |
865 } | 860 } |
866 | 861 |
867 for (int e = 0; e < fColorEffects.count(); ++e) { | 862 for (int e = 0; e < fColorEffects.count(); ++e) { |
868 // We may have omitted the GrGLEffect because of the color filter logic
in genProgram. | 863 // We may have omitted the GrGLEffect because of the color filter logic
in genProgram. |
869 // This can be removed when the color filter is an effect. | 864 // This can be removed when the color filter is an effect. |
870 if (NULL != fColorEffects[e].fGLEffect) { | 865 if (NULL != fColorEffects[e].fGLEffect) { |
871 this->setEffectData(gpu, *colorStages[e], fColorEffects[e]); | 866 this->setEffectData(gpu, *colorStages[e], fColorEffects[e]); |
872 } | 867 } |
873 } | 868 } |
874 | 869 |
(...skipping 20 matching lines...) Expand all Loading... |
895 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); | 890 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
896 sharedState->fConstAttribColor = color; | 891 sharedState->fConstAttribColor = color; |
897 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; | 892 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; |
898 } | 893 } |
899 break; | 894 break; |
900 case GrGLProgramDesc::kUniform_ColorInput: | 895 case GrGLProgramDesc::kUniform_ColorInput: |
901 if (fColor != color) { | 896 if (fColor != color) { |
902 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 897 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
903 GrGLfloat c[4]; | 898 GrGLfloat c[4]; |
904 GrColorToRGBAFloat(color, c); | 899 GrColorToRGBAFloat(color, c); |
905 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | |
906 fUniformHandles.fColorUni); | |
907 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); | 900 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); |
908 fColor = color; | 901 fColor = color; |
909 } | 902 } |
910 sharedState->fConstAttribColorIndex = -1; | 903 sharedState->fConstAttribColorIndex = -1; |
911 break; | 904 break; |
912 case GrGLProgramDesc::kSolidWhite_ColorInput: | 905 case GrGLProgramDesc::kSolidWhite_ColorInput: |
913 case GrGLProgramDesc::kTransBlack_ColorInput: | 906 case GrGLProgramDesc::kTransBlack_ColorInput: |
914 sharedState->fConstAttribColorIndex = -1; | 907 sharedState->fConstAttribColorIndex = -1; |
915 break; | 908 break; |
916 default: | 909 default: |
(...skipping 19 matching lines...) Expand all Loading... |
936 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); | 929 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
937 sharedState->fConstAttribCoverage = coverage; | 930 sharedState->fConstAttribCoverage = coverage; |
938 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; | 931 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; |
939 } | 932 } |
940 break; | 933 break; |
941 case GrGLProgramDesc::kUniform_ColorInput: | 934 case GrGLProgramDesc::kUniform_ColorInput: |
942 if (fCoverage != coverage) { | 935 if (fCoverage != coverage) { |
943 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 936 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
944 GrGLfloat c[4]; | 937 GrGLfloat c[4]; |
945 GrColorToRGBAFloat(coverage, c); | 938 GrColorToRGBAFloat(coverage, c); |
946 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | |
947 fUniformHandles.fCoverageUni); | |
948 fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
); | 939 fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
); |
949 fCoverage = coverage; | 940 fCoverage = coverage; |
950 } | 941 } |
951 sharedState->fConstAttribCoverageIndex = -1; | 942 sharedState->fConstAttribCoverageIndex = -1; |
952 break; | 943 break; |
953 case GrGLProgramDesc::kSolidWhite_ColorInput: | 944 case GrGLProgramDesc::kSolidWhite_ColorInput: |
954 case GrGLProgramDesc::kTransBlack_ColorInput: | 945 case GrGLProgramDesc::kTransBlack_ColorInput: |
955 sharedState->fConstAttribCoverageIndex = -1; | 946 sharedState->fConstAttribCoverageIndex = -1; |
956 break; | 947 break; |
957 default: | 948 default: |
958 GrCrash("Unknown coverage type."); | 949 GrCrash("Unknown coverage type."); |
959 } | 950 } |
960 } else { | 951 } else { |
961 sharedState->fConstAttribCoverageIndex = -1; | 952 sharedState->fConstAttribCoverageIndex = -1; |
962 } | 953 } |
963 } | 954 } |
964 | 955 |
965 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { | 956 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { |
966 const GrRenderTarget* rt = drawState.getRenderTarget(); | 957 const GrRenderTarget* rt = drawState.getRenderTarget(); |
967 SkISize size; | 958 SkISize size; |
968 size.set(rt->width(), rt->height()); | 959 size.set(rt->width(), rt->height()); |
969 | 960 |
970 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 961 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
971 if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fRTHeightUn
i && | 962 if (fUniformHandles.fRTHeightUni.isValid() && |
972 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { | 963 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { |
973 fUniformManager.set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size.f
Height)); | 964 fUniformManager.set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size.f
Height)); |
974 } | 965 } |
975 | 966 |
976 if (fMatrixState.fRenderTargetOrigin != rt->origin() || | 967 if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
977 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) || | 968 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) || |
978 fMatrixState.fRenderTargetSize != size) { | 969 fMatrixState.fRenderTargetSize != size) { |
979 SkMatrix m; | 970 SkMatrix m; |
980 if (kBottomLeft_GrSurfaceOrigin == rt->origin()) { | 971 if (kBottomLeft_GrSurfaceOrigin == rt->origin()) { |
981 m.setAll( | 972 m.setAll( |
(...skipping 19 matching lines...) Expand all Loading... |
1001 SkScalarToFloat(m[SkMatrix::kMTransX]), | 992 SkScalarToFloat(m[SkMatrix::kMTransX]), |
1002 SkScalarToFloat(m[SkMatrix::kMTransY]), | 993 SkScalarToFloat(m[SkMatrix::kMTransY]), |
1003 SkScalarToFloat(m[SkMatrix::kMPersp2]) | 994 SkScalarToFloat(m[SkMatrix::kMPersp2]) |
1004 }; | 995 }; |
1005 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 996 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); |
1006 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 997 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
1007 fMatrixState.fRenderTargetSize = size; | 998 fMatrixState.fRenderTargetSize = size; |
1008 fMatrixState.fRenderTargetOrigin = rt->origin(); | 999 fMatrixState.fRenderTargetOrigin = rt->origin(); |
1009 } | 1000 } |
1010 } | 1001 } |
OLD | NEW |