| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1 | /* |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "GrGLProgram.h" |
| 9 | |
| tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 10 | #include "GrAllocator.h" |
| bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 11 | #include "GrEffect.h" |
| bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 12 | #include "GrCoordTransform.h" |
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 13 | #include "GrDrawEffect.h" |
| bsalomon@google.com | d698f77 | 2012-10-25 13:22:00 +0000 | [diff] [blame] | 14 | #include "GrGLEffect.h" |
| bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 15 | #include "GrGpuGL.h" |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 16 | #include "GrGLShaderVar.h" |
| bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 17 | #include "GrGLSL.h" |
| Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 18 | #include "SkXfermode.h" |
| 19 | |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 20 | #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
| 21 | #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
| bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 22 | |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 23 | GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 24 | const GrGLProgramDesc& desc, |
| bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 25 | const GrEffectStage* colorStages[], |
| 26 | const GrEffectStage* coverageStages[]) { |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 27 | GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gpu, desc, colorStages, coverageStages)); |
| bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 28 | if (!program->succeeded()) { |
| 29 | delete program; |
| 30 | program = NULL; |
| 31 | } |
| 32 | return program; |
| 33 | } |
| 34 | |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 35 | GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 36 | const GrGLProgramDesc& desc, |
| bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 37 | const GrEffectStage* colorStages[], |
| 38 | const GrEffectStage* coverageStages[]) |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 39 | : fGpu(gpu) |
| commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 40 | , fUniformManager(gpu) |
| 41 | , fHasVertexShader(false) |
| 42 | , fNumTexCoordSets(0) { |
| bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 43 | fDesc = desc; |
| bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 44 | fProgramID = 0; |
| bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 45 | |
| bsalomon@google.com | 804e994 | 2013-06-06 18:04:38 +0000 | [diff] [blame] | 46 | fDstCopyTexUnit = -1; |
| 47 | |
| bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 48 | fColor = GrColor_ILLEGAL; |
| bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 49 | |
| commit-bot@chromium.org | 0365261 | 2014-05-29 19:09:52 +0000 | [diff] [blame^] | 50 | GrGLShaderBuilder::GenProgramOutput output; |
| 51 | |
| 52 | if (GrGLShaderBuilder::GenProgram(gpu, fUniformManager, desc, colorStages, coverageStages, |
| 53 | &output)) { |
| 54 | fProgramID = output.fProgramID; |
| 55 | fUniformHandles = output.fUniformHandles; |
| 56 | fColorEffects.reset(output.fColorEffects); |
| 57 | fCoverageEffects.reset(output.fCoverageEffects); |
| 58 | fHasVertexShader = output.fHasVS; |
| 59 | fNumTexCoordSets = output.fNumTexCoordSets; |
| 60 | fGpu = gpu; |
| 61 | this->initSamplerUniforms(); |
| commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 62 | } |
| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | GrGLProgram::~GrGLProgram() { |
| bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 66 | if (fProgramID) { |
| 67 | GL_CALL(DeleteProgram(fProgramID)); |
| 68 | } |
| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 71 | void GrGLProgram::abandon() { |
| bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 72 | fProgramID = 0; |
| 73 | } |
| 74 | |
| tomhudson@google.com | 0d3f1fb | 2011-06-01 19:27:31 +0000 | [diff] [blame] | 75 | void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 76 | GrBlendCoeff* dstCoeff) const { |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 77 | switch (fDesc.getHeader().fCoverageOutput) { |
| bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 78 | case GrGLProgramDesc::kModulate_CoverageOutput: |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 79 | break; |
| bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 80 | // The prog will write a coverage value to the secondary |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 81 | // output and the dst is blended by one minus that value. |
| bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 82 | case GrGLProgramDesc::kSecondaryCoverage_CoverageOutput: |
| 83 | case GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput: |
| 84 | case GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput: |
| 85 | *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 86 | break; |
| 87 | case GrGLProgramDesc::kCombineWithDst_CoverageOutput: |
| 88 | // We should only have set this if the blend was specified as (1, 0) |
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 89 | SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *dstCoeff); |
| bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 90 | break; |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 91 | default: |
| commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 92 | SkFAIL("Unexpected coverage output"); |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 93 | break; |
| 94 | } |
| 95 | } |
| 96 | |
| bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 97 | void GrGLProgram::initSamplerUniforms() { |
| bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 98 | GL_CALL(UseProgram(fProgramID)); |
| bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 99 | GrGLint texUnitIdx = 0; |
| commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 100 | if (fUniformHandles.fDstCopySamplerUni.isValid()) { |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 101 | fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitIdx); |
| bsalomon@google.com | 804e994 | 2013-06-06 18:04:38 +0000 | [diff] [blame] | 102 | fDstCopyTexUnit = texUnitIdx++; |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 103 | } |
| commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 104 | fColorEffects->initSamplers(fUniformManager, &texUnitIdx); |
| 105 | fCoverageEffects->initSamplers(fUniformManager, &texUnitIdx); |
| bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 108 | /////////////////////////////////////////////////////////////////////////////// |
| junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 109 | |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 110 | void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts, |
| bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 111 | const GrEffectStage* colorStages[], |
| 112 | const GrEffectStage* coverageStages[], |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 113 | const GrDeviceCoordTexture* dstCopy, |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 114 | SharedGLState* sharedState) { |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 115 | const GrDrawState& drawState = fGpu->getDrawState(); |
| bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 116 | |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 117 | GrColor color; |
| 118 | GrColor coverage; |
| 119 | if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { |
| 120 | color = 0; |
| 121 | coverage = 0; |
| 122 | } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) { |
| 123 | color = 0xffffffff; |
| commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 124 | coverage = drawState.getCoverageColor(); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 125 | } else { |
| 126 | color = drawState.getColor(); |
| commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 127 | coverage = drawState.getCoverageColor(); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 130 | this->setColor(drawState, color, sharedState); |
| 131 | this->setCoverage(drawState, coverage, sharedState); |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 132 | this->setMatrixAndRenderTargetHeight(drawState); |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 133 | |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 134 | if (NULL != dstCopy) { |
| commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 135 | if (fUniformHandles.fDstCopyTopLeftUni.isValid()) { |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 136 | fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, |
| 137 | static_cast<GrGLfloat>(dstCopy->offset().fX), |
| 138 | static_cast<GrGLfloat>(dstCopy->offset().fY)); |
| 139 | fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, |
| 140 | 1.f / dstCopy->texture()->width(), |
| 141 | 1.f / dstCopy->texture()->height()); |
| 142 | GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()); |
| 143 | static GrTextureParams kParams; // the default is clamp, nearest filtering. |
| commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 144 | fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 145 | } else { |
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 146 | SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); |
| 147 | SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 148 | } |
| 149 | } else { |
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 150 | SkASSERT(!fUniformHandles.fDstCopyTopLeftUni.isValid()); |
| 151 | SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); |
| 152 | SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); |
| bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 153 | } |
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 154 | |
| commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 155 | fColorEffects->setData(fGpu, fUniformManager, colorStages); |
| 156 | fCoverageEffects->setData(fGpu, fUniformManager, coverageStages); |
| commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 157 | |
| commit-bot@chromium.org | 2080722 | 2013-11-01 11:54:54 +0000 | [diff] [blame] | 158 | |
| commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 159 | // PathTexGen state applies to the the fixed function vertex shader. For |
| 160 | // custom shaders, it's ignored, so we don't need to change the texgen |
| 161 | // settings in that case. |
| commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 162 | if (!fHasVertexShader) { |
| commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 163 | fGpu->flushPathTexGenSettings(fNumTexCoordSets); |
| commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 164 | } |
| skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 165 | } |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 166 | |
| 167 | void GrGLProgram::setColor(const GrDrawState& drawState, |
| 168 | GrColor color, |
| 169 | SharedGLState* sharedState) { |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 170 | const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 171 | if (!drawState.hasColorVertexAttribute()) { |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 172 | switch (header.fColorInput) { |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 173 | case GrGLProgramDesc::kAttribute_ColorInput: |
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 174 | SkASSERT(-1 != header.fColorAttributeIndex); |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 175 | if (sharedState->fConstAttribColor != color || |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 176 | sharedState->fConstAttribColorIndex != header.fColorAttributeIndex) { |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 177 | // OpenGL ES only supports the float varieties of glVertexAttrib |
| 178 | GrGLfloat c[4]; |
| 179 | GrColorToRGBAFloat(color, c); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 180 | GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 181 | sharedState->fConstAttribColor = color; |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 182 | sharedState->fConstAttribColorIndex = header.fColorAttributeIndex; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 183 | } |
| 184 | break; |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 185 | case GrGLProgramDesc::kUniform_ColorInput: |
| commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 186 | if (fColor != color && fUniformHandles.fColorUni.isValid()) { |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 187 | // OpenGL ES doesn't support unsigned byte varieties of glUniform |
| 188 | GrGLfloat c[4]; |
| 189 | GrColorToRGBAFloat(color, c); |
| commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 190 | fUniformManager.set4fv(fUniformHandles.fColorUni, 1, c); |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 191 | fColor = color; |
| 192 | } |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 193 | sharedState->fConstAttribColorIndex = -1; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 194 | break; |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 195 | case GrGLProgramDesc::kSolidWhite_ColorInput: |
| 196 | case GrGLProgramDesc::kTransBlack_ColorInput: |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 197 | sharedState->fConstAttribColorIndex = -1; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 198 | break; |
| 199 | default: |
| commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 200 | SkFAIL("Unknown color type."); |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 201 | } |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 202 | } else { |
| 203 | sharedState->fConstAttribColorIndex = -1; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | void GrGLProgram::setCoverage(const GrDrawState& drawState, |
| 208 | GrColor coverage, |
| 209 | SharedGLState* sharedState) { |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 210 | const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 211 | if (!drawState.hasCoverageVertexAttribute()) { |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 212 | switch (header.fCoverageInput) { |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 213 | case GrGLProgramDesc::kAttribute_ColorInput: |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 214 | if (sharedState->fConstAttribCoverage != coverage || |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 215 | sharedState->fConstAttribCoverageIndex != header.fCoverageAttributeIndex) { |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 216 | // OpenGL ES only supports the float varieties of glVertexAttrib |
| 217 | GrGLfloat c[4]; |
| 218 | GrColorToRGBAFloat(coverage, c); |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 219 | GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 220 | sharedState->fConstAttribCoverage = coverage; |
| bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 221 | sharedState->fConstAttribCoverageIndex = header.fCoverageAttributeIndex; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 222 | } |
| 223 | break; |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 224 | case GrGLProgramDesc::kUniform_ColorInput: |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 225 | if (fCoverage != coverage) { |
| 226 | // OpenGL ES doesn't support unsigned byte varieties of glUniform |
| 227 | GrGLfloat c[4]; |
| 228 | GrColorToRGBAFloat(coverage, c); |
| commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 229 | fUniformManager.set4fv(fUniformHandles.fCoverageUni, 1, c); |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 230 | fCoverage = coverage; |
| 231 | } |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 232 | sharedState->fConstAttribCoverageIndex = -1; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 233 | break; |
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 234 | case GrGLProgramDesc::kSolidWhite_ColorInput: |
| 235 | case GrGLProgramDesc::kTransBlack_ColorInput: |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 236 | sharedState->fConstAttribCoverageIndex = -1; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 237 | break; |
| 238 | default: |
| commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 239 | SkFAIL("Unknown coverage type."); |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 240 | } |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 241 | } else { |
| 242 | sharedState->fConstAttribCoverageIndex = -1; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 245 | |
| 246 | void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { |
| 247 | const GrRenderTarget* rt = drawState.getRenderTarget(); |
| 248 | SkISize size; |
| 249 | size.set(rt->width(), rt->height()); |
| 250 | |
| 251 | // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
| commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 252 | if (fUniformHandles.fRTHeightUni.isValid() && |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 253 | fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { |
| 254 | fUniformManager.set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size.fHeight)); |
| 255 | } |
| 256 | |
| commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 257 | if (!fHasVertexShader) { |
| 258 | SkASSERT(!fUniformHandles.fViewMatrixUni.isValid()); |
| commit-bot@chromium.org | 47c66dd | 2014-05-29 01:12:10 +0000 | [diff] [blame] | 259 | SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid()); |
| commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 260 | fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()); |
| 261 | } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
| 262 | fMatrixState.fRenderTargetSize != size || |
| 263 | !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix())) { |
| 264 | SkASSERT(fUniformHandles.fViewMatrixUni.isValid()); |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 265 | |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 266 | fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
| 267 | fMatrixState.fRenderTargetSize = size; |
| 268 | fMatrixState.fRenderTargetOrigin = rt->origin(); |
| commit-bot@chromium.org | 215a682 | 2013-09-05 18:28:42 +0000 | [diff] [blame] | 269 | |
| 270 | GrGLfloat viewMatrix[3 * 3]; |
| 271 | fMatrixState.getGLMatrix<3>(viewMatrix); |
| 272 | fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); |
| commit-bot@chromium.org | 47c66dd | 2014-05-29 01:12:10 +0000 | [diff] [blame] | 273 | |
| 274 | GrGLfloat rtAdjustmentVec[4]; |
| 275 | fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
| 276 | fUniformManager.set4fv(fUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 277 | } |
| 278 | } |