blob: 78719206cebdcd3712c3ba67c5b04c1f4dc2be61 [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
joshualitt30ba4362014-08-21 20:18:45 -07008#include "gl/builders/GrGLProgramBuilder.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +00009#include "GrSimpleTextureEffect.h"
10#include "gl/GrGLEffect.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:
joshualitt49586be2014-09-16 08:21:41 -070018 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrEffect&)
bsalomon@google.com77af6802013-10-02 13:04:56 +000019 : INHERITED (factory) {
bsalomon@google.comc7818882013-03-20 19:19:53 +000020 }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000021
joshualitt30ba4362014-08-21 20:18:45 -070022 virtual void emitCode(GrGLProgramBuilder* builder,
joshualitt49586be2014-09-16 08:21:41 -070023 const GrEffect& effect,
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 {
joshualitt30ba4362014-08-21 20:18:45 -070029 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
30 fsBuilder->codeAppendf("\t%s = ", outputColor);
31 fsBuilder->appendTextureLookupAndModulate(inputColor,
commit-bot@chromium.org74a3a212013-08-30 19:43:59 +000032 samplers[0],
bsalomon@google.com77af6802013-10-02 13:04:56 +000033 coords[0].c_str(),
34 coords[0].type());
joshualitt30ba4362014-08-21 20:18:45 -070035 fsBuilder->codeAppend(";\n");
bsalomon@google.com68b58c92013-01-17 16:50:08 +000036 }
37
bsalomon@google.com68b58c92013-01-17 16:50:08 +000038private:
bsalomon@google.com68b58c92013-01-17 16:50:08 +000039 typedef GrGLEffect INHERITED;
40};
41
42///////////////////////////////////////////////////////////////////////////////
43
44void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
45 this->updateConstantColorComponentsForModulation(color, validFlags);
46}
47
48const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const {
49 return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance();
50}
51
52///////////////////////////////////////////////////////////////////////////////
53
54GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect);
55
bsalomon83d081a2014-07-08 09:56:10 -070056GrEffect* GrSimpleTextureEffect::TestCreate(SkRandom* random,
57 GrContext*,
58 const GrDrawTargetCaps&,
59 GrTexture* textures[]) {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000060 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
61 GrEffectUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000062 static const SkShader::TileMode kTileModes[] = {
63 SkShader::kClamp_TileMode,
64 SkShader::kRepeat_TileMode,
65 SkShader::kMirror_TileMode,
66 };
67 SkShader::TileMode tileModes[] = {
68 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
69 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
70 };
humper@google.comb86add12013-07-25 18:49:07 +000071 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
72 GrTextureParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +000073
bsalomon@google.com77af6802013-10-02 13:04:56 +000074 static const GrCoordSet kCoordSets[] = {
75 kLocal_GrCoordSet,
76 kPosition_GrCoordSet
bsalomon@google.comc7818882013-03-20 19:19:53 +000077 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000078 GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
bsalomon@google.comc7818882013-03-20 19:19:53 +000079
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000080 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
bsalomon@google.com77af6802013-10-02 13:04:56 +000081 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000082}