OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkNormalMapSource.h" | 8 #include "SkNormalMapSource.h" |
9 | 9 |
10 #include "SkLightingShader.h" | 10 #include "SkLightingShader.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 class NormalMapFP : public GrFragmentProcessor { | 25 class NormalMapFP : public GrFragmentProcessor { |
26 public: | 26 public: |
27 NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM) | 27 NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM) |
28 : fInvCTM(invCTM) { | 28 : fInvCTM(invCTM) { |
29 this->registerChildProcessor(mapFP); | 29 this->registerChildProcessor(mapFP); |
30 | 30 |
31 this->initClassID<NormalMapFP>(); | 31 this->initClassID<NormalMapFP>(); |
32 } | 32 } |
33 | 33 |
34 class GLSLNormalMapFP : public GrGLSLFragmentProcessor { | 34 class GLSLNormalMapFP : public GLSLNormalFP { |
35 public: | 35 public: |
36 GLSLNormalMapFP() | 36 GLSLNormalMapFP() |
37 : fColumnMajorInvCTM22{0.0f} {} | 37 : fColumnMajorInvCTM22{0.0f} {} |
38 | 38 |
39 void emitCode(EmitArgs& args) override { | 39 void onEmitCode(EmitArgs& args) override { |
40 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 40 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
41 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 41 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
42 | 42 |
43 // add uniform | 43 // add uniform |
44 const char* xformUniName = nullptr; | 44 const char* xformUniName = nullptr; |
45 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat2
2f_GrSLType, | 45 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat2
2f_GrSLType, |
46 kDefault_GrSLPrecision, "Xfor
m", &xformUniName); | 46 kDefault_GrSLPrecision, "Xfor
m", &xformUniName); |
47 | 47 |
48 SkString dstNormalColorName("dstNormalColor"); | 48 SkString dstNormalColorName("dstNormalColor"); |
49 this->emitChild(0, nullptr, &dstNormalColorName, args); | 49 this->emitChild(0, nullptr, &dstNormalColorName, args); |
50 fragBuilder->codeAppendf("vec3 normal = normalize(%s.rgb - vec3(0.5)
);", | 50 fragBuilder->codeAppendf("vec3 normal = normalize(%s.rgb - vec3(0.5)
);", |
(...skipping 20 matching lines...) Expand all Loading... |
71 args.fOutputColor); | 71 args.fOutputColor); |
72 fragBuilder->codeAppend( "}"); | 72 fragBuilder->codeAppend( "}"); |
73 } | 73 } |
74 | 74 |
75 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 75 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
76 GrProcessorKeyBuilder* b) { | 76 GrProcessorKeyBuilder* b) { |
77 b->add32(0x0); | 77 b->add32(0x0); |
78 } | 78 } |
79 | 79 |
80 protected: | 80 protected: |
81 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override { | 81 void setNormalData(const GrGLSLProgramDataManager& pdman, |
| 82 const GrProcessor& proc) override { |
82 const NormalMapFP& normalMapFP = proc.cast<NormalMapFP>(); | 83 const NormalMapFP& normalMapFP = proc.cast<NormalMapFP>(); |
83 | 84 |
84 const SkMatrix& invCTM = normalMapFP.invCTM(); | 85 const SkMatrix& invCTM = normalMapFP.invCTM(); |
85 fColumnMajorInvCTM22[0] = invCTM.get(SkMatrix::kMScaleX); | 86 fColumnMajorInvCTM22[0] = invCTM.get(SkMatrix::kMScaleX); |
86 fColumnMajorInvCTM22[1] = invCTM.get(SkMatrix::kMSkewY); | 87 fColumnMajorInvCTM22[1] = invCTM.get(SkMatrix::kMSkewY); |
87 fColumnMajorInvCTM22[2] = invCTM.get(SkMatrix::kMSkewX); | 88 fColumnMajorInvCTM22[2] = invCTM.get(SkMatrix::kMSkewX); |
88 fColumnMajorInvCTM22[3] = invCTM.get(SkMatrix::kMScaleY); | 89 fColumnMajorInvCTM22[3] = invCTM.get(SkMatrix::kMScaleY); |
89 pdman.setMatrix2f(fXformUni, fColumnMajorInvCTM22); | 90 pdman.setMatrix2f(fXformUni, fColumnMajorInvCTM22); |
90 } | 91 } |
91 | 92 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 262 |
262 sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con
st SkMatrix& ctm) { | 263 sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con
st SkMatrix& ctm) { |
263 SkMatrix invCTM; | 264 SkMatrix invCTM; |
264 | 265 |
265 if (!ctm.invert(&invCTM) || !map) { | 266 if (!ctm.invert(&invCTM) || !map) { |
266 return nullptr; | 267 return nullptr; |
267 } | 268 } |
268 | 269 |
269 return sk_make_sp<SkNormalMapSourceImpl>(std::move(map), invCTM); | 270 return sk_make_sp<SkNormalMapSourceImpl>(std::move(map), invCTM); |
270 } | 271 } |
OLD | NEW |