aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrSingleTextureEffect.cpp
blob: 03a36f6aafaec600a2a72473f53bc05161589d87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "effects/GrSingleTextureEffect.h"
#include "gl/GrGLEffect.h"
#include "gl/GrGLSL.h"
#include "gl/GrGLTexture.h"
#include "GrProgramStageFactory.h"
#include "GrTexture.h"

class GrGLSingleTextureEffect : public GrGLLegacyEffect {
public:
    GrGLSingleTextureEffect(const GrProgramStageFactory& factory, const GrEffect&)
    : INHERITED (factory) {
    }

    virtual void emitVS(GrGLShaderBuilder* builder,
                        const char* vertexCoords) SK_OVERRIDE { }
    virtual void emitFS(GrGLShaderBuilder* builder,
                        const char* outputColor,
                        const char* inputColor,
                        const TextureSamplerArray& samplers) SK_OVERRIDE {
        builder->fFSCode.appendf("\t%s = ", outputColor);
        builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplers[0]);
        builder->fFSCode.append(";\n");
    }

    static inline StageKey GenKey(const GrEffect&, const GrGLCaps&) { return 0; }

private:

    typedef GrGLLegacyEffect INHERITED;
};

///////////////////////////////////////////////////////////////////////////////

GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
    : INHERITED(1)
    , fTextureAccess(texture) {
}

GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, bool bilerp)
    : INHERITED(1)
    , fTextureAccess(texture, bilerp) {
}

GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const GrTextureParams& params)
    : INHERITED(1)
    , fTextureAccess(texture, params) {
}

GrSingleTextureEffect::~GrSingleTextureEffect() {
}

const GrTextureAccess& GrSingleTextureEffect::textureAccess(int index) const {
    GrAssert(0 == index);
    return fTextureAccess;
}

const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const {
    return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance();
}

///////////////////////////////////////////////////////////////////////////////

GR_DEFINE_EFFECT_TEST(GrSingleTextureEffect);

GrEffect* GrSingleTextureEffect::TestCreate(SkRandom* random,
                                            GrContext* context,
                                            GrTexture* textures[]) {
    int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
                                      GrEffectUnitTest::kAlphaTextureIdx;
    return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx]));
}