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, |
| 25 | const char* samplerName) SK_OVERRIDE { |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame^] | 26 | builder->fFSCode.appendf("\t%s = ", outputColor); |
| 27 | builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplerName); |
| 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) |
| 41 | : fTexture (texture) { |
| 42 | SkSafeRef(fTexture); |
| 43 | } |
| 44 | |
| 45 | GrSingleTextureEffect::~GrSingleTextureEffect() { |
| 46 | SkSafeUnref(fTexture); |
| 47 | } |
| 48 | |
| 49 | unsigned int GrSingleTextureEffect::numTextures() const { |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | GrTexture* GrSingleTextureEffect::texture(unsigned int index) const { |
| 54 | GrAssert(0 == index); |
| 55 | return fTexture; |
| 56 | } |
| 57 | |
tomhudson@google.com | aa72eab | 2012-07-19 18:01:07 +0000 | [diff] [blame] | 58 | const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const { |
| 59 | return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance(); |
| 60 | } |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 61 | |
| 62 | /////////////////////////////////////////////////////////////////////////////// |
| 63 | |
| 64 | GR_DEFINE_CUSTOM_STAGE_TEST(GrSingleTextureEffect); |
| 65 | |
| 66 | GrCustomStage* GrSingleTextureEffect::TestCreate(SkRandom* random, |
| 67 | GrContext* context, |
| 68 | GrTexture* textures[]) { |
bsalomon@google.com | 8d3d210 | 2012-08-03 18:49:51 +0000 | [diff] [blame] | 69 | int texIdx = random->nextBool() ? GrCustomStageUnitTest::kSkiaPMTextureIdx : |
| 70 | GrCustomStageUnitTest::kAlphaTextureIdx; |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 71 | return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx])); |
| 72 | } |