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