blob: 74926bc1455aa1c556e439d65b1c34d871018d94 [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"
bsalomon848faf02014-07-11 10:01:02 -070010#include "gl/GrGLShaderBuilder.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000011#include "gl/GrGLSL.h"
12#include "gl/GrGLTexture.h"
13#include "GrTBackendEffectFactory.h"
14#include "GrTexture.h"
15
16class GrGLSimpleTextureEffect : public GrGLEffect {
17public:
bsalomon@google.com77af6802013-10-02 13:04:56 +000018 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
19 : INHERITED (factory) {
bsalomon@google.comc7818882013-03-20 19:19:53 +000020 }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000021
22 virtual void emitCode(GrGLShaderBuilder* builder,
bsalomon@google.comc7818882013-03-20 19:19:53 +000023 const GrDrawEffect& drawEffect,
bsalomon63e99f72014-07-21 08:03:14 -070024 const GrEffectKey& key,
bsalomon@google.com68b58c92013-01-17 16:50:08 +000025 const char* outputColor,
26 const char* inputColor,
bsalomon@google.com77af6802013-10-02 13:04:56 +000027 const TransformedCoordsArray& coords,
bsalomon@google.com68b58c92013-01-17 16:50:08 +000028 const TextureSamplerArray& samplers) SK_OVERRIDE {
bsalomon@google.comf910d3b2013-03-07 17:06:57 +000029 builder->fsCodeAppendf("\t%s = ", outputColor);
commit-bot@chromium.org74a3a212013-08-30 19:43:59 +000030 builder->fsAppendTextureLookupAndModulate(inputColor,
31 samplers[0],
bsalomon@google.com77af6802013-10-02 13:04:56 +000032 coords[0].c_str(),
33 coords[0].type());
bsalomon@google.comf910d3b2013-03-07 17:06:57 +000034 builder->fsCodeAppend(";\n");
bsalomon@google.com68b58c92013-01-17 16:50:08 +000035 }
36
bsalomon@google.com68b58c92013-01-17 16:50:08 +000037private:
bsalomon@google.com68b58c92013-01-17 16:50:08 +000038 typedef GrGLEffect INHERITED;
39};
40
41///////////////////////////////////////////////////////////////////////////////
42
43void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
44 this->updateConstantColorComponentsForModulation(color, validFlags);
45}
46
47const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const {
48 return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance();
49}
50
51///////////////////////////////////////////////////////////////////////////////
52
53GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect);
54
bsalomon83d081a2014-07-08 09:56:10 -070055GrEffect* GrSimpleTextureEffect::TestCreate(SkRandom* random,
56 GrContext*,
57 const GrDrawTargetCaps&,
58 GrTexture* textures[]) {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000059 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
60 GrEffectUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000061 static const SkShader::TileMode kTileModes[] = {
62 SkShader::kClamp_TileMode,
63 SkShader::kRepeat_TileMode,
64 SkShader::kMirror_TileMode,
65 };
66 SkShader::TileMode tileModes[] = {
67 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
68 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
69 };
humper@google.comb86add12013-07-25 18:49:07 +000070 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
71 GrTextureParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +000072
bsalomon@google.com77af6802013-10-02 13:04:56 +000073 static const GrCoordSet kCoordSets[] = {
74 kLocal_GrCoordSet,
75 kPosition_GrCoordSet
bsalomon@google.comc7818882013-03-20 19:19:53 +000076 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000077 GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
bsalomon@google.comc7818882013-03-20 19:19:53 +000078
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000079 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
bsalomon@google.com77af6802013-10-02 13:04:56 +000080 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000081}