bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +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 "GrSimpleTextureEffect.h" |
| 9 | #include "gl/GrGLEffect.h" |
| 10 | #include "gl/GrGLEffectMatrix.h" |
| 11 | #include "gl/GrGLSL.h" |
| 12 | #include "gl/GrGLTexture.h" |
| 13 | #include "GrTBackendEffectFactory.h" |
| 14 | #include "GrTexture.h" |
| 15 | |
| 16 | class GrGLSimpleTextureEffect : public GrGLEffect { |
| 17 | public: |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 18 | GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrEffectRef&) |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 19 | : INHERITED (factory) {} |
| 20 | |
| 21 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 22 | const GrEffectStage&, |
| 23 | EffectKey key, |
| 24 | const char* vertexCoords, |
| 25 | const char* outputColor, |
| 26 | const char* inputColor, |
| 27 | const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 28 | const char* coordName; |
| 29 | GrSLType coordType = fEffectMatrix.emitCode(builder, key, vertexCoords, &coordName); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 30 | builder->fsCodeAppendf("\t%s = ", outputColor); |
| 31 | builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType, |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 32 | inputColor, |
| 33 | samplers[0], |
| 34 | coordName, |
| 35 | coordType); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 36 | builder->fsCodeAppend(";\n"); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 40 | const GrSimpleTextureEffect& ste = GetEffectFromStage<GrSimpleTextureEffect>(stage); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 41 | return GrGLEffectMatrix::GenKey(ste.getMatrix(), |
| 42 | stage.getCoordChangeMatrix(), |
| 43 | ste.texture(0)); |
| 44 | } |
| 45 | |
| 46 | virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 47 | const GrSimpleTextureEffect& ste = GetEffectFromStage<GrSimpleTextureEffect>(stage); |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 48 | fEffectMatrix.setData(uman, ste.getMatrix(), stage.getCoordChangeMatrix(), ste.texture(0)); |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | GrGLEffectMatrix fEffectMatrix; |
| 53 | typedef GrGLEffect INHERITED; |
| 54 | }; |
| 55 | |
| 56 | /////////////////////////////////////////////////////////////////////////////// |
| 57 | |
| 58 | void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
| 59 | this->updateConstantColorComponentsForModulation(color, validFlags); |
| 60 | } |
| 61 | |
| 62 | const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { |
| 63 | return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance(); |
| 64 | } |
| 65 | |
| 66 | /////////////////////////////////////////////////////////////////////////////// |
| 67 | |
| 68 | GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect); |
| 69 | |
bsalomon@google.com | 73a9694 | 2013-02-13 16:31:19 +0000 | [diff] [blame] | 70 | GrEffectRef* GrSimpleTextureEffect::TestCreate(SkMWCRandom* random, |
sugoi@google.com | e0e385c | 2013-03-11 18:50:03 +0000 | [diff] [blame^] | 71 | GrContext*, |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 72 | GrTexture* textures[]) { |
| 73 | int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
| 74 | GrEffectUnitTest::kAlphaTextureIdx; |
| 75 | const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
| 76 | return GrSimpleTextureEffect::Create(textures[texIdx], matrix); |
| 77 | } |