blob: ebd09130c00b785cd9e0eb401eedc014060ccaf7 [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 {
26 builder->emitDefaultFetch(outputColor, samplerName);
27 }
28
twiz@google.coma5e65ec2012-08-02 15:15:16 +000029 static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&) { return 0; }
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000030
31private:
32
33 typedef GrGLProgramStage INHERITED;
34};
35
36///////////////////////////////////////////////////////////////////////////////
37
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000038GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
39 : fTexture (texture) {
40 SkSafeRef(fTexture);
41}
42
43GrSingleTextureEffect::~GrSingleTextureEffect() {
44 SkSafeUnref(fTexture);
45}
46
47unsigned int GrSingleTextureEffect::numTextures() const {
48 return 1;
49}
50
51GrTexture* GrSingleTextureEffect::texture(unsigned int index) const {
52 GrAssert(0 == index);
53 return fTexture;
54}
55
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000056const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const {
57 return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance();
58}
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000059
60///////////////////////////////////////////////////////////////////////////////
61
62GR_DEFINE_CUSTOM_STAGE_TEST(GrSingleTextureEffect);
63
64GrCustomStage* GrSingleTextureEffect::TestCreate(SkRandom* random,
65 GrContext* context,
66 GrTexture* textures[]) {
67 int texIdx = random->nextBool() ? GrCustomStageTestFactory::kSkiaPMTextureIdx :
68 GrCustomStageTestFactory::kAlphaTextureIdx;
69 return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx]));
70}