blob: 0e67e81e863af88d73555ec5d1ec977713b7607e [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
egdaniel170f90b2014-09-16 12:54:40 -0700129void GrGLProgram::setData(const GrOptDrawState& optState,
130 GrGpu::DrawType drawType,
joshualitt0e602822014-10-28 10:27:44 -0700131 const GrDeviceCoordTexture* dstCopy) {
egdaniel170f90b2014-09-16 12:54:40 -0700132 GrColor color = optState.getColor();
egdaniel37b4d862014-11-03 10:07:07 -0800133 uint8_t coverage = optState.getCoverage();
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000134
joshualitt0e602822014-10-28 10:27:44 -0700135 this->setColor(optState, color);
136 this->setCoverage(optState, coverage);
egdaniel170f90b2014-09-16 12:54:40 -0700137 this->setMatrixAndRenderTargetHeight(drawType, optState);
bsalomon@google.com91207482013-02-12 21:45:24 +0000138
bsalomon49f085d2014-09-05 13:34:00 -0700139 if (dstCopy) {
kkinnunendddc18a2014-08-03 23:19:46 -0700140 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
141 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
kkinnunen7510b222014-07-30 00:04:16 -0700142 static_cast<GrGLfloat>(dstCopy->offset().fX),
143 static_cast<GrGLfloat>(dstCopy->offset().fY));
kkinnunendddc18a2014-08-03 23:19:46 -0700144 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
kkinnunen7510b222014-07-30 00:04:16 -0700145 1.f / dstCopy->texture()->width(),
146 1.f / dstCopy->texture()->height());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000147 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture());
148 static GrTextureParams kParams; // the default is clamp, nearest filtering.
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000149 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000150 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700151 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
152 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000153 }
154 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700155 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid());
156 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
157 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000158 }
bsalomon@google.comc7818882013-03-20 19:19:53 +0000159
joshualitt47bb3822014-10-07 16:43:25 -0700160 // we set the textures, and uniforms for installed processors in a generic way, but subclasses
161 // of GLProgram determine how to set coord transforms
bsalomon49f085d2014-09-05 13:34:00 -0700162 if (fGeometryProcessor.get()) {
joshualitta5305a12014-10-10 17:47:00 -0700163 SkASSERT(optState.hasGeometryProcessor());
164 const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
165 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp);
166 this->bindTextures(fGeometryProcessor, gp);
joshualittbd769d02014-09-04 08:56:46 -0700167 }
joshualitta5305a12014-10-10 17:47:00 -0700168 this->setFragmentData(optState);
commit-bot@chromium.org20807222013-11-01 11:54:54 +0000169
joshualitt47bb3822014-10-07 16:43:25 -0700170 // Some of GrGLProgram subclasses need to update state here
171 this->didSetData(drawType);
172}
173
joshualitta5305a12014-10-10 17:47:00 -0700174void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
175 int numProcessors = fFragmentProcessors->fProcs.count();
176 for (int e = 0; e < numProcessors; ++e) {
bsalomonae59b772014-11-19 08:23:49 -0800177 const GrPendingFragmentStage& stage = optState.getFragmentStage(e);
joshualitta5305a12014-10-10 17:47:00 -0700178 const GrProcessor& processor = *stage.getProcessor();
179 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
180 this->setTransformData(stage, fFragmentProcessors->fProcs[e]);
181 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
182 }
183}
bsalomonae59b772014-11-19 08:23:49 -0800184void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor,
185 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700186 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700187 int numTransforms = transforms.count();
188 SkASSERT(numTransforms == processor.getProcessor()->numTransforms());
189 for (int t = 0; t < numTransforms; ++t) {
190 SkASSERT(transforms[t].fHandle.isValid());
joshualitta5305a12014-10-10 17:47:00 -0700191 const SkMatrix& matrix = get_transform_matrix(processor, ip->fLocalCoordAttrib, t);
joshualitt47bb3822014-10-07 16:43:25 -0700192 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix);
194 transforms[t].fCurrentValue = matrix;
195 }
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000196 }
skia.committer@gmail.com8ae714b2013-01-05 02:02:05 +0000197}
bsalomon@google.com91207482013-02-12 21:45:24 +0000198
joshualitt47bb3822014-10-07 16:43:25 -0700199void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
200 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
201}
202
joshualitt0e602822014-10-28 10:27:44 -0700203void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) {
joshualitt79f8fae2014-10-28 17:59:26 -0700204 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700205 switch (header.fColorInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700206 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700207 // Attribute case is handled in GrGpuGL::setupGeometry
208 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700209 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700210 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) {
211 // OpenGL ES doesn't support unsigned byte varieties of glUniform
212 GrGLfloat c[4];
213 GrColorToRGBAFloat(color, c);
214 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c);
215 fColor = color;
216 }
217 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700218 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700219 // Handled by shader creation
220 break;
221 default:
222 SkFAIL("Unexpected color type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000223 }
224}
225
egdaniel37b4d862014-11-03 10:07:07 -0800226void GrGLProgram::setCoverage(const GrOptDrawState& optState, uint8_t coverage) {
joshualitt79f8fae2014-10-28 17:59:26 -0700227 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700228 switch (header.fCoverageInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700229 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700230 // Attribute case is handled in GrGpuGL::setupGeometry
231 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700232 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700233 if (fCoverage != coverage) {
234 // OpenGL ES doesn't support unsigned byte varieties of glUniform
egdaniele27065a2014-11-06 08:00:48 -0800235 GrGLfloat c = GrNormalizeByteToFloat(coverage);
egdaniel37b4d862014-11-03 10:07:07 -0800236 fProgramDataManager.set1f(fBuiltinUniformHandles.fCoverageUni, c);
joshualitt0e602822014-10-28 10:27:44 -0700237 fCoverage = coverage;
238 }
239 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700240 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700241 // Handled by shader creation
242 break;
243 default:
244 SkFAIL("Unexpected coverage type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000245 }
246}
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000247
kkinnunenec56e452014-08-25 22:21:16 -0700248void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
egdaniel170f90b2014-09-16 12:54:40 -0700249 const GrOptDrawState& optState) {
joshualitt47bb3822014-10-07 16:43:25 -0700250 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
251 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
252 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
253 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
254 SkIntToScalar(optState.getRenderTarget()->height()));
255 }
256
257 // call subclasses to set the actual view matrix
258 this->onSetMatrixAndRenderTargetHeight(drawType, optState);
259}
260
261void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
262 const GrOptDrawState& optState) {
egdaniel170f90b2014-09-16 12:54:40 -0700263 const GrRenderTarget* rt = optState.getRenderTarget();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000264 SkISize size;
265 size.set(rt->width(), rt->height());
joshualitt47bb3822014-10-07 16:43:25 -0700266 if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
267 fMatrixState.fRenderTargetSize != size ||
268 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
kkinnunendddc18a2014-08-03 23:19:46 -0700269 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000270
egdaniel170f90b2014-09-16 12:54:40 -0700271 fMatrixState.fViewMatrix = optState.getViewMatrix();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000272 fMatrixState.fRenderTargetSize = size;
273 fMatrixState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org215a6822013-09-05 18:28:42 +0000274
275 GrGLfloat viewMatrix[3 * 3];
276 fMatrixState.getGLMatrix<3>(viewMatrix);
kkinnunendddc18a2014-08-03 23:19:46 -0700277 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000278
279 GrGLfloat rtAdjustmentVec[4];
280 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700281 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000282 }
283}
joshualitt47bb3822014-10-07 16:43:25 -0700284
285/////////////////////////////////////////////////////////////////////////////////////////
286
287GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700288 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700289 const BuiltinUniformHandles& builtinUniforms,
290 GrGLuint programID,
291 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700292 GrGLInstalledFragProcs* fragmentProcessors)
293 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700294}
295
296void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
297 const GrOptDrawState& optState) {
298 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
299 const GrRenderTarget* rt = optState.getRenderTarget();
300 SkISize size;
301 size.set(rt->width(), rt->height());
302 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
303}
304
305/////////////////////////////////////////////////////////////////////////////////////////
306
307GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700308 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700309 const BuiltinUniformHandles& builtinUniforms,
310 GrGLuint programID,
311 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700312 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700313 const SeparableVaryingInfoArray& separableVaryings)
joshualitta5305a12014-10-10 17:47:00 -0700314 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700315 int count = separableVaryings.count();
316 fVaryings.push_back_n(count);
317 for (int i = 0; i < count; i++) {
318 Varying& varying = fVaryings[i];
319 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
320 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
321 SkDEBUGCODE(
322 varying.fType = builderVarying.fVariable.getType();
323 );
324 varying.fLocation = builderVarying.fLocation;
325 }
326}
327
328void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
329 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
330}
331
bsalomonae59b772014-11-19 08:23:49 -0800332void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
333 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700334 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700335 int numTransforms = transforms.count();
joshualitta5305a12014-10-10 17:47:00 -0700336 SkASSERT(numTransforms == proc.getProcessor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700337 for (int t = 0; t < numTransforms; ++t) {
338 SkASSERT(transforms[t].fHandle.isValid());
joshualitta5305a12014-10-10 17:47:00 -0700339 const SkMatrix& transform = get_transform_matrix(proc, false, t);
joshualitt47bb3822014-10-07 16:43:25 -0700340 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
341 continue;
342 }
343 transforms[t].fCurrentValue = transform;
344 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
345 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
346 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
347 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
348 fragmentInput.fLocation,
349 GR_GL_OBJECT_LINEAR,
350 components,
351 transform);
352 }
353}
354
355//////////////////////////////////////////////////////////////////////////////////////
356
357GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700358 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700359 const BuiltinUniformHandles& builtinUniforms,
360 GrGLuint programID,
361 const UniformInfoArray& uniforms,
362 GrGLInstalledFragProcs* fps,
363 int texCoordSetCnt)
364 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700365 , fTexCoordSetCnt(texCoordSetCnt) {
366}
367
368void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
369 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
370 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
371}
372
joshualitta5305a12014-10-10 17:47:00 -0700373void
bsalomonae59b772014-11-19 08:23:49 -0800374GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
375 GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700376 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700377 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
378 int numTransforms = proc.getProcessor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700379 for (int t = 0; t < numTransforms; ++t) {
joshualitta5305a12014-10-10 17:47:00 -0700380 const SkMatrix& transform = get_transform_matrix(proc, false, t);
joshualitt47bb3822014-10-07 16:43:25 -0700381 GrGLPathRendering::PathTexGenComponents components =
382 GrGLPathRendering::kST_PathTexGenComponents;
bsalomonae59b772014-11-19 08:23:49 -0800383 if (proc.isPerspectiveCoordTransform(t)) {
joshualitt47bb3822014-10-07 16:43:25 -0700384 components = GrGLPathRendering::kSTR_PathTexGenComponents;
385 }
386 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
387 }
388}