blob: 89b354632a23a672789f79317328c24568802561 [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"
wangyix6af0c932015-07-22 10:21:17 -070012#include "gl/GrGLFragmentProcessor.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
wangyix7c157a92015-07-22 15:08:53 -070020 virtual void emitCode(EmitArgs& args) override {
21 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
22 fsBuilder->codeAppendf("\t%s = ", args.fOutputColor);
23 fsBuilder->appendTextureLookupAndModulate(args.fInputColor,
24 args.fSamplers[0],
25 args.fCoords[0].c_str(),
26 args.fCoords[0].getType());
joshualitt30ba4362014-08-21 20:18:45 -070027 fsBuilder->codeAppend(";\n");
bsalomon@google.com68b58c92013-01-17 16:50:08 +000028 }
29
bsalomon@google.com68b58c92013-01-17 16:50:08 +000030private:
joshualittb0a8a372014-09-23 09:50:21 -070031 typedef GrGLFragmentProcessor INHERITED;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000032};
33
34///////////////////////////////////////////////////////////////////////////////
35
egdaniel605dd0f2014-11-12 08:35:25 -080036void GrSimpleTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
egdaniel1a8ecdf2014-10-03 06:24:12 -070037 this->updateInvariantOutputForModulation(inout);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000038}
39
wangyix4b3050b2015-08-04 07:59:37 -070040void GrSimpleTextureEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
joshualitteb2a6762014-12-04 11:35:33 -080041 GrProcessorKeyBuilder* b) const {
42 GrGLSimpleTextureEffect::GenKey(*this, caps, b);
43}
44
wangyixb1daa862015-08-18 11:29:31 -070045GrGLFragmentProcessor* GrSimpleTextureEffect::onCreateGLInstance() const {
halcanary385fe4d2015-08-26 13:07:48 -070046 return new GrGLSimpleTextureEffect(*this);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000047}
48
49///////////////////////////////////////////////////////////////////////////////
50
joshualittb0a8a372014-09-23 09:50:21 -070051GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000052
bsalomonc21b09e2015-08-28 18:46:56 -070053const GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(GrProcessorTestData* d) {
joshualitt0067ff52015-07-08 14:26:19 -070054 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
55 GrProcessorUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000056 static const SkShader::TileMode kTileModes[] = {
57 SkShader::kClamp_TileMode,
58 SkShader::kRepeat_TileMode,
59 SkShader::kMirror_TileMode,
60 };
61 SkShader::TileMode tileModes[] = {
joshualitt0067ff52015-07-08 14:26:19 -070062 kTileModes[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
63 kTileModes[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
bsalomon@google.comc7818882013-03-20 19:19:53 +000064 };
joshualitt0067ff52015-07-08 14:26:19 -070065 GrTextureParams params(tileModes, d->fRandom->nextBool() ? GrTextureParams::kBilerp_FilterMode :
66 GrTextureParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +000067
bsalomon@google.com77af6802013-10-02 13:04:56 +000068 static const GrCoordSet kCoordSets[] = {
69 kLocal_GrCoordSet,
bsalomon309d4d52014-12-18 10:17:44 -080070 kDevice_GrCoordSet
bsalomon@google.comc7818882013-03-20 19:19:53 +000071 };
joshualitt0067ff52015-07-08 14:26:19 -070072 GrCoordSet coordSet = kCoordSets[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
bsalomon@google.comc7818882013-03-20 19:19:53 +000073
joshualitt0067ff52015-07-08 14:26:19 -070074 const SkMatrix& matrix = GrTest::TestMatrix(d->fRandom);
bsalomon4a339522015-10-06 08:40:50 -070075 return GrSimpleTextureEffect::Create(d->fTextures[texIdx], matrix, coordSet);
bsalomon@google.com68b58c92013-01-17 16:50:08 +000076}