blob: b732913c38774c6553c72f2cbec92b0e0a909f81 [file] [log] [blame]
tomhudson@google.comd0c1a062012-07-12 17:23:52 +00001/*
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.coma469c282012-10-24 18:28:34 +000011#include "GrEffect.h"
bsalomon@google.comb9086a02012-11-01 18:02:54 +000012#include "SkMatrix.h"
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000013
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000014class GrGLSingleTextureEffect;
bsalomon@google.com34cccde2013-01-04 18:34:30 +000015class GrTexture;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000016
17/**
bsalomon@google.com17fc6512012-11-02 21:45:01 +000018 * 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.comaa72eab2012-07-19 18:01:07 +000020 */
bsalomon@google.coma469c282012-10-24 18:28:34 +000021class GrSingleTextureEffect : public GrEffect {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000022
23public:
bsalomon@google.com17fc6512012-11-02 21:45:01 +000024 /** These three constructors assume an identity matrix. TODO: Remove these.*/
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000025 GrSingleTextureEffect(GrTexture* texture); /* unfiltered, clamp mode */
26 GrSingleTextureEffect(GrTexture* texture, bool bilerp); /* clamp mode */
bsalomon@google.com115b06f2012-11-01 15:47:55 +000027 GrSingleTextureEffect(GrTexture* texture, const GrTextureParams&);
bsalomon@google.comc3a58f32012-11-01 15:40:47 +000028
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000029 /** These three constructors take an explicit matrix */
bsalomon@google.comb9086a02012-11-01 18:02:54 +000030 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.comd8b5fac2012-11-01 17:02:46 +000033
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000034 virtual ~GrSingleTextureEffect();
35
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000036 static const char* Name() { return "Single Texture"; }
37
bsalomon@google.com371e1052013-01-11 21:08:55 +000038 /** Note that if this class is sub-classed, the subclass may have to override this function.
39 */
40 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
41
bsalomon@google.comb9086a02012-11-01 18:02:54 +000042 const SkMatrix& getMatrix() const { return fMatrix; }
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000043
bsalomon@google.com422e81a2012-10-25 14:11:03 +000044 typedef GrGLSingleTextureEffect GLEffect;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000045
bsalomon@google.com396e61f2012-10-25 19:00:29 +000046 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000047
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000048 virtual bool isEqual(const GrEffect& effect) const SK_OVERRIDE {
49 const GrSingleTextureEffect& ste = static_cast<const GrSingleTextureEffect&>(effect);
50 return INHERITED::isEqual(effect) && fMatrix.cheapEqualTo(ste.getMatrix());
51 }
bsalomon@google.com17fc6512012-11-02 21:45:01 +000052
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000053private:
bsalomon@google.comf271cc72012-10-24 19:35:13 +000054 GR_DECLARE_EFFECT_TEST;
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000055
bsalomon@google.com6d003d12012-09-11 15:45:20 +000056 GrTextureAccess fTextureAccess;
bsalomon@google.comb9086a02012-11-01 18:02:54 +000057 SkMatrix fMatrix;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000058
bsalomon@google.coma469c282012-10-24 18:28:34 +000059 typedef GrEffect INHERITED;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000060};
61
62#endif