blob: a7707da8af089ad71340a2cb926da0f71f0a4304 [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"
joshualittb0a8a372014-09-23 09:50:21 -070010#include "gl/GrGLProcessor.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000011#include "gl/GrGLSL.h"
12#include "gl/GrGLTexture.h"
joshualittb0a8a372014-09-23 09:50:21 -070013#include "GrTBackendProcessorFactory.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000014#include "GrTexture.h"
15
joshualittb0a8a372014-09-23 09:50:21 -070016class GrGLSimpleTextureEffect : public GrGLFragmentProcessor {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000017public:
joshualittb0a8a372014-09-23 09:50:21 -070018 GrGLSimpleTextureEffect(const GrBackendProcessorFactory& factory, const GrProcessor&)
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,
joshualittb0a8a372014-09-23 09:50:21 -070023 const GrFragmentProcessor& fp,
24 const GrProcessorKey& 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(),
joshualitt23e280d2014-09-18 12:26:38 -070034 coords[0].getType());
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:
joshualittb0a8a372014-09-23 09:50:21 -070039 typedef GrGLFragmentProcessor INHERITED;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000040};
41
42///////////////////////////////////////////////////////////////////////////////
43
egdaniel1a8ecdf2014-10-03 06:24:12 -070044void GrSimpleTextureEffect::onComputeInvariantOutput(InvariantOutput* inout) const {
45 this->updateInvariantOutputForModulation(inout);
46 inout->fIsSingleComponent = false;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000047}
48
joshualittb0a8a372014-09-23 09:50:21 -070049const GrBackendFragmentProcessorFactory& GrSimpleTextureEffect::getFactory() const {
50 return GrTBackendFragmentProcessorFactory<GrSimpleTextureEffect>::getInstance();
bsalomon@google.com68b58c92013-01-17 16:50:08 +000051}
52
53///////////////////////////////////////////////////////////////////////////////
54
joshualittb0a8a372014-09-23 09:50:21 -070055GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000056
joshualittb0a8a372014-09-23 09:50:21 -070057GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(SkRandom* random,
58 GrContext*,
59 const GrDrawTargetCaps&,
60 GrTexture* textures[]) {
61 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
62 GrProcessorUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000063 static const SkShader::TileMode kTileModes[] = {
64 SkShader::kClamp_TileMode,
65 SkShader::kRepeat_TileMode,
66 SkShader::kMirror_TileMode,
67 };
68 SkShader::TileMode tileModes[] = {
69 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
70 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
71 };
humper@google.comb86add12013-07-25 18:49:07 +000072 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
73 GrTextureParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +000074
bsalomon@google.com77af6802013-10-02 13:04:56 +000075 static const GrCoordSet kCoordSets[] = {
76 kLocal_GrCoordSet,
77 kPosition_GrCoordSet
bsalomon@google.comc7818882013-03-20 19:19:53 +000078 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000079 GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
bsalomon@google.comc7818882013-03-20 19:19:53 +000080
joshualittb0a8a372014-09-23 09:50:21 -070081 const SkMatrix& matrix = GrProcessorUnitTest::TestMatrix(random);
bsalomon@google.com77af6802013-10-02 13:04:56 +000082 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000083}