| 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 #include "SkDevice.h" | 9 #include "SkDevice.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 546 |
| 547 fScaleUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, | 547 fScaleUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, |
| 548 kVec2f_GrSLType, kDefault_GrSLP
recision, "Scale"); | 548 kVec2f_GrSLType, kDefault_GrSLP
recision, "Scale"); |
| 549 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); | 549 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); |
| 550 const char* dColor = "dColor"; | 550 const char* dColor = "dColor"; |
| 551 const char* cCoords = "cCoords"; | 551 const char* cCoords = "cCoords"; |
| 552 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use | 552 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use |
| 553 // a number smaller than that to approximate
0, but | 553 // a number smaller than that to approximate
0, but |
| 554 // leave room for 32-bit float GPU rounding e
rrors. | 554 // leave room for 32-bit float GPU rounding e
rrors. |
| 555 | 555 |
| 556 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 556 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 557 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); | 557 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); |
| 558 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(), | 558 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(), |
| 559 args.fCoords[0].getType()); | 559 args.fCoords[0].getType()); |
| 560 fragBuilder->codeAppend(";\n"); | 560 fragBuilder->codeAppend(";\n"); |
| 561 | 561 |
| 562 // Unpremultiply the displacement | 562 // Unpremultiply the displacement |
| 563 fragBuilder->codeAppendf( | 563 fragBuilder->codeAppendf( |
| 564 "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);"
, | 564 "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);"
, |
| 565 dColor, dColor, nearZero, dColor, dColor); | 565 dColor, dColor, nearZero, dColor, dColor); |
| 566 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); | 566 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 630 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
| 631 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 631 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 632 | 632 |
| 633 uint32_t xKey = displacementMap.xChannelSelector(); | 633 uint32_t xKey = displacementMap.xChannelSelector(); |
| 634 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 634 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 635 | 635 |
| 636 b->add32(xKey | yKey); | 636 b->add32(xKey | yKey); |
| 637 } | 637 } |
| 638 #endif | 638 #endif |
| 639 | 639 |
| OLD | NEW |