blob: f6f7b8c5bd116651c74d31520b2eb3ce34e8d9da [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,
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000025 const TextureSamplerArray& samplers) SK_OVERRIDE {
bsalomon@google.com868a8e72012-08-30 19:11:34 +000026 builder->fFSCode.appendf("\t%s = ", outputColor);
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000027 builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplers[0]);
bsalomon@google.com868a8e72012-08-30 19:11:34 +000028 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)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000041 : INHERITED(1)
42 , fTextureAccess(texture) {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000043}
44
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000045GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, bool bilerp)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000046 : INHERITED(1)
47 , fTextureAccess(texture, bilerp) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000048}
49
50GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const GrTextureParams& params)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000051 : INHERITED(1)
52 , fTextureAccess(texture, params) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000053}
54
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000055GrSingleTextureEffect::~GrSingleTextureEffect() {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000056}
57
bsalomon@google.com6d003d12012-09-11 15:45:20 +000058const GrTextureAccess& GrSingleTextureEffect::textureAccess(int index) const {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000059 GrAssert(0 == index);
bsalomon@google.com6d003d12012-09-11 15:45:20 +000060 return fTextureAccess;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000061}
62
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000063const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const {
64 return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance();
65}
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000066
67///////////////////////////////////////////////////////////////////////////////
68
69GR_DEFINE_CUSTOM_STAGE_TEST(GrSingleTextureEffect);
70
71GrCustomStage* GrSingleTextureEffect::TestCreate(SkRandom* random,
72 GrContext* context,
73 GrTexture* textures[]) {
bsalomon@google.com8d3d2102012-08-03 18:49:51 +000074 int texIdx = random->nextBool() ? GrCustomStageUnitTest::kSkiaPMTextureIdx :
75 GrCustomStageUnitTest::kAlphaTextureIdx;
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000076 return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx]));
77}