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" |
11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
12 #include "SkNormalSource.h" | 12 #include "SkNormalSource.h" |
13 #include "SkNormalSourcePriv.h" | |
14 #include "SkPM4f.h" | 13 #include "SkPM4f.h" |
15 #include "SkReadBuffer.h" | 14 #include "SkReadBuffer.h" |
16 #include "SkWriteBuffer.h" | 15 #include "SkWriteBuffer.h" |
17 | 16 |
18 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
19 #include "GrCoordTransform.h" | 18 #include "GrCoordTransform.h" |
20 #include "GrInvariantOutput.h" | 19 #include "GrInvariantOutput.h" |
21 #include "GrTextureParams.h" | 20 #include "GrTextureParams.h" |
22 #include "glsl/GrGLSLFragmentProcessor.h" | 21 #include "glsl/GrGLSLFragmentProcessor.h" |
23 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 22 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
24 #include "SkGr.h" | 23 #include "SkGr.h" |
25 | 24 |
26 class NormalMapFP : public GrFragmentProcessor { | 25 class NormalMapFP : public GrFragmentProcessor { |
27 public: | 26 public: |
28 NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM) | 27 NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM) |
29 : fInvCTM(invCTM) { | 28 : fInvCTM(invCTM) { |
30 this->registerChildProcessor(mapFP); | 29 this->registerChildProcessor(mapFP); |
31 | 30 |
32 this->initClassID<NormalMapFP>(); | 31 this->initClassID<NormalMapFP>(); |
33 } | 32 } |
34 | 33 |
35 class GLSLNormalMapFP : public GLSLNormalFP { | 34 class GLSLNormalMapFP : public GrGLSLFragmentProcessor { |
36 public: | 35 public: |
37 GLSLNormalMapFP() | 36 GLSLNormalMapFP() |
38 : fColumnMajorInvCTM22{0.0f} {} | 37 : fColumnMajorInvCTM22{0.0f} {} |
39 | 38 |
40 void onEmitCode(EmitArgs& args) override { | 39 void emitCode(EmitArgs& args) override { |
41 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 40 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
42 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 41 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
43 | 42 |
44 // add uniform | 43 // add uniform |
45 const char* xformUniName = nullptr; | 44 const char* xformUniName = nullptr; |
46 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat2
2f_GrSLType, | 45 fXformUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat2
2f_GrSLType, |
47 kDefault_GrSLPrecision, "Xfor
m", &xformUniName); | 46 kDefault_GrSLPrecision, "Xfor
m", &xformUniName); |
48 | 47 |
49 SkString dstNormalColorName("dstNormalColor"); | 48 SkString dstNormalColorName("dstNormalColor"); |
50 this->emitChild(0, nullptr, &dstNormalColorName, args); | 49 this->emitChild(0, nullptr, &dstNormalColorName, args); |
51 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... |
72 args.fOutputColor); | 71 args.fOutputColor); |
73 fragBuilder->codeAppend( "}"); | 72 fragBuilder->codeAppend( "}"); |
74 } | 73 } |
75 | 74 |
76 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 75 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
77 GrProcessorKeyBuilder* b) { | 76 GrProcessorKeyBuilder* b) { |
78 b->add32(0x0); | 77 b->add32(0x0); |
79 } | 78 } |
80 | 79 |
81 protected: | 80 protected: |
82 void setNormalData(const GrGLSLProgramDataManager& pdman, | 81 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override { |
83 const GrProcessor& proc) override { | |
84 const NormalMapFP& normalMapFP = proc.cast<NormalMapFP>(); | 82 const NormalMapFP& normalMapFP = proc.cast<NormalMapFP>(); |
85 | 83 |
86 const SkMatrix& invCTM = normalMapFP.invCTM(); | 84 const SkMatrix& invCTM = normalMapFP.invCTM(); |
87 fColumnMajorInvCTM22[0] = invCTM.get(SkMatrix::kMScaleX); | 85 fColumnMajorInvCTM22[0] = invCTM.get(SkMatrix::kMScaleX); |
88 fColumnMajorInvCTM22[1] = invCTM.get(SkMatrix::kMSkewY); | 86 fColumnMajorInvCTM22[1] = invCTM.get(SkMatrix::kMSkewY); |
89 fColumnMajorInvCTM22[2] = invCTM.get(SkMatrix::kMSkewX); | 87 fColumnMajorInvCTM22[2] = invCTM.get(SkMatrix::kMSkewX); |
90 fColumnMajorInvCTM22[3] = invCTM.get(SkMatrix::kMScaleY); | 88 fColumnMajorInvCTM22[3] = invCTM.get(SkMatrix::kMScaleY); |
91 pdman.setMatrix2f(fXformUni, fColumnMajorInvCTM22); | 89 pdman.setMatrix2f(fXformUni, fColumnMajorInvCTM22); |
92 } | 90 } |
93 | 91 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 256 |
259 sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con
st SkMatrix& ctm) { | 257 sk_sp<SkNormalSource> SkNormalSource::MakeFromNormalMap(sk_sp<SkShader> map, con
st SkMatrix& ctm) { |
260 SkMatrix invCTM; | 258 SkMatrix invCTM; |
261 | 259 |
262 if (!ctm.invert(&invCTM) || !map) { | 260 if (!ctm.invert(&invCTM) || !map) { |
263 return nullptr; | 261 return nullptr; |
264 } | 262 } |
265 | 263 |
266 return sk_make_sp<SkNormalMapSourceImpl>(std::move(map), invCTM); | 264 return sk_make_sp<SkNormalMapSourceImpl>(std::move(map), invCTM); |
267 } | 265 } |
OLD | NEW |