OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
9 | 9 |
10 #include "builders/GrGLFullProgramBuilder.h" | |
11 #include "builders/GrGLFragmentOnlyProgramBuilder.h" | |
12 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
13 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
14 #include "GrCoordTransform.h" | 12 #include "GrCoordTransform.h" |
15 #include "GrGLProcessor.h" | 13 #include "GrGLProcessor.h" |
16 #include "GrGpuGL.h" | 14 #include "GrGpuGL.h" |
17 #include "GrGLPathRendering.h" | 15 #include "GrGLPathRendering.h" |
18 #include "GrGLShaderVar.h" | 16 #include "GrGLShaderVar.h" |
19 #include "GrGLSL.h" | 17 #include "GrGLSL.h" |
20 #include "GrOptDrawState.h" | 18 #include "GrOptDrawState.h" |
21 #include "SkXfermode.h" | 19 #include "SkXfermode.h" |
22 | 20 |
23 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
24 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
25 | 23 |
26 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, | 24 /** |
27 const GrGLProgramDesc& desc, | 25 * Retrieves the final matrix that a transform needs to apply to its source coor ds. |
28 const GrGeometryStage* geometryProcessor, | 26 */ |
29 const GrFragmentStage* colorStages[], | 27 static SkMatrix get_transform_matrix(const GrProcessorStage& processorStage, |
30 const GrFragmentStage* coverageStages[]) { | 28 bool useExplicitLocalCoords, |
31 SkAutoTDelete<GrGLProgramBuilder> builder; | 29 int transformIdx) { |
32 if (desc.getHeader().fUseFragShaderOnly) { | 30 const GrCoordTransform& coordTransform = |
33 SkASSERT(gpu->glCaps().pathRenderingSupport()); | 31 processorStage.getProcessor()->coordTransform(transformIdx); |
34 SkASSERT(gpu->glPathRendering()->texturingMode() == | 32 SkMatrix combined; |
35 GrGLPathRendering::FixedFunction_TexturingMode); | 33 |
36 SkASSERT(NULL == geometryProcessor); | 34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
37 builder.reset(SkNEW_ARGS(GrGLFragmentOnlyProgramBuilder, (gpu, desc))); | 35 // If we have explicit local coords then we shouldn't need a coord chang e. |
36 const SkMatrix& ccm = | |
37 useExplicitLocalCoords ? SkMatrix::I() : processorStage.getCoord ChangeMatrix(); | |
38 combined.setConcat(coordTransform.getMatrix(), ccm); | |
38 } else { | 39 } else { |
39 builder.reset(SkNEW_ARGS(GrGLFullProgramBuilder, (gpu, desc))); | 40 combined = coordTransform.getMatrix(); |
40 } | 41 } |
41 if (builder->genProgram(geometryProcessor, colorStages, coverageStages)) { | 42 if (coordTransform.reverseY()) { |
42 SkASSERT(0 != builder->getProgramID()); | 43 // combined.postScale(1,-1); |
43 return SkNEW_ARGS(GrGLProgram, (gpu, desc, *builder)); | 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]); | |
44 } | 51 } |
45 return NULL; | 52 return combined; |
46 } | 53 } |
47 | 54 |
55 //////////////////////////////////////////////////////////////////////////////// /////////////////// | |
56 | |
48 GrGLProgram::GrGLProgram(GrGpuGL* gpu, | 57 GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
49 const GrGLProgramDesc& desc, | 58 const GrGLProgramDesc& desc, |
50 const GrGLProgramBuilder& builder) | 59 const BuiltinUniformHandles& builtinUniforms, |
60 GrGLuint programID, | |
61 const UniformInfoArray& uniforms, | |
62 GrGLInstalledProcessors* geometryProcessor, | |
63 GrGLInstalledProcessors* colorProcessors, | |
64 GrGLInstalledProcessors* coverageProcessors) | |
51 : fColor(GrColor_ILLEGAL) | 65 : fColor(GrColor_ILLEGAL) |
52 , fCoverage(GrColor_ILLEGAL) | 66 , fCoverage(GrColor_ILLEGAL) |
53 , fDstCopyTexUnit(-1) | 67 , fDstCopyTexUnit(-1) |
54 , fBuiltinUniformHandles(builder.getBuiltinUniformHandles()) | 68 , fBuiltinUniformHandles(builtinUniforms) |
55 , fGeometryProcessor(SkSafeRef(builder.getGeometryProcessor())) | 69 , fProgramID(programID) |
56 , fColorEffects(SkRef(builder.getColorEffects())) | 70 , fGeometryProcessor(SkSafeRef(geometryProcessor)) |
57 , fCoverageEffects(SkRef(builder.getCoverageEffects())) | 71 , fColorEffects(SkRef(colorProcessors)) |
58 , fProgramID(builder.getProgramID()) | 72 , fCoverageEffects(SkRef(coverageProcessors)) |
59 , fHasVertexShader(builder.hasVertexShader()) | |
60 , fTexCoordSetCnt(builder.getTexCoordSetCount()) | |
61 , fDesc(desc) | 73 , fDesc(desc) |
62 , fGpu(gpu) | 74 , fGpu(gpu) |
63 , fProgramDataManager(gpu, this, builder) { | 75 , fProgramDataManager(gpu, uniforms) { |
64 this->initSamplerUniforms(); | 76 this->initSamplerUniforms(); |
65 } | 77 } |
66 | 78 |
67 GrGLProgram::~GrGLProgram() { | 79 GrGLProgram::~GrGLProgram() { |
68 if (fProgramID) { | 80 if (fProgramID) { |
69 GL_CALL(DeleteProgram(fProgramID)); | 81 GL_CALL(DeleteProgram(fProgramID)); |
70 } | 82 } |
71 } | 83 } |
72 | 84 |
73 void GrGLProgram::abandon() { | 85 void GrGLProgram::abandon() { |
74 fProgramID = 0; | 86 fProgramID = 0; |
75 } | 87 } |
76 | 88 |
77 void GrGLProgram::initSamplerUniforms() { | 89 void GrGLProgram::initSamplerUniforms() { |
78 GL_CALL(UseProgram(fProgramID)); | 90 GL_CALL(UseProgram(fProgramID)); |
79 GrGLint texUnitIdx = 0; | 91 GrGLint texUnitIdx = 0; |
80 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { | 92 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { |
81 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni , texUnitIdx); | 93 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni , texUnitIdx); |
82 fDstCopyTexUnit = texUnitIdx++; | 94 fDstCopyTexUnit = texUnitIdx++; |
83 } | 95 } |
84 if (fGeometryProcessor.get()) { | 96 if (fGeometryProcessor.get()) { |
85 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx); | 97 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx); |
86 } | 98 } |
87 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); | 99 this->initSamplers(fColorEffects.get(), &texUnitIdx); |
88 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); | 100 this->initSamplers(fCoverageEffects.get(), &texUnitIdx); |
89 } | 101 } |
90 | 102 |
103 void GrGLProgram::initSamplers(GrGLInstalledProcessors* ip, int* texUnitIdx) { | |
104 int numEffects = ip->fGLProcessors.count(); | |
105 SkASSERT(numEffects == ip->fSamplers.count()); | |
106 for (int e = 0; e < numEffects; ++e) { | |
107 SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSample rs[e]; | |
108 int numSamplers = samplers.count(); | |
109 for (int s = 0; s < numSamplers; ++s) { | |
110 SkASSERT(samplers[s].fUniform.isValid()); | |
111 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx); | |
112 samplers[s].fTextureUnit = (*texUnitIdx)++; | |
113 } | |
114 } | |
115 } | |
116 | |
117 void GrGLProgram::bindTextures(const GrGLInstalledProcessors* ip, | |
118 const GrProcessor& processor, | |
119 int effectIdx) { | |
120 const SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSamp lers[effectIdx]; | |
121 int numSamplers = samplers.count(); | |
122 SkASSERT(numSamplers == processor.numTextures()); | |
123 for (int s = 0; s < numSamplers; ++s) { | |
124 SkASSERT(samplers[s].fTextureUnit >= 0); | |
125 const GrTextureAccess& textureAccess = processor.textureAccess(s); | |
126 fGpu->bindTexture(samplers[s].fTextureUnit, | |
127 textureAccess.getParams(), | |
128 static_cast<GrGLTexture*>(textureAccess.getTexture())) ; | |
129 } | |
130 } | |
131 | |
132 | |
91 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
92 | 134 |
93 void GrGLProgram::setData(const GrOptDrawState& optState, | 135 void GrGLProgram::setData(const GrOptDrawState& optState, |
94 GrGpu::DrawType drawType, | 136 GrGpu::DrawType drawType, |
95 const GrGeometryStage* geometryProcessor, | 137 const GrGeometryStage* geometryProcessor, |
96 const GrFragmentStage* colorStages[], | 138 const GrFragmentStage* colorStages[], |
97 const GrFragmentStage* coverageStages[], | 139 const GrFragmentStage* coverageStages[], |
98 const GrDeviceCoordTexture* dstCopy, | 140 const GrDeviceCoordTexture* dstCopy, |
99 SharedGLState* sharedState) { | 141 SharedGLState* sharedState) { |
100 GrColor color = optState.getColor(); | 142 GrColor color = optState.getColor(); |
(...skipping 17 matching lines...) Expand all Loading... | |
118 } else { | 160 } else { |
119 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 161 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
120 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 162 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
121 } | 163 } |
122 } else { | 164 } else { |
123 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); | 165 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); |
124 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); | 166 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); |
125 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); | 167 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); |
126 } | 168 } |
127 | 169 |
170 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses | |
171 // of GLPrograms determine how to set coord transforms | |
bsalomon
2014/10/06 18:49:40
GLProgram? no s?
| |
128 if (fGeometryProcessor.get()) { | 172 if (fGeometryProcessor.get()) { |
129 SkASSERT(geometryProcessor); | 173 SkASSERT(geometryProcessor); |
130 fGeometryProcessor->setData(fGpu, drawType, fProgramDataManager, geometr yProcessor); | 174 this->setData<GrGeometryStage>(&geometryProcessor, fGeometryProcessor.ge t()); |
131 } | 175 } |
132 fColorEffects->setData(fGpu, drawType, fProgramDataManager, colorStages); | 176 this->setData<GrFragmentStage>(colorStages, fColorEffects.get()); |
133 fCoverageEffects->setData(fGpu, drawType, fProgramDataManager, coverageStage s); | 177 this->setData<GrFragmentStage>(coverageStages, fCoverageEffects.get()); |
134 | 178 |
135 // PathTexGen state applies to the the fixed function vertex shader. For | 179 // Some of GrGLProgram subclasses need to update state here |
136 // custom shaders, it's ignored, so we don't need to change the texgen | 180 this->didSetData(drawType); |
137 // settings in that case. | 181 } |
138 if (!fHasVertexShader) { | 182 |
139 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 183 void GrGLProgram::setTransformData(const GrProcessorStage& processor, |
184 int effectIdx, | |
185 GrGLInstalledProcessors* ip) { | |
186 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransf orms[effectIdx]; | |
187 int numTransforms = transforms.count(); | |
188 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | |
189 for (int t = 0; t < numTransforms; ++t) { | |
190 SkASSERT(transforms[t].fHandle.isValid()); | |
191 const SkMatrix& matrix = get_transform_matrix(processor, ip->fHasExplici tLocalCoords, t); | |
192 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | |
193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo rmHandle(), matrix); | |
194 transforms[t].fCurrentValue = matrix; | |
195 } | |
140 } | 196 } |
141 } | 197 } |
142 | 198 |
199 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | |
200 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | |
bsalomon
2014/10/06 18:49:40
why don't we set data for nvpr? or is this just a
joshua.litt
2014/10/06 19:16:57
Exactly, this is just a generic assert. The only
| |
201 } | |
202 | |
143 void GrGLProgram::setColor(const GrOptDrawState& optState, | 203 void GrGLProgram::setColor(const GrOptDrawState& optState, |
144 GrColor color, | 204 GrColor color, |
145 SharedGLState* sharedState) { | 205 SharedGLState* sharedState) { |
146 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 206 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
147 if (!optState.hasColorVertexAttribute()) { | 207 if (!optState.hasColorVertexAttribute()) { |
148 switch (header.fColorInput) { | 208 switch (header.fColorInput) { |
149 case GrGLProgramDesc::kAttribute_ColorInput: | 209 case GrGLProgramDesc::kAttribute_ColorInput: |
150 SkASSERT(-1 != header.fColorAttributeIndex); | 210 SkASSERT(-1 != header.fColorAttributeIndex); |
151 if (sharedState->fConstAttribColor != color || | 211 if (sharedState->fConstAttribColor != color || |
152 sharedState->fConstAttribColorIndex != header.fColorAttribut eIndex) { | 212 sharedState->fConstAttribColorIndex != header.fColorAttribut eIndex) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 default: | 272 default: |
213 SkFAIL("Unexpected coverage type."); | 273 SkFAIL("Unexpected coverage type."); |
214 } | 274 } |
215 } else { | 275 } else { |
216 sharedState->fConstAttribCoverageIndex = -1; | 276 sharedState->fConstAttribCoverageIndex = -1; |
217 } | 277 } |
218 } | 278 } |
219 | 279 |
220 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | 280 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
221 const GrOptDrawState& optState) { | 281 const GrOptDrawState& optState) { |
282 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | |
283 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | |
284 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->wi dth()) { | |
285 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | |
286 SkIntToScalar(optState.getRenderTarget()->hei ght())); | |
287 } | |
288 | |
289 // call subclasses to set the actual view matrix | |
290 this->onSetMatrixAndRenderTargetHeight(drawType, optState); | |
291 } | |
292 | |
293 void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | |
294 const GrOptDrawState& optStat e) { | |
222 const GrRenderTarget* rt = optState.getRenderTarget(); | 295 const GrRenderTarget* rt = optState.getRenderTarget(); |
223 SkISize size; | 296 SkISize size; |
224 size.set(rt->width(), rt->height()); | 297 size.set(rt->width(), rt->height()); |
225 | 298 if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
226 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 299 fMatrixState.fRenderTargetSize != size || |
227 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | 300 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix ())) { |
228 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { | |
229 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | |
230 SkIntToScalar(size.fHeight)); | |
231 } | |
232 | |
233 if (GrGpu::IsPathRenderingDrawType(drawType)) { | |
234 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s ize, rt->origin()); | |
235 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || | |
236 fMatrixState.fRenderTargetSize != size || | |
237 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) { | |
238 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); | 301 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); |
239 | 302 |
240 fMatrixState.fViewMatrix = optState.getViewMatrix(); | 303 fMatrixState.fViewMatrix = optState.getViewMatrix(); |
241 fMatrixState.fRenderTargetSize = size; | 304 fMatrixState.fRenderTargetSize = size; |
242 fMatrixState.fRenderTargetOrigin = rt->origin(); | 305 fMatrixState.fRenderTargetOrigin = rt->origin(); |
243 | 306 |
244 GrGLfloat viewMatrix[3 * 3]; | 307 GrGLfloat viewMatrix[3 * 3]; |
245 fMatrixState.getGLMatrix<3>(viewMatrix); | 308 fMatrixState.getGLMatrix<3>(viewMatrix); |
246 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v iewMatrix); | 309 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v iewMatrix); |
247 | 310 |
248 GrGLfloat rtAdjustmentVec[4]; | 311 GrGLfloat rtAdjustmentVec[4]; |
249 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); | 312 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
250 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r tAdjustmentVec); | 313 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r tAdjustmentVec); |
251 } | 314 } |
252 } | 315 } |
316 | |
317 //////////////////////////////////////////////////////////////////////////////// ///////// | |
318 | |
319 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, | |
320 const GrGLProgramDesc& desc, | |
321 const BuiltinUniformHandles& builtinUni forms, | |
322 GrGLuint programID, | |
323 const UniformInfoArray& uniforms, | |
324 GrGLInstalledProcessors* colorProcessor s, | |
325 GrGLInstalledProcessors* coverageProces sors) | |
326 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, colorProc essors, | |
327 coverageProcessors) { | |
328 } | |
329 | |
330 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawT ype, | |
331 const GrOptDrawState& optState) { | |
332 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | |
333 const GrRenderTarget* rt = optState.getRenderTarget(); | |
334 SkISize size; | |
335 size.set(rt->width(), rt->height()); | |
336 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin()); | |
337 } | |
338 | |
339 //////////////////////////////////////////////////////////////////////////////// ///////// | |
340 | |
341 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, | |
342 const GrGLProgramDesc& desc, | |
343 const BuiltinUniformHandles& builtinUniforms, | |
344 GrGLuint programID, | |
345 const UniformInfoArray& uniforms, | |
346 GrGLInstalledProcessors* colorProcessors, | |
347 GrGLInstalledProcessors* coverageProcessors, | |
348 const SeparableVaryingInfoArray& separableVaryi ngs) | |
349 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, colorProcessors , | |
350 coverageProcessors) { | |
351 int count = separableVaryings.count(); | |
352 fVaryings.push_back_n(count); | |
353 for (int i = 0; i < count; i++) { | |
354 Varying& varying = fVaryings[i]; | |
355 const SeparableVaryingInfo& builderVarying = separableVaryings[i]; | |
356 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCo unt()); | |
357 SkDEBUGCODE( | |
358 varying.fType = builderVarying.fVariable.getType(); | |
359 ); | |
360 varying.fLocation = builderVarying.fLocation; | |
361 } | |
362 } | |
363 | |
364 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { | |
365 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | |
366 } | |
367 | |
368 void GrGLNvprProgram::setTransformData(const GrProcessorStage& processor, | |
369 int effectIdx, | |
370 GrGLInstalledProcessors* ip) { | |
371 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransf orms[effectIdx]; | |
372 int numTransforms = transforms.count(); | |
373 SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); | |
374 for (int t = 0; t < numTransforms; ++t) { | |
375 SkASSERT(transforms[t].fHandle.isValid()); | |
376 const SkMatrix& transform = get_transform_matrix(processor, ip->fHasExpl icitLocalCoords, t); | |
377 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { | |
378 continue; | |
379 } | |
380 transforms[t].fCurrentValue = transform; | |
381 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()] ; | |
382 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType = = kVec3f_GrSLType); | |
383 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; | |
384 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID , | |
385 fragmentIn put.fLocation, | |
386 GR_GL_OBJE CT_LINEAR, | |
387 components , | |
388 transform) ; | |
389 } | |
390 } | |
391 | |
392 //////////////////////////////////////////////////////////////////////////////// ////// | |
393 | |
394 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, | |
395 const GrGLProgramDesc& desc, | |
396 const BuiltinUniformHandles& builtinUniforms, | |
397 GrGLuint programID, | |
398 const UniformInfoArray& uniforms, | |
399 GrGLInstalledProcessors* colorProcessors, | |
400 GrGLInstalledProcessors* coverageProcessors, | |
401 int texCoordSetCnt) | |
402 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, colorProcessors , | |
403 coverageProcessors) | |
404 , fTexCoordSetCnt(texCoordSetCnt) { | |
405 } | |
406 | |
407 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { | |
408 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | |
409 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | |
410 } | |
411 | |
412 void GrGLLegacyNvprProgram::setTransformData(const GrProcessorStage& processorSt age, | |
413 int effectIdx, | |
414 GrGLInstalledProcessors* ip) { | |
415 // We've hidden the texcoord index in the first entry of the transforms arra y for each effect | |
416 int texCoordIndex = ip->fTransforms[effectIdx][0].fHandle.handle(); | |
417 int numTransforms = processorStage.getProcessor()->numTransforms(); | |
418 for (int t = 0; t < numTransforms; ++t) { | |
419 const SkMatrix& transform = get_transform_matrix(processorStage, false, t); | |
420 GrGLPathRendering::PathTexGenComponents components = | |
421 GrGLPathRendering::kST_PathTexGenComponents; | |
422 if (processorStage.isPerspectiveCoordTransform(t, false)) { | |
423 components = GrGLPathRendering::kSTR_PathTexGenComponents; | |
424 } | |
425 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t ransform); | |
426 } | |
427 } | |
OLD | NEW |