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" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 89 |
90 void GrGLProgram::abandon() { | 90 void GrGLProgram::abandon() { |
91 fVShaderID = 0; | 91 fVShaderID = 0; |
92 fGShaderID = 0; | 92 fGShaderID = 0; |
93 fFShaderID = 0; | 93 fFShaderID = 0; |
94 fProgramID = 0; | 94 fProgramID = 0; |
95 } | 95 } |
96 | 96 |
97 void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, | 97 void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, |
98 GrBlendCoeff* dstCoeff) const { | 98 GrBlendCoeff* dstCoeff) const { |
99 switch (fDesc.fDualSrcOutput) { | 99 switch (fDesc.fCoverageOutput) { |
100 case GrGLProgramDesc::kNone_DualSrcOutput: | 100 case GrGLProgramDesc::kModulate_CoverageOutput: |
101 break; | 101 break; |
102 // the prog will write a coverage value to the secondary | 102 // The prog will write a coverage value to the secondary |
103 // output and the dst is blended by one minus that value. | 103 // output and the dst is blended by one minus that value. |
104 case GrGLProgramDesc::kCoverage_DualSrcOutput: | 104 case GrGLProgramDesc::kSecondaryCoverage_CoverageOutput: |
105 case GrGLProgramDesc::kCoverageISA_DualSrcOutput: | 105 case GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput: |
106 case GrGLProgramDesc::kCoverageISC_DualSrcOutput: | 106 case GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput: |
107 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 107 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
108 break; | 108 break; |
109 case GrGLProgramDesc::kCombineWithDst_CoverageOutput: | |
robertphillips
2013/04/18 22:02:03
rm trailing /?
bsalomon
2013/04/19 13:14:49
Done.
| |
110 // We should only have set this if the blend was specified as (1, 0) / | |
111 GrAssert(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds tCoeff); | |
112 break; | |
109 default: | 113 default: |
110 GrCrash("Unexpected dual source blend output"); | 114 GrCrash("Unexpected coverage output"); |
111 break; | 115 break; |
112 } | 116 } |
113 } | 117 } |
114 | 118 |
115 namespace { | 119 namespace { |
116 // given two blend coeffecients determine whether the src | 120 // given two blend coeffecients determine whether the src |
117 // and/or dst computation can be omitted. | 121 // and/or dst computation can be omitted. |
118 inline void need_blend_inputs(SkXfermode::Coeff srcCoeff, | 122 inline void need_blend_inputs(SkXfermode::Coeff srcCoeff, |
119 SkXfermode::Coeff dstCoeff, | 123 SkXfermode::Coeff dstCoeff, |
120 bool* needSrcValue, | 124 bool* needSrcValue, |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 if (c_PrintShaders) { | 414 if (c_PrintShaders) { |
411 GrPrintf(shader.c_str()); | 415 GrPrintf(shader.c_str()); |
412 GrPrintf("\n"); | 416 GrPrintf("\n"); |
413 } | 417 } |
414 if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader))) { | 418 if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader))) { |
415 return false; | 419 return false; |
416 } | 420 } |
417 | 421 |
418 return true; | 422 return true; |
419 } | 423 } |
420 | 424 |
robertphillips
2013/04/18 22:02:03
move into above namespace?
bsalomon
2013/04/19 13:14:49
Done.
| |
425 void expand_known_value4f(SkString* string, GrSLConstantVec vec) { | |
426 GrAssert(string->isEmpty() == (vec != kNone_GrSLConstantVec)); | |
427 switch (vec) { | |
428 case kNone_GrSLConstantVec: | |
429 break; | |
430 case kZeros_GrSLConstantVec: | |
431 *string = GrGLSLZerosVecf(4); | |
432 break; | |
433 case kOnes_GrSLConstantVec: | |
434 *string = GrGLSLOnesVecf(4); | |
435 break; | |
436 } | |
437 } | |
438 | |
421 bool GrGLProgram::genProgram(const GrEffectStage* stages[]) { | 439 bool GrGLProgram::genProgram(const GrEffectStage* stages[]) { |
422 GrAssert(0 == fProgramID); | 440 GrAssert(0 == fProgramID); |
423 | 441 |
424 GrGLShaderBuilder builder(fContext.info(), fUniformManager, fDesc); | 442 GrGLShaderBuilder builder(fContext.info(), fUniformManager, fDesc); |
425 | 443 |
426 // the dual source output has no canonical var name, have to | 444 // the dual source output has no canonical var name, have to |
427 // declare an output, which is incompatible with gl_FragColor/gl_FragData. | 445 // declare an output, which is incompatible with gl_FragColor/gl_FragData. |
428 bool dualSourceOutputWritten = false; | 446 bool dualSourceOutputWritten = false; |
429 | 447 |
430 GrGLShaderVar colorOutput; | 448 GrGLShaderVar colorOutput; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 if (fDesc.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageVa lue) { | 575 if (fDesc.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageVa lue) { |
558 if (kZeros_GrSLConstantVec == knownCoverageValue) { | 576 if (kZeros_GrSLConstantVec == knownCoverageValue) { |
559 // This is unfortunate. | 577 // This is unfortunate. |
560 builder.fsCodeAppend("\tdiscard;\n"); | 578 builder.fsCodeAppend("\tdiscard;\n"); |
561 } else { | 579 } else { |
562 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n", | 580 builder.fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\ t\tdiscard;\n\t}\n", |
563 inCoverage.c_str()); | 581 inCoverage.c_str()); |
564 } | 582 } |
565 } | 583 } |
566 | 584 |
567 if (GrGLProgramDesc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) { | 585 GrGLProgramDesc::CoverageOutput coverageOutput = |
586 static_cast<GrGLProgramDesc::CoverageOutput>(fDesc.fCoverageOutput); | |
587 if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(coverageOutput)) { | |
568 builder.fFSOutputs.push_back().set(kVec4f_GrSLType, | 588 builder.fFSOutputs.push_back().set(kVec4f_GrSLType, |
569 GrGLShaderVar::kOut_TypeModifier, | 589 GrGLShaderVar::kOut_TypeModifier, |
570 dual_source_output_name()); | 590 dual_source_output_name()); |
571 // default coeff to ones for kCoverage_DualSrcOutput | 591 // default coeff to ones for kCoverage_DualSrcOutput |
572 SkString coeff; | 592 SkString coeff; |
573 GrSLConstantVec knownCoeffValue = kOnes_GrSLConstantVec; | 593 GrSLConstantVec knownCoeffValue = kOnes_GrSLConstantVec; |
robertphillips
2013/04/18 22:02:03
Why not use coverageOutput here rather than fDesc.
| |
574 if (GrGLProgramDesc::kCoverageISA_DualSrcOutput == fDesc.fDualSrcOutput) { | 594 if (GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput == fDesc.fCove rageOutput) { |
575 // Get (1-A) into coeff | 595 // Get (1-A) into coeff |
576 SkString inColorAlpha; | 596 SkString inColorAlpha; |
577 GrGLSLGetComponent4f(&inColorAlpha, | 597 GrGLSLGetComponent4f(&inColorAlpha, |
578 inColor.c_str(), | 598 inColor.c_str(), |
579 kA_GrColorComponentFlag, | 599 kA_GrColorComponentFlag, |
580 knownColorValue, | 600 knownColorValue, |
581 true); | 601 true); |
582 knownCoeffValue = GrGLSLSubtractf<1>(&coeff, | 602 knownCoeffValue = GrGLSLSubtractf<1>(&coeff, |
583 NULL, | 603 NULL, |
584 inColorAlpha.c_str(), | 604 inColorAlpha.c_str(), |
585 kOnes_GrSLConstantVec, | 605 kOnes_GrSLConstantVec, |
586 knownColorValue, | 606 knownColorValue, |
587 true); | 607 true); |
588 } else if (GrGLProgramDesc::kCoverageISC_DualSrcOutput == fDesc.fDualSrc Output) { | 608 } else if (GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput == cove rageOutput) { |
589 // Get (1-RGBA) into coeff | 609 // Get (1-RGBA) into coeff |
590 knownCoeffValue = GrGLSLSubtractf<4>(&coeff, | 610 knownCoeffValue = GrGLSLSubtractf<4>(&coeff, |
591 NULL, | 611 NULL, |
592 inColor.c_str(), | 612 inColor.c_str(), |
593 kOnes_GrSLConstantVec, | 613 kOnes_GrSLConstantVec, |
594 knownColorValue, | 614 knownColorValue, |
595 true); | 615 true); |
596 } | 616 } |
597 // Get coeff * coverage into modulate and then write that to the dual so urce output. | 617 // Get coeff * coverage into modulate and then write that to the dual so urce output. |
598 SkString modulate; | 618 SkString modulate; |
599 GrGLSLModulatef<4>(&modulate, | 619 GrGLSLModulatef<4>(&modulate, |
600 coeff.c_str(), | 620 coeff.c_str(), |
601 inCoverage.c_str(), | 621 inCoverage.c_str(), |
602 knownCoeffValue, | 622 knownCoeffValue, |
603 knownCoverageValue, | 623 knownCoverageValue, |
604 false); | 624 false); |
605 builder.fsCodeAppendf("\t%s = %s;\n", dual_source_output_name(), modulat e.c_str()); | 625 builder.fsCodeAppendf("\t%s = %s;\n", dual_source_output_name(), modulat e.c_str()); |
606 dualSourceOutputWritten = true; | 626 dualSourceOutputWritten = true; |
607 } | 627 } |
608 | 628 |
609 /////////////////////////////////////////////////////////////////////////// | 629 /////////////////////////////////////////////////////////////////////////// |
610 // combine color and coverage as frag color | 630 // combine color and coverage as frag color |
611 | 631 |
robertphillips
2013/04/18 22:02:03
Add quotes ... "color * coverage"?
bsalomon
2013/04/19 13:14:49
Done.
| |
612 // Get color * coverage into modulate and write that to frag shader's output . | 632 // Get color * coverage into fragColor |
613 SkString modulate; | 633 SkString fragColor; |
614 GrGLSLModulatef<4>(&modulate, | 634 GrSLConstantVec knownFragColorValue = GrGLSLModulatef<4>(&fragColor, |
615 inColor.c_str(), | 635 inColor.c_str(), |
616 inCoverage.c_str(), | 636 inCoverage.c_str(), |
617 knownColorValue, | 637 knownColorValue, |
618 knownCoverageValue, | 638 knownCoverageValue, |
619 false); | 639 true); |
robertphillips
2013/04/18 22:02:03
"+(1-coverage)dst"?
bsalomon
2013/04/19 13:14:49
Done.
| |
620 builder.fsCodeAppendf("\t%s = %s;\n", colorOutput.getName().c_str(), modulat e.c_str()); | 640 // Now tack on +(1-coverage)dst onto the frag color if we were asked to do s o. |
641 if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == coverageOutput) { | |
642 SkString dstCoeff; | |
643 GrSLConstantVec knownDstCoeffValue = GrGLSLSubtractf<4>(&dstCoeff, | |
644 NULL, | |
645 inCoverage.c_str (), | |
646 kOnes_GrSLConsta ntVec, | |
647 knownCoverageVal ue, | |
robertphillips
2013/04/18 22:02:03
indent on true?
bsalomon
2013/04/19 13:14:49
Done.
| |
648 true); | |
649 SkString dstContribution; | |
650 GrSLConstantVec knownDstContributionValue = GrGLSLModulatef<4>(&dstContr ibution, | |
651 dstCoeff. c_str(), | |
652 builder.d stColor(), | |
653 knownDstC oeffValue, | |
654 kNone_GrS LConstantVec, | |
655 true); | |
656 SkString oldFragColor = fragColor; | |
657 fragColor.reset(); | |
658 GrGLSLAddf<4>(&fragColor, | |
659 oldFragColor.c_str(), | |
660 dstContribution.c_str(), | |
661 knownFragColorValue, | |
662 knownDstContributionValue, | |
663 false); | |
664 } else { | |
665 expand_known_value4f(&fragColor, knownFragColorValue); | |
666 } | |
667 builder.fsCodeAppendf("\t%s = %s;\n", colorOutput.getName().c_str(), fragCol or.c_str()); | |
621 | 668 |
622 /////////////////////////////////////////////////////////////////////////// | 669 /////////////////////////////////////////////////////////////////////////// |
623 // insert GS | 670 // insert GS |
624 #if GR_DEBUG | 671 #if GR_DEBUG |
625 this->genGeometryShader(&builder); | 672 this->genGeometryShader(&builder); |
626 #endif | 673 #endif |
627 | 674 |
628 /////////////////////////////////////////////////////////////////////////// | 675 /////////////////////////////////////////////////////////////////////////// |
629 // compile and setup attribs and unis | 676 // compile and setup attribs and unis |
630 | 677 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 SkScalarToFloat(m[SkMatrix::kMTransX]), | 982 SkScalarToFloat(m[SkMatrix::kMTransX]), |
936 SkScalarToFloat(m[SkMatrix::kMTransY]), | 983 SkScalarToFloat(m[SkMatrix::kMTransY]), |
937 SkScalarToFloat(m[SkMatrix::kMPersp2]) | 984 SkScalarToFloat(m[SkMatrix::kMPersp2]) |
938 }; | 985 }; |
939 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 986 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); |
940 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 987 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
941 fMatrixState.fRenderTargetSize = size; | 988 fMatrixState.fRenderTargetSize = size; |
942 fMatrixState.fRenderTargetOrigin = rt->origin(); | 989 fMatrixState.fRenderTargetOrigin = rt->origin(); |
943 } | 990 } |
944 } | 991 } |
OLD | NEW |