blob: dc91a68c20b4a3a7820af9abb487e58802f0d79e [file] [log] [blame]
tomhudson@google.comd0c1a062012-07-12 17:23:52 +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 "effects/GrSingleTextureEffect.h"
tomhudson@google.comaa72eab2012-07-19 18:01:07 +00009#include "gl/GrGLProgramStage.h"
10#include "gl/GrGLSL.h"
11#include "gl/GrGLTexture.h"
12#include "GrProgramStageFactory.h"
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000013#include "GrTexture.h"
14
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000015class GrGLSingleTextureEffect : public GrGLProgramStage {
16public:
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.com868a8e72012-08-30 19:11:34 +000026 builder->fFSCode.appendf("\t%s = ", outputColor);
27 builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplerName);
28 builder->fFSCode.append(";\n");
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000029 }
30
twiz@google.coma5e65ec2012-08-02 15:15:16 +000031 static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&) { return 0; }
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000032
33private:
34
35 typedef GrGLProgramStage INHERITED;
36};
37
38///////////////////////////////////////////////////////////////////////////////
39
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000040GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
41 : fTexture (texture) {
42 SkSafeRef(fTexture);
43}
44
45GrSingleTextureEffect::~GrSingleTextureEffect() {
46 SkSafeUnref(fTexture);
47}
48
49unsigned int GrSingleTextureEffect::numTextures() const {
50 return 1;
51}
52
53GrTexture* GrSingleTextureEffect::texture(unsigned int index) const {
54 GrAssert(0 == index);
55 return fTexture;
56}
57
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000058const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const {
59 return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance();
60}
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000061
62///////////////////////////////////////////////////////////////////////////////
63
64GR_DEFINE_CUSTOM_STAGE_TEST(GrSingleTextureEffect);
65
66GrCustomStage* GrSingleTextureEffect::TestCreate(SkRandom* random,
67 GrContext* context,
68 GrTexture* textures[]) {
bsalomon@google.com8d3d2102012-08-03 18:49:51 +000069 int texIdx = random->nextBool() ? GrCustomStageUnitTest::kSkiaPMTextureIdx :
70 GrCustomStageUnitTest::kAlphaTextureIdx;
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000071 return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx]));
72}