blob: 3249793d6241baf5d76ab5dfd227d4cbbcf12410 [file] [log] [blame]
junov@google.comf93e7172011-03-31 21:26:24 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comf93e7172011-03-31 21:26:24 +00006 */
joshualitt23e280d2014-09-18 12:26:38 -07007
junov@google.comf93e7172011-03-31 21:26:24 +00008#include "GrGLProgram.h"
9
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000010#include "GrAllocator.h"
joshualittb0a8a372014-09-23 09:50:21 -070011#include "GrProcessor.h"
bsalomon@google.com77af6802013-10-02 13:04:56 +000012#include "GrCoordTransform.h"
joshualitta5305a12014-10-10 17:47:00 -070013#include "GrGLGeometryProcessor.h"
joshualittb0a8a372014-09-23 09:50:21 -070014#include "GrGLProcessor.h"
bsalomon@google.com34cccde2013-01-04 18:34:30 +000015#include "GrGpuGL.h"
kkinnunenec56e452014-08-25 22:21:16 -070016#include "GrGLPathRendering.h"
bsalomon@google.com4fa66942011-09-20 19:06:12 +000017#include "GrGLShaderVar.h"
bsalomon@google.com018f1792013-04-18 19:36:09 +000018#include "GrGLSL.h"
egdaniel170f90b2014-09-16 12:54:40 -070019#include "GrOptDrawState.h"
Scroggo97c88c22011-05-11 14:05:25 +000020#include "SkXfermode.h"
21
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000022#define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X)
23#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000024
joshualitt47bb3822014-10-07 16:43:25 -070025/**
26 * Retrieves the final matrix that a transform needs to apply to its source coords.
27 */
bsalomonae59b772014-11-19 08:23:49 -080028static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage,
joshualitt47bb3822014-10-07 16:43:25 -070029 bool useExplicitLocalCoords,
30 int transformIdx) {
bsalomonae59b772014-11-19 08:23:49 -080031 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransform(transformIdx);
joshualitt47bb3822014-10-07 16:43:25 -070032 SkMatrix combined;
33
34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
35 // If we have explicit local coords then we shouldn't need a coord change.
36 const SkMatrix& ccm =
bsalomonae59b772014-11-19 08:23:49 -080037 useExplicitLocalCoords ? SkMatrix::I() : stage.getCoordChangeMatrix();
joshualitt47bb3822014-10-07 16:43:25 -070038 combined.setConcat(coordTransform.getMatrix(), ccm);
kkinnunenec56e452014-08-25 22:21:16 -070039 } else {
joshualitt47bb3822014-10-07 16:43:25 -070040 combined = coordTransform.getMatrix();
kkinnunendddc18a2014-08-03 23:19:46 -070041 }
joshualitt47bb3822014-10-07 16:43:25 -070042 if (coordTransform.reverseY()) {
43 // combined.postScale(1,-1);
44 // combined.postTranslate(0,1);
45 combined.set(SkMatrix::kMSkewY,
46 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
47 combined.set(SkMatrix::kMScaleY,
48 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
49 combined.set(SkMatrix::kMTransY,
50 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000051 }
joshualitt47bb3822014-10-07 16:43:25 -070052 return combined;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000053}
54
joshualitt47bb3822014-10-07 16:43:25 -070055///////////////////////////////////////////////////////////////////////////////////////////////////
56
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000057GrGLProgram::GrGLProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -070058 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -070059 const BuiltinUniformHandles& builtinUniforms,
60 GrGLuint programID,
61 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -070062 GrGLInstalledGeoProc* geometryProcessor,
63 GrGLInstalledFragProcs* fragmentProcessors)
commit-bot@chromium.orga05fa062014-05-30 18:55:03 +000064 : fColor(GrColor_ILLEGAL)
egdaniel37b4d862014-11-03 10:07:07 -080065 , fCoverage(0)
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000066 , fDstCopyTexUnit(-1)
joshualitt47bb3822014-10-07 16:43:25 -070067 , fBuiltinUniformHandles(builtinUniforms)
68 , fProgramID(programID)
joshualitta5305a12014-10-10 17:47:00 -070069 , fGeometryProcessor(geometryProcessor)
70 , fFragmentProcessors(SkRef(fragmentProcessors))
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000071 , fDesc(desc)
72 , fGpu(gpu)
joshualitt47bb3822014-10-07 16:43:25 -070073 , fProgramDataManager(gpu, uniforms) {
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000074 this->initSamplerUniforms();
junov@google.comf93e7172011-03-31 21:26:24 +000075}
76
77GrGLProgram::~GrGLProgram() {
kkinnunendddc18a2014-08-03 23:19:46 -070078 if (fProgramID) {
79 GL_CALL(DeleteProgram(fProgramID));
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000080 }
junov@google.comf93e7172011-03-31 21:26:24 +000081}
82
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000083void GrGLProgram::abandon() {
kkinnunendddc18a2014-08-03 23:19:46 -070084 fProgramID = 0;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000085}
86
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000087void GrGLProgram::initSamplerUniforms() {
kkinnunendddc18a2014-08-03 23:19:46 -070088 GL_CALL(UseProgram(fProgramID));
bsalomon@google.com34cccde2013-01-04 18:34:30 +000089 GrGLint texUnitIdx = 0;
kkinnunendddc18a2014-08-03 23:19:46 -070090 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) {
91 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni, texUnitIdx);
bsalomon@google.com804e9942013-06-06 18:04:38 +000092 fDstCopyTexUnit = texUnitIdx++;
bsalomon@google.com26e18b52013-03-29 19:22:36 +000093 }
bsalomon49f085d2014-09-05 13:34:00 -070094 if (fGeometryProcessor.get()) {
joshualitt47bb3822014-10-07 16:43:25 -070095 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx);
joshualittbd769d02014-09-04 08:56:46 -070096 }
joshualitta5305a12014-10-10 17:47:00 -070097 int numProcs = fFragmentProcessors->fProcs.count();
98 for (int i = 0; i < numProcs; i++) {
99 this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx);
joshualitt47bb3822014-10-07 16:43:25 -0700100 }
101}
102
joshualitta5305a12014-10-10 17:47:00 -0700103void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) {
104 SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
105 int numSamplers = samplers.count();
106 for (int s = 0; s < numSamplers; ++s) {
107 SkASSERT(samplers[s].fUniform.isValid());
108 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx);
109 samplers[s].fTextureUnit = (*texUnitIdx)++;
110 }
111}
112
113void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& processor) {
114 const SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
joshualitt47bb3822014-10-07 16:43:25 -0700115 int numSamplers = samplers.count();
116 SkASSERT(numSamplers == processor.numTextures());
117 for (int s = 0; s < numSamplers; ++s) {
118 SkASSERT(samplers[s].fTextureUnit >= 0);
119 const GrTextureAccess& textureAccess = processor.textureAccess(s);
120 fGpu->bindTexture(samplers[s].fTextureUnit,
121 textureAccess.getParams(),
122 static_cast<GrGLTexture*>(textureAccess.getTexture()));
123 }
124}
125
126
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000127///////////////////////////////////////////////////////////////////////////////
junov@google.comf93e7172011-03-31 21:26:24 +0000128
joshualitt9176e2c2014-11-20 07:28:52 -0800129void GrGLProgram::setData(const GrOptDrawState& optState, GrGpu::DrawType drawType) {
egdaniel170f90b2014-09-16 12:54:40 -0700130 GrColor color = optState.getColor();
egdaniel37b4d862014-11-03 10:07:07 -0800131 uint8_t coverage = optState.getCoverage();
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000132
joshualitt0e602822014-10-28 10:27:44 -0700133 this->setColor(optState, color);
134 this->setCoverage(optState, coverage);
egdaniel170f90b2014-09-16 12:54:40 -0700135 this->setMatrixAndRenderTargetHeight(drawType, optState);
bsalomon@google.com91207482013-02-12 21:45:24 +0000136
joshualitt9176e2c2014-11-20 07:28:52 -0800137 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy();
bsalomon49f085d2014-09-05 13:34:00 -0700138 if (dstCopy) {
kkinnunendddc18a2014-08-03 23:19:46 -0700139 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
140 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
kkinnunen7510b222014-07-30 00:04:16 -0700141 static_cast<GrGLfloat>(dstCopy->offset().fX),
142 static_cast<GrGLfloat>(dstCopy->offset().fY));
kkinnunendddc18a2014-08-03 23:19:46 -0700143 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
kkinnunen7510b222014-07-30 00:04:16 -0700144 1.f / dstCopy->texture()->width(),
145 1.f / dstCopy->texture()->height());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000146 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture());
147 static GrTextureParams kParams; // the default is clamp, nearest filtering.
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000148 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000149 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700150 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
151 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000152 }
153 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700154 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid());
155 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
156 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000157 }
bsalomon@google.comc7818882013-03-20 19:19:53 +0000158
joshualitt47bb3822014-10-07 16:43:25 -0700159 // we set the textures, and uniforms for installed processors in a generic way, but subclasses
160 // of GLProgram determine how to set coord transforms
bsalomon49f085d2014-09-05 13:34:00 -0700161 if (fGeometryProcessor.get()) {
joshualitta5305a12014-10-10 17:47:00 -0700162 SkASSERT(optState.hasGeometryProcessor());
163 const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
164 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp);
165 this->bindTextures(fGeometryProcessor, gp);
joshualittbd769d02014-09-04 08:56:46 -0700166 }
joshualitta5305a12014-10-10 17:47:00 -0700167 this->setFragmentData(optState);
commit-bot@chromium.org20807222013-11-01 11:54:54 +0000168
joshualitt47bb3822014-10-07 16:43:25 -0700169 // Some of GrGLProgram subclasses need to update state here
170 this->didSetData(drawType);
171}
172
joshualitta5305a12014-10-10 17:47:00 -0700173void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
174 int numProcessors = fFragmentProcessors->fProcs.count();
175 for (int e = 0; e < numProcessors; ++e) {
bsalomonae59b772014-11-19 08:23:49 -0800176 const GrPendingFragmentStage& stage = optState.getFragmentStage(e);
joshualitta5305a12014-10-10 17:47:00 -0700177 const GrProcessor& processor = *stage.getProcessor();
178 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
179 this->setTransformData(stage, fFragmentProcessors->fProcs[e]);
180 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
181 }
182}
bsalomonae59b772014-11-19 08:23:49 -0800183void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor,
184 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700185 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700186 int numTransforms = transforms.count();
187 SkASSERT(numTransforms == processor.getProcessor()->numTransforms());
188 for (int t = 0; t < numTransforms; ++t) {
189 SkASSERT(transforms[t].fHandle.isValid());
joshualitta5305a12014-10-10 17:47:00 -0700190 const SkMatrix& matrix = get_transform_matrix(processor, ip->fLocalCoordAttrib, t);
joshualitt47bb3822014-10-07 16:43:25 -0700191 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
192 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix);
193 transforms[t].fCurrentValue = matrix;
194 }
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000195 }
skia.committer@gmail.com8ae714b2013-01-05 02:02:05 +0000196}
bsalomon@google.com91207482013-02-12 21:45:24 +0000197
joshualitt47bb3822014-10-07 16:43:25 -0700198void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
199 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
200}
201
joshualitt0e602822014-10-28 10:27:44 -0700202void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) {
joshualitt79f8fae2014-10-28 17:59:26 -0700203 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700204 switch (header.fColorInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700205 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700206 // Attribute case is handled in GrGpuGL::setupGeometry
207 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700208 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700209 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) {
210 // OpenGL ES doesn't support unsigned byte varieties of glUniform
211 GrGLfloat c[4];
212 GrColorToRGBAFloat(color, c);
213 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c);
214 fColor = color;
215 }
216 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700217 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700218 // Handled by shader creation
219 break;
220 default:
221 SkFAIL("Unexpected color type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000222 }
223}
224
egdaniel37b4d862014-11-03 10:07:07 -0800225void GrGLProgram::setCoverage(const GrOptDrawState& optState, uint8_t coverage) {
joshualitt79f8fae2014-10-28 17:59:26 -0700226 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700227 switch (header.fCoverageInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700228 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700229 // Attribute case is handled in GrGpuGL::setupGeometry
230 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700231 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700232 if (fCoverage != coverage) {
233 // OpenGL ES doesn't support unsigned byte varieties of glUniform
egdaniele27065a2014-11-06 08:00:48 -0800234 GrGLfloat c = GrNormalizeByteToFloat(coverage);
egdaniel37b4d862014-11-03 10:07:07 -0800235 fProgramDataManager.set1f(fBuiltinUniformHandles.fCoverageUni, c);
joshualitt0e602822014-10-28 10:27:44 -0700236 fCoverage = coverage;
237 }
238 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700239 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700240 // Handled by shader creation
241 break;
242 default:
243 SkFAIL("Unexpected coverage type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000244 }
245}
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000246
kkinnunenec56e452014-08-25 22:21:16 -0700247void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
egdaniel170f90b2014-09-16 12:54:40 -0700248 const GrOptDrawState& optState) {
joshualitt47bb3822014-10-07 16:43:25 -0700249 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
250 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
251 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
252 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
253 SkIntToScalar(optState.getRenderTarget()->height()));
254 }
255
256 // call subclasses to set the actual view matrix
257 this->onSetMatrixAndRenderTargetHeight(drawType, optState);
258}
259
260void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
261 const GrOptDrawState& optState) {
egdaniel170f90b2014-09-16 12:54:40 -0700262 const GrRenderTarget* rt = optState.getRenderTarget();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000263 SkISize size;
264 size.set(rt->width(), rt->height());
joshualitt47bb3822014-10-07 16:43:25 -0700265 if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
266 fMatrixState.fRenderTargetSize != size ||
267 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
kkinnunendddc18a2014-08-03 23:19:46 -0700268 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000269
egdaniel170f90b2014-09-16 12:54:40 -0700270 fMatrixState.fViewMatrix = optState.getViewMatrix();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000271 fMatrixState.fRenderTargetSize = size;
272 fMatrixState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org215a6822013-09-05 18:28:42 +0000273
274 GrGLfloat viewMatrix[3 * 3];
275 fMatrixState.getGLMatrix<3>(viewMatrix);
kkinnunendddc18a2014-08-03 23:19:46 -0700276 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000277
278 GrGLfloat rtAdjustmentVec[4];
279 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700280 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000281 }
282}
joshualitt47bb3822014-10-07 16:43:25 -0700283
284/////////////////////////////////////////////////////////////////////////////////////////
285
286GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700287 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700288 const BuiltinUniformHandles& builtinUniforms,
289 GrGLuint programID,
290 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700291 GrGLInstalledFragProcs* fragmentProcessors)
292 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700293}
294
295void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
296 const GrOptDrawState& optState) {
297 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
298 const GrRenderTarget* rt = optState.getRenderTarget();
299 SkISize size;
300 size.set(rt->width(), rt->height());
301 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
302}
303
304/////////////////////////////////////////////////////////////////////////////////////////
305
306GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700307 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700308 const BuiltinUniformHandles& builtinUniforms,
309 GrGLuint programID,
310 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700311 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700312 const SeparableVaryingInfoArray& separableVaryings)
joshualitta5305a12014-10-10 17:47:00 -0700313 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700314 int count = separableVaryings.count();
315 fVaryings.push_back_n(count);
316 for (int i = 0; i < count; i++) {
317 Varying& varying = fVaryings[i];
318 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
319 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
320 SkDEBUGCODE(
321 varying.fType = builderVarying.fVariable.getType();
322 );
323 varying.fLocation = builderVarying.fLocation;
324 }
325}
326
327void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
328 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
329}
330
bsalomonae59b772014-11-19 08:23:49 -0800331void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
332 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700333 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700334 int numTransforms = transforms.count();
joshualitta5305a12014-10-10 17:47:00 -0700335 SkASSERT(numTransforms == proc.getProcessor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700336 for (int t = 0; t < numTransforms; ++t) {
337 SkASSERT(transforms[t].fHandle.isValid());
joshualitta5305a12014-10-10 17:47:00 -0700338 const SkMatrix& transform = get_transform_matrix(proc, false, t);
joshualitt47bb3822014-10-07 16:43:25 -0700339 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
340 continue;
341 }
342 transforms[t].fCurrentValue = transform;
343 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
344 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
345 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
346 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
347 fragmentInput.fLocation,
348 GR_GL_OBJECT_LINEAR,
349 components,
350 transform);
351 }
352}
353
354//////////////////////////////////////////////////////////////////////////////////////
355
356GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700357 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700358 const BuiltinUniformHandles& builtinUniforms,
359 GrGLuint programID,
360 const UniformInfoArray& uniforms,
361 GrGLInstalledFragProcs* fps,
362 int texCoordSetCnt)
363 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700364 , fTexCoordSetCnt(texCoordSetCnt) {
365}
366
367void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
368 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
369 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
370}
371
joshualitta5305a12014-10-10 17:47:00 -0700372void
bsalomonae59b772014-11-19 08:23:49 -0800373GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
374 GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700375 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700376 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
377 int numTransforms = proc.getProcessor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700378 for (int t = 0; t < numTransforms; ++t) {
joshualitta5305a12014-10-10 17:47:00 -0700379 const SkMatrix& transform = get_transform_matrix(proc, false, t);
joshualitt47bb3822014-10-07 16:43:25 -0700380 GrGLPathRendering::PathTexGenComponents components =
381 GrGLPathRendering::kST_PathTexGenComponents;
bsalomonae59b772014-11-19 08:23:49 -0800382 if (proc.isPerspectiveCoordTransform(t)) {
joshualitt47bb3822014-10-07 16:43:25 -0700383 components = GrGLPathRendering::kSTR_PathTexGenComponents;
384 }
385 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
386 }
387}