| 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 "SkFlattenableBuffers.h" | 9 #include "SkFlattenableBuffers.h" |
| 10 #include "SkUnPreMultiply.h" | 10 #include "SkUnPreMultiply.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 394 |
| 395 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { | 395 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { |
| 396 } | 396 } |
| 397 | 397 |
| 398 void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder, | 398 void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder, |
| 399 const GrDrawEffect&, | 399 const GrDrawEffect&, |
| 400 EffectKey key, | 400 EffectKey key, |
| 401 const char* outputColor, | 401 const char* outputColor, |
| 402 const char* inputColor, | 402 const char* inputColor, |
| 403 const TextureSamplerArray& samplers) { | 403 const TextureSamplerArray& samplers) { |
| 404 sk_ignore_unused_variable(inputColor); |
| 405 |
| 404 fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 406 fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| 405 kVec2f_GrSLType, "Scale"); | 407 kVec2f_GrSLType, "Scale"); |
| 406 const char* scaleUni = builder->getUniformCStr(fScaleUni); | 408 const char* scaleUni = builder->getUniformCStr(fScaleUni); |
| 407 | 409 |
| 408 const char* dCoordsIn; | 410 const char* dCoordsIn; |
| 409 GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode( | 411 GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode( |
| 410 builder, key, &dCoordsIn, NULL, "DISPL"); | 412 builder, key, &dCoordsIn, NULL, "DISPL"); |
| 411 const char* cCoordsIn; | 413 const char* cCoordsIn; |
| 412 GrSLType cCoordsType = fColorEffectMatrix.emitCode( | 414 GrSLType cCoordsType = fColorEffectMatrix.emitCode( |
| 413 builder, key, &cCoordsIn, NULL, "COLOR"); | 415 builder, key, &cCoordsIn, NULL, "COLOR"); |
| 414 | 416 |
| 415 const char* dColor = "dColor"; | 417 const char* dColor = "dColor"; |
| 416 const char* cCoords = "cCoords"; | 418 const char* cCoords = "cCoords"; |
| 419 const char* outOfBounds = "outOfBounds"; |
| 417 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use | 420 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use |
| 418 // a number smaller than that to approximate
0, but | 421 // a number smaller than that to approximate
0, but |
| 419 // leave room for 32-bit float GPU rounding e
rrors. | 422 // leave room for 32-bit float GPU rounding e
rrors. |
| 420 | 423 |
| 421 builder->fsCodeAppendf("\t\tvec4 %s = ", dColor); | 424 builder->fsCodeAppendf("\t\tvec4 %s = ", dColor); |
| 422 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, | 425 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, |
| 423 samplers[0], | 426 samplers[0], |
| 424 dCoordsIn, | 427 dCoordsIn, |
| 425 dCoordsType); | 428 dCoordsType); |
| 426 builder->fsCodeAppend(";\n"); | 429 builder->fsCodeAppend(";\n"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 break; | 468 break; |
| 466 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType: | 469 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType: |
| 467 default: | 470 default: |
| 468 SkASSERT(!"Unknown Y channel selector"); | 471 SkASSERT(!"Unknown Y channel selector"); |
| 469 } | 472 } |
| 470 builder->fsCodeAppend("-vec2(0.5));\t\t"); | 473 builder->fsCodeAppend("-vec2(0.5));\t\t"); |
| 471 | 474 |
| 472 // FIXME : This can be achieved with a "clamp to border" texture repeat mode
and | 475 // FIXME : This can be achieved with a "clamp to border" texture repeat mode
and |
| 473 // a 0 border color instead of computing if cCoords is out of bounds
here. | 476 // a 0 border color instead of computing if cCoords is out of bounds
here. |
| 474 builder->fsCodeAppendf( | 477 builder->fsCodeAppendf( |
| 475 "%s = any(greaterThan(vec4(vec2(0.0), %s), vec4(%s, vec2(1.0)))) ? vec4(
0.0) : ", | 478 "bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0);
\t\t", |
| 476 outputColor, cCoords, cCoords); | 479 outOfBounds, cCoords, cCoords, cCoords, cCoords); |
| 480 builder->fsCodeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds); |
| 477 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, | 481 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, |
| 478 samplers[1], | 482 samplers[1], |
| 479 cCoords, | 483 cCoords, |
| 480 cCoordsType); | 484 cCoordsType); |
| 481 builder->fsCodeAppend(";\n"); | 485 builder->fsCodeAppend(";\n"); |
| 482 } | 486 } |
| 483 | 487 |
| 484 void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, | 488 void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, |
| 485 const GrDrawEffect& drawEffect) { | 489 const GrDrawEffect& drawEffect) { |
| 486 const GrDisplacementMapEffect& displacementMap = | 490 const GrDisplacementMapEffect& displacementMap = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 colorTex); | 526 colorTex); |
| 523 | 527 |
| 524 colorKey <<= GrGLEffectMatrix::kKeyBits; | 528 colorKey <<= GrGLEffectMatrix::kKeyBits; |
| 525 EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix
::kKeyBits); | 529 EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix
::kKeyBits); |
| 526 EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix
::kKeyBits + | 530 EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix
::kKeyBits + |
| 527 SkDisplacementMapEff
ect::kKeyBits); | 531 SkDisplacementMapEff
ect::kKeyBits); |
| 528 | 532 |
| 529 return xKey | yKey | displKey | colorKey; | 533 return xKey | yKey | displKey | colorKey; |
| 530 } | 534 } |
| 531 #endif | 535 #endif |
| OLD | NEW |