blob: 8afc23583e80df5cd2d8cf13eb079567bb433c8b [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
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 */
joshualittb0a8a372014-09-23 09:50:21 -070026 static GrFragmentProcessor* Create(GrTexture* tex,
27 const SkMatrix& matrix,
28 GrCoordSet coordSet = kLocal_GrCoordSet) {
bsalomon55fad7a2014-07-08 07:34:20 -070029 return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, GrTextureParams::kNone_FilterMode,
30 coordSet));
bsalomon@google.com68b58c92013-01-17 16:50:08 +000031 }
32
33 /* clamp mode */
joshualittb0a8a372014-09-23 09:50:21 -070034 static GrFragmentProcessor* Create(GrTexture* tex,
35 const SkMatrix& matrix,
36 GrTextureParams::FilterMode filterMode,
37 GrCoordSet coordSet = kLocal_GrCoordSet) {
bsalomon55fad7a2014-07-08 07:34:20 -070038 return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordSet));
bsalomon@google.com68b58c92013-01-17 16:50:08 +000039 }
40
joshualittb0a8a372014-09-23 09:50:21 -070041 static GrFragmentProcessor* Create(GrTexture* tex,
42 const SkMatrix& matrix,
43 const GrTextureParams& p,
44 GrCoordSet coordSet = kLocal_GrCoordSet) {
bsalomon55fad7a2014-07-08 07:34:20 -070045 return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordSet));
bsalomon@google.comc7818882013-03-20 19:19:53 +000046 }
47
bsalomon@google.com68b58c92013-01-17 16:50:08 +000048 virtual ~GrSimpleTextureEffect() {}
49
mtklein72c9faa2015-01-09 10:06:39 -080050 const char* name() const SK_OVERRIDE { return "SimpleTexture"; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000051
mtklein72c9faa2015-01-09 10:06:39 -080052 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const SK_OVERRIDE;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000053
mtklein72c9faa2015-01-09 10:06:39 -080054 GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000055
56private:
bsalomon@google.comc7818882013-03-20 19:19:53 +000057 GrSimpleTextureEffect(GrTexture* texture,
58 const SkMatrix& matrix,
humper@google.comb86add12013-07-25 18:49:07 +000059 GrTextureParams::FilterMode filterMode,
bsalomon@google.com77af6802013-10-02 13:04:56 +000060 GrCoordSet coordSet)
61 : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) {
joshualitteb2a6762014-12-04 11:35:33 -080062 this->initClassID<GrSimpleTextureEffect>();
bsalomon@google.comc7818882013-03-20 19:19:53 +000063 }
64
65 GrSimpleTextureEffect(GrTexture* texture,
66 const SkMatrix& matrix,
67 const GrTextureParams& params,
bsalomon@google.com77af6802013-10-02 13:04:56 +000068 GrCoordSet coordSet)
69 : GrSingleTextureEffect(texture, matrix, params, coordSet) {
joshualitteb2a6762014-12-04 11:35:33 -080070 this->initClassID<GrSimpleTextureEffect>();
bsalomon@google.comc7818882013-03-20 19:19:53 +000071 }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000072
mtklein72c9faa2015-01-09 10:06:39 -080073 bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { return true; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000074
mtklein72c9faa2015-01-09 10:06:39 -080075 void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE;
egdaniel1a8ecdf2014-10-03 06:24:12 -070076
joshualittb0a8a372014-09-23 09:50:21 -070077 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000078
79 typedef GrSingleTextureEffect INHERITED;
80};
81
82#endif