michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrSimpleTextureEffect_DEFINED michael@0: #define GrSimpleTextureEffect_DEFINED michael@0: michael@0: #include "GrSingleTextureEffect.h" michael@0: michael@0: class GrGLSimpleTextureEffect; michael@0: michael@0: /** michael@0: * The output color of this effect is a modulation of the input color and a sample from a texture. michael@0: * It allows explicit specification of the filtering and wrap modes (GrTextureParams). It can use michael@0: * local coords, positions, or a custom vertex attribute as input texture coords. The input coords michael@0: * can have a matrix applied in the VS in both the local and position cases but not with a custom michael@0: * attribute coords at this time. It will add a varying to input interpolate texture coords to the michael@0: * FS. michael@0: */ michael@0: class GrSimpleTextureEffect : public GrSingleTextureEffect { michael@0: public: michael@0: /* unfiltered, clamp mode */ michael@0: static GrEffectRef* Create(GrTexture* tex, michael@0: const SkMatrix& matrix, michael@0: GrCoordSet coordSet = kLocal_GrCoordSet) { michael@0: AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, GrTextureParams::kNone_FilterMode, coordSet))); michael@0: return CreateEffectRef(effect); michael@0: } michael@0: michael@0: /* clamp mode */ michael@0: static GrEffectRef* Create(GrTexture* tex, michael@0: const SkMatrix& matrix, michael@0: GrTextureParams::FilterMode filterMode, michael@0: GrCoordSet coordSet = kLocal_GrCoordSet) { michael@0: AutoEffectUnref effect( michael@0: SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordSet))); michael@0: return CreateEffectRef(effect); michael@0: } michael@0: michael@0: static GrEffectRef* Create(GrTexture* tex, michael@0: const SkMatrix& matrix, michael@0: const GrTextureParams& p, michael@0: GrCoordSet coordSet = kLocal_GrCoordSet) { michael@0: AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordSet))); michael@0: return CreateEffectRef(effect); michael@0: } michael@0: michael@0: virtual ~GrSimpleTextureEffect() {} michael@0: michael@0: static const char* Name() { return "Texture"; } michael@0: michael@0: virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; michael@0: michael@0: typedef GrGLSimpleTextureEffect GLEffect; michael@0: michael@0: virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; michael@0: michael@0: private: michael@0: GrSimpleTextureEffect(GrTexture* texture, michael@0: const SkMatrix& matrix, michael@0: GrTextureParams::FilterMode filterMode, michael@0: GrCoordSet coordSet) michael@0: : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) { michael@0: } michael@0: michael@0: GrSimpleTextureEffect(GrTexture* texture, michael@0: const SkMatrix& matrix, michael@0: const GrTextureParams& params, michael@0: GrCoordSet coordSet) michael@0: : GrSingleTextureEffect(texture, matrix, params, coordSet) { michael@0: } michael@0: michael@0: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { michael@0: const GrSimpleTextureEffect& ste = CastEffect(other); michael@0: return this->hasSameTextureParamsMatrixAndSourceCoords(ste); michael@0: } michael@0: michael@0: GR_DECLARE_EFFECT_TEST; michael@0: michael@0: typedef GrSingleTextureEffect INHERITED; michael@0: }; michael@0: michael@0: #endif