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/builders/GrGLProgramBuilder.h" | 9 #include "gl/builders/GrGLProgramBuilder.h" |
10 #include "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
12 #include "gl/GrGLTexture.h" | 12 #include "gl/GrGLTexture.h" |
13 #include "gl/GrGLGeometryProcessor.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
14 #include "GrTBackendProcessorFactory.h" | 14 #include "GrTBackendProcessorFactory.h" |
15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
16 | 16 |
17 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { | 17 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { |
18 public: | 18 public: |
19 GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory, cons
t GrProcessor&) | 19 GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory, cons
t GrProcessor&) |
20 : INHERITED (factory) {} | 20 : INHERITED (factory) {} |
21 | 21 |
22 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 22 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
23 const GrCustomCoordsTextureEffect& customCoordsTextureEffect = | 23 const GrCustomCoordsTextureEffect& customCoordsTextureEffect = |
24 args.fGP.cast<GrCustomCoordsTextureEffect>(); | 24 args.fGP.cast<GrCustomCoordsTextureEffect>(); |
25 SkASSERT(1 == customCoordsTextureEffect.getVertexAttribs().count()); | 25 SkASSERT(1 == customCoordsTextureEffect.getVertexAttribs().count()); |
26 | 26 |
27 GrGLVertToFrag v(kVec2f_GrSLType); | 27 SkString fsCoordName; |
28 args.fPB->addVarying("TextureCoords", &v); | 28 const char* vsVaryingName; |
| 29 const char* fsVaryingNamePtr; |
| 30 args.fPB->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &
fsVaryingNamePtr); |
| 31 fsCoordName = fsVaryingNamePtr; |
29 | 32 |
30 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 33 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
31 const GrShaderVar& inTextureCoords = customCoordsTextureEffect.inTexture
Coords(); | 34 const GrShaderVar& inTextureCoords = customCoordsTextureEffect.inTexture
Coords(); |
32 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), inTextureCoords.c_str()); | 35 vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, inTextureCoords.c_
str()); |
33 | 36 |
34 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 37 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
35 fsBuilder->codeAppendf("%s = ", args.fOutput); | 38 fsBuilder->codeAppendf("\t%s = ", args.fOutput); |
36 fsBuilder->appendTextureLookupAndModulate(args.fInput, | 39 fsBuilder->appendTextureLookupAndModulate(args.fInput, |
37 args.fSamplers[0], | 40 args.fSamplers[0], |
38 v.fsIn(), | 41 fsCoordName.c_str(), |
39 kVec2f_GrSLType); | 42 kVec2f_GrSLType); |
40 fsBuilder->codeAppend(";"); | 43 fsBuilder->codeAppend(";\n"); |
41 } | 44 } |
42 | 45 |
43 virtual void setData(const GrGLProgramDataManager&, | 46 virtual void setData(const GrGLProgramDataManager&, |
44 const GrProcessor&) SK_OVERRIDE {} | 47 const GrProcessor&) SK_OVERRIDE {} |
45 | 48 |
46 private: | 49 private: |
47 typedef GrGLGeometryProcessor INHERITED; | 50 typedef GrGLGeometryProcessor INHERITED; |
48 }; | 51 }; |
49 | 52 |
50 /////////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 }; | 94 }; |
92 SkShader::TileMode tileModes[] = { | 95 SkShader::TileMode tileModes[] = { |
93 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 96 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
94 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 97 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
95 }; | 98 }; |
96 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 99 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
97 GrTextureParams::kNon
e_FilterMode); | 100 GrTextureParams::kNon
e_FilterMode); |
98 | 101 |
99 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); | 102 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); |
100 } | 103 } |
OLD | NEW |