bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrSimpleTextureEffect_DEFINED |
| 9 | #define GrSimpleTextureEffect_DEFINED |
| 10 | |
| 11 | #include "GrSingleTextureEffect.h" |
| 12 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 13 | class GrInvariantOutput; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * The output color of this effect is a modulation of the input color and a sample from a texture. |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 17 | * It allows explicit specification of the filtering and wrap modes (GrTextureParams). It can use |
| 18 | * local coords, positions, or a custom vertex attribute as input texture coords. The input coords |
| 19 | * can have a matrix applied in the VS in both the local and position cases but not with a custom |
| 20 | * attribute coords at this time. It will add a varying to input interpolate texture coords to the |
| 21 | * FS. |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 22 | */ |
| 23 | class GrSimpleTextureEffect : public GrSingleTextureEffect { |
| 24 | public: |
| 25 | /* unfiltered, clamp mode */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 26 | static GrFragmentProcessor* Create(GrTexture* tex, |
| 27 | const SkMatrix& matrix, |
| 28 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 29 | return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, GrTextureParams::kNone_FilterMode, |
| 30 | coordSet)); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | /* clamp mode */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 34 | static GrFragmentProcessor* Create(GrTexture* tex, |
| 35 | const SkMatrix& matrix, |
| 36 | GrTextureParams::FilterMode filterMode, |
| 37 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 38 | return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordSet)); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 39 | } |
| 40 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 41 | static GrFragmentProcessor* Create(GrTexture* tex, |
| 42 | const SkMatrix& matrix, |
| 43 | const GrTextureParams& p, |
| 44 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 45 | return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordSet)); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 46 | } |
| 47 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 48 | virtual ~GrSimpleTextureEffect() {} |
| 49 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 50 | const char* name() const SK_OVERRIDE { return "SimpleTexture"; } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 51 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 52 | void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const SK_OVERRIDE; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 53 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 54 | GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 55 | |
| 56 | private: |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 57 | GrSimpleTextureEffect(GrTexture* texture, |
| 58 | const SkMatrix& matrix, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 59 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 60 | GrCoordSet coordSet) |
| 61 | : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 62 | this->initClassID<GrSimpleTextureEffect>(); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | GrSimpleTextureEffect(GrTexture* texture, |
| 66 | const SkMatrix& matrix, |
| 67 | const GrTextureParams& params, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 68 | GrCoordSet coordSet) |
| 69 | : GrSingleTextureEffect(texture, matrix, params, coordSet) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 70 | this->initClassID<GrSimpleTextureEffect>(); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 71 | } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 72 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 73 | bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { return true; } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 74 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 75 | void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 76 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 77 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 78 | |
| 79 | typedef GrSingleTextureEffect INHERITED; |
| 80 | }; |
| 81 | |
| 82 | #endif |