| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 program = NULL; | 46 program = NULL; |
| 47 } | 47 } |
| 48 return program; | 48 return program; |
| 49 } | 49 } |
| 50 | 50 |
| 51 GrGLProgram::GrGLProgram(GrGpuGL* gpu, | 51 GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
| 52 const GrGLProgramDesc& desc, | 52 const GrGLProgramDesc& desc, |
| 53 const GrEffectStage* colorStages[], | 53 const GrEffectStage* colorStages[], |
| 54 const GrEffectStage* coverageStages[]) | 54 const GrEffectStage* coverageStages[]) |
| 55 : fGpu(gpu) | 55 : fGpu(gpu) |
| 56 , fUniformManager(gpu) { | 56 , fUniformManager(gpu) |
| 57 , fHasVertexShader(false) |
| 58 , fNumTexGenUnits(0) { |
| 57 fDesc = desc; | 59 fDesc = desc; |
| 58 fVShaderID = 0; | 60 fVShaderID = 0; |
| 59 fGShaderID = 0; | 61 fGShaderID = 0; |
| 60 fFShaderID = 0; | 62 fFShaderID = 0; |
| 61 fProgramID = 0; | 63 fProgramID = 0; |
| 62 | 64 |
| 63 fDstCopyTexUnit = -1; | 65 fDstCopyTexUnit = -1; |
| 64 | 66 |
| 65 fColor = GrColor_ILLEGAL; | 67 fColor = GrColor_ILLEGAL; |
| 66 fColorFilterColor = GrColor_ILLEGAL; | 68 fColorFilterColor = GrColor_ILLEGAL; |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 return false; | 681 return false; |
| 680 } | 682 } |
| 681 | 683 |
| 682 if (!this->bindOutputsAttribsAndLinkProgram(builder, | 684 if (!this->bindOutputsAttribsAndLinkProgram(builder, |
| 683 isColorDeclared, | 685 isColorDeclared, |
| 684 dualSourceOutputWritten)) { | 686 dualSourceOutputWritten)) { |
| 685 return false; | 687 return false; |
| 686 } | 688 } |
| 687 | 689 |
| 688 builder.finished(fProgramID); | 690 builder.finished(fProgramID); |
| 691 fHasVertexShader = (NULL != builder.getVertexBuilder()); |
| 692 fNumTexGenUnits = builder.getNumTexGenUnits(); |
| 689 fUniformHandles.fRTHeightUni = builder.getRTHeightUniform(); | 693 fUniformHandles.fRTHeightUni = builder.getRTHeightUniform(); |
| 690 fUniformHandles.fDstCopyTopLeftUni = builder.getDstCopyTopLeftUniform(); | 694 fUniformHandles.fDstCopyTopLeftUni = builder.getDstCopyTopLeftUniform(); |
| 691 fUniformHandles.fDstCopyScaleUni = builder.getDstCopyScaleUniform(); | 695 fUniformHandles.fDstCopyScaleUni = builder.getDstCopyScaleUniform(); |
| 692 fUniformHandles.fDstCopySamplerUni = builder.getDstCopySamplerUniform(); | 696 fUniformHandles.fDstCopySamplerUni = builder.getDstCopySamplerUniform(); |
| 693 // This must be called after we set fDstCopySamplerUni above. | 697 // This must be called after we set fDstCopySamplerUni above. |
| 694 this->initSamplerUniforms(); | 698 this->initSamplerUniforms(); |
| 695 | 699 |
| 696 return true; | 700 return true; |
| 697 } | 701 } |
| 698 | 702 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 if (NULL != fColorEffects[e].fGLEffect) { | 911 if (NULL != fColorEffects[e].fGLEffect) { |
| 908 this->setEffectData(*colorStages[e], fColorEffects[e]); | 912 this->setEffectData(*colorStages[e], fColorEffects[e]); |
| 909 } | 913 } |
| 910 } | 914 } |
| 911 | 915 |
| 912 for (int e = 0; e < fCoverageEffects.count(); ++e) { | 916 for (int e = 0; e < fCoverageEffects.count(); ++e) { |
| 913 if (NULL != fCoverageEffects[e].fGLEffect) { | 917 if (NULL != fCoverageEffects[e].fGLEffect) { |
| 914 this->setEffectData(*coverageStages[e], fCoverageEffects[e]); | 918 this->setEffectData(*coverageStages[e], fCoverageEffects[e]); |
| 915 } | 919 } |
| 916 } | 920 } |
| 921 |
| 922 fGpu->disableUnusedTexGenUnits(fNumTexGenUnits); |
| 917 } | 923 } |
| 918 | 924 |
| 919 void GrGLProgram::setColor(const GrDrawState& drawState, | 925 void GrGLProgram::setColor(const GrDrawState& drawState, |
| 920 GrColor color, | 926 GrColor color, |
| 921 SharedGLState* sharedState) { | 927 SharedGLState* sharedState) { |
| 922 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 928 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 923 if (!drawState.hasColorVertexAttribute()) { | 929 if (!drawState.hasColorVertexAttribute()) { |
| 924 switch (header.fColorInput) { | 930 switch (header.fColorInput) { |
| 925 case GrGLProgramDesc::kAttribute_ColorInput: | 931 case GrGLProgramDesc::kAttribute_ColorInput: |
| 926 SkASSERT(-1 != header.fColorAttributeIndex); | 932 SkASSERT(-1 != header.fColorAttributeIndex); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 const GrRenderTarget* rt = drawState.getRenderTarget(); | 1005 const GrRenderTarget* rt = drawState.getRenderTarget(); |
| 1000 SkISize size; | 1006 SkISize size; |
| 1001 size.set(rt->width(), rt->height()); | 1007 size.set(rt->width(), rt->height()); |
| 1002 | 1008 |
| 1003 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 1009 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
| 1004 if (fUniformHandles.fRTHeightUni.isValid() && | 1010 if (fUniformHandles.fRTHeightUni.isValid() && |
| 1005 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { | 1011 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { |
| 1006 fUniformManager.set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size.f
Height)); | 1012 fUniformManager.set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size.f
Height)); |
| 1007 } | 1013 } |
| 1008 | 1014 |
| 1009 if (fMatrixState.fRenderTargetOrigin != rt->origin() || | 1015 if (!fHasVertexShader) { |
| 1010 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) || | 1016 fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin())
; |
| 1011 fMatrixState.fRenderTargetSize != size) { | 1017 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
| 1018 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix())
|| |
| 1019 fMatrixState.fRenderTargetSize != size) { |
| 1012 | 1020 |
| 1013 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 1021 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
| 1014 fMatrixState.fRenderTargetSize = size; | 1022 fMatrixState.fRenderTargetSize = size; |
| 1015 fMatrixState.fRenderTargetOrigin = rt->origin(); | 1023 fMatrixState.fRenderTargetOrigin = rt->origin(); |
| 1016 | 1024 |
| 1017 GrGLfloat viewMatrix[3 * 3]; | 1025 GrGLfloat viewMatrix[3 * 3]; |
| 1018 fMatrixState.getGLMatrix<3>(viewMatrix); | 1026 fMatrixState.getGLMatrix<3>(viewMatrix); |
| 1019 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); | 1027 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); |
| 1020 } | 1028 } |
| 1021 } | 1029 } |
| OLD | NEW |