blob: abbd89cafa85f6044bc420c656c94da027cb7a8c [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"
egdaniel605dd0f2014-11-12 08:35:25 -08009#include "GrInvariantOutput.h"
egdaniel605dd0f2014-11-12 08:35:25 -080010#include "GrTexture.h"
joshualitteb2a6762014-12-04 11:35:33 -080011#include "gl/GrGLCaps.h"
joshualittb0a8a372014-09-23 09:50:21 -070012#include "gl/GrGLProcessor.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000013#include "gl/GrGLSL.h"
14#include "gl/GrGLTexture.h"
egdaniel605dd0f2014-11-12 08:35:25 -080015#include "gl/builders/GrGLProgramBuilder.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000016
joshualittb0a8a372014-09-23 09:50:21 -070017class GrGLSimpleTextureEffect : public GrGLFragmentProcessor {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000018public:
joshualitteb2a6762014-12-04 11:35:33 -080019 GrGLSimpleTextureEffect(const GrProcessor&) {}
bsalomon@google.com68b58c92013-01-17 16:50:08 +000020
joshualitt15988992014-10-09 15:04:05 -070021 virtual void emitCode(GrGLFPBuilder* builder,
joshualittb0a8a372014-09-23 09:50:21 -070022 const GrFragmentProcessor& fp,
bsalomon@google.com68b58c92013-01-17 16:50:08 +000023 const char* outputColor,
24 const char* inputColor,
bsalomon@google.com77af6802013-10-02 13:04:56 +000025 const TransformedCoordsArray& coords,
mtklein36352bf2015-03-25 18:17:31 -070026 const TextureSamplerArray& samplers) override {
joshualitt15988992014-10-09 15:04:05 -070027 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
joshualitt30ba4362014-08-21 20:18:45 -070028 fsBuilder->codeAppendf("\t%s = ", outputColor);
29 fsBuilder->appendTextureLookupAndModulate(inputColor,
commit-bot@chromium.org74a3a212013-08-30 19:43:59 +000030 samplers[0],
bsalomon@google.com77af6802013-10-02 13:04:56 +000031 coords[0].c_str(),
joshualitt23e280d2014-09-18 12:26:38 -070032 coords[0].getType());
joshualitt30ba4362014-08-21 20:18:45 -070033 fsBuilder->codeAppend(";\n");
bsalomon@google.com68b58c92013-01-17 16:50:08 +000034 }
35
bsalomon@google.com68b58c92013-01-17 16:50:08 +000036private:
joshualittb0a8a372014-09-23 09:50:21 -070037 typedef GrGLFragmentProcessor INHERITED;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000038};
39
40///////////////////////////////////////////////////////////////////////////////
41
egdaniel605dd0f2014-11-12 08:35:25 -080042void GrSimpleTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
egdaniel1a8ecdf2014-10-03 06:24:12 -070043 this->updateInvariantOutputForModulation(inout);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000044}
45
jvanverthcfc18862015-04-28 08:48:20 -070046void GrSimpleTextureEffect::getGLProcessorKey(const GrGLSLCaps& caps,
joshualitteb2a6762014-12-04 11:35:33 -080047 GrProcessorKeyBuilder* b) const {
48 GrGLSimpleTextureEffect::GenKey(*this, caps, b);
49}
50
51GrGLFragmentProcessor* GrSimpleTextureEffect::createGLInstance() const {
52 return SkNEW_ARGS(GrGLSimpleTextureEffect, (*this));
bsalomon@google.com68b58c92013-01-17 16:50:08 +000053}
54
55///////////////////////////////////////////////////////////////////////////////
56
joshualittb0a8a372014-09-23 09:50:21 -070057GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000058
joshualittb0a8a372014-09-23 09:50:21 -070059GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(SkRandom* random,
60 GrContext*,
61 const GrDrawTargetCaps&,
62 GrTexture* textures[]) {
63 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
64 GrProcessorUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000065 static const SkShader::TileMode kTileModes[] = {
66 SkShader::kClamp_TileMode,
67 SkShader::kRepeat_TileMode,
68 SkShader::kMirror_TileMode,
69 };
70 SkShader::TileMode tileModes[] = {
71 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
72 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
73 };
humper@google.comb86add12013-07-25 18:49:07 +000074 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
75 GrTextureParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +000076
bsalomon@google.com77af6802013-10-02 13:04:56 +000077 static const GrCoordSet kCoordSets[] = {
78 kLocal_GrCoordSet,
bsalomon309d4d52014-12-18 10:17:44 -080079 kDevice_GrCoordSet
bsalomon@google.comc7818882013-03-20 19:19:53 +000080 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000081 GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
bsalomon@google.comc7818882013-03-20 19:19:53 +000082
joshualittb0a8a372014-09-23 09:50:21 -070083 const SkMatrix& matrix = GrProcessorUnitTest::TestMatrix(random);
bsalomon@google.com77af6802013-10-02 13:04:56 +000084 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000085}