blob: c326ccf4c86d82d1dc621cf54efd513479c30a73 [file] [log] [blame]
bsalomon@google.com68b58c92013-01-17 16:50:08 +00001/*
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
13class 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.comc7818882013-03-20 19:19:53 +000017 * 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.com68b58c92013-01-17 16:50:08 +000022 */
23class GrSimpleTextureEffect : public GrSingleTextureEffect {
24public:
25 /* unfiltered, clamp mode */
bsalomon@google.comc7818882013-03-20 19:19:53 +000026 static GrEffectRef* Create(GrTexture* tex,
27 const SkMatrix& matrix,
bsalomon@google.com77af6802013-10-02 13:04:56 +000028 GrCoordSet coordSet = kLocal_GrCoordSet) {
29 AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, GrTextureParams::kNone_FilterMode, coordSet)));
bsalomon@google.com68b58c92013-01-17 16:50:08 +000030 return CreateEffectRef(effect);
31 }
32
33 /* clamp mode */
bsalomon@google.comc7818882013-03-20 19:19:53 +000034 static GrEffectRef* Create(GrTexture* tex,
35 const SkMatrix& matrix,
humper@google.comb86add12013-07-25 18:49:07 +000036 GrTextureParams::FilterMode filterMode,
bsalomon@google.com77af6802013-10-02 13:04:56 +000037 GrCoordSet coordSet = kLocal_GrCoordSet) {
bsalomon@google.comc7818882013-03-20 19:19:53 +000038 AutoEffectUnref effect(
bsalomon@google.com77af6802013-10-02 13:04:56 +000039 SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordSet)));
bsalomon@google.com68b58c92013-01-17 16:50:08 +000040 return CreateEffectRef(effect);
41 }
42
bsalomon@google.comc7818882013-03-20 19:19:53 +000043 static GrEffectRef* Create(GrTexture* tex,
44 const SkMatrix& matrix,
45 const GrTextureParams& p,
bsalomon@google.com77af6802013-10-02 13:04:56 +000046 GrCoordSet coordSet = kLocal_GrCoordSet) {
47 AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordSet)));
bsalomon@google.comc7818882013-03-20 19:19:53 +000048 return CreateEffectRef(effect);
49 }
50
bsalomon@google.com68b58c92013-01-17 16:50:08 +000051 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
61private:
bsalomon@google.comc7818882013-03-20 19:19:53 +000062 GrSimpleTextureEffect(GrTexture* texture,
63 const SkMatrix& matrix,
humper@google.comb86add12013-07-25 18:49:07 +000064 GrTextureParams::FilterMode filterMode,
bsalomon@google.com77af6802013-10-02 13:04:56 +000065 GrCoordSet coordSet)
66 : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) {
bsalomon@google.comc7818882013-03-20 19:19:53 +000067 }
68
69 GrSimpleTextureEffect(GrTexture* texture,
70 const SkMatrix& matrix,
71 const GrTextureParams& params,
bsalomon@google.com77af6802013-10-02 13:04:56 +000072 GrCoordSet coordSet)
73 : GrSingleTextureEffect(texture, matrix, params, coordSet) {
bsalomon@google.comc7818882013-03-20 19:19:53 +000074 }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000075
bsalomon@google.com8a252f72013-01-22 20:35:13 +000076 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE {
bsalomon@google.com6340a412013-01-22 19:55:59 +000077 const GrSimpleTextureEffect& ste = CastEffect<GrSimpleTextureEffect>(other);
bsalomon@google.com77af6802013-10-02 13:04:56 +000078 return this->hasSameTextureParamsMatrixAndSourceCoords(ste);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000079 }
80
81 GR_DECLARE_EFFECT_TEST;
82
83 typedef GrSingleTextureEffect INHERITED;
84};
85
86#endif