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