blob: 8866153962337aa8abc19fb4c7975266dd9253e4 [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"
bsalomon@google.com2eaaefd2012-10-29 19:51:22 +000012#include "GrTBackendEffectFactory.h"
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000013#include "GrTexture.h"
14
bsalomon@google.com22a800a2012-10-26 19:16:46 +000015class GrGLSingleTextureEffect : public GrGLEffect {
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000016public:
bsalomon@google.com396e61f2012-10-25 19:00:29 +000017 GrGLSingleTextureEffect(const GrBackendEffectFactory& factory, const GrEffect&)
bsalomon@google.com021fc732012-10-25 12:47:42 +000018 : INHERITED (factory) {
19 }
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000020
bsalomon@google.com22a800a2012-10-26 19:16:46 +000021 virtual void emitCode(GrGLShaderBuilder* builder,
bsalomon@google.com2eaaefd2012-10-29 19:51:22 +000022 const GrEffectStage&,
bsalomon@google.com66e534d2012-11-01 14:02:43 +000023 EffectKey,
bsalomon@google.com22a800a2012-10-26 19:16:46 +000024 const char* vertexCoords,
25 const char* outputColor,
26 const char* inputColor,
27 const TextureSamplerArray& samplers) SK_OVERRIDE {
bsalomon@google.com66e534d2012-11-01 14:02:43 +000028
bsalomon@google.com868a8e72012-08-30 19:11:34 +000029 builder->fFSCode.appendf("\t%s = ", outputColor);
bsalomon@google.com66e534d2012-11-01 14:02:43 +000030 builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColor, samplers[0]);
bsalomon@google.com868a8e72012-08-30 19:11:34 +000031 builder->fFSCode.append(";\n");
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000032 }
33
bsalomon@google.com66e534d2012-11-01 14:02:43 +000034 static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&) { return 0; }
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000035
36private:
bsalomon@google.com66e534d2012-11-01 14:02:43 +000037
bsalomon@google.com22a800a2012-10-26 19:16:46 +000038 typedef GrGLEffect INHERITED;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000039};
40
41///////////////////////////////////////////////////////////////////////////////
42
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000043GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000044 : INHERITED(1)
45 , fTextureAccess(texture) {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000046}
47
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000048GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, bool bilerp)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000049 : INHERITED(1)
50 , fTextureAccess(texture, bilerp) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000051}
52
53GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const GrTextureParams& params)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000054 : INHERITED(1)
55 , fTextureAccess(texture, params) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000056}
57
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000058GrSingleTextureEffect::~GrSingleTextureEffect() {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000059}
60
bsalomon@google.com6d003d12012-09-11 15:45:20 +000061const GrTextureAccess& GrSingleTextureEffect::textureAccess(int index) const {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000062 GrAssert(0 == index);
bsalomon@google.com6d003d12012-09-11 15:45:20 +000063 return fTextureAccess;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000064}
65
bsalomon@google.com396e61f2012-10-25 19:00:29 +000066const GrBackendEffectFactory& GrSingleTextureEffect::getFactory() const {
67 return GrTBackendEffectFactory<GrSingleTextureEffect>::getInstance();
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000068}
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000069
70///////////////////////////////////////////////////////////////////////////////
71
bsalomon@google.comf271cc72012-10-24 19:35:13 +000072GR_DEFINE_EFFECT_TEST(GrSingleTextureEffect);
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000073
bsalomon@google.coma469c282012-10-24 18:28:34 +000074GrEffect* GrSingleTextureEffect::TestCreate(SkRandom* random,
75 GrContext* context,
76 GrTexture* textures[]) {
bsalomon@google.com6f261be2012-10-24 19:07:10 +000077 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
78 GrEffectUnitTest::kAlphaTextureIdx;
bsalomon@google.com66e534d2012-11-01 14:02:43 +000079 return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx]));
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000080}