tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | #include "effects/GrSingleTextureEffect.h" |
bsalomon@google.com | d698f77 | 2012-10-25 13:22:00 +0000 | [diff] [blame] | 9 | #include "gl/GrGLEffect.h" |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 10 | #include "gl/GrGLSL.h" |
| 11 | #include "gl/GrGLTexture.h" |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 12 | #include "GrTBackendEffectFactory.h" |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 13 | #include "GrTexture.h" |
| 14 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 15 | class GrGLSingleTextureEffect : public GrGLEffect { |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 16 | public: |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 17 | GrGLSingleTextureEffect(const GrBackendEffectFactory& factory, const GrEffect&) |
bsalomon@google.com | 021fc73 | 2012-10-25 12:47:42 +0000 | [diff] [blame] | 18 | : INHERITED (factory) { |
| 19 | } |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 20 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 21 | virtual void emitCode(GrGLShaderBuilder* builder, |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 22 | const GrEffectStage&, |
bsalomon@google.com | 66e534d | 2012-11-01 14:02:43 +0000 | [diff] [blame^] | 23 | EffectKey, |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 24 | const char* vertexCoords, |
| 25 | const char* outputColor, |
| 26 | const char* inputColor, |
| 27 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
bsalomon@google.com | 66e534d | 2012-11-01 14:02:43 +0000 | [diff] [blame^] | 28 | |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 29 | builder->fFSCode.appendf("\t%s = ", outputColor); |
bsalomon@google.com | 66e534d | 2012-11-01 14:02:43 +0000 | [diff] [blame^] | 30 | builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplers[0]); |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 31 | builder->fFSCode.append(";\n"); |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 32 | } |
| 33 | |
bsalomon@google.com | 66e534d | 2012-11-01 14:02:43 +0000 | [diff] [blame^] | 34 | static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&) { return 0; } |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 35 | |
| 36 | private: |
bsalomon@google.com | 66e534d | 2012-11-01 14:02:43 +0000 | [diff] [blame^] | 37 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 38 | typedef GrGLEffect INHERITED; |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | /////////////////////////////////////////////////////////////////////////////// |
| 42 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 43 | GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture) |
bsalomon@google.com | e6e62d1 | 2012-10-04 14:38:48 +0000 | [diff] [blame] | 44 | : INHERITED(1) |
| 45 | , fTextureAccess(texture) { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 46 | } |
| 47 | |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 48 | GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, bool bilerp) |
bsalomon@google.com | e6e62d1 | 2012-10-04 14:38:48 +0000 | [diff] [blame] | 49 | : INHERITED(1) |
| 50 | , fTextureAccess(texture, bilerp) { |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const GrTextureParams& params) |
bsalomon@google.com | e6e62d1 | 2012-10-04 14:38:48 +0000 | [diff] [blame] | 54 | : INHERITED(1) |
| 55 | , fTextureAccess(texture, params) { |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 56 | } |
| 57 | |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 58 | GrSingleTextureEffect::~GrSingleTextureEffect() { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 59 | } |
| 60 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 61 | const GrTextureAccess& GrSingleTextureEffect::textureAccess(int index) const { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 62 | GrAssert(0 == index); |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 63 | return fTextureAccess; |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 64 | } |
| 65 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 66 | const GrBackendEffectFactory& GrSingleTextureEffect::getFactory() const { |
| 67 | return GrTBackendEffectFactory<GrSingleTextureEffect>::getInstance(); |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 68 | } |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 69 | |
| 70 | /////////////////////////////////////////////////////////////////////////////// |
| 71 | |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 72 | GR_DEFINE_EFFECT_TEST(GrSingleTextureEffect); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 73 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 74 | GrEffect* GrSingleTextureEffect::TestCreate(SkRandom* random, |
| 75 | GrContext* context, |
| 76 | GrTexture* textures[]) { |
bsalomon@google.com | 6f261be | 2012-10-24 19:07:10 +0000 | [diff] [blame] | 77 | int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
| 78 | GrEffectUnitTest::kAlphaTextureIdx; |
bsalomon@google.com | 66e534d | 2012-11-01 14:02:43 +0000 | [diff] [blame^] | 79 | return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx])); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 80 | } |