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 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 10 | #include "GrAllocator.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 11 | #include "GrProcessor.h" |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 12 | #include "GrCoordTransform.h" |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 13 | #include "GrGLGeometryProcessor.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 14 | #include "GrGLProcessor.h" |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 15 | #include "GrGLXferProcessor.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" |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 21 | #include "GrXferProcessor.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 22 | #include "SkXfermode.h" |
| 23 | |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 24 | #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
| 25 | #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] | 26 | |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Retrieves the final matrix that a transform needs to apply to its source coords. |
| 29 | */ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 30 | static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, int transformIdx) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 31 | const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransform(transformIdx); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 32 | SkMatrix combined; |
| 33 | |
| 34 | if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
| 35 | // If we have explicit local coords then we shouldn't need a coord change. |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 36 | const SkMatrix& ccm = stage.getCoordChangeMatrix(); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 37 | combined.setConcat(coordTransform.getMatrix(), ccm); |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 38 | } else { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 39 | combined = coordTransform.getMatrix(); |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 40 | } |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 41 | if (coordTransform.reverseY()) { |
| 42 | // combined.postScale(1,-1); |
| 43 | // combined.postTranslate(0,1); |
| 44 | combined.set(SkMatrix::kMSkewY, |
| 45 | combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 46 | combined.set(SkMatrix::kMScaleY, |
| 47 | combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| 48 | combined.set(SkMatrix::kMTransY, |
| 49 | combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 50 | } |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 51 | return combined; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 52 | } |
| 53 | |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 54 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 55 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 56 | GrGLProgram::GrGLProgram(GrGLGpu* gpu, |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 57 | const GrProgramDesc& desc, |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 58 | const BuiltinUniformHandles& builtinUniforms, |
| 59 | GrGLuint programID, |
| 60 | const UniformInfoArray& uniforms, |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 61 | GrGLInstalledGeoProc* geometryProcessor, |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 62 | GrGLInstalledXferProc* xferProcessor, |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 63 | GrGLInstalledFragProcs* fragmentProcessors) |
commit-bot@chromium.org | a05fa06 | 2014-05-30 18:55:03 +0000 | [diff] [blame] | 64 | : fColor(GrColor_ILLEGAL) |
egdaniel | 37b4d86 | 2014-11-03 10:07:07 -0800 | [diff] [blame] | 65 | , fCoverage(0) |
commit-bot@chromium.org | 6eac42e | 2014-05-29 21:29:51 +0000 | [diff] [blame] | 66 | , fDstCopyTexUnit(-1) |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 67 | , fBuiltinUniformHandles(builtinUniforms) |
| 68 | , fProgramID(programID) |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 69 | , fGeometryProcessor(geometryProcessor) |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 70 | , fXferProcessor(xferProcessor) |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 71 | , fFragmentProcessors(SkRef(fragmentProcessors)) |
commit-bot@chromium.org | 6eac42e | 2014-05-29 21:29:51 +0000 | [diff] [blame] | 72 | , fDesc(desc) |
| 73 | , fGpu(gpu) |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 74 | , fProgramDataManager(gpu, uniforms) { |
commit-bot@chromium.org | 6eac42e | 2014-05-29 21:29:51 +0000 | [diff] [blame] | 75 | this->initSamplerUniforms(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | GrGLProgram::~GrGLProgram() { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 79 | if (fProgramID) { |
| 80 | GL_CALL(DeleteProgram(fProgramID)); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 81 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 82 | } |
| 83 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 84 | void GrGLProgram::abandon() { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 85 | fProgramID = 0; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 86 | } |
| 87 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 88 | void GrGLProgram::initSamplerUniforms() { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 89 | GL_CALL(UseProgram(fProgramID)); |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 90 | GrGLint texUnitIdx = 0; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 91 | if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { |
| 92 | fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni, texUnitIdx); |
bsalomon@google.com | 804e994 | 2013-06-06 18:04:38 +0000 | [diff] [blame] | 93 | fDstCopyTexUnit = texUnitIdx++; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 94 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 95 | if (fGeometryProcessor.get()) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 96 | this->initSamplers(fGeometryProcessor.get(), &texUnitIdx); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 97 | } |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 98 | if (fXferProcessor.get()) { |
| 99 | this->initSamplers(fXferProcessor.get(), &texUnitIdx); |
| 100 | } |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 101 | int numProcs = fFragmentProcessors->fProcs.count(); |
| 102 | for (int i = 0; i < numProcs; i++) { |
| 103 | this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 107 | void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) { |
| 108 | SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers; |
| 109 | int numSamplers = samplers.count(); |
| 110 | for (int s = 0; s < numSamplers; ++s) { |
| 111 | SkASSERT(samplers[s].fUniform.isValid()); |
| 112 | fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx); |
| 113 | samplers[s].fTextureUnit = (*texUnitIdx)++; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& processor) { |
| 118 | const SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 119 | int numSamplers = samplers.count(); |
| 120 | SkASSERT(numSamplers == processor.numTextures()); |
| 121 | for (int s = 0; s < numSamplers; ++s) { |
| 122 | SkASSERT(samplers[s].fTextureUnit >= 0); |
| 123 | const GrTextureAccess& textureAccess = processor.textureAccess(s); |
| 124 | fGpu->bindTexture(samplers[s].fTextureUnit, |
| 125 | textureAccess.getParams(), |
| 126 | static_cast<GrGLTexture*>(textureAccess.getTexture())); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 131 | /////////////////////////////////////////////////////////////////////////////// |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 132 | |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 133 | void GrGLProgram::setData(const GrOptDrawState& optState) { |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 134 | this->setMatrixAndRenderTargetHeight(optState); |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 135 | |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 136 | const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 137 | if (dstCopy) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 138 | if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { |
| 139 | fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 140 | static_cast<GrGLfloat>(dstCopy->offset().fX), |
| 141 | static_cast<GrGLfloat>(dstCopy->offset().fY)); |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 142 | fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 143 | 1.f / dstCopy->texture()->width(), |
| 144 | 1.f / dstCopy->texture()->height()); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 145 | GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()); |
| 146 | static GrTextureParams kParams; // the default is clamp, nearest filtering. |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 147 | fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 148 | } else { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 149 | SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
| 150 | SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 151 | } |
| 152 | } else { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 153 | SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); |
| 154 | SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
| 155 | SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 156 | } |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 157 | |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 158 | // we set the textures, and uniforms for installed processors in a generic way, but subclasses |
| 159 | // of GLProgram determine how to set coord transforms |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 160 | const GrPrimitiveProcessor& primProc = *optState.getPrimitiveProcessor(); |
| 161 | const GrBatchTracker& bt = optState.getBatchTracker(); |
| 162 | fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, bt); |
| 163 | this->bindTextures(fGeometryProcessor, primProc); |
| 164 | |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 165 | if (fXferProcessor.get()) { |
| 166 | const GrXferProcessor& xp = *optState.getXferProcessor(); |
| 167 | fXferProcessor->fGLProc->setData(fProgramDataManager, xp); |
| 168 | this->bindTextures(fXferProcessor, xp); |
| 169 | } |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 170 | this->setFragmentData(optState); |
commit-bot@chromium.org | 2080722 | 2013-11-01 11:54:54 +0000 | [diff] [blame] | 171 | |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 172 | // Some of GrGLProgram subclasses need to update state here |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 173 | this->didSetData(optState.drawType()); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 174 | } |
| 175 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 176 | void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { |
| 177 | int numProcessors = fFragmentProcessors->fProcs.count(); |
| 178 | for (int e = 0; e < numProcessors; ++e) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 179 | const GrPendingFragmentStage& stage = optState.getFragmentStage(e); |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 180 | const GrProcessor& processor = *stage.getProcessor(); |
| 181 | fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor); |
| 182 | this->setTransformData(stage, fFragmentProcessors->fProcs[e]); |
| 183 | this->bindTextures(fFragmentProcessors->fProcs[e], processor); |
| 184 | } |
| 185 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 186 | void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor, |
| 187 | GrGLInstalledFragProc* ip) { |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 188 | SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 189 | int numTransforms = transforms.count(); |
| 190 | SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); |
| 191 | for (int t = 0; t < numTransforms; ++t) { |
| 192 | SkASSERT(transforms[t].fHandle.isValid()); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 193 | const SkMatrix& matrix = get_transform_matrix(processor, t); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 194 | if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
| 195 | fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix); |
| 196 | transforms[t].fCurrentValue = matrix; |
| 197 | } |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 198 | } |
skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 199 | } |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 200 | |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 201 | void GrGLProgram::didSetData(GrGpu::DrawType drawType) { |
| 202 | SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
| 203 | } |
| 204 | |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 205 | void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 206 | // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
| 207 | if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
| 208 | fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) { |
| 209 | fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
| 210 | SkIntToScalar(optState.getRenderTarget()->height())); |
| 211 | } |
| 212 | |
| 213 | // call subclasses to set the actual view matrix |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 214 | this->onSetMatrixAndRenderTargetHeight(optState); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 215 | } |
| 216 | |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 217 | void GrGLProgram::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) { |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 218 | const GrRenderTarget* rt = optState.getRenderTarget(); |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 219 | SkISize size; |
| 220 | size.set(rt->width(), rt->height()); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 221 | if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
| 222 | fMatrixState.fRenderTargetSize != size || |
| 223 | !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) { |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 224 | SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 225 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 226 | fMatrixState.fViewMatrix = optState.getViewMatrix(); |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 227 | fMatrixState.fRenderTargetSize = size; |
| 228 | fMatrixState.fRenderTargetOrigin = rt->origin(); |
commit-bot@chromium.org | 215a682 | 2013-09-05 18:28:42 +0000 | [diff] [blame] | 229 | |
| 230 | GrGLfloat viewMatrix[3 * 3]; |
| 231 | fMatrixState.getGLMatrix<3>(viewMatrix); |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 232 | fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix); |
commit-bot@chromium.org | 47c66dd | 2014-05-29 01:12:10 +0000 | [diff] [blame] | 233 | |
| 234 | GrGLfloat rtAdjustmentVec[4]; |
| 235 | fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 236 | fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 239 | |
| 240 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 241 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 242 | GrGLNvprProgramBase::GrGLNvprProgramBase(GrGLGpu* gpu, |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 243 | const GrProgramDesc& desc, |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 244 | const BuiltinUniformHandles& builtinUniforms, |
| 245 | GrGLuint programID, |
| 246 | const UniformInfoArray& uniforms, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 247 | GrGLInstalledGeoProc* primProc, |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 248 | GrGLInstalledXferProc* xferProcessor, |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 249 | GrGLInstalledFragProcs* fragmentProcessors) |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 250 | : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 251 | xferProcessor, fragmentProcessors) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 252 | } |
| 253 | |
joshualitt | dafa4d0 | 2014-12-04 08:59:10 -0800 | [diff] [blame] | 254 | void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) { |
| 255 | SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType())); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 256 | const GrRenderTarget* rt = optState.getRenderTarget(); |
| 257 | SkISize size; |
| 258 | size.set(rt->width(), rt->height()); |
| 259 | fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin()); |
| 260 | } |
| 261 | |
| 262 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 263 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 264 | GrGLNvprProgram::GrGLNvprProgram(GrGLGpu* gpu, |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 265 | const GrProgramDesc& desc, |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 266 | const BuiltinUniformHandles& builtinUniforms, |
| 267 | GrGLuint programID, |
| 268 | const UniformInfoArray& uniforms, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 269 | GrGLInstalledGeoProc* primProc, |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 270 | GrGLInstalledXferProc* xferProcessor, |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 271 | GrGLInstalledFragProcs* fragmentProcessors, |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 272 | const SeparableVaryingInfoArray& separableVaryings) |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 273 | : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 274 | xferProcessor, fragmentProcessors) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 275 | int count = separableVaryings.count(); |
| 276 | fVaryings.push_back_n(count); |
| 277 | for (int i = 0; i < count; i++) { |
| 278 | Varying& varying = fVaryings[i]; |
| 279 | const SeparableVaryingInfo& builderVarying = separableVaryings[i]; |
| 280 | SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount()); |
| 281 | SkDEBUGCODE( |
| 282 | varying.fType = builderVarying.fVariable.getType(); |
| 283 | ); |
| 284 | varying.fLocation = builderVarying.fLocation; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 289 | SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 290 | } |
| 291 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 292 | void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
| 293 | GrGLInstalledFragProc* ip) { |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 294 | SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 295 | int numTransforms = transforms.count(); |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 296 | SkASSERT(numTransforms == proc.getProcessor()->numTransforms()); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 297 | for (int t = 0; t < numTransforms; ++t) { |
| 298 | SkASSERT(transforms[t].fHandle.isValid()); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 299 | const SkMatrix& transform = get_transform_matrix(proc, t); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 300 | if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
| 301 | continue; |
| 302 | } |
| 303 | transforms[t].fCurrentValue = transform; |
| 304 | const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()]; |
| 305 | SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType); |
| 306 | unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; |
| 307 | fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, |
| 308 | fragmentInput.fLocation, |
| 309 | GR_GL_OBJECT_LINEAR, |
| 310 | components, |
| 311 | transform); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | ////////////////////////////////////////////////////////////////////////////////////// |
| 316 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 317 | GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGLGpu* gpu, |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 318 | const GrProgramDesc& desc, |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 319 | const BuiltinUniformHandles& builtinUniforms, |
| 320 | GrGLuint programID, |
| 321 | const UniformInfoArray& uniforms, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 322 | GrGLInstalledGeoProc* primProc, |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 323 | GrGLInstalledXferProc* xp, |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 324 | GrGLInstalledFragProcs* fps, |
| 325 | int texCoordSetCnt) |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 326 | : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, xp, fps) |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 327 | , fTexCoordSetCnt(texCoordSetCnt) { |
| 328 | } |
| 329 | |
| 330 | void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 331 | SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 332 | fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| 333 | } |
| 334 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 335 | void |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 336 | GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, |
| 337 | GrGLInstalledFragProc* ip) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 338 | // We've hidden the texcoord index in the first entry of the transforms array for each effect |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 339 | int texCoordIndex = ip->fTransforms[0].fHandle.handle(); |
| 340 | int numTransforms = proc.getProcessor()->numTransforms(); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 341 | for (int t = 0; t < numTransforms; ++t) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 342 | const SkMatrix& transform = get_transform_matrix(proc, t); |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 343 | GrGLPathRendering::PathTexGenComponents components = |
| 344 | GrGLPathRendering::kST_PathTexGenComponents; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 345 | if (proc.isPerspectiveCoordTransform(t)) { |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 346 | components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| 347 | } |
| 348 | fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform); |
| 349 | } |
| 350 | } |