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