blob: 709d3dcd2b6278b8bf796c6848234b71392f25d4 [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"
bsalomon@google.com17fc6512012-11-02 21:45:01 +000013#include "GrTexture.h"
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000014
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000015class GrGLSingleTextureEffect;
16
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
bsalomon@google.com6d003d12012-09-11 15:45:20 +000036 virtual const GrTextureAccess& textureAccess(int index) const SK_OVERRIDE;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000037
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000038 static const char* Name() { return "Single Texture"; }
39
bsalomon@google.comb9086a02012-11-01 18:02:54 +000040 const SkMatrix& getMatrix() const { return fMatrix; }
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000041
bsalomon@google.com422e81a2012-10-25 14:11:03 +000042 typedef GrGLSingleTextureEffect GLEffect;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000043
bsalomon@google.com396e61f2012-10-25 19:00:29 +000044 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000045
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000046 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.com17fc6512012-11-02 21:45:01 +000050
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.comd0c1a062012-07-12 17:23:52 +000058private:
bsalomon@google.comf271cc72012-10-24 19:35:13 +000059 GR_DECLARE_EFFECT_TEST;
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000060
bsalomon@google.com6d003d12012-09-11 15:45:20 +000061 GrTextureAccess fTextureAccess;
bsalomon@google.comb9086a02012-11-01 18:02:54 +000062 SkMatrix fMatrix;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000063
bsalomon@google.coma469c282012-10-24 18:28:34 +000064 typedef GrEffect INHERITED;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000065};
66
67#endif