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 |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 18 | * local coords or device space coords as input texture coords. The input coords may be transformed |
| 19 | * by a matrix. |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 20 | */ |
| 21 | class GrSimpleTextureEffect : public GrSingleTextureEffect { |
| 22 | public: |
| 23 | /* unfiltered, clamp mode */ |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 24 | static const GrFragmentProcessor* Create(GrTexture* tex, |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 25 | const SkMatrix& matrix, |
| 26 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 27 | return new GrSimpleTextureEffect(tex, matrix, GrTextureParams::kNone_FilterMode, coordSet); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /* clamp mode */ |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 31 | static GrFragmentProcessor* Create(GrTexture* tex, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 32 | const SkMatrix& matrix, |
| 33 | GrTextureParams::FilterMode filterMode, |
| 34 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 35 | return new GrSimpleTextureEffect(tex, matrix, filterMode, coordSet); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 36 | } |
| 37 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 38 | static GrFragmentProcessor* Create(GrTexture* tex, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 39 | const SkMatrix& matrix, |
| 40 | const GrTextureParams& p, |
| 41 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 42 | return new GrSimpleTextureEffect(tex, matrix, p, coordSet); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 43 | } |
| 44 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 45 | virtual ~GrSimpleTextureEffect() {} |
| 46 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 47 | const char* name() const override { return "SimpleTexture"; } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 48 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 49 | private: |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 50 | GrSimpleTextureEffect(GrTexture* texture, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 51 | const SkMatrix& matrix, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 52 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 53 | GrCoordSet coordSet) |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 54 | : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 55 | this->initClassID<GrSimpleTextureEffect>(); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 56 | } |
| 57 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 58 | GrSimpleTextureEffect(GrTexture* texture, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 59 | const SkMatrix& matrix, |
| 60 | const GrTextureParams& params, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 61 | GrCoordSet coordSet) |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 62 | : GrSingleTextureEffect(texture, matrix, params, coordSet) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 63 | this->initClassID<GrSimpleTextureEffect>(); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 64 | } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 65 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 66 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 67 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 68 | void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 69 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 70 | bool onIsEqual(const GrFragmentProcessor& other) const override { return true; } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 71 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 72 | void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 73 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 74 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 75 | |
| 76 | typedef GrSingleTextureEffect INHERITED; |
| 77 | }; |
| 78 | |
| 79 | #endif |