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