blob: d8b90a15fc12d380f54391e1d29d0f3402b84e17 [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 +000015// For brevity, and these definitions are likely to move to a different class soon.
16typedef GrGLShaderBuilder::UniformHandle UniformHandle;
17static const UniformHandle kInvalidUniformHandle = GrGLShaderBuilder::kInvalidUniformHandle;
18
19class GrGLSingleTextureEffect : public GrGLProgramStage {
20public:
21 GrGLSingleTextureEffect(const GrProgramStageFactory& factory,
22 const GrCustomStage& stage) : INHERITED (factory) { }
23
24 virtual void emitVS(GrGLShaderBuilder* builder,
25 const char* vertexCoords) SK_OVERRIDE { }
26 virtual void emitFS(GrGLShaderBuilder* builder,
27 const char* outputColor,
28 const char* inputColor,
29 const char* samplerName) SK_OVERRIDE {
30 builder->emitDefaultFetch(outputColor, samplerName);
31 }
32
33 static inline StageKey GenKey(const GrCustomStage&) { return 0; }
34
35private:
36
37 typedef GrGLProgramStage INHERITED;
38};
39
40///////////////////////////////////////////////////////////////////////////////
41
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000042GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
43 : fTexture (texture) {
44 SkSafeRef(fTexture);
45}
46
47GrSingleTextureEffect::~GrSingleTextureEffect() {
48 SkSafeUnref(fTexture);
49}
50
51unsigned int GrSingleTextureEffect::numTextures() const {
52 return 1;
53}
54
55GrTexture* GrSingleTextureEffect::texture(unsigned int index) const {
56 GrAssert(0 == index);
57 return fTexture;
58}
59
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000060const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const {
61 return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance();
62}
63
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000064