blob: 715303098b2f1ae1465302d2c522d89d345ed58b [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"
bsalomon@google.comd698f772012-10-25 13:22:00 +00009#include "gl/GrGLEffect.h"
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000010#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
bsalomon@google.com374e7592012-10-23 17:30:45 +000015class GrGLSingleTextureEffect : public GrGLLegacyProgramStage {
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000016public:
bsalomon@google.com021fc732012-10-25 12:47:42 +000017 GrGLSingleTextureEffect(const GrProgramStageFactory& factory, const GrEffect&)
18 : INHERITED (factory) {
19 }
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000020
21 virtual void emitVS(GrGLShaderBuilder* builder,
22 const char* vertexCoords) SK_OVERRIDE { }
23 virtual void emitFS(GrGLShaderBuilder* builder,
24 const char* outputColor,
25 const char* inputColor,
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000026 const TextureSamplerArray& samplers) SK_OVERRIDE {
bsalomon@google.com868a8e72012-08-30 19:11:34 +000027 builder->fFSCode.appendf("\t%s = ", outputColor);
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000028 builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplers[0]);
bsalomon@google.com868a8e72012-08-30 19:11:34 +000029 builder->fFSCode.append(";\n");
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000030 }
31
bsalomon@google.coma469c282012-10-24 18:28:34 +000032 static inline StageKey GenKey(const GrEffect&, const GrGLCaps&) { return 0; }
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000033
34private:
35
bsalomon@google.com374e7592012-10-23 17:30:45 +000036 typedef GrGLLegacyProgramStage INHERITED;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000037};
38
39///////////////////////////////////////////////////////////////////////////////
40
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000041GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000042 : INHERITED(1)
43 , fTextureAccess(texture) {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000044}
45
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000046GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, bool bilerp)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000047 : INHERITED(1)
48 , fTextureAccess(texture, bilerp) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000049}
50
51GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const GrTextureParams& params)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000052 : INHERITED(1)
53 , fTextureAccess(texture, params) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000054}
55
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000056GrSingleTextureEffect::~GrSingleTextureEffect() {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000057}
58
bsalomon@google.com6d003d12012-09-11 15:45:20 +000059const GrTextureAccess& GrSingleTextureEffect::textureAccess(int index) const {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000060 GrAssert(0 == index);
bsalomon@google.com6d003d12012-09-11 15:45:20 +000061 return fTextureAccess;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000062}
63
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000064const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const {
65 return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance();
66}
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000067
68///////////////////////////////////////////////////////////////////////////////
69
bsalomon@google.comf271cc72012-10-24 19:35:13 +000070GR_DEFINE_EFFECT_TEST(GrSingleTextureEffect);
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000071
bsalomon@google.coma469c282012-10-24 18:28:34 +000072GrEffect* GrSingleTextureEffect::TestCreate(SkRandom* random,
73 GrContext* context,
74 GrTexture* textures[]) {
bsalomon@google.com6f261be2012-10-24 19:07:10 +000075 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
76 GrEffectUnitTest::kAlphaTextureIdx;
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000077 return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx]));
78}