OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrSimpleTextureEffect.h" | 8 #include "GrSimpleTextureEffect.h" |
9 #include "gl/GrGLEffect.h" | 9 #include "gl/GrGLEffect.h" |
10 #include "gl/GrGLEffectMatrix.h" | |
11 #include "gl/GrGLSL.h" | 10 #include "gl/GrGLSL.h" |
12 #include "gl/GrGLTexture.h" | 11 #include "gl/GrGLTexture.h" |
13 #include "GrTBackendEffectFactory.h" | 12 #include "GrTBackendEffectFactory.h" |
14 #include "GrTexture.h" | 13 #include "GrTexture.h" |
15 | 14 |
16 class GrGLSimpleTextureEffect : public GrGLEffect { | 15 class GrGLSimpleTextureEffect : public GrGLEffect { |
17 public: | 16 public: |
18 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawE
ffect& drawEffect) | 17 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawE
ffect&) |
19 : INHERITED (factory) | 18 : INHERITED (factory) { |
20 , fEffectMatrix(drawEffect.castEffect<GrSimpleTextureEffect>().coordsTyp
e()) { | |
21 } | 19 } |
22 | 20 |
23 virtual void emitCode(GrGLShaderBuilder* builder, | 21 virtual void emitCode(GrGLShaderBuilder* builder, |
24 const GrDrawEffect& drawEffect, | 22 const GrDrawEffect& drawEffect, |
25 EffectKey key, | 23 EffectKey key, |
26 const char* outputColor, | 24 const char* outputColor, |
27 const char* inputColor, | 25 const char* inputColor, |
| 26 const TransformedCoordsArray& coords, |
28 const TextureSamplerArray& samplers) SK_OVERRIDE { | 27 const TextureSamplerArray& samplers) SK_OVERRIDE { |
29 SkString fsCoordName; | |
30 GrSLType fsCoordSLType; | |
31 fsCoordSLType = fEffectMatrix.emitCode(builder, key, &fsCoordName); | |
32 | |
33 builder->fsCodeAppendf("\t%s = ", outputColor); | 28 builder->fsCodeAppendf("\t%s = ", outputColor); |
34 builder->fsAppendTextureLookupAndModulate(inputColor, | 29 builder->fsAppendTextureLookupAndModulate(inputColor, |
35 samplers[0], | 30 samplers[0], |
36 fsCoordName.c_str(), | 31 coords[0].c_str(), |
37 fsCoordSLType); | 32 coords[0].type()); |
38 builder->fsCodeAppend(";\n"); | 33 builder->fsCodeAppend(";\n"); |
39 } | 34 } |
40 | 35 |
41 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { | |
42 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture
Effect>(); | |
43 return GrGLEffectMatrix::GenKey(ste.getMatrix(), | |
44 drawEffect, | |
45 ste.coordsType(), | |
46 ste.texture(0)); | |
47 } | |
48 | |
49 virtual void setData(const GrGLUniformManager& uman, | |
50 const GrDrawEffect& drawEffect) SK_OVERRIDE { | |
51 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture
Effect>(); | |
52 fEffectMatrix.setData(uman, ste.getMatrix(), drawEffect, ste.texture(0))
; | |
53 } | |
54 | |
55 private: | 36 private: |
56 GrGLEffectMatrix fEffectMatrix; | |
57 typedef GrGLEffect INHERITED; | 37 typedef GrGLEffect INHERITED; |
58 }; | 38 }; |
59 | 39 |
60 /////////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////////// |
61 | 41 |
62 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { | 42 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { |
63 this->updateConstantColorComponentsForModulation(color, validFlags); | 43 this->updateConstantColorComponentsForModulation(color, validFlags); |
64 } | 44 } |
65 | 45 |
66 const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { | 46 const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { |
(...skipping 15 matching lines...) Expand all Loading... |
82 SkShader::kRepeat_TileMode, | 62 SkShader::kRepeat_TileMode, |
83 SkShader::kMirror_TileMode, | 63 SkShader::kMirror_TileMode, |
84 }; | 64 }; |
85 SkShader::TileMode tileModes[] = { | 65 SkShader::TileMode tileModes[] = { |
86 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 66 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
87 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 67 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
88 }; | 68 }; |
89 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 69 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
90 GrTextureParams::kNon
e_FilterMode); | 70 GrTextureParams::kNon
e_FilterMode); |
91 | 71 |
92 static const CoordsType kCoordsTypes[] = { | 72 static const GrCoordSet kCoordSets[] = { |
93 kLocal_CoordsType, | 73 kLocal_GrCoordSet, |
94 kPosition_CoordsType | 74 kPosition_GrCoordSet |
95 }; | 75 }; |
96 CoordsType coordsType = kCoordsTypes[random->nextULessThan(GR_ARRAY_COUNT(kC
oordsTypes))]; | 76 GrCoordSet coordSet = kCoordSets[random->nextULessThan(GR_ARRAY_COUNT(kCoord
Sets))]; |
97 | 77 |
98 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); | 78 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
99 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordsType); | 79 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet); |
100 } | 80 } |
OLD | NEW |