OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrSimpleTextureEffect_DEFINED | 8 #ifndef GrSimpleTextureEffect_DEFINED |
9 #define GrSimpleTextureEffect_DEFINED | 9 #define GrSimpleTextureEffect_DEFINED |
10 | 10 |
11 #include "GrSingleTextureEffect.h" | 11 #include "GrSingleTextureEffect.h" |
12 | 12 |
13 class GrGLSimpleTextureEffect; | 13 class GrGLSimpleTextureEffect; |
14 | 14 |
15 /** | 15 /** |
16 * The output color of this effect is a modulation of the input color and a samp
le from a texture. | 16 * The output color of this effect is a modulation of the input color and a samp
le from a texture. |
17 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). It can use | 17 * It allows explicit specification of the filtering and wrap modes (GrTexturePa
rams). It can use |
18 * local coords, positions, or a custom vertex attribute as input texture coords
. The input coords | 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 | 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 tex
ture coords to the | 20 * attribute coords at this time. It will add a varying to input interpolate tex
ture coords to the |
21 * FS. | 21 * FS. |
22 */ | 22 */ |
23 class GrSimpleTextureEffect : public GrSingleTextureEffect { | 23 class GrSimpleTextureEffect : public GrSingleTextureEffect { |
24 public: | 24 public: |
25 /* unfiltered, clamp mode */ | 25 /* unfiltered, clamp mode */ |
26 static GrEffectRef* Create(GrTexture* tex, | 26 static GrEffectRef* Create(GrTexture* tex, |
27 const SkMatrix& matrix, | 27 const SkMatrix& matrix, |
28 CoordsType coordsType = kLocal_CoordsType) { | 28 CoordsType coordsType = kLocal_CoordsType) { |
29 SkASSERT(kLocal_CoordsType == coordsType || kPosition_CoordsType == coor
dsType); | |
30 AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, G
rTextureParams::kNone_FilterMode, coordsType))); | 29 AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, G
rTextureParams::kNone_FilterMode, coordsType))); |
31 return CreateEffectRef(effect); | 30 return CreateEffectRef(effect); |
32 } | 31 } |
33 | 32 |
34 /* clamp mode */ | 33 /* clamp mode */ |
35 static GrEffectRef* Create(GrTexture* tex, | 34 static GrEffectRef* Create(GrTexture* tex, |
36 const SkMatrix& matrix, | 35 const SkMatrix& matrix, |
37 GrTextureParams::FilterMode filterMode, | 36 GrTextureParams::FilterMode filterMode, |
38 CoordsType coordsType = kLocal_CoordsType) { | 37 CoordsType coordsType = kLocal_CoordsType) { |
39 SkASSERT(kLocal_CoordsType == coordsType || kPosition_CoordsType == coor
dsType); | |
40 AutoEffectUnref effect( | 38 AutoEffectUnref effect( |
41 SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordsTy
pe))); | 39 SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordsTy
pe))); |
42 return CreateEffectRef(effect); | 40 return CreateEffectRef(effect); |
43 } | 41 } |
44 | 42 |
45 static GrEffectRef* Create(GrTexture* tex, | 43 static GrEffectRef* Create(GrTexture* tex, |
46 const SkMatrix& matrix, | 44 const SkMatrix& matrix, |
47 const GrTextureParams& p, | 45 const GrTextureParams& p, |
48 CoordsType coordsType = kLocal_CoordsType) { | 46 CoordsType coordsType = kLocal_CoordsType) { |
49 SkASSERT(kLocal_CoordsType == coordsType || kPosition_CoordsType == coor
dsType); | |
50 AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p
, coordsType))); | 47 AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p
, coordsType))); |
51 return CreateEffectRef(effect); | 48 return CreateEffectRef(effect); |
52 } | 49 } |
53 | 50 |
54 /** Variant that requires the client to install a custom kVec2 vertex attrib
ute that will be | |
55 the source of the coords. No matrix is allowed in this mode. */ | |
56 static GrEffectRef* CreateWithCustomCoords(GrTexture* tex, const GrTexturePa
rams& p) { | |
57 AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, | |
58 SkMatrix::I(), | |
59 p, | |
60 kCustom_Coords
Type))); | |
61 return CreateEffectRef(effect); | |
62 } | |
63 | |
64 virtual ~GrSimpleTextureEffect() {} | 51 virtual ~GrSimpleTextureEffect() {} |
65 | 52 |
66 static const char* Name() { return "Texture"; } | 53 static const char* Name() { return "Texture"; } |
67 | 54 |
68 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 55 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
69 | 56 |
70 typedef GrGLSimpleTextureEffect GLEffect; | 57 typedef GrGLSimpleTextureEffect GLEffect; |
71 | 58 |
72 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 59 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
73 | 60 |
74 private: | 61 private: |
75 GrSimpleTextureEffect(GrTexture* texture, | 62 GrSimpleTextureEffect(GrTexture* texture, |
76 const SkMatrix& matrix, | 63 const SkMatrix& matrix, |
77 GrTextureParams::FilterMode filterMode, | 64 GrTextureParams::FilterMode filterMode, |
78 CoordsType coordsType) | 65 CoordsType coordsType) |
79 : GrSingleTextureEffect(texture, matrix, filterMode, coordsType) { | 66 : GrSingleTextureEffect(texture, matrix, filterMode, coordsType) { |
80 SkASSERT(kLocal_CoordsType == coordsType || kPosition_CoordsType == coor
dsType); | |
81 } | 67 } |
82 | 68 |
83 GrSimpleTextureEffect(GrTexture* texture, | 69 GrSimpleTextureEffect(GrTexture* texture, |
84 const SkMatrix& matrix, | 70 const SkMatrix& matrix, |
85 const GrTextureParams& params, | 71 const GrTextureParams& params, |
86 CoordsType coordsType) | 72 CoordsType coordsType) |
87 : GrSingleTextureEffect(texture, matrix, params, coordsType) { | 73 : GrSingleTextureEffect(texture, matrix, params, coordsType) { |
88 if (kCustom_CoordsType == coordsType) { | |
89 SkASSERT(matrix.isIdentity()); | |
90 this->addVertexAttrib(kVec2f_GrSLType); | |
91 } | |
92 } | 74 } |
93 | 75 |
94 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | 76 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { |
95 const GrSimpleTextureEffect& ste = CastEffect<GrSimpleTextureEffect>(oth
er); | 77 const GrSimpleTextureEffect& ste = CastEffect<GrSimpleTextureEffect>(oth
er); |
96 return this->hasSameTextureParamsMatrixAndCoordsType(ste); | 78 return this->hasSameTextureParamsMatrixAndCoordsType(ste); |
97 } | 79 } |
98 | 80 |
99 GR_DECLARE_EFFECT_TEST; | 81 GR_DECLARE_EFFECT_TEST; |
100 | 82 |
101 typedef GrSingleTextureEffect INHERITED; | 83 typedef GrSingleTextureEffect INHERITED; |
102 }; | 84 }; |
103 | 85 |
104 #endif | 86 #endif |
OLD | NEW |