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" | |
11 #include "GrEffect.h" | 10 #include "GrEffect.h" |
12 #include "GrDrawEffect.h" | 11 #include "GrDrawEffect.h" |
13 #include "GrGLEffect.h" | 12 #include "GrGLEffect.h" |
14 #include "GrGpuGL.h" | 13 #include "GrGpuGL.h" |
15 #include "GrGLShaderVar.h" | 14 #include "GrGLShaderVar.h" |
16 #include "GrGLSL.h" | 15 #include "GrGLSL.h" |
17 #include "SkTrace.h" | 16 #include "SkTrace.h" |
18 #include "SkXfermode.h" | 17 #include "SkXfermode.h" |
19 | 18 |
20 #include "SkRTConf.h" | 19 #include "SkRTConf.h" |
21 | 20 |
22 SK_DEFINE_INST_COUNT(GrGLProgram) | 21 SK_DEFINE_INST_COUNT(GrGLProgram) |
23 | 22 |
24 #define GL_CALL(X) GR_GL_CALL(fContext.interface(), X) | 23 #define GL_CALL(X) GR_GL_CALL(fContext.interface(), X) |
25 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fContext.interface(), R, X) | 24 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fContext.interface(), R, X) |
26 | 25 |
27 SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false, | 26 SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false, |
28 "Print the source code for all shaders generated."); | 27 "Print the source code for all shaders generated."); |
29 | 28 |
30 #define COL_ATTR_NAME "aColor" | 29 #define COL_ATTR_NAME "aColor" |
31 #define COV_ATTR_NAME "aCoverage" | 30 #define COV_ATTR_NAME "aCoverage" |
32 #define EDGE_ATTR_NAME "aEdge" | 31 #define EDGE_ATTR_NAME "aEdge" |
33 | 32 |
34 namespace { | 33 namespace { |
35 inline const char* declared_color_output_name() { return "fsColorOut"; } | 34 inline const char* declared_color_output_name() { return "fsColorOut"; } |
36 inline const char* dual_source_output_name() { return "dualSourceOut"; } | 35 inline const char* dual_source_output_name() { return "dualSourceOut"; } |
| 36 enum { |
| 37 // Number of uniforms in a single allocation block. |
| 38 kUniformsPerBlock = 8 |
| 39 }; |
37 } | 40 } |
38 | 41 |
39 GrGLProgram* GrGLProgram::Create(const GrGLContext& gl, | 42 GrGLProgram* GrGLProgram::Create(const GrGLContext& gl, |
40 const GrGLProgramDesc& desc, | 43 const GrGLProgramDesc& desc, |
41 const GrEffectStage* colorStages[], | 44 const GrEffectStage* colorStages[], |
42 const GrEffectStage* coverageStages[]) { | 45 const GrEffectStage* coverageStages[]) { |
43 GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, colorStages, cover
ageStages)); | 46 GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, colorStages, cover
ageStages)); |
44 if (!program->succeeded()) { | 47 if (!program->succeeded()) { |
45 delete program; | 48 delete program; |
46 program = NULL; | 49 program = NULL; |
47 } | 50 } |
48 return program; | 51 return program; |
49 } | 52 } |
50 | 53 |
51 GrGLProgram::GrGLProgram(const GrGLContext& gl, | 54 GrGLProgram::GrGLProgram(const GrGLContext& gl, |
52 const GrGLProgramDesc& desc, | 55 const GrGLProgramDesc& desc, |
53 const GrEffectStage* colorStages[], | 56 const GrEffectStage* colorStages[], |
54 const GrEffectStage* coverageStages[]) | 57 const GrEffectStage* coverageStages[]) |
55 : fContext(gl) | 58 : fContext(gl) |
56 , fUniformManager(gl) { | 59 , fUniforms(kUniformsPerBlock) { |
57 fDesc = desc; | 60 fDesc = desc; |
58 fVShaderID = 0; | 61 fVShaderID = 0; |
59 fGShaderID = 0; | 62 fGShaderID = 0; |
60 fFShaderID = 0; | 63 fFShaderID = 0; |
61 fProgramID = 0; | 64 fProgramID = 0; |
62 | 65 |
63 fDstCopyTexUnit = -1; | 66 fDstCopyTexUnit = -1; |
64 | 67 |
65 fColor = GrColor_ILLEGAL; | 68 fColor = GrColor_ILLEGAL; |
66 fColorFilterColor = GrColor_ILLEGAL; | 69 fColorFilterColor = GrColor_ILLEGAL; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 case GrGLProgramDesc::kAttribute_ColorInput: { | 227 case GrGLProgramDesc::kAttribute_ColorInput: { |
225 builder->addAttribute(kVec4f_GrSLType, COL_ATTR_NAME); | 228 builder->addAttribute(kVec4f_GrSLType, COL_ATTR_NAME); |
226 const char *vsName, *fsName; | 229 const char *vsName, *fsName; |
227 builder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); | 230 builder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); |
228 builder->vsCodeAppendf("\t%s = " COL_ATTR_NAME ";\n", vsName); | 231 builder->vsCodeAppendf("\t%s = " COL_ATTR_NAME ";\n", vsName); |
229 *inColor = fsName; | 232 *inColor = fsName; |
230 return kNone_GrSLConstantVec; | 233 return kNone_GrSLConstantVec; |
231 } | 234 } |
232 case GrGLProgramDesc::kUniform_ColorInput: { | 235 case GrGLProgramDesc::kUniform_ColorInput: { |
233 const char* name; | 236 const char* name; |
234 fUniformHandles.fColorUni = builder->addUniform(GrGLShaderBuilder::k
Fragment_ShaderType, | 237 fNamedUniforms.fColorUni = builder->addUniform(GrGLShaderBuilder::kF
ragment_ShaderType, |
235 kVec4f_GrSLType, "Co
lor", &name); | 238 kVec4f_GrSLType, "Col
or", &name)->glUniform(); |
236 *inColor = name; | 239 *inColor = name; |
237 return kNone_GrSLConstantVec; | 240 return kNone_GrSLConstantVec; |
238 } | 241 } |
239 case GrGLProgramDesc::kTransBlack_ColorInput: | 242 case GrGLProgramDesc::kTransBlack_ColorInput: |
240 inColor->reset(); | 243 inColor->reset(); |
241 return kZeros_GrSLConstantVec; | 244 return kZeros_GrSLConstantVec; |
242 case GrGLProgramDesc::kSolidWhite_ColorInput: | 245 case GrGLProgramDesc::kSolidWhite_ColorInput: |
243 inColor->reset(); | 246 inColor->reset(); |
244 return kOnes_GrSLConstantVec; | 247 return kOnes_GrSLConstantVec; |
245 default: | 248 default: |
246 GrCrash("Unknown color type."); | 249 GrCrash("Unknown color type."); |
247 return kNone_GrSLConstantVec; | 250 return kNone_GrSLConstantVec; |
248 } | 251 } |
249 } | 252 } |
250 | 253 |
251 GrSLConstantVec GrGLProgram::genInputCoverage(GrGLShaderBuilder* builder, SkStri
ng* inCoverage) { | 254 GrSLConstantVec GrGLProgram::genInputCoverage(GrGLShaderBuilder* builder, SkStri
ng* inCoverage) { |
252 switch (fDesc.getHeader().fCoverageInput) { | 255 switch (fDesc.getHeader().fCoverageInput) { |
253 case GrGLProgramDesc::kAttribute_ColorInput: { | 256 case GrGLProgramDesc::kAttribute_ColorInput: { |
254 builder->addAttribute(kVec4f_GrSLType, COV_ATTR_NAME); | 257 builder->addAttribute(kVec4f_GrSLType, COV_ATTR_NAME); |
255 const char *vsName, *fsName; | 258 const char *vsName, *fsName; |
256 builder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName); | 259 builder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName); |
257 builder->vsCodeAppendf("\t%s = " COV_ATTR_NAME ";\n", vsName); | 260 builder->vsCodeAppendf("\t%s = " COV_ATTR_NAME ";\n", vsName); |
258 *inCoverage = fsName; | 261 *inCoverage = fsName; |
259 return kNone_GrSLConstantVec; | 262 return kNone_GrSLConstantVec; |
260 } | 263 } |
261 case GrGLProgramDesc::kUniform_ColorInput: { | 264 case GrGLProgramDesc::kUniform_ColorInput: { |
262 const char* name; | 265 const char* name; |
263 fUniformHandles.fCoverageUni = | 266 fNamedUniforms.fCoverageUni = |
264 builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 267 builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
265 kVec4f_GrSLType, "Coverage", &name); | 268 kVec4f_GrSLType, "Coverage", &name)->glUnifo
rm(); |
266 *inCoverage = name; | 269 *inCoverage = name; |
267 return kNone_GrSLConstantVec; | 270 return kNone_GrSLConstantVec; |
268 } | 271 } |
269 case GrGLProgramDesc::kTransBlack_ColorInput: | 272 case GrGLProgramDesc::kTransBlack_ColorInput: |
270 inCoverage->reset(); | 273 inCoverage->reset(); |
271 return kZeros_GrSLConstantVec; | 274 return kZeros_GrSLConstantVec; |
272 case GrGLProgramDesc::kSolidWhite_ColorInput: | 275 case GrGLProgramDesc::kSolidWhite_ColorInput: |
273 inCoverage->reset(); | 276 inCoverage->reset(); |
274 return kOnes_GrSLConstantVec; | 277 return kOnes_GrSLConstantVec; |
275 default: | 278 default: |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 437 |
435 return true; | 438 return true; |
436 } | 439 } |
437 | 440 |
438 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], | 441 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], |
439 const GrEffectStage* coverageStages[]) { | 442 const GrEffectStage* coverageStages[]) { |
440 GrAssert(0 == fProgramID); | 443 GrAssert(0 == fProgramID); |
441 | 444 |
442 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 445 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
443 | 446 |
444 GrGLShaderBuilder builder(fContext.info(), fUniformManager, fDesc); | 447 GrGLShaderBuilder builder(fContext.info(), *this, fDesc); |
445 | 448 |
446 // the dual source output has no canonical var name, have to | 449 // the dual source output has no canonical var name, have to |
447 // declare an output, which is incompatible with gl_FragColor/gl_FragData. | 450 // declare an output, which is incompatible with gl_FragColor/gl_FragData. |
448 bool dualSourceOutputWritten = false; | 451 bool dualSourceOutputWritten = false; |
449 | 452 |
450 GrGLShaderVar colorOutput; | 453 GrGLShaderVar colorOutput; |
451 bool isColorDeclared = GrGLSLSetupFSColorOuput(fContext.info().glslGeneratio
n(), | 454 bool isColorDeclared = GrGLSLSetupFSColorOuput(fContext.info().glslGeneratio
n(), |
452 declared_color_output_name(), | 455 declared_color_output_name(), |
453 &colorOutput); | 456 &colorOutput); |
454 if (isColorDeclared) { | 457 if (isColorDeclared) { |
455 builder.fFSOutputs.push_back(colorOutput); | 458 builder.fFSOutputs.push_back(colorOutput); |
456 } | 459 } |
457 | 460 |
458 const char* viewMName; | 461 const char* viewMName; |
459 fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::kVert
ex_ShaderType, | 462 fNamedUniforms.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::kVerte
x_ShaderType, |
460 kMat33f_GrSLType, "ViewM
", &viewMName); | 463 kMat33f_GrSLType, "ViewM", &vi
ewMName)->glUniform(); |
461 | 464 |
462 | 465 |
463 builder.vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n" | 466 builder.vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n" |
464 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n", | 467 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n", |
465 viewMName, builder.positionAttribute().getName().c_str
()); | 468 viewMName, builder.positionAttribute().getName().c_str
()); |
466 | 469 |
467 // incoming color to current stage being processed. | 470 // incoming color to current stage being processed. |
468 SkString inColor; | 471 SkString inColor; |
469 GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor); | 472 GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor); |
470 | 473 |
(...skipping 10 matching lines...) Expand all Loading... |
481 SkXfermode::Coeff colorCoeff; | 484 SkXfermode::Coeff colorCoeff; |
482 SkXfermode::Coeff filterColorCoeff; | 485 SkXfermode::Coeff filterColorCoeff; |
483 SkAssertResult( | 486 SkAssertResult( |
484 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte
rXfermode), | 487 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte
rXfermode), |
485 &filterColorCoeff, | 488 &filterColorCoeff, |
486 &colorCoeff)); | 489 &colorCoeff)); |
487 bool needColor, needFilterColor; | 490 bool needColor, needFilterColor; |
488 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor
); | 491 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor
); |
489 | 492 |
490 // used in order for builder to return the per-stage uniform handles. | 493 // used in order for builder to return the per-stage uniform handles. |
491 typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr
; | 494 typedef SkTArray<GrGLUniform*, true>* UniHandleArrayPtr; |
492 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag
eEffects()); | 495 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag
eEffects()); |
493 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt); | 496 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt); |
494 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt); | 497 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt); |
495 | 498 |
496 if (needColor) { | 499 if (needColor) { |
497 for (int e = 0; e < fDesc.numColorEffects(); ++e) { | 500 for (int e = 0; e < fDesc.numColorEffects(); ++e) { |
498 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis; | 501 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis; |
499 } | 502 } |
500 | 503 |
501 builder.emitEffects(colorStages, | 504 builder.emitEffects(colorStages, |
502 fDesc.effectKeys(), | 505 fDesc.effectKeys(), |
503 fDesc.numColorEffects(), | 506 fDesc.numColorEffects(), |
504 &inColor, | 507 &inColor, |
505 &knownColorValue, | 508 &knownColorValue, |
506 effectUniformArrays.get(), | 509 effectUniformArrays.get(), |
507 glEffects.get()); | 510 glEffects.get()); |
508 | 511 |
509 for (int e = 0; e < fDesc.numColorEffects(); ++e) { | 512 for (int e = 0; e < fDesc.numColorEffects(); ++e) { |
510 fColorEffects[e].fGLEffect = glEffects[e]; | 513 fColorEffects[e].fGLEffect = glEffects[e]; |
511 } | 514 } |
512 } | 515 } |
513 | 516 |
514 // Insert the color filter. This will soon be replaced by a color effect. | 517 // Insert the color filter. This will soon be replaced by a color effect. |
515 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) { | 518 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) { |
516 const char* colorFilterColorUniName = NULL; | 519 const char* colorFilterColorUniName = NULL; |
517 fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder::
kFragment_ShaderType, | 520 fNamedUniforms.fColorFilterUni = builder.addUniform(GrGLShaderBuilder::k
Fragment_ShaderType, |
518 kVec4f_GrSLType, "F
ilterColor", | 521 kVec4f_GrSLType, "FilterC
olor", |
519 &colorFilterColorUn
iName); | 522 &colorFilterColorUni
Name)->glUniform(); |
520 | 523 |
521 builder.fsCodeAppend("\tvec4 filteredColor;\n"); | 524 builder.fsCodeAppend("\tvec4 filteredColor;\n"); |
522 const char* color; | 525 const char* color; |
523 // add_color_filter requires a real input string. | 526 // add_color_filter requires a real input string. |
524 if (knownColorValue == kOnes_GrSLConstantVec) { | 527 if (knownColorValue == kOnes_GrSLConstantVec) { |
525 color = GrGLSLOnesVecf(4); | 528 color = GrGLSLOnesVecf(4); |
526 } else if (knownColorValue == kZeros_GrSLConstantVec) { | 529 } else if (knownColorValue == kZeros_GrSLConstantVec) { |
527 color = GrGLSLZerosVecf(4); | 530 color = GrGLSLZerosVecf(4); |
528 } else { | 531 } else { |
529 color = inColor.c_str(); | 532 color = inColor.c_str(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 if (!this->compileShaders(builder)) { | 663 if (!this->compileShaders(builder)) { |
661 return false; | 664 return false; |
662 } | 665 } |
663 | 666 |
664 if (!this->bindOutputsAttribsAndLinkProgram(builder, | 667 if (!this->bindOutputsAttribsAndLinkProgram(builder, |
665 isColorDeclared, | 668 isColorDeclared, |
666 dualSourceOutputWritten)) { | 669 dualSourceOutputWritten)) { |
667 return false; | 670 return false; |
668 } | 671 } |
669 | 672 |
670 builder.finished(fProgramID); | 673 builder.finished(fContext, fProgramID); |
671 fUniformHandles.fRTHeightUni = builder.getRTHeightUniform(); | 674 fNamedUniforms.fRTHeightUni = builder.getRTHeightUniform(); |
672 fUniformHandles.fDstCopyTopLeftUni = builder.getDstCopyTopLeftUniform(); | 675 fNamedUniforms.fDstCopyTopLeftUni = builder.getDstCopyTopLeftUniform(); |
673 fUniformHandles.fDstCopyScaleUni = builder.getDstCopyScaleUniform(); | 676 fNamedUniforms.fDstCopyScaleUni = builder.getDstCopyScaleUniform(); |
674 fUniformHandles.fDstCopySamplerUni = builder.getDstCopySamplerUniform(); | 677 fNamedUniforms.fDstCopySamplerUni = builder.getDstCopySamplerUniform(); |
675 // This must be called after we set fDstCopySamplerUni above. | 678 // This must be called after we set fDstCopySamplerUni above. |
676 this->initSamplerUniforms(); | 679 this->initSamplerUniforms(); |
677 | 680 |
678 return true; | 681 return true; |
679 } | 682 } |
680 | 683 |
681 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil
der, | 684 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil
der, |
682 bool bindColorOut, | 685 bool bindColorOut, |
683 bool bindDualSrcOut) { | 686 bool bindDualSrcOut) { |
684 GL_CALL_RET(fProgramID, CreateProgram()); | 687 GL_CALL_RET(fProgramID, CreateProgram()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 GL_CALL(DeleteProgram(fProgramID)); | 749 GL_CALL(DeleteProgram(fProgramID)); |
747 fProgramID = 0; | 750 fProgramID = 0; |
748 return false; | 751 return false; |
749 } | 752 } |
750 return true; | 753 return true; |
751 } | 754 } |
752 | 755 |
753 void GrGLProgram::initSamplerUniforms() { | 756 void GrGLProgram::initSamplerUniforms() { |
754 GL_CALL(UseProgram(fProgramID)); | 757 GL_CALL(UseProgram(fProgramID)); |
755 GrGLint texUnitIdx = 0; | 758 GrGLint texUnitIdx = 0; |
756 if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fDstCopySam
plerUni) { | 759 if (NULL != fNamedUniforms.fDstCopySamplerUni) { |
757 fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitId
x); | 760 fNamedUniforms.fDstCopySamplerUni->setSampler(fContext, texUnitIdx); |
758 fDstCopyTexUnit = texUnitIdx++; | 761 fDstCopyTexUnit = texUnitIdx++; |
759 } | 762 } |
760 | 763 |
761 for (int e = 0; e < fColorEffects.count(); ++e) { | 764 for (int e = 0; e < fColorEffects.count(); ++e) { |
762 this->initEffectSamplerUniforms(&fColorEffects[e], &texUnitIdx); | 765 this->initEffectSamplerUniforms(&fColorEffects[e], &texUnitIdx); |
763 } | 766 } |
764 | 767 |
765 for (int e = 0; e < fCoverageEffects.count(); ++e) { | 768 for (int e = 0; e < fCoverageEffects.count(); ++e) { |
766 this->initEffectSamplerUniforms(&fCoverageEffects[e], &texUnitIdx); | 769 this->initEffectSamplerUniforms(&fCoverageEffects[e], &texUnitIdx); |
767 } | 770 } |
768 } | 771 } |
769 | 772 |
770 void GrGLProgram::initEffectSamplerUniforms(EffectAndSamplers* effect, int* texU
nitIdx) { | 773 void GrGLProgram::initEffectSamplerUniforms(EffectAndSamplers* effect, int* texU
nitIdx) { |
771 int numSamplers = effect->fSamplerUnis.count(); | 774 int numSamplers = effect->fSamplerUnis.count(); |
772 effect->fTextureUnits.reset(numSamplers); | 775 effect->fTextureUnits.reset(numSamplers); |
773 for (int s = 0; s < numSamplers; ++s) { | 776 for (int s = 0; s < numSamplers; ++s) { |
774 UniformHandle handle = effect->fSamplerUnis[s]; | 777 GrGLUniform* handle = effect->fSamplerUnis[s]; |
775 if (GrGLUniformManager::kInvalidUniformHandle != handle) { | 778 if (NULL != handle) { |
776 fUniformManager.setSampler(handle, *texUnitIdx); | 779 handle->setSampler(fContext, *texUnitIdx); |
777 effect->fTextureUnits[s] = (*texUnitIdx)++; | 780 effect->fTextureUnits[s] = (*texUnitIdx)++; |
778 } | 781 } |
779 } | 782 } |
780 } | 783 } |
781 | 784 |
782 /////////////////////////////////////////////////////////////////////////////// | 785 /////////////////////////////////////////////////////////////////////////////// |
783 | 786 |
784 void GrGLProgram::setEffectData(GrGpuGL* gpu, | 787 void GrGLProgram::setEffectData(GrGpuGL* gpu, |
785 const GrEffectStage& stage, | 788 const GrEffectStage& stage, |
786 const EffectAndSamplers& effect) { | 789 const EffectAndSamplers& effect) { |
787 | 790 |
788 // Let the GrGLEffect set its data. | 791 // Let the GrGLEffect set its data. |
789 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex
; | 792 bool explicitLocalCoords = -1 != fDesc.getHeader().fLocalCoordAttributeIndex
; |
790 GrDrawEffect drawEffect(stage, explicitLocalCoords); | 793 GrDrawEffect drawEffect(stage, explicitLocalCoords); |
791 effect.fGLEffect->setData(fUniformManager, drawEffect); | 794 effect.fGLEffect->setData(fContext, drawEffect); |
792 | 795 |
793 // Bind the texures for the effect. | 796 // Bind the texures for the effect. |
794 int numSamplers = effect.fSamplerUnis.count(); | 797 int numSamplers = effect.fSamplerUnis.count(); |
795 GrAssert((*stage.getEffect())->numTextures() == numSamplers); | 798 GrAssert((*stage.getEffect())->numTextures() == numSamplers); |
796 for (int s = 0; s < numSamplers; ++s) { | 799 for (int s = 0; s < numSamplers; ++s) { |
797 UniformHandle handle = effect.fSamplerUnis[s]; | 800 GrGLUniform* handle = effect.fSamplerUnis[s]; |
798 if (GrGLUniformManager::kInvalidUniformHandle != handle) { | 801 if (NULL != handle) { |
799 const GrTextureAccess& access = (*stage.getEffect())->textureAccess(
s); | 802 const GrTextureAccess& access = (*stage.getEffect())->textureAccess(
s); |
800 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()
); | 803 GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture()
); |
801 int unit = effect.fTextureUnits[s]; | 804 int unit = effect.fTextureUnits[s]; |
802 gpu->bindTexture(unit, access.getParams(), texture); | 805 gpu->bindTexture(unit, access.getParams(), texture); |
803 } | 806 } |
804 } | 807 } |
805 } | 808 } |
806 | 809 |
807 void GrGLProgram::setData(GrGpuGL* gpu, | 810 void GrGLProgram::setData(GrGpuGL* gpu, |
808 GrDrawState::BlendOptFlags blendOpts, | 811 GrDrawState::BlendOptFlags blendOpts, |
(...skipping 14 matching lines...) Expand all Loading... |
823 } else { | 826 } else { |
824 color = drawState.getColor(); | 827 color = drawState.getColor(); |
825 coverage = drawState.getCoverage(); | 828 coverage = drawState.getCoverage(); |
826 } | 829 } |
827 | 830 |
828 this->setColor(drawState, color, sharedState); | 831 this->setColor(drawState, color, sharedState); |
829 this->setCoverage(drawState, coverage, sharedState); | 832 this->setCoverage(drawState, coverage, sharedState); |
830 this->setMatrixAndRenderTargetHeight(drawState); | 833 this->setMatrixAndRenderTargetHeight(drawState); |
831 | 834 |
832 // Setup the SkXfermode::Mode-based colorfilter uniform if necessary | 835 // Setup the SkXfermode::Mode-based colorfilter uniform if necessary |
833 if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fColorFilte
rUni && | 836 if (NULL != fNamedUniforms.fColorFilterUni && |
834 fColorFilterColor != drawState.getColorFilterColor()) { | 837 fColorFilterColor != drawState.getColorFilterColor()) { |
835 GrGLfloat c[4]; | 838 GrGLfloat c[4]; |
836 GrColorToRGBAFloat(drawState.getColorFilterColor(), c); | 839 GrColorToRGBAFloat(drawState.getColorFilterColor(), c); |
837 fUniformManager.set4fv(fUniformHandles.fColorFilterUni, 0, 1, c); | 840 fNamedUniforms.fColorFilterUni->set4fv(fContext, 0, 1, c); |
838 fColorFilterColor = drawState.getColorFilterColor(); | 841 fColorFilterColor = drawState.getColorFilterColor(); |
839 } | 842 } |
840 | 843 |
841 if (NULL != dstCopy) { | 844 if (NULL != dstCopy) { |
842 if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fDstCop
yTopLeftUni) { | 845 if (NULL != fNamedUniforms.fDstCopyTopLeftUni) { |
843 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fUniformHandle
s.fDstCopyScaleUni); | 846 fNamedUniforms.fDstCopyTopLeftUni->set2f(fContext, |
844 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | |
845 fUniformHandles.fDstCopySamplerUni); | |
846 fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, | |
847 static_cast<GrGLfloat>(dstCopy->offset().fX), | 847 static_cast<GrGLfloat>(dstCopy->offset().fX), |
848 static_cast<GrGLfloat>(dstCopy->offset().fY)); | 848 static_cast<GrGLfloat>(dstCopy->offset().fY)); |
849 fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, | 849 fNamedUniforms.fDstCopyScaleUni->set2f(fContext, |
850 1.f / dstCopy->texture()->width(), | 850 1.f / dstCopy->texture()->width(), |
851 1.f / dstCopy->texture()->height()); | 851 1.f / dstCopy->texture()->height()); |
852 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; | 852 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; |
853 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. | 853 static GrTextureParams kParams; // the default is clamp, nearest fil
tering. |
854 gpu->bindTexture(fDstCopyTexUnit, kParams, texture); | 854 gpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
855 } else { | 855 } else { |
856 GrAssert(GrGLUniformManager::kInvalidUniformHandle == | 856 GrAssert(NULL == fNamedUniforms.fDstCopyScaleUni); |
857 fUniformHandles.fDstCopyScaleUni); | 857 GrAssert(NULL == fNamedUniforms.fDstCopySamplerUni); |
858 GrAssert(GrGLUniformManager::kInvalidUniformHandle == | |
859 fUniformHandles.fDstCopySamplerUni); | |
860 } | 858 } |
861 } else { | 859 } else { |
862 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fD
stCopyTopLeftUni); | 860 GrAssert(NULL == fNamedUniforms.fDstCopyTopLeftUni); |
863 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fD
stCopyScaleUni); | 861 GrAssert(NULL == fNamedUniforms.fDstCopyScaleUni); |
864 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fD
stCopySamplerUni); | 862 GrAssert(NULL == fNamedUniforms.fDstCopySamplerUni); |
865 } | 863 } |
866 | 864 |
867 for (int e = 0; e < fColorEffects.count(); ++e) { | 865 for (int e = 0; e < fColorEffects.count(); ++e) { |
868 // We may have omitted the GrGLEffect because of the color filter logic
in genProgram. | 866 // We may have omitted the GrGLEffect because of the color filter logic
in genProgram. |
869 // This can be removed when the color filter is an effect. | 867 // This can be removed when the color filter is an effect. |
870 if (NULL != fColorEffects[e].fGLEffect) { | 868 if (NULL != fColorEffects[e].fGLEffect) { |
871 this->setEffectData(gpu, *colorStages[e], fColorEffects[e]); | 869 this->setEffectData(gpu, *colorStages[e], fColorEffects[e]); |
872 } | 870 } |
873 } | 871 } |
874 | 872 |
(...skipping 20 matching lines...) Expand all Loading... |
895 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); | 893 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
896 sharedState->fConstAttribColor = color; | 894 sharedState->fConstAttribColor = color; |
897 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; | 895 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; |
898 } | 896 } |
899 break; | 897 break; |
900 case GrGLProgramDesc::kUniform_ColorInput: | 898 case GrGLProgramDesc::kUniform_ColorInput: |
901 if (fColor != color) { | 899 if (fColor != color) { |
902 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 900 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
903 GrGLfloat c[4]; | 901 GrGLfloat c[4]; |
904 GrColorToRGBAFloat(color, c); | 902 GrColorToRGBAFloat(color, c); |
905 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | 903 fNamedUniforms.fColorUni->set4fv(fContext, 0, 1, c); |
906 fUniformHandles.fColorUni); | |
907 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); | |
908 fColor = color; | 904 fColor = color; |
909 } | 905 } |
910 sharedState->fConstAttribColorIndex = -1; | 906 sharedState->fConstAttribColorIndex = -1; |
911 break; | 907 break; |
912 case GrGLProgramDesc::kSolidWhite_ColorInput: | 908 case GrGLProgramDesc::kSolidWhite_ColorInput: |
913 case GrGLProgramDesc::kTransBlack_ColorInput: | 909 case GrGLProgramDesc::kTransBlack_ColorInput: |
914 sharedState->fConstAttribColorIndex = -1; | 910 sharedState->fConstAttribColorIndex = -1; |
915 break; | 911 break; |
916 default: | 912 default: |
917 GrCrash("Unknown color type."); | 913 GrCrash("Unknown color type."); |
(...skipping 18 matching lines...) Expand all Loading... |
936 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); | 932 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
937 sharedState->fConstAttribCoverage = coverage; | 933 sharedState->fConstAttribCoverage = coverage; |
938 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; | 934 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; |
939 } | 935 } |
940 break; | 936 break; |
941 case GrGLProgramDesc::kUniform_ColorInput: | 937 case GrGLProgramDesc::kUniform_ColorInput: |
942 if (fCoverage != coverage) { | 938 if (fCoverage != coverage) { |
943 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 939 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
944 GrGLfloat c[4]; | 940 GrGLfloat c[4]; |
945 GrColorToRGBAFloat(coverage, c); | 941 GrColorToRGBAFloat(coverage, c); |
946 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | 942 fNamedUniforms.fCoverageUni->set4fv(fContext, 0, 1, c); |
947 fUniformHandles.fCoverageUni); | |
948 fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
); | |
949 fCoverage = coverage; | 943 fCoverage = coverage; |
950 } | 944 } |
951 sharedState->fConstAttribCoverageIndex = -1; | 945 sharedState->fConstAttribCoverageIndex = -1; |
952 break; | 946 break; |
953 case GrGLProgramDesc::kSolidWhite_ColorInput: | 947 case GrGLProgramDesc::kSolidWhite_ColorInput: |
954 case GrGLProgramDesc::kTransBlack_ColorInput: | 948 case GrGLProgramDesc::kTransBlack_ColorInput: |
955 sharedState->fConstAttribCoverageIndex = -1; | 949 sharedState->fConstAttribCoverageIndex = -1; |
956 break; | 950 break; |
957 default: | 951 default: |
958 GrCrash("Unknown coverage type."); | 952 GrCrash("Unknown coverage type."); |
959 } | 953 } |
960 } else { | 954 } else { |
961 sharedState->fConstAttribCoverageIndex = -1; | 955 sharedState->fConstAttribCoverageIndex = -1; |
962 } | 956 } |
963 } | 957 } |
964 | 958 |
965 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { | 959 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { |
966 const GrRenderTarget* rt = drawState.getRenderTarget(); | 960 const GrRenderTarget* rt = drawState.getRenderTarget(); |
967 SkISize size; | 961 SkISize size; |
968 size.set(rt->width(), rt->height()); | 962 size.set(rt->width(), rt->height()); |
969 | 963 |
970 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 964 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
971 if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fRTHeightUn
i && | 965 if (NULL != fNamedUniforms.fRTHeightUni && |
972 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { | 966 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { |
973 fUniformManager.set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size.f
Height)); | 967 fNamedUniforms.fRTHeightUni->set1f(fContext, SkIntToScalar(size.fHeight)
); |
974 } | 968 } |
975 | 969 |
976 if (fMatrixState.fRenderTargetOrigin != rt->origin() || | 970 if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
977 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) || | 971 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) || |
978 fMatrixState.fRenderTargetSize != size) { | 972 fMatrixState.fRenderTargetSize != size) { |
979 SkMatrix m; | 973 SkMatrix m; |
980 if (kBottomLeft_GrSurfaceOrigin == rt->origin()) { | 974 if (kBottomLeft_GrSurfaceOrigin == rt->origin()) { |
981 m.setAll( | 975 m.setAll( |
982 SkIntToScalar(2) / size.fWidth, 0, -SK_Scalar1, | 976 SkIntToScalar(2) / size.fWidth, 0, -SK_Scalar1, |
983 0,-SkIntToScalar(2) / size.fHeight, SK_Scalar1, | 977 0,-SkIntToScalar(2) / size.fHeight, SK_Scalar1, |
(...skipping 11 matching lines...) Expand all Loading... |
995 SkScalarToFloat(m[SkMatrix::kMScaleX]), | 989 SkScalarToFloat(m[SkMatrix::kMScaleX]), |
996 SkScalarToFloat(m[SkMatrix::kMSkewY]), | 990 SkScalarToFloat(m[SkMatrix::kMSkewY]), |
997 SkScalarToFloat(m[SkMatrix::kMPersp0]), | 991 SkScalarToFloat(m[SkMatrix::kMPersp0]), |
998 SkScalarToFloat(m[SkMatrix::kMSkewX]), | 992 SkScalarToFloat(m[SkMatrix::kMSkewX]), |
999 SkScalarToFloat(m[SkMatrix::kMScaleY]), | 993 SkScalarToFloat(m[SkMatrix::kMScaleY]), |
1000 SkScalarToFloat(m[SkMatrix::kMPersp1]), | 994 SkScalarToFloat(m[SkMatrix::kMPersp1]), |
1001 SkScalarToFloat(m[SkMatrix::kMTransX]), | 995 SkScalarToFloat(m[SkMatrix::kMTransX]), |
1002 SkScalarToFloat(m[SkMatrix::kMTransY]), | 996 SkScalarToFloat(m[SkMatrix::kMTransY]), |
1003 SkScalarToFloat(m[SkMatrix::kMPersp2]) | 997 SkScalarToFloat(m[SkMatrix::kMPersp2]) |
1004 }; | 998 }; |
1005 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 999 fNamedUniforms.fViewMatrixUni->setMatrix3f(fContext, mt); |
1006 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 1000 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
1007 fMatrixState.fRenderTargetSize = size; | 1001 fMatrixState.fRenderTargetSize = size; |
1008 fMatrixState.fRenderTargetOrigin = rt->origin(); | 1002 fMatrixState.fRenderTargetOrigin = rt->origin(); |
1009 } | 1003 } |
1010 } | 1004 } |
OLD | NEW |