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 SkString fsCoordName; | 27 GrGLVertToFrag v("TextureCoords", kVec2f_GrSLType); |
28 const char* vsVaryingName; | 28 args.fPB->addVarying(&v); |
29 const char* fsVaryingNamePtr; | |
30 args.fPB->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &
fsVaryingNamePtr); | |
31 fsCoordName = fsVaryingNamePtr; | |
32 | 29 |
33 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 30 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
34 const GrShaderVar& inTextureCoords = customCoordsTextureEffect.inTexture
Coords(); | 31 const GrShaderVar& inTextureCoords = customCoordsTextureEffect.inTexture
Coords(); |
35 vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, inTextureCoords.c_
str()); | 32 vsBuilder->codeAppendf("\t%s = %s;\n", v.vsOut(), inTextureCoords.c_str(
)); |
36 | 33 |
37 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 34 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
38 fsBuilder->codeAppendf("\t%s = ", args.fOutput); | 35 fsBuilder->codeAppendf("\t%s = ", args.fOutput); |
39 fsBuilder->appendTextureLookupAndModulate(args.fInput, | 36 fsBuilder->appendTextureLookupAndModulate(args.fInput, |
40 args.fSamplers[0], | 37 args.fSamplers[0], |
41 fsCoordName.c_str(), | 38 v.fsIn(), |
42 kVec2f_GrSLType); | 39 kVec2f_GrSLType); |
43 fsBuilder->codeAppend(";\n"); | 40 fsBuilder->codeAppend(";\n"); |
44 } | 41 } |
45 | 42 |
46 virtual void setData(const GrGLProgramDataManager&, | 43 virtual void setData(const GrGLProgramDataManager&, |
47 const GrProcessor&) SK_OVERRIDE {} | 44 const GrProcessor&) SK_OVERRIDE {} |
48 | 45 |
49 private: | 46 private: |
50 typedef GrGLGeometryProcessor INHERITED; | 47 typedef GrGLGeometryProcessor INHERITED; |
51 }; | 48 }; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 }; | 91 }; |
95 SkShader::TileMode tileModes[] = { | 92 SkShader::TileMode tileModes[] = { |
96 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 93 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
97 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 94 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
98 }; | 95 }; |
99 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 96 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
100 GrTextureParams::kNon
e_FilterMode); | 97 GrTextureParams::kNon
e_FilterMode); |
101 | 98 |
102 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); | 99 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); |
103 } | 100 } |
OLD | NEW |