Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: src/effects/SkLightingShader.cpp

Issue 1287023009: Added tree structure to GrGLFragmentProcessor, i.e. GL instances (Closed) Base URL: https://skia.googlesource.com/skia@cs3_isequal_nonrecursive
Patch Set: moved onSetData from public to protected, onCreateGLInstance from public to private in subclasses Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkLightingImageFilter.cpp ('k') | src/effects/SkLumaColorFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 fpb->codeAppend("vec3 normal = normalize(normalColor.rgb - vec3(0.5) );"); 178 fpb->codeAppend("vec3 normal = normalize(normalColor.rgb - vec3(0.5) );");
179 fpb->codeAppendf("vec3 lightDir = normalize(%s);", lightDirUniName); 179 fpb->codeAppendf("vec3 lightDir = normalize(%s);", lightDirUniName);
180 fpb->codeAppend("float NdotL = dot(normal, lightDir);"); 180 fpb->codeAppend("float NdotL = dot(normal, lightDir);");
181 // diffuse light 181 // diffuse light
182 fpb->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;", lightCo lorUniName); 182 fpb->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;", lightCo lorUniName);
183 // ambient light 183 // ambient light
184 fpb->codeAppendf("result += %s;", ambientColorUniName); 184 fpb->codeAppendf("result += %s;", ambientColorUniName);
185 fpb->codeAppendf("%s = vec4(result.rgb, diffuseColor.a);", args.fOut putColor); 185 fpb->codeAppendf("%s = vec4(result.rgb, diffuseColor.a);", args.fOut putColor);
186 } 186 }
187 187
188 void setData(const GrGLProgramDataManager& pdman, const GrProcessor& pro c) override { 188 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
189 GrProcessorKeyBuilder* b) {
190 // const LightingFP& lightingFP = proc.cast<LightingFP>();
191 // only one shader generated currently
192 b->add32(0x0);
193 }
194
195 protected:
196 void onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& p roc) override {
189 const LightingFP& lightingFP = proc.cast<LightingFP>(); 197 const LightingFP& lightingFP = proc.cast<LightingFP>();
190 198
191 const SkVector3& lightDir = lightingFP.lightDir(); 199 const SkVector3& lightDir = lightingFP.lightDir();
192 if (lightDir != fLightDir) { 200 if (lightDir != fLightDir) {
193 pdman.set3fv(fLightDirUni, 1, &lightDir.fX); 201 pdman.set3fv(fLightDirUni, 1, &lightDir.fX);
194 fLightDir = lightDir; 202 fLightDir = lightDir;
195 } 203 }
196 204
197 const SkColor3f& lightColor = lightingFP.lightColor(); 205 const SkColor3f& lightColor = lightingFP.lightColor();
198 if (lightColor != fLightColor) { 206 if (lightColor != fLightColor) {
199 pdman.set3fv(fLightColorUni, 1, &lightColor.fX); 207 pdman.set3fv(fLightColorUni, 1, &lightColor.fX);
200 fLightColor = lightColor; 208 fLightColor = lightColor;
201 } 209 }
202 210
203 const SkColor3f& ambientColor = lightingFP.ambientColor(); 211 const SkColor3f& ambientColor = lightingFP.ambientColor();
204 if (ambientColor != fAmbientColor) { 212 if (ambientColor != fAmbientColor) {
205 pdman.set3fv(fAmbientColorUni, 1, &ambientColor.fX); 213 pdman.set3fv(fAmbientColorUni, 1, &ambientColor.fX);
206 fAmbientColor = ambientColor; 214 fAmbientColor = ambientColor;
207 } 215 }
208 } 216 }
209 217
210 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
211 GrProcessorKeyBuilder* b) {
212 // const LightingFP& lightingFP = proc.cast<LightingFP>();
213 // only one shader generated currently
214 b->add32(0x0);
215 }
216
217 private: 218 private:
218 SkVector3 fLightDir; 219 SkVector3 fLightDir;
219 GrGLProgramDataManager::UniformHandle fLightDirUni; 220 GrGLProgramDataManager::UniformHandle fLightDirUni;
220 221
221 SkColor3f fLightColor; 222 SkColor3f fLightColor;
222 GrGLProgramDataManager::UniformHandle fLightColorUni; 223 GrGLProgramDataManager::UniformHandle fLightColorUni;
223 224
224 SkColor3f fAmbientColor; 225 SkColor3f fAmbientColor;
225 GrGLProgramDataManager::UniformHandle fAmbientColorUni; 226 GrGLProgramDataManager::UniformHandle fAmbientColorUni;
226 }; 227 };
227 228
228 GrGLFragmentProcessor* createGLInstance() const override { return SkNEW(Ligh tingGLFP); }
229
230 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override { 229 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override {
231 LightingGLFP::GenKey(*this, caps, b); 230 LightingGLFP::GenKey(*this, caps, b);
232 } 231 }
233 232
234 const char* name() const override { return "LightingFP"; } 233 const char* name() const override { return "LightingFP"; }
235 234
236 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 235 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
237 inout->mulByUnknownFourComponents(); 236 inout->mulByUnknownFourComponents();
238 } 237 }
239 238
240 const SkVector3& lightDir() const { return fLightDir; } 239 const SkVector3& lightDir() const { return fLightDir; }
241 const SkColor3f& lightColor() const { return fLightColor; } 240 const SkColor3f& lightColor() const { return fLightColor; }
242 const SkColor3f& ambientColor() const { return fAmbientColor; } 241 const SkColor3f& ambientColor() const { return fAmbientColor; }
243 242
244 private: 243 private:
244 GrGLFragmentProcessor* onCreateGLInstance() const override { return SkNEW(Li ghtingGLFP); }
245
245 bool onIsEqual(const GrFragmentProcessor& proc) const override { 246 bool onIsEqual(const GrFragmentProcessor& proc) const override {
246 const LightingFP& lightingFP = proc.cast<LightingFP>(); 247 const LightingFP& lightingFP = proc.cast<LightingFP>();
247 return fDeviceTransform == lightingFP.fDeviceTransform && 248 return fDeviceTransform == lightingFP.fDeviceTransform &&
248 fDiffuseTextureAccess == lightingFP.fDiffuseTextureAccess && 249 fDiffuseTextureAccess == lightingFP.fDiffuseTextureAccess &&
249 fNormalTextureAccess == lightingFP.fNormalTextureAccess && 250 fNormalTextureAccess == lightingFP.fNormalTextureAccess &&
250 fLightDir == lightingFP.fLightDir && 251 fLightDir == lightingFP.fLightDir &&
251 fLightColor == lightingFP.fLightColor && 252 fLightColor == lightingFP.fLightColor &&
252 fAmbientColor == lightingFP.fAmbientColor; 253 fAmbientColor == lightingFP.fAmbientColor;
253 } 254 }
254 255
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return SkNEW_ARGS(SkLightingShaderImpl, (diffuse, normal, light, ambient, lo calMatrix)); 579 return SkNEW_ARGS(SkLightingShaderImpl, (diffuse, normal, light, ambient, lo calMatrix));
579 } 580 }
580 581
581 /////////////////////////////////////////////////////////////////////////////// 582 ///////////////////////////////////////////////////////////////////////////////
582 583
583 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) 584 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader)
584 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) 585 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl)
585 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 586 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
586 587
587 /////////////////////////////////////////////////////////////////////////////// 588 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/effects/SkLightingImageFilter.cpp ('k') | src/effects/SkLumaColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698