GrSimpleTextureEffect.h revision 1a8ecdfb73a15de600d5779b75d7c4b61863c50b
168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com/* 268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * Copyright 2013 Google Inc. 368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * 468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * Use of this source code is governed by a BSD-style license that can be 568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * found in the LICENSE file. 668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com */ 768b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#ifndef GrSimpleTextureEffect_DEFINED 968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#define GrSimpleTextureEffect_DEFINED 1068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 1168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#include "GrSingleTextureEffect.h" 1268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 1368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.comclass GrGLSimpleTextureEffect; 1468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 1568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com/** 1668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * The output color of this effect is a modulation of the input color and a sample from a texture. 17c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * It allows explicit specification of the filtering and wrap modes (GrTextureParams). It can use 18c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * local coords, positions, or a custom vertex attribute as input texture coords. The input coords 19c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * can have a matrix applied in the VS in both the local and position cases but not with a custom 20c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * attribute coords at this time. It will add a varying to input interpolate texture coords to the 21c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com * FS. 2268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com */ 2368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.comclass GrSimpleTextureEffect : public GrSingleTextureEffect { 2468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.compublic: 2568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com /* unfiltered, clamp mode */ 26b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt static GrFragmentProcessor* Create(GrTexture* tex, 27b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const SkMatrix& matrix, 28b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt GrCoordSet coordSet = kLocal_GrCoordSet) { 2955fad7af61c21d502acb9891d631e8aa29e3628cbsalomon return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, GrTextureParams::kNone_FilterMode, 3055fad7af61c21d502acb9891d631e8aa29e3628cbsalomon coordSet)); 3168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com } 3268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 3368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com /* clamp mode */ 34b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt static GrFragmentProcessor* Create(GrTexture* tex, 35b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const SkMatrix& matrix, 36b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt GrTextureParams::FilterMode filterMode, 37b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt GrCoordSet coordSet = kLocal_GrCoordSet) { 3855fad7af61c21d502acb9891d631e8aa29e3628cbsalomon return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordSet)); 3968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com } 4068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 41b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt static GrFragmentProcessor* Create(GrTexture* tex, 42b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const SkMatrix& matrix, 43b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt const GrTextureParams& p, 44b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt GrCoordSet coordSet = kLocal_GrCoordSet) { 4555fad7af61c21d502acb9891d631e8aa29e3628cbsalomon return SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordSet)); 46c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com } 47c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com 4868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com virtual ~GrSimpleTextureEffect() {} 4968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 5068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com static const char* Name() { return "Texture"; } 5168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 52b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt typedef GrGLSimpleTextureEffect GLProcessor; 5368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 54b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE; 5568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 5668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.comprivate: 57c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com GrSimpleTextureEffect(GrTexture* texture, 58c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const SkMatrix& matrix, 59b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com GrTextureParams::FilterMode filterMode, 6077af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com GrCoordSet coordSet) 6177af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) { 62c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com } 63c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com 64c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com GrSimpleTextureEffect(GrTexture* texture, 65c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const SkMatrix& matrix, 66c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrTextureParams& params, 6777af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com GrCoordSet coordSet) 6877af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com : GrSingleTextureEffect(texture, matrix, params, coordSet) { 69c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com } 7068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 71b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE { 7249586bec7383d4ccb81f85f8e2dc4162e2d4f6a8joshualitt const GrSimpleTextureEffect& ste = other.cast<GrSimpleTextureEffect>(); 7377af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com return this->hasSameTextureParamsMatrixAndSourceCoords(ste); 7468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com } 7568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 761a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; 771a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel 78b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 7968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 8068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com typedef GrSingleTextureEffect INHERITED; 8168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com}; 8268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 8368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#endif 84