blob: 69ab13ebe1ac9cde22faf72ea04346d7f13c8c3d [file] [log] [blame]
bsalomon@google.com68b58c92013-01-17 16:50:08 +00001/*
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
16class GrGLSimpleTextureEffect : public GrGLEffect {
17public:
18 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrEffect&)
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);
30 builder->fFSCode.appendf("\t%s = ", outputColor);
31 builder->appendTextureLookupAndModulate(&builder->fFSCode,
32 inputColor,
33 samplers[0],
34 coordName,
35 coordType);
36 builder->fFSCode.append(";\n");
37 }
38
39 static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
40 const GrSimpleTextureEffect& ste =
41 static_cast<const GrSimpleTextureEffect&>(*stage.getEffect());
42 return GrGLEffectMatrix::GenKey(ste.getMatrix(),
43 stage.getCoordChangeMatrix(),
44 ste.texture(0));
45 }
46
47 virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE {
48 const GrSimpleTextureEffect& ste =
49 static_cast<const GrSimpleTextureEffect&>(*stage.getEffect());
50 fEffectMatrix.setData(uman, ste.getMatrix(), stage.getCoordChangeMatrix(), ste.texture(0));
51 }
52
53private:
54 GrGLEffectMatrix fEffectMatrix;
55 typedef GrGLEffect INHERITED;
56};
57
58///////////////////////////////////////////////////////////////////////////////
59
60void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
61 this->updateConstantColorComponentsForModulation(color, validFlags);
62}
63
64const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const {
65 return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance();
66}
67
68///////////////////////////////////////////////////////////////////////////////
69
70GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect);
71
72GrEffectRef* GrSimpleTextureEffect::TestCreate(SkRandom* random,
73 GrContext* context,
74 GrTexture* textures[]) {
75 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
76 GrEffectUnitTest::kAlphaTextureIdx;
77 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
78 return GrSimpleTextureEffect::Create(textures[texIdx], matrix);
79}