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 "GrAllocator.h" | 10 #include "GrAllocator.h" |
11 #include "GrEffect.h" | 11 #include "GrEffect.h" |
| 12 #include "GrCoordTransform.h" |
12 #include "GrDrawEffect.h" | 13 #include "GrDrawEffect.h" |
13 #include "GrGLEffect.h" | 14 #include "GrGLEffect.h" |
14 #include "GrGpuGL.h" | 15 #include "GrGpuGL.h" |
15 #include "GrGLShaderVar.h" | 16 #include "GrGLShaderVar.h" |
16 #include "GrGLSL.h" | 17 #include "GrGLSL.h" |
17 #include "SkXfermode.h" | 18 #include "SkXfermode.h" |
18 | 19 |
19 SK_DEFINE_INST_COUNT(GrGLProgram) | 20 SK_DEFINE_INST_COUNT(GrGLProgram) |
20 | 21 |
21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 22 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 SkXfermode::Coeff colorCoeff; | 229 SkXfermode::Coeff colorCoeff; |
229 SkXfermode::Coeff filterColorCoeff; | 230 SkXfermode::Coeff filterColorCoeff; |
230 SkAssertResult( | 231 SkAssertResult( |
231 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte
rXfermode), | 232 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte
rXfermode), |
232 &filterColorCoeff, | 233 &filterColorCoeff, |
233 &colorCoeff)); | 234 &colorCoeff)); |
234 bool needColor, needFilterColor; | 235 bool needColor, needFilterColor; |
235 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor
); | 236 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor
); |
236 | 237 |
237 // used in order for builder to return the per-stage uniform handles. | 238 // used in order for builder to return the per-stage uniform handles. |
| 239 typedef SkTArray<GrGLCoordTransform, false>* CoordTransformArrayPtr; |
238 typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr
; | 240 typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr
; |
239 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag
eEffects()); | 241 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag
eEffects()); |
| 242 SkAutoTArray<CoordTransformArrayPtr> effectCoordTransformArrays(maxColorOrCo
vEffectCnt); |
240 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt); | 243 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt); |
241 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt); | 244 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt); |
242 | 245 |
243 if (needColor) { | 246 if (needColor) { |
244 for (int e = 0; e < fDesc.numColorEffects(); ++e) { | 247 for (int e = 0; e < fDesc.numColorEffects(); ++e) { |
| 248 effectCoordTransformArrays[e] = &fColorEffects[e].fCoordTransforms; |
245 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis; | 249 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis; |
246 } | 250 } |
247 | 251 |
248 builder.emitEffects(colorStages, | 252 builder.emitEffects(colorStages, |
249 fDesc.effectKeys(), | 253 fDesc.effectKeys(), |
250 fDesc.numColorEffects(), | 254 fDesc.numColorEffects(), |
251 &inColor, | 255 &inColor, |
252 &knownColorValue, | 256 &knownColorValue, |
| 257 effectCoordTransformArrays.get(), |
253 effectUniformArrays.get(), | 258 effectUniformArrays.get(), |
254 glEffects.get()); | 259 glEffects.get()); |
255 | 260 |
256 for (int e = 0; e < fDesc.numColorEffects(); ++e) { | 261 for (int e = 0; e < fDesc.numColorEffects(); ++e) { |
257 fColorEffects[e].fGLEffect = glEffects[e]; | 262 fColorEffects[e].fGLEffect = glEffects[e]; |
258 } | 263 } |
259 } | 264 } |
260 | 265 |
261 // Insert the color filter. This will soon be replaced by a color effect. | 266 // Insert the color filter. This will soon be replaced by a color effect. |
262 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) { | 267 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) { |
(...skipping 16 matching lines...) Expand all Loading... |
279 colorCoeff, colorFilterColorUniName, color); | 284 colorCoeff, colorFilterColorUniName, color); |
280 inColor = "filteredColor"; | 285 inColor = "filteredColor"; |
281 } | 286 } |
282 | 287 |
283 /////////////////////////////////////////////////////////////////////////// | 288 /////////////////////////////////////////////////////////////////////////// |
284 // compute the partial coverage | 289 // compute the partial coverage |
285 SkString inCoverage = builder.getInputCoverage(); | 290 SkString inCoverage = builder.getInputCoverage(); |
286 GrSLConstantVec knownCoverageValue = builder.getKnownCoverageValue(); | 291 GrSLConstantVec knownCoverageValue = builder.getKnownCoverageValue(); |
287 | 292 |
288 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) { | 293 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) { |
| 294 effectCoordTransformArrays[e] = &fCoverageEffects[e].fCoordTransforms; |
289 effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis; | 295 effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis; |
290 } | 296 } |
291 | 297 |
292 builder.emitEffects(coverageStages, | 298 builder.emitEffects(coverageStages, |
293 fDesc.getEffectKeys() + fDesc.numColorEffects(), | 299 fDesc.getEffectKeys() + fDesc.numColorEffects(), |
294 fDesc.numCoverageEffects(), | 300 fDesc.numCoverageEffects(), |
295 &inCoverage, | 301 &inCoverage, |
296 &knownCoverageValue, | 302 &knownCoverageValue, |
| 303 effectCoordTransformArrays.get(), |
297 effectUniformArrays.get(), | 304 effectUniformArrays.get(), |
298 glEffects.get()); | 305 glEffects.get()); |
299 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) { | 306 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) { |
300 fCoverageEffects[e].fGLEffect = glEffects[e]; | 307 fCoverageEffects[e].fGLEffect = glEffects[e]; |
301 } | 308 } |
302 | 309 |
303 // discard if coverage is zero | 310 // discard if coverage is zero |
304 if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageV
alue) { | 311 if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageV
alue) { |
305 if (kZeros_GrSLConstantVec == knownCoverageValue) { | 312 if (kZeros_GrSLConstantVec == knownCoverageValue) { |
306 // This is unfortunate. | 313 // This is unfortunate. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (handle.isValid()) { | 441 if (handle.isValid()) { |
435 fUniformManager.setSampler(handle, *texUnitIdx); | 442 fUniformManager.setSampler(handle, *texUnitIdx); |
436 effect->fTextureUnits[s] = (*texUnitIdx)++; | 443 effect->fTextureUnits[s] = (*texUnitIdx)++; |
437 } | 444 } |
438 } | 445 } |
439 } | 446 } |
440 | 447 |
441 /////////////////////////////////////////////////////////////////////////////// | 448 /////////////////////////////////////////////////////////////////////////////// |
442 | 449 |
443 void GrGLProgram::setEffectData(const GrEffectStage& stage, | 450 void GrGLProgram::setEffectData(const GrEffectStage& stage, |
444 const EffectAndSamplers& effect) { | 451 EffectAndSamplers& effect) { |
445 | 452 |
446 // Let the GrGLEffect set its data. | 453 // Let the GrGLEffect set its data. |
447 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex
; | 454 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex
; |
448 GrDrawEffect drawEffect(stage, explicitLocalCoords); | 455 GrDrawEffect drawEffect(stage, explicitLocalCoords); |
449 effect.fGLEffect->setData(fUniformManager, drawEffect); | 456 effect.fGLEffect->setData(fUniformManager, drawEffect); |
450 | 457 |
| 458 // Set the effect's coord transform matrices. |
| 459 int numTransforms = effect.fCoordTransforms.count(); |
| 460 SkASSERT((*stage.getEffect())->numTransforms() == numTransforms); |
| 461 for (int c = 0; c < numTransforms; ++c) { |
| 462 effect.fCoordTransforms[c].setData(fUniformManager, drawEffect, c); |
| 463 } |
| 464 |
451 // Bind the texures for the effect. | 465 // Bind the texures for the effect. |
452 int numSamplers = effect.fSamplerUnis.count(); | 466 int numSamplers = effect.fSamplerUnis.count(); |
453 SkASSERT((*stage.getEffect())->numTextures() == numSamplers); | 467 SkASSERT((*stage.getEffect())->numTextures() == numSamplers); |
454 for (int s = 0; s < numSamplers; ++s) { | 468 for (int s = 0; s < numSamplers; ++s) { |
455 UniformHandle handle = effect.fSamplerUnis[s]; | 469 UniformHandle handle = effect.fSamplerUnis[s]; |
456 if (handle.isValid()) { | 470 if (handle.isValid()) { |
457 const GrTextureAccess& access = (*stage.getEffect())->textureAccess(
s); | 471 const GrTextureAccess& access = (*stage.getEffect())->textureAccess(
s); |
458 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()
); | 472 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()
); |
459 int unit = effect.fTextureUnits[s]; | 473 int unit = effect.fTextureUnits[s]; |
460 fGpu->bindTexture(unit, access.getParams(), texture); | 474 fGpu->bindTexture(unit, access.getParams(), texture); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 641 |
628 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 642 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
629 fMatrixState.fRenderTargetSize = size; | 643 fMatrixState.fRenderTargetSize = size; |
630 fMatrixState.fRenderTargetOrigin = rt->origin(); | 644 fMatrixState.fRenderTargetOrigin = rt->origin(); |
631 | 645 |
632 GrGLfloat viewMatrix[3 * 3]; | 646 GrGLfloat viewMatrix[3 * 3]; |
633 fMatrixState.getGLMatrix<3>(viewMatrix); | 647 fMatrixState.getGLMatrix<3>(viewMatrix); |
634 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); | 648 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); |
635 } | 649 } |
636 } | 650 } |
OLD | NEW |