OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrCustomCoordsTextureEffect.h" | 8 #include "GrCustomCoordsTextureEffect.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 GrGLCustomCoordsTextureEffect : public GrGLEffect { | 15 class GrGLCustomCoordsTextureEffect : public GrGLEffect { |
17 public: | 16 public: |
18 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G
rDrawEffect& drawEffect) | 17 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G
rDrawEffect& drawEffect) |
19 : INHERITED (factory) {} | 18 : INHERITED (factory) {} |
20 | 19 |
21 virtual void emitCode(GrGLShaderBuilder* builder, | 20 virtual void emitCode(GrGLShaderBuilder* builder, |
22 const GrDrawEffect& drawEffect, | 21 const GrDrawEffect& drawEffect, |
23 EffectKey key, | 22 EffectKey key, |
24 const char* outputColor, | 23 const char* outputColor, |
25 const char* inputColor, | 24 const char* inputColor, |
| 25 const TransformedCoordsArray&, |
26 const TextureSamplerArray& samplers) SK_OVERRIDE { | 26 const TextureSamplerArray& samplers) SK_OVERRIDE { |
27 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuil
der(); | 27 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuil
der(); |
28 SkASSERT(NULL != vertexBuilder); | 28 SkASSERT(NULL != vertexBuilder); |
29 SkASSERT(1 == drawEffect.castEffect<GrCustomCoordsTextureEffect>().numVe
rtexAttribs()); | 29 SkASSERT(1 == drawEffect.castEffect<GrCustomCoordsTextureEffect>().numVe
rtexAttribs()); |
30 | 30 |
31 SkString fsCoordName; | 31 SkString fsCoordName; |
32 const char* vsVaryingName; | 32 const char* vsVaryingName; |
33 const char* fsVaryingNamePtr; | 33 const char* fsVaryingNamePtr; |
34 vertexBuilder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingNa
me, &fsVaryingNamePtr); | 34 vertexBuilder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingNa
me, &fsVaryingNamePtr); |
35 fsCoordName = fsVaryingNamePtr; | 35 fsCoordName = fsVaryingNamePtr; |
36 | 36 |
37 const char* attrName = | 37 const char* attrName = |
38 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndi
ces()[0])->c_str(); | 38 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndi
ces()[0])->c_str(); |
39 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName); | 39 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName); |
40 | 40 |
41 builder->fsCodeAppendf("\t%s = ", outputColor); | 41 builder->fsCodeAppendf("\t%s = ", outputColor); |
42 builder->fsAppendTextureLookupAndModulate(inputColor, | 42 builder->fsAppendTextureLookupAndModulate(inputColor, |
43 samplers[0], | 43 samplers[0], |
44 fsCoordName.c_str(), | 44 fsCoordName.c_str(), |
45 kVec2f_GrSLType); | 45 kVec2f_GrSLType); |
46 builder->fsCodeAppend(";\n"); | 46 builder->fsCodeAppend(";\n"); |
47 } | 47 } |
48 | 48 |
49 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { | |
50 return 1 << GrGLEffectMatrix::kKeyBits; | |
51 } | |
52 | |
53 virtual void setData(const GrGLUniformManager& uman, | 49 virtual void setData(const GrGLUniformManager& uman, |
54 const GrDrawEffect& drawEffect) SK_OVERRIDE {} | 50 const GrDrawEffect& drawEffect) SK_OVERRIDE {} |
55 | 51 |
56 private: | 52 private: |
57 typedef GrGLEffect INHERITED; | 53 typedef GrGLEffect INHERITED; |
58 }; | 54 }; |
59 | 55 |
60 /////////////////////////////////////////////////////////////////////////////// | 56 /////////////////////////////////////////////////////////////////////////////// |
61 | 57 |
62 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, | 58 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 }; | 98 }; |
103 SkShader::TileMode tileModes[] = { | 99 SkShader::TileMode tileModes[] = { |
104 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 100 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
105 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 101 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
106 }; | 102 }; |
107 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 103 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
108 GrTextureParams::kNon
e_FilterMode); | 104 GrTextureParams::kNon
e_FilterMode); |
109 | 105 |
110 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); | 106 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); |
111 } | 107 } |
OLD | NEW |