OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 //////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////// |
127 | 127 |
128 #if SK_SUPPORT_GPU | 128 #if SK_SUPPORT_GPU |
129 | 129 |
130 #include "GrCoordTransform.h" | 130 #include "GrCoordTransform.h" |
131 #include "GrFragmentProcessor.h" | 131 #include "GrFragmentProcessor.h" |
132 #include "GrTextureAccess.h" | 132 #include "GrTextureAccess.h" |
133 #include "gl/GrGLProcessor.h" | 133 #include "gl/GrGLProcessor.h" |
134 #include "gl/builders/GrGLProgramBuilder.h" | 134 #include "gl/builders/GrGLProgramBuilder.h" |
| 135 #include "glsl/GrGLSLProgramDataManager.h" |
135 #include "SkGr.h" | 136 #include "SkGr.h" |
136 #include "SkGrPriv.h" | 137 #include "SkGrPriv.h" |
137 | 138 |
138 class LightingFP : public GrFragmentProcessor { | 139 class LightingFP : public GrFragmentProcessor { |
139 public: | 140 public: |
140 LightingFP(GrTexture* diffuse, GrTexture* normal, const SkMatrix& diffMatrix
, | 141 LightingFP(GrTexture* diffuse, GrTexture* normal, const SkMatrix& diffMatrix
, |
141 const SkMatrix& normMatrix, const GrTextureParams& diffParams, | 142 const SkMatrix& normMatrix, const GrTextureParams& diffParams, |
142 const GrTextureParams& normParams, const SkLightingShader::Lights
* lights, | 143 const GrTextureParams& normParams, const SkLightingShader::Lights
* lights, |
143 const SkVector& invNormRotation) | 144 const SkVector& invNormRotation) |
144 : fDiffDeviceTransform(kLocal_GrCoordSet, diffMatrix, diffuse, diffParam
s.filterMode()) | 145 : fDiffDeviceTransform(kLocal_GrCoordSet, diffMatrix, diffuse, diffParam
s.filterMode()) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 231 } |
231 | 232 |
232 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 233 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
233 GrProcessorKeyBuilder* b) { | 234 GrProcessorKeyBuilder* b) { |
234 // const LightingFP& lightingFP = proc.cast<LightingFP>(); | 235 // const LightingFP& lightingFP = proc.cast<LightingFP>(); |
235 // only one shader generated currently | 236 // only one shader generated currently |
236 b->add32(0x0); | 237 b->add32(0x0); |
237 } | 238 } |
238 | 239 |
239 protected: | 240 protected: |
240 void onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& p
roc) override { | 241 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&
proc) override { |
241 const LightingFP& lightingFP = proc.cast<LightingFP>(); | 242 const LightingFP& lightingFP = proc.cast<LightingFP>(); |
242 | 243 |
243 const SkVector3& lightDir = lightingFP.lightDir(); | 244 const SkVector3& lightDir = lightingFP.lightDir(); |
244 if (lightDir != fLightDir) { | 245 if (lightDir != fLightDir) { |
245 pdman.set3fv(fLightDirUni, 1, &lightDir.fX); | 246 pdman.set3fv(fLightDirUni, 1, &lightDir.fX); |
246 fLightDir = lightDir; | 247 fLightDir = lightDir; |
247 } | 248 } |
248 | 249 |
249 const SkColor3f& lightColor = lightingFP.lightColor(); | 250 const SkColor3f& lightColor = lightingFP.lightColor(); |
250 if (lightColor != fLightColor) { | 251 if (lightColor != fLightColor) { |
251 pdman.set3fv(fLightColorUni, 1, &lightColor.fX); | 252 pdman.set3fv(fLightColorUni, 1, &lightColor.fX); |
252 fLightColor = lightColor; | 253 fLightColor = lightColor; |
253 } | 254 } |
254 | 255 |
255 const SkColor3f& ambientColor = lightingFP.ambientColor(); | 256 const SkColor3f& ambientColor = lightingFP.ambientColor(); |
256 if (ambientColor != fAmbientColor) { | 257 if (ambientColor != fAmbientColor) { |
257 pdman.set3fv(fAmbientColorUni, 1, &ambientColor.fX); | 258 pdman.set3fv(fAmbientColorUni, 1, &ambientColor.fX); |
258 fAmbientColor = ambientColor; | 259 fAmbientColor = ambientColor; |
259 } | 260 } |
260 | 261 |
261 const SkVector& invNormRotation = lightingFP.invNormRotation(); | 262 const SkVector& invNormRotation = lightingFP.invNormRotation(); |
262 if (invNormRotation != fInvNormRotation) { | 263 if (invNormRotation != fInvNormRotation) { |
263 pdman.set2fv(fXformUni, 1, &invNormRotation.fX); | 264 pdman.set2fv(fXformUni, 1, &invNormRotation.fX); |
264 fInvNormRotation = invNormRotation; | 265 fInvNormRotation = invNormRotation; |
265 } | 266 } |
266 } | 267 } |
267 | 268 |
268 private: | 269 private: |
269 SkVector3 fLightDir; | 270 SkVector3 fLightDir; |
270 GrGLProgramDataManager::UniformHandle fLightDirUni; | 271 GrGLSLProgramDataManager::UniformHandle fLightDirUni; |
271 | 272 |
272 SkColor3f fLightColor; | 273 SkColor3f fLightColor; |
273 GrGLProgramDataManager::UniformHandle fLightColorUni; | 274 GrGLSLProgramDataManager::UniformHandle fLightColorUni; |
274 | 275 |
275 SkColor3f fAmbientColor; | 276 SkColor3f fAmbientColor; |
276 GrGLProgramDataManager::UniformHandle fAmbientColorUni; | 277 GrGLSLProgramDataManager::UniformHandle fAmbientColorUni; |
277 | 278 |
278 SkVector fInvNormRotation; | 279 SkVector fInvNormRotation; |
279 GrGLProgramDataManager::UniformHandle fXformUni; | 280 GrGLSLProgramDataManager::UniformHandle fXformUni; |
280 }; | 281 }; |
281 | 282 |
282 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override { | 283 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override { |
283 LightingGLFP::GenKey(*this, caps, b); | 284 LightingGLFP::GenKey(*this, caps, b); |
284 } | 285 } |
285 | 286 |
286 const char* name() const override { return "LightingFP"; } | 287 const char* name() const override { return "LightingFP"; } |
287 | 288 |
288 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 289 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
289 inout->mulByUnknownFourComponents(); | 290 inout->mulByUnknownFourComponents(); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 normLocalM); | 713 normLocalM); |
713 } | 714 } |
714 | 715 |
715 /////////////////////////////////////////////////////////////////////////////// | 716 /////////////////////////////////////////////////////////////////////////////// |
716 | 717 |
717 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 718 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
718 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 719 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
719 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 720 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
720 | 721 |
721 /////////////////////////////////////////////////////////////////////////////// | 722 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |