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 | |
| 13 | class GrGLSimpleTextureEffect; |
| 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 */ |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 26 | static GrEffectRef* Create(GrTexture* tex, |
| 27 | const SkMatrix& matrix, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 28 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
| 29 | AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, GrTextureParams::kNone_FilterMode, coordSet))); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 30 | return CreateEffectRef(effect); |
| 31 | } |
| 32 | |
| 33 | /* clamp mode */ |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 34 | static GrEffectRef* Create(GrTexture* tex, |
| 35 | const SkMatrix& matrix, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 36 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 37 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 38 | AutoEffectUnref effect( |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 39 | SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordSet))); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 40 | return CreateEffectRef(effect); |
| 41 | } |
| 42 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 43 | static GrEffectRef* Create(GrTexture* tex, |
| 44 | const SkMatrix& matrix, |
| 45 | const GrTextureParams& p, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 46 | GrCoordSet coordSet = kLocal_GrCoordSet) { |
| 47 | AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordSet))); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 48 | return CreateEffectRef(effect); |
| 49 | } |
| 50 | |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 51 | virtual ~GrSimpleTextureEffect() {} |
| 52 | |
| 53 | static const char* Name() { return "Texture"; } |
| 54 | |
| 55 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| 56 | |
| 57 | typedef GrGLSimpleTextureEffect GLEffect; |
| 58 | |
| 59 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 60 | |
| 61 | private: |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 62 | GrSimpleTextureEffect(GrTexture* texture, |
| 63 | const SkMatrix& matrix, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 64 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 65 | GrCoordSet coordSet) |
| 66 | : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | GrSimpleTextureEffect(GrTexture* texture, |
| 70 | const SkMatrix& matrix, |
| 71 | const GrTextureParams& params, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 72 | GrCoordSet coordSet) |
| 73 | : GrSingleTextureEffect(texture, matrix, params, coordSet) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 74 | } |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 75 | |
bsalomon@google.com | 8a252f7 | 2013-01-22 20:35:13 +0000 | [diff] [blame] | 76 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 77 | const GrSimpleTextureEffect& ste = CastEffect<GrSimpleTextureEffect>(other); |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 78 | return this->hasSameTextureParamsMatrixAndSourceCoords(ste); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | GR_DECLARE_EFFECT_TEST; |
| 82 | |
| 83 | typedef GrSingleTextureEffect INHERITED; |
| 84 | }; |
| 85 | |
| 86 | #endif |