blob: 370b2ce9a9446d3e0a289586663ac868272312d1 [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/GrGLTexture.h"
egdaniel605dd0f2014-11-12 08:35:25 -080014#include "gl/builders/GrGLProgramBuilder.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000015
joshualittb0a8a372014-09-23 09:50:21 -070016class GrGLSimpleTextureEffect : public GrGLFragmentProcessor {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000017public:
joshualitteb2a6762014-12-04 11:35:33 -080018 GrGLSimpleTextureEffect(const GrProcessor&) {}
bsalomon@google.com68b58c92013-01-17 16:50:08 +000019
joshualitt15988992014-10-09 15:04:05 -070020 virtual void emitCode(GrGLFPBuilder* builder,
joshualittb0a8a372014-09-23 09:50:21 -070021 const GrFragmentProcessor& fp,
bsalomon@google.com68b58c92013-01-17 16:50:08 +000022 const char* outputColor,
23 const char* inputColor,
bsalomon@google.com77af6802013-10-02 13:04:56 +000024 const TransformedCoordsArray& coords,
mtklein36352bf2015-03-25 18:17:31 -070025 const TextureSamplerArray& samplers) override {
egdaniel29bee0f2015-04-29 11:54:42 -070026 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
joshualitt30ba4362014-08-21 20:18:45 -070027 fsBuilder->codeAppendf("\t%s = ", outputColor);
28 fsBuilder->appendTextureLookupAndModulate(inputColor,
commit-bot@chromium.org74a3a212013-08-30 19:43:59 +000029 samplers[0],
bsalomon@google.com77af6802013-10-02 13:04:56 +000030 coords[0].c_str(),
joshualitt23e280d2014-09-18 12:26:38 -070031 coords[0].getType());
joshualitt30ba4362014-08-21 20:18:45 -070032 fsBuilder->codeAppend(";\n");
bsalomon@google.com68b58c92013-01-17 16:50:08 +000033 }
34
bsalomon@google.com68b58c92013-01-17 16:50:08 +000035private:
joshualittb0a8a372014-09-23 09:50:21 -070036 typedef GrGLFragmentProcessor INHERITED;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000037};
38
39///////////////////////////////////////////////////////////////////////////////
40
egdaniel605dd0f2014-11-12 08:35:25 -080041void GrSimpleTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
egdaniel1a8ecdf2014-10-03 06:24:12 -070042 this->updateInvariantOutputForModulation(inout);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000043}
44
jvanverthcfc18862015-04-28 08:48:20 -070045void GrSimpleTextureEffect::getGLProcessorKey(const GrGLSLCaps& caps,
joshualitteb2a6762014-12-04 11:35:33 -080046 GrProcessorKeyBuilder* b) const {
47 GrGLSimpleTextureEffect::GenKey(*this, caps, b);
48}
49
50GrGLFragmentProcessor* GrSimpleTextureEffect::createGLInstance() const {
51 return SkNEW_ARGS(GrGLSimpleTextureEffect, (*this));
bsalomon@google.com68b58c92013-01-17 16:50:08 +000052}
53
54///////////////////////////////////////////////////////////////////////////////
55
joshualittb0a8a372014-09-23 09:50:21 -070056GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000057
joshualittb0a8a372014-09-23 09:50:21 -070058GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(SkRandom* random,
59 GrContext*,
bsalomon4b91f762015-05-19 09:29:46 -070060 const GrCaps&,
joshualittb0a8a372014-09-23 09:50:21 -070061 GrTexture* textures[]) {
62 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
63 GrProcessorUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000064 static const SkShader::TileMode kTileModes[] = {
65 SkShader::kClamp_TileMode,
66 SkShader::kRepeat_TileMode,
67 SkShader::kMirror_TileMode,
68 };
69 SkShader::TileMode tileModes[] = {
70 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
71 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
72 };
humper@google.comb86add12013-07-25 18:49:07 +000073 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
74 GrTextureParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +000075
bsalomon@google.com77af6802013-10-02 13:04:56 +000076 static const GrCoordSet kCoordSets[] = {
77 kLocal_GrCoordSet,
bsalomon309d4d52014-12-18 10:17:44 -080078 kDevice_GrCoordSet
bsalomon@google.comc7818882013-03-20 19:19:53 +000079 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000080 GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
bsalomon@google.comc7818882013-03-20 19:19:53 +000081
joshualitt4eaf9ce2015-04-28 13:31:18 -070082 const SkMatrix& matrix = GrTest::TestMatrix(random);
bsalomon@google.com77af6802013-10-02 13:04:56 +000083 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000084}