OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkDisplacementMapEffect.h" | 8 #include "SkDisplacementMapEffect.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 kVec2f_GrSLType, kDefault_GrSLP
recision, "Scale"); | 544 kVec2f_GrSLType, kDefault_GrSLP
recision, "Scale"); |
545 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); | 545 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); |
546 const char* dColor = "dColor"; | 546 const char* dColor = "dColor"; |
547 const char* cCoords = "cCoords"; | 547 const char* cCoords = "cCoords"; |
548 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use | 548 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use |
549 // a number smaller than that to approximate
0, but | 549 // a number smaller than that to approximate
0, but |
550 // leave room for 32-bit float GPU rounding e
rrors. | 550 // leave room for 32-bit float GPU rounding e
rrors. |
551 | 551 |
552 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 552 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
553 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); | 553 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); |
554 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(), | 554 fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fCoords[0].c_str
(), |
555 args.fCoords[0].getType()); | 555 args.fCoords[0].getType()); |
556 fragBuilder->codeAppend(";\n"); | 556 fragBuilder->codeAppend(";\n"); |
557 | 557 |
558 // Unpremultiply the displacement | 558 // Unpremultiply the displacement |
559 fragBuilder->codeAppendf( | 559 fragBuilder->codeAppendf( |
560 "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);"
, | 560 "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);"
, |
561 dColor, dColor, nearZero, dColor, dColor); | 561 dColor, dColor, nearZero, dColor, dColor); |
562 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); | 562 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); |
563 fragBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.", | 563 fragBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.", |
564 cCoords, coords2D.c_str(), scaleUni, dColor); | 564 cCoords, coords2D.c_str(), scaleUni, dColor); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 SkDEBUGFAIL("Unknown Y channel selector"); | 599 SkDEBUGFAIL("Unknown Y channel selector"); |
600 } | 600 } |
601 fragBuilder->codeAppend("-vec2(0.5));\t\t"); | 601 fragBuilder->codeAppend("-vec2(0.5));\t\t"); |
602 | 602 |
603 fGLDomain.sampleTexture(fragBuilder, | 603 fGLDomain.sampleTexture(fragBuilder, |
604 args.fUniformHandler, | 604 args.fUniformHandler, |
605 args.fGLSLCaps, | 605 args.fGLSLCaps, |
606 domain, | 606 domain, |
607 args.fOutputColor, | 607 args.fOutputColor, |
608 SkString(cCoords), | 608 SkString(cCoords), |
609 args.fSamplers[1]); | 609 args.fTexSamplers[1]); |
610 fragBuilder->codeAppend(";\n"); | 610 fragBuilder->codeAppend(";\n"); |
611 } | 611 } |
612 | 612 |
613 void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 613 void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
614 const GrProcessor& proc) { | 614 const GrProcessor& proc) { |
615 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 615 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
616 GrTexture* colorTex = displacementMap.texture(1); | 616 GrTexture* colorTex = displacementMap.texture(1); |
617 SkScalar scaleX = displacementMap.scale().fX / colorTex->width(); | 617 SkScalar scaleX = displacementMap.scale().fX / colorTex->width(); |
618 SkScalar scaleY = displacementMap.scale().fY / colorTex->height(); | 618 SkScalar scaleY = displacementMap.scale().fY / colorTex->height(); |
619 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), | 619 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), |
620 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? | 620 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? |
621 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); | 621 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); |
622 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); | 622 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); |
623 } | 623 } |
624 | 624 |
625 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 625 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
626 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 626 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
627 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 627 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
628 | 628 |
629 uint32_t xKey = displacementMap.xChannelSelector(); | 629 uint32_t xKey = displacementMap.xChannelSelector(); |
630 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 630 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
631 | 631 |
632 b->add32(xKey | yKey); | 632 b->add32(xKey | yKey); |
633 } | 633 } |
634 #endif | 634 #endif |
OLD | NEW |