tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 GrSingleTextureEffect_DEFINED |
| 9 | #define GrSingleTextureEffect_DEFINED |
| 10 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 11 | #include "GrEffect.h" |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 12 | #include "SkMatrix.h" |
bsalomon@google.com | 17fc651 | 2012-11-02 21:45:01 +0000 | [diff] [blame^] | 13 | #include "GrTexture.h" |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 14 | |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 15 | class GrGLSingleTextureEffect; |
| 16 | |
| 17 | /** |
bsalomon@google.com | 17fc651 | 2012-11-02 21:45:01 +0000 | [diff] [blame^] | 18 | * An effect that draws a single texture with a texture matrix; commonly used as a base class. The |
| 19 | * output color is the texture color is modulated against the input color. |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 20 | */ |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 21 | class GrSingleTextureEffect : public GrEffect { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 22 | |
| 23 | public: |
bsalomon@google.com | 17fc651 | 2012-11-02 21:45:01 +0000 | [diff] [blame^] | 24 | /** These three constructors assume an identity matrix. TODO: Remove these.*/ |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 25 | GrSingleTextureEffect(GrTexture* texture); /* unfiltered, clamp mode */ |
| 26 | GrSingleTextureEffect(GrTexture* texture, bool bilerp); /* clamp mode */ |
bsalomon@google.com | 115b06f | 2012-11-01 15:47:55 +0000 | [diff] [blame] | 27 | GrSingleTextureEffect(GrTexture* texture, const GrTextureParams&); |
bsalomon@google.com | c3a58f3 | 2012-11-01 15:40:47 +0000 | [diff] [blame] | 28 | |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 29 | /** These three constructors take an explicit matrix */ |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 30 | GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */ |
| 31 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */ |
| 32 | GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 33 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 34 | virtual ~GrSingleTextureEffect(); |
| 35 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 36 | virtual const GrTextureAccess& textureAccess(int index) const SK_OVERRIDE; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 37 | |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 38 | static const char* Name() { return "Single Texture"; } |
| 39 | |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 40 | const SkMatrix& getMatrix() const { return fMatrix; } |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 41 | |
bsalomon@google.com | 422e81a | 2012-10-25 14:11:03 +0000 | [diff] [blame] | 42 | typedef GrGLSingleTextureEffect GLEffect; |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 43 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 44 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 45 | |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 46 | virtual bool isEqual(const GrEffect& effect) const SK_OVERRIDE { |
| 47 | const GrSingleTextureEffect& ste = static_cast<const GrSingleTextureEffect&>(effect); |
| 48 | return INHERITED::isEqual(effect) && fMatrix.cheapEqualTo(ste.getMatrix()); |
| 49 | } |
bsalomon@google.com | 17fc651 | 2012-11-02 21:45:01 +0000 | [diff] [blame^] | 50 | |
| 51 | static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { |
| 52 | GrAssert(NULL != texture); |
| 53 | SkMatrix mat; |
| 54 | mat.setIDiv(texture->width(), texture->height()); |
| 55 | return mat; |
| 56 | } |
| 57 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 58 | private: |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 59 | GR_DECLARE_EFFECT_TEST; |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 60 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 61 | GrTextureAccess fTextureAccess; |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 62 | SkMatrix fMatrix; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 63 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 64 | typedef GrEffect INHERITED; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif |