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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 kVec2f_GrSLType, kDefault_GrSLP
recision, "Scale"); | 537 kVec2f_GrSLType, kDefault_GrSLP
recision, "Scale"); |
538 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); | 538 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); |
539 const char* dColor = "dColor"; | 539 const char* dColor = "dColor"; |
540 const char* cCoords = "cCoords"; | 540 const char* cCoords = "cCoords"; |
541 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use | 541 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use |
542 // a number smaller than that to approximate
0, but | 542 // a number smaller than that to approximate
0, but |
543 // leave room for 32-bit float GPU rounding e
rrors. | 543 // leave room for 32-bit float GPU rounding e
rrors. |
544 | 544 |
545 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 545 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
546 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); | 546 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); |
547 fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fCoords[0].c_str
(), | 547 fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fTransformedCoor
ds[0].c_str(), |
548 args.fCoords[0].getType()); | 548 args.fTransformedCoords[0].getType()); |
549 fragBuilder->codeAppend(";\n"); | 549 fragBuilder->codeAppend(";\n"); |
550 | 550 |
551 // Unpremultiply the displacement | 551 // Unpremultiply the displacement |
552 fragBuilder->codeAppendf( | 552 fragBuilder->codeAppendf( |
553 "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);"
, | 553 "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);"
, |
554 dColor, dColor, nearZero, dColor, dColor); | 554 dColor, dColor, nearZero, dColor, dColor); |
555 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); | 555 SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[1]); |
556 fragBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.", | 556 fragBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.", |
557 cCoords, coords2D.c_str(), scaleUni, dColor); | 557 cCoords, coords2D.c_str(), scaleUni, dColor); |
558 | 558 |
559 switch (displacementMap.xChannelSelector()) { | 559 switch (displacementMap.xChannelSelector()) { |
560 case SkDisplacementMapEffect::kR_ChannelSelectorType: | 560 case SkDisplacementMapEffect::kR_ChannelSelectorType: |
561 fragBuilder->codeAppend("r"); | 561 fragBuilder->codeAppend("r"); |
562 break; | 562 break; |
563 case SkDisplacementMapEffect::kG_ChannelSelectorType: | 563 case SkDisplacementMapEffect::kG_ChannelSelectorType: |
564 fragBuilder->codeAppend("g"); | 564 fragBuilder->codeAppend("g"); |
565 break; | 565 break; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 618 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
619 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 619 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
620 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 620 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
621 | 621 |
622 uint32_t xKey = displacementMap.xChannelSelector(); | 622 uint32_t xKey = displacementMap.xChannelSelector(); |
623 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 623 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
624 | 624 |
625 b->add32(xKey | yKey); | 625 b->add32(xKey | yKey); |
626 } | 626 } |
627 #endif | 627 #endif |
OLD | NEW |