GrSimpleTextureEffect.h revision 36352bf5e38f45a70ee4f4fc132a38048d38206d
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 13605dd0fbce9dbb2a0d3313e13e161f2bd54870d7egdanielclass GrInvariantOutput; 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 5036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein const char* name() const override { return "SimpleTexture"; } 5168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 5236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const override; 5368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 5436352bf5e38f45a70ee4f4fc132a38048d38206dmtklein GrGLFragmentProcessor* createGLInstance() const 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) { 62eb2a6761654307e8aeeeaabdd63c6bf9ab0411e9joshualitt this->initClassID<GrSimpleTextureEffect>(); 63c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com } 64c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com 65c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com GrSimpleTextureEffect(GrTexture* texture, 66c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const SkMatrix& matrix, 67c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrTextureParams& params, 6877af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com GrCoordSet coordSet) 6977af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com : GrSingleTextureEffect(texture, matrix, params, coordSet) { 70eb2a6761654307e8aeeeaabdd63c6bf9ab0411e9joshualitt this->initClassID<GrSimpleTextureEffect>(); 71c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com } 7268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 7336352bf5e38f45a70ee4f4fc132a38048d38206dmtklein bool onIsEqual(const GrFragmentProcessor& other) const override { return true; } 7468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 7536352bf5e38f45a70ee4f4fc132a38048d38206dmtklein void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 761a8ecdfb73a15de600d5779b75d7c4b61863c50begdaniel 77b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 7868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 7968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com typedef GrSingleTextureEffect INHERITED; 8068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com}; 8168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 8268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#endif 83