OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkError.h" | 8 #include "SkError.h" |
9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
10 #include "SkLightingShader.h" | 10 #include "SkLightingShader.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 378 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
379 #include "SkGr.h" | 379 #include "SkGr.h" |
380 #endif | 380 #endif |
381 | 381 |
382 class NormalBevelFP : public GrFragmentProcessor { | 382 class NormalBevelFP : public GrFragmentProcessor { |
383 public: | 383 public: |
384 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh
t) | 384 NormalBevelFP(SkNormalSource::BevelType type, SkScalar width, SkScalar heigh
t) |
385 : fType(type) | 385 : fType(type) |
386 , fWidth(width) | 386 , fWidth(width) |
387 , fHeight(height) { | 387 , fHeight(height) { |
| 388 fUsesDistanceVectorField = true; |
| 389 |
388 this->initClassID<NormalBevelFP>(); | 390 this->initClassID<NormalBevelFP>(); |
389 } | 391 } |
390 | 392 |
391 class GLSLNormalBevelFP : public GrGLSLFragmentProcessor { | 393 class GLSLNormalBevelFP : public GrGLSLFragmentProcessor { |
392 public: | 394 public: |
393 GLSLNormalBevelFP() {} | 395 GLSLNormalBevelFP() {} |
394 | 396 |
395 void emitCode(EmitArgs& args) override { | 397 void emitCode(EmitArgs& args) override { |
396 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 398 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
397 | 399 |
398 fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor
); | 400 fragBuilder->codeAppendf("if (%s == vec2(0.0, 0.0)) {", |
| 401 fragBuilder->distanceVectorName()); |
| 402 fragBuilder->codeAppendf(" %s = normalize(vec4(0.0, 0.0, 1.0, 0.0
));", |
| 403 args.fOutputColor); |
| 404 fragBuilder->codeAppend( "} else {"); |
| 405 // TODO (dvonbeck): emit normals according to bevel type and distanc
e vector |
| 406 fragBuilder->codeAppendf(" %s = normalize(vec4(0.0, 0.0, 1.0, 0.0
));", |
| 407 args.fOutputColor); |
| 408 fragBuilder->codeAppend( "}"); |
399 } | 409 } |
400 | 410 |
401 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 411 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
402 GrProcessorKeyBuilder* b) { | 412 GrProcessorKeyBuilder* b) { |
403 b->add32(0x0); | 413 b->add32(0x0); |
404 } | 414 } |
405 | 415 |
406 protected: | 416 protected: |
407 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override { | 417 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override { |
408 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); | 418 const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 //////////////////////////////////////////////////////////////////////////// | 516 //////////////////////////////////////////////////////////////////////////// |
507 | 517 |
508 //////////////////////////////////////////////////////////////////////////// | 518 //////////////////////////////////////////////////////////////////////////// |
509 | 519 |
510 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) | 520 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) |
511 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) | 521 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) |
512 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalBevelSourceImpl) | 522 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalBevelSourceImpl) |
513 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 523 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
514 | 524 |
515 //////////////////////////////////////////////////////////////////////////// | 525 //////////////////////////////////////////////////////////////////////////// |
OLD | NEW |