blob: b27b737f39f36dc653a2c641c44efa0354f985af [file] [log] [blame]
bsalomon@google.com68b58c92013-01-17 16:50:08 +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 "GrSimpleTextureEffect.h"
9#include "gl/GrGLEffect.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000010#include "gl/GrGLSL.h"
11#include "gl/GrGLTexture.h"
12#include "GrTBackendEffectFactory.h"
13#include "GrTexture.h"
14
15class GrGLSimpleTextureEffect : public GrGLEffect {
16public:
bsalomon@google.com77af6802013-10-02 13:04:56 +000017 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
18 : INHERITED (factory) {
bsalomon@google.comc7818882013-03-20 19:19:53 +000019 }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000020
21 virtual void emitCode(GrGLShaderBuilder* builder,
bsalomon@google.comc7818882013-03-20 19:19:53 +000022 const GrDrawEffect& drawEffect,
bsalomon@google.com68b58c92013-01-17 16:50:08 +000023 EffectKey key,
bsalomon@google.com68b58c92013-01-17 16:50:08 +000024 const char* outputColor,
25 const char* inputColor,
bsalomon@google.com77af6802013-10-02 13:04:56 +000026 const TransformedCoordsArray& coords,
bsalomon@google.com68b58c92013-01-17 16:50:08 +000027 const TextureSamplerArray& samplers) SK_OVERRIDE {
bsalomon@google.comf910d3b2013-03-07 17:06:57 +000028 builder->fsCodeAppendf("\t%s = ", outputColor);
commit-bot@chromium.org74a3a212013-08-30 19:43:59 +000029 builder->fsAppendTextureLookupAndModulate(inputColor,
30 samplers[0],
bsalomon@google.com77af6802013-10-02 13:04:56 +000031 coords[0].c_str(),
32 coords[0].type());
bsalomon@google.comf910d3b2013-03-07 17:06:57 +000033 builder->fsCodeAppend(";\n");
bsalomon@google.com68b58c92013-01-17 16:50:08 +000034 }
35
bsalomon@google.com68b58c92013-01-17 16:50:08 +000036private:
bsalomon@google.com68b58c92013-01-17 16:50:08 +000037 typedef GrGLEffect INHERITED;
38};
39
40///////////////////////////////////////////////////////////////////////////////
41
42void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
43 this->updateConstantColorComponentsForModulation(color, validFlags);
44}
45
46const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const {
47 return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance();
48}
49
50///////////////////////////////////////////////////////////////////////////////
51
52GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect);
53
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000054GrEffectRef* GrSimpleTextureEffect::TestCreate(SkRandom* random,
sugoi@google.come0e385c2013-03-11 18:50:03 +000055 GrContext*,
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000056 const GrDrawTargetCaps&,
bsalomon@google.com68b58c92013-01-17 16:50:08 +000057 GrTexture* textures[]) {
58 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
59 GrEffectUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000060 static const SkShader::TileMode kTileModes[] = {
61 SkShader::kClamp_TileMode,
62 SkShader::kRepeat_TileMode,
63 SkShader::kMirror_TileMode,
64 };
65 SkShader::TileMode tileModes[] = {
66 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
67 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
68 };
humper@google.comb86add12013-07-25 18:49:07 +000069 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
70 GrTextureParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +000071
bsalomon@google.com77af6802013-10-02 13:04:56 +000072 static const GrCoordSet kCoordSets[] = {
73 kLocal_GrCoordSet,
74 kPosition_GrCoordSet
bsalomon@google.comc7818882013-03-20 19:19:53 +000075 };
bsalomon@google.com77af6802013-10-02 13:04:56 +000076 GrCoordSet coordSet = kCoordSets[random->nextULessThan(GR_ARRAY_COUNT(kCoordSets))];
bsalomon@google.comc7818882013-03-20 19:19:53 +000077
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000078 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
bsalomon@google.com77af6802013-10-02 13:04:56 +000079 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000080}