blob: 18a8a78fc453594125e8de068729a669139be784 [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
egdaniel605dd0f2014-11-12 08:35:25 -080013class GrInvariantOutput;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000014
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
bsalomonae4738f2015-09-15 15:33:27 -070018 * local coords or device space coords as input texture coords. The input coords may be transformed
19 * by a matrix.
bsalomon@google.com68b58c92013-01-17 16:50:08 +000020 */
21class GrSimpleTextureEffect : public GrSingleTextureEffect {
22public:
23 /* unfiltered, clamp mode */
bsalomon4a339522015-10-06 08:40:50 -070024 static const GrFragmentProcessor* Create(GrTexture* tex,
bsalomonae4738f2015-09-15 15:33:27 -070025 const SkMatrix& matrix,
26 GrCoordSet coordSet = kLocal_GrCoordSet) {
bsalomon4a339522015-10-06 08:40:50 -070027 return new GrSimpleTextureEffect(tex, matrix, GrTextureParams::kNone_FilterMode, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000028 }
29
30 /* clamp mode */
bsalomon4a339522015-10-06 08:40:50 -070031 static GrFragmentProcessor* Create(GrTexture* tex,
joshualittb0a8a372014-09-23 09:50:21 -070032 const SkMatrix& matrix,
33 GrTextureParams::FilterMode filterMode,
34 GrCoordSet coordSet = kLocal_GrCoordSet) {
bsalomon4a339522015-10-06 08:40:50 -070035 return new GrSimpleTextureEffect(tex, matrix, filterMode, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000036 }
37
bsalomon4a339522015-10-06 08:40:50 -070038 static GrFragmentProcessor* Create(GrTexture* tex,
joshualittb0a8a372014-09-23 09:50:21 -070039 const SkMatrix& matrix,
40 const GrTextureParams& p,
41 GrCoordSet coordSet = kLocal_GrCoordSet) {
bsalomon4a339522015-10-06 08:40:50 -070042 return new GrSimpleTextureEffect(tex, matrix, p, coordSet);
bsalomon@google.comc7818882013-03-20 19:19:53 +000043 }
44
bsalomon@google.com68b58c92013-01-17 16:50:08 +000045 virtual ~GrSimpleTextureEffect() {}
46
mtklein36352bf2015-03-25 18:17:31 -070047 const char* name() const override { return "SimpleTexture"; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000048
bsalomon@google.com68b58c92013-01-17 16:50:08 +000049private:
bsalomon4a339522015-10-06 08:40:50 -070050 GrSimpleTextureEffect(GrTexture* texture,
bsalomon@google.comc7818882013-03-20 19:19:53 +000051 const SkMatrix& matrix,
humper@google.comb86add12013-07-25 18:49:07 +000052 GrTextureParams::FilterMode filterMode,
bsalomon@google.com77af6802013-10-02 13:04:56 +000053 GrCoordSet coordSet)
bsalomon4a339522015-10-06 08:40:50 -070054 : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) {
joshualitteb2a6762014-12-04 11:35:33 -080055 this->initClassID<GrSimpleTextureEffect>();
bsalomon@google.comc7818882013-03-20 19:19:53 +000056 }
57
bsalomon4a339522015-10-06 08:40:50 -070058 GrSimpleTextureEffect(GrTexture* texture,
bsalomon@google.comc7818882013-03-20 19:19:53 +000059 const SkMatrix& matrix,
60 const GrTextureParams& params,
bsalomon@google.com77af6802013-10-02 13:04:56 +000061 GrCoordSet coordSet)
bsalomon4a339522015-10-06 08:40:50 -070062 : GrSingleTextureEffect(texture, matrix, params, coordSet) {
joshualitteb2a6762014-12-04 11:35:33 -080063 this->initClassID<GrSimpleTextureEffect>();
bsalomon@google.comc7818882013-03-20 19:19:53 +000064 }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000065
egdaniel57d3b032015-11-13 11:57:27 -080066 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070067
egdaniel57d3b032015-11-13 11:57:27 -080068 void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070069
mtklein36352bf2015-03-25 18:17:31 -070070 bool onIsEqual(const GrFragmentProcessor& other) const override { return true; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000071
mtklein36352bf2015-03-25 18:17:31 -070072 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
egdaniel1a8ecdf2014-10-03 06:24:12 -070073
joshualittb0a8a372014-09-23 09:50:21 -070074 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000075
76 typedef GrSingleTextureEffect INHERITED;
77};
78
79#endif