Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: src/gpu/gl/GrGLProgram.cpp

Issue 23471008: Add a requiresVertexShader method to GrGLEffect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: brace formatting issue Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLShaderBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 439 }
440 440
441 return true; 441 return true;
442 } 442 }
443 443
444 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[], 444 bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
445 const GrEffectStage* coverageStages[]) { 445 const GrEffectStage* coverageStages[]) {
446 SkASSERT(0 == fProgramID); 446 SkASSERT(0 == fProgramID);
447 447
448 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); 448 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
449 bool hasExplicitLocalCoords = -1 != header.fLocalCoordAttributeIndex;
449 450
450 bool needsVertexShader = true; 451 // Get the coeffs for the Mode-based color filter, determine if color is nee ded.
452 SkXfermode::Coeff colorCoeff;
453 SkXfermode::Coeff filterColorCoeff;
454 SkAssertResult(
455 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte rXfermode),
456 &filterColorCoeff,
457 &colorCoeff));
458 bool needColor, needFilterColor;
459 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor );
451 460
452 GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, needsVert exShader); 461 // Create the GL effects.
462 bool hasVertexShaderEffects = false;
463
464 SkTArray<GrDrawEffect> colorDrawEffects(needColor ? fDesc.numColorEffects() : 0);
465 if (needColor) {
466 this->buildGLEffects(&GrGLProgram::fColorEffects, colorStages, fDesc.num ColorEffects(),
467 hasExplicitLocalCoords, &colorDrawEffects, &hasVert exShaderEffects);
468 }
469
470 SkTArray<GrDrawEffect> coverageDrawEffects(fDesc.numCoverageEffects());
471 this->buildGLEffects(&GrGLProgram::fCoverageEffects, coverageStages, fDesc.n umCoverageEffects(),
472 hasExplicitLocalCoords, &coverageDrawEffects, &hasVerte xShaderEffects);
473
474 GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, hasVertex ShaderEffects);
453 475
454 if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuild er()) { 476 if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuild er()) {
455 const char* viewMName; 477 const char* viewMName;
456 fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::k Vertex_Visibility, 478 fUniformHandles.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::k Vertex_Visibility,
457 kMat33f_GrSLType, "V iewM", &viewMName); 479 kMat33f_GrSLType, "V iewM", &viewMName);
458 480
459 vertexBuilder->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n" 481 vertexBuilder->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n"
460 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\ n", 482 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\ n",
461 viewMName, vertexBuilder->positionAttribute ().c_str()); 483 viewMName, vertexBuilder->positionAttribute ().c_str());
462 484
(...skipping 16 matching lines...) Expand all
479 declared_color_output_name(), 501 declared_color_output_name(),
480 &colorOutput); 502 &colorOutput);
481 if (isColorDeclared) { 503 if (isColorDeclared) {
482 builder.fsOutputAppend(colorOutput); 504 builder.fsOutputAppend(colorOutput);
483 } 505 }
484 506
485 // incoming color to current stage being processed. 507 // incoming color to current stage being processed.
486 SkString inColor; 508 SkString inColor;
487 GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor); 509 GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor);
488 510
489 // Get the coeffs for the Mode-based color filter, determine if color is nee ded.
490 SkXfermode::Coeff colorCoeff;
491 SkXfermode::Coeff filterColorCoeff;
492 SkAssertResult(
493 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilte rXfermode),
494 &filterColorCoeff,
495 &colorCoeff));
496 bool needColor, needFilterColor;
497 need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor );
498
499 // used in order for builder to return the per-stage uniform handles. 511 // used in order for builder to return the per-stage uniform handles.
500 typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr ; 512 typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr ;
501 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag eEffects()); 513 int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverag eEffects());
502 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt); 514 SkAutoTArray<UniHandleArrayPtr> effectUniformArrays(maxColorOrCovEffectCnt);
503 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt); 515 SkAutoTArray<GrGLEffect*> glEffects(maxColorOrCovEffectCnt);
504 516
505 if (needColor) { 517 if (needColor) {
506 for (int e = 0; e < fDesc.numColorEffects(); ++e) { 518 for (int e = 0; e < fDesc.numColorEffects(); ++e) {
519 glEffects[e] = fColorEffects[e].fGLEffect;
507 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis; 520 effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis;
508 } 521 }
509 522
510 builder.emitEffects(colorStages, 523 builder.emitEffects(glEffects.get(),
524 colorDrawEffects.begin(),
511 fDesc.effectKeys(), 525 fDesc.effectKeys(),
512 fDesc.numColorEffects(), 526 fDesc.numColorEffects(),
513 &inColor, 527 &inColor,
514 &knownColorValue, 528 &knownColorValue,
515 effectUniformArrays.get(), 529 effectUniformArrays.get());
516 glEffects.get());
517
518 for (int e = 0; e < fDesc.numColorEffects(); ++e) {
519 fColorEffects[e].fGLEffect = glEffects[e];
520 }
521 } 530 }
522 531
523 // Insert the color filter. This will soon be replaced by a color effect. 532 // Insert the color filter. This will soon be replaced by a color effect.
524 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) { 533 if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) {
525 const char* colorFilterColorUniName = NULL; 534 const char* colorFilterColorUniName = NULL;
526 fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder:: kFragment_Visibility, 535 fUniformHandles.fColorFilterUni = builder.addUniform(GrGLShaderBuilder:: kFragment_Visibility,
527 kVec4f_GrSLType, "F ilterColor", 536 kVec4f_GrSLType, "F ilterColor",
528 &colorFilterColorUn iName); 537 &colorFilterColorUn iName);
529 538
530 builder.fsCodeAppend("\tvec4 filteredColor;\n"); 539 builder.fsCodeAppend("\tvec4 filteredColor;\n");
(...skipping 10 matching lines...) Expand all
541 colorCoeff, colorFilterColorUniName, color); 550 colorCoeff, colorFilterColorUniName, color);
542 inColor = "filteredColor"; 551 inColor = "filteredColor";
543 } 552 }
544 553
545 /////////////////////////////////////////////////////////////////////////// 554 ///////////////////////////////////////////////////////////////////////////
546 // compute the partial coverage 555 // compute the partial coverage
547 SkString inCoverage; 556 SkString inCoverage;
548 GrSLConstantVec knownCoverageValue = this->genInputCoverage(&builder, &inCov erage); 557 GrSLConstantVec knownCoverageValue = this->genInputCoverage(&builder, &inCov erage);
549 558
550 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) { 559 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) {
560 glEffects[e] = fCoverageEffects[e].fGLEffect;
551 effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis; 561 effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis;
552 } 562 }
553 563
554 builder.emitEffects(coverageStages, 564 builder.emitEffects(glEffects.get(),
565 coverageDrawEffects.begin(),
555 fDesc.getEffectKeys() + fDesc.numColorEffects(), 566 fDesc.getEffectKeys() + fDesc.numColorEffects(),
556 fDesc.numCoverageEffects(), 567 fDesc.numCoverageEffects(),
557 &inCoverage, 568 &inCoverage,
558 &knownCoverageValue, 569 &knownCoverageValue,
559 effectUniformArrays.get(), 570 effectUniformArrays.get());
560 glEffects.get());
561 for (int e = 0; e < fDesc.numCoverageEffects(); ++e) {
562 fCoverageEffects[e].fGLEffect = glEffects[e];
563 }
564 571
565 // discard if coverage is zero 572 // discard if coverage is zero
566 if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageV alue) { 573 if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageV alue) {
567 if (kZeros_GrSLConstantVec == knownCoverageValue) { 574 if (kZeros_GrSLConstantVec == knownCoverageValue) {
568 // This is unfortunate. 575 // This is unfortunate.
569 builder.fsCodeAppend("\tdiscard;\n"); 576 builder.fsCodeAppend("\tdiscard;\n");
570 } else { 577 } else {
571 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n", 578 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n",
572 inCoverage.c_str()); 579 inCoverage.c_str());
573 } 580 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 fUniformHandles.fRTHeightUni = builder.getRTHeightUniform(); 689 fUniformHandles.fRTHeightUni = builder.getRTHeightUniform();
683 fUniformHandles.fDstCopyTopLeftUni = builder.getDstCopyTopLeftUniform(); 690 fUniformHandles.fDstCopyTopLeftUni = builder.getDstCopyTopLeftUniform();
684 fUniformHandles.fDstCopyScaleUni = builder.getDstCopyScaleUniform(); 691 fUniformHandles.fDstCopyScaleUni = builder.getDstCopyScaleUniform();
685 fUniformHandles.fDstCopySamplerUni = builder.getDstCopySamplerUniform(); 692 fUniformHandles.fDstCopySamplerUni = builder.getDstCopySamplerUniform();
686 // This must be called after we set fDstCopySamplerUni above. 693 // This must be called after we set fDstCopySamplerUni above.
687 this->initSamplerUniforms(); 694 this->initSamplerUniforms();
688 695
689 return true; 696 return true;
690 } 697 }
691 698
699 void GrGLProgram::buildGLEffects(SkTArray<EffectAndSamplers> GrGLProgram::* effe ctSet,
700 const GrEffectStage* stages[],
701 int count,
702 bool hasExplicitLocalCoords,
703 SkTArray<GrDrawEffect>* drawEffects,
704 bool* hasVertexShaderEffects) {
705 for (int e = 0; e < count; ++e) {
706 SkASSERT(NULL != stages[e] && NULL != stages[e]->getEffect());
707
708 const GrEffectStage& stage = *stages[e];
709 SkNEW_APPEND_TO_TARRAY(drawEffects, GrDrawEffect, (stage, hasExplicitLoc alCoords));
710
711 const GrDrawEffect& drawEffect = (*drawEffects)[e];
712 GrGLEffect* effect = (this->*effectSet)[e].fGLEffect =
713 (*stage.getEffect())->getFactory().createGLInstance(drawEffect);
714
715 if (!*hasVertexShaderEffects && effect->requiresVertexShader(drawEffect) ) {
716 *hasVertexShaderEffects = true;
717 }
718 }
719 }
720
692 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil der, 721 bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil der,
693 bool bindColorOut, 722 bool bindColorOut,
694 bool bindDualSrcOut) { 723 bool bindDualSrcOut) {
695 GL_CALL_RET(fProgramID, CreateProgram()); 724 GL_CALL_RET(fProgramID, CreateProgram());
696 if (!fProgramID) { 725 if (!fProgramID) {
697 return false; 726 return false;
698 } 727 }
699 728
700 if (fVShaderID) { 729 if (fVShaderID) {
701 GL_CALL(AttachShader(fProgramID, fVShaderID)); 730 GL_CALL(AttachShader(fProgramID, fVShaderID));
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 1012
984 fMatrixState.fViewMatrix = drawState.getViewMatrix(); 1013 fMatrixState.fViewMatrix = drawState.getViewMatrix();
985 fMatrixState.fRenderTargetSize = size; 1014 fMatrixState.fRenderTargetSize = size;
986 fMatrixState.fRenderTargetOrigin = rt->origin(); 1015 fMatrixState.fRenderTargetOrigin = rt->origin();
987 1016
988 GrGLfloat viewMatrix[3 * 3]; 1017 GrGLfloat viewMatrix[3 * 3];
989 fMatrixState.getGLMatrix<3>(viewMatrix); 1018 fMatrixState.getGLMatrix<3>(viewMatrix);
990 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); 1019 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix);
991 } 1020 }
992 } 1021 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698