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

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

Issue 1428543003: Create GLSL base class for ProgramDataManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add space Created 5 years, 1 month 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/SkDisplacementMapEffect.cpp ('k') | src/effects/SkMagnifierImageFilter.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 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 "SkLightingImageFilter.h" 8 #include "SkLightingImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkPoint3.h" 12 #include "SkPoint3.h"
13 #include "SkReadBuffer.h" 13 #include "SkReadBuffer.h"
14 #include "SkTypes.h" 14 #include "SkTypes.h"
15 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
16 16
17 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
18 #include "GrContext.h" 18 #include "GrContext.h"
19 #include "GrDrawContext.h" 19 #include "GrDrawContext.h"
20 #include "GrFragmentProcessor.h" 20 #include "GrFragmentProcessor.h"
21 #include "GrInvariantOutput.h" 21 #include "GrInvariantOutput.h"
22 #include "GrPaint.h" 22 #include "GrPaint.h"
23 #include "effects/GrSingleTextureEffect.h" 23 #include "effects/GrSingleTextureEffect.h"
24 #include "gl/GrGLFragmentProcessor.h" 24 #include "gl/GrGLFragmentProcessor.h"
25 #include "gl/builders/GrGLProgramBuilder.h" 25 #include "gl/builders/GrGLProgramBuilder.h"
26 #include "glsl/GrGLSLProgramDataManager.h"
26 27
27 class GrGLDiffuseLightingEffect; 28 class GrGLDiffuseLightingEffect;
28 class GrGLSpecularLightingEffect; 29 class GrGLSpecularLightingEffect;
29 30
30 // For brevity 31 // For brevity
31 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 32 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
32 #endif 33 #endif
33 34
34 namespace { 35 namespace {
35 36
36 const SkScalar gOneThird = SkIntToScalar(1) / 3; 37 const SkScalar gOneThird = SkIntToScalar(1) / 3;
37 const SkScalar gTwoThirds = SkIntToScalar(2) / 3; 38 const SkScalar gTwoThirds = SkIntToScalar(2) / 3;
38 const SkScalar gOneHalf = 0.5f; 39 const SkScalar gOneHalf = 0.5f;
39 const SkScalar gOneQuarter = 0.25f; 40 const SkScalar gOneQuarter = 0.25f;
40 41
41 #if SK_SUPPORT_GPU 42 #if SK_SUPPORT_GPU
42 void setUniformPoint3(const GrGLProgramDataManager& pdman, UniformHandle uni, 43 void setUniformPoint3(const GrGLSLProgramDataManager& pdman, UniformHandle uni,
43 const SkPoint3& point) { 44 const SkPoint3& point) {
44 GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat)); 45 GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(float));
45 pdman.set3fv(uni, 1, &point.fX); 46 pdman.set3fv(uni, 1, &point.fX);
46 } 47 }
47 48
48 void setUniformNormal3(const GrGLProgramDataManager& pdman, UniformHandle uni, 49 void setUniformNormal3(const GrGLSLProgramDataManager& pdman, UniformHandle uni,
49 const SkPoint3& point) { 50 const SkPoint3& point) {
50 setUniformPoint3(pdman, uni, point); 51 setUniformPoint3(pdman, uni, point);
51 } 52 }
52 #endif 53 #endif
53 54
54 // Shift matrix components to the left, as we advance pixels to the right. 55 // Shift matrix components to the left, as we advance pixels to the right.
55 inline void shiftMatrixLeft(int m[9]) { 56 inline void shiftMatrixLeft(int m[9]) {
56 m[0] = m[1]; 57 m[0] = m[1];
57 m[3] = m[4]; 58 m[3] = m[4];
58 m[6] = m[7]; 59 m[6] = m[7];
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 * the light. The expression will be used in the FS. emitLightColor writes a n expression into 605 * the light. The expression will be used in the FS. emitLightColor writes a n expression into
605 * the FS that is the color of the light. Either function may add functions and/or uniforms to 606 * the FS that is the color of the light. Either function may add functions and/or uniforms to
606 * the FS. The default of emitLightColor appends the name of the constant li ght color uniform 607 * the FS. The default of emitLightColor appends the name of the constant li ght color uniform
607 * and so this function only needs to be overridden if the light color varie s spatially. 608 * and so this function only needs to be overridden if the light color varie s spatially.
608 */ 609 */
609 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) = 0; 610 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) = 0;
610 virtual void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight); 611 virtual void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight);
611 612
612 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig ht must call 613 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig ht must call
613 // INHERITED::setData(). 614 // INHERITED::setData().
614 virtual void setData(const GrGLProgramDataManager&, const SkImageFilterLight * light) const; 615 virtual void setData(const GrGLSLProgramDataManager&, const SkImageFilterLig ht* light) const;
615 616
616 protected: 617 protected:
617 /** 618 /**
618 * Gets the constant light color uniform. Subclasses can use this in their e mitLightColor 619 * Gets the constant light color uniform. Subclasses can use this in their e mitLightColor
619 * function. 620 * function.
620 */ 621 */
621 UniformHandle lightColorUni() const { return fColorUni; } 622 UniformHandle lightColorUni() const { return fColorUni; }
622 623
623 private: 624 private:
624 UniformHandle fColorUni; 625 UniformHandle fColorUni;
625 626
626 typedef SkRefCnt INHERITED; 627 typedef SkRefCnt INHERITED;
627 }; 628 };
628 629
629 /////////////////////////////////////////////////////////////////////////////// 630 ///////////////////////////////////////////////////////////////////////////////
630 631
631 class GrGLDistantLight : public GrGLLight { 632 class GrGLDistantLight : public GrGLLight {
632 public: 633 public:
633 virtual ~GrGLDistantLight() {} 634 virtual ~GrGLDistantLight() {}
634 void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override; 635 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh t) const override;
635 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 636 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
636 637
637 private: 638 private:
638 typedef GrGLLight INHERITED; 639 typedef GrGLLight INHERITED;
639 UniformHandle fDirectionUni; 640 UniformHandle fDirectionUni;
640 }; 641 };
641 642
642 /////////////////////////////////////////////////////////////////////////////// 643 ///////////////////////////////////////////////////////////////////////////////
643 644
644 class GrGLPointLight : public GrGLLight { 645 class GrGLPointLight : public GrGLLight {
645 public: 646 public:
646 virtual ~GrGLPointLight() {} 647 virtual ~GrGLPointLight() {}
647 void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override; 648 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh t) const override;
648 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 649 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
649 650
650 private: 651 private:
651 typedef GrGLLight INHERITED; 652 typedef GrGLLight INHERITED;
652 UniformHandle fLocationUni; 653 UniformHandle fLocationUni;
653 }; 654 };
654 655
655 /////////////////////////////////////////////////////////////////////////////// 656 ///////////////////////////////////////////////////////////////////////////////
656 657
657 class GrGLSpotLight : public GrGLLight { 658 class GrGLSpotLight : public GrGLLight {
658 public: 659 public:
659 virtual ~GrGLSpotLight() {} 660 virtual ~GrGLSpotLight() {}
660 void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override; 661 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh t) const override;
661 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; 662 void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override;
662 void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) override; 663 void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) override;
663 664
664 private: 665 private:
665 typedef GrGLLight INHERITED; 666 typedef GrGLLight INHERITED;
666 667
667 SkString fLightColorFunc; 668 SkString fLightColorFunc;
668 UniformHandle fLocationUni; 669 UniformHandle fLocationUni;
669 UniformHandle fExponentUni; 670 UniformHandle fExponentUni;
670 UniformHandle fCosOuterConeAngleUni; 671 UniformHandle fCosOuterConeAngleUni;
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 virtual ~GrGLLightingEffect(); 1513 virtual ~GrGLLightingEffect();
1513 1514
1514 void emitCode(EmitArgs&) override; 1515 void emitCode(EmitArgs&) override;
1515 1516
1516 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder* b); 1517 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder* b);
1517 1518
1518 protected: 1519 protected:
1519 /** 1520 /**
1520 * Subclasses of GrGLLightingEffect must call INHERITED::onSetData(); 1521 * Subclasses of GrGLLightingEffect must call INHERITED::onSetData();
1521 */ 1522 */
1522 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 1523 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
1523 1524
1524 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; 1525 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0;
1525 1526
1526 private: 1527 private:
1527 typedef GrGLFragmentProcessor INHERITED; 1528 typedef GrGLFragmentProcessor INHERITED;
1528 1529
1529 UniformHandle fImageIncrementUni; 1530 UniformHandle fImageIncrementUni;
1530 UniformHandle fSurfaceScaleUni; 1531 UniformHandle fSurfaceScaleUni;
1531 GrGLLight* fLight; 1532 GrGLLight* fLight;
1532 BoundaryMode fBoundaryMode; 1533 BoundaryMode fBoundaryMode;
1533 }; 1534 };
1534 1535
1535 /////////////////////////////////////////////////////////////////////////////// 1536 ///////////////////////////////////////////////////////////////////////////////
1536 1537
1537 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { 1538 class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
1538 public: 1539 public:
1539 GrGLDiffuseLightingEffect(const GrProcessor&); 1540 GrGLDiffuseLightingEffect(const GrProcessor&);
1540 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override; 1541 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override;
1541 1542
1542 protected: 1543 protected:
1543 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 1544 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
1544 1545
1545 private: 1546 private:
1546 typedef GrGLLightingEffect INHERITED; 1547 typedef GrGLLightingEffect INHERITED;
1547 1548
1548 UniformHandle fKDUni; 1549 UniformHandle fKDUni;
1549 }; 1550 };
1550 1551
1551 /////////////////////////////////////////////////////////////////////////////// 1552 ///////////////////////////////////////////////////////////////////////////////
1552 1553
1553 class GrGLSpecularLightingEffect : public GrGLLightingEffect { 1554 class GrGLSpecularLightingEffect : public GrGLLightingEffect {
1554 public: 1555 public:
1555 GrGLSpecularLightingEffect(const GrProcessor&); 1556 GrGLSpecularLightingEffect(const GrProcessor&);
1556 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override; 1557 void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override;
1557 1558
1558 protected: 1559 protected:
1559 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 1560 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
1560 1561
1561 private: 1562 private:
1562 typedef GrGLLightingEffect INHERITED; 1563 typedef GrGLLightingEffect INHERITED;
1563 1564
1564 UniformHandle fKSUni; 1565 UniformHandle fKSUni;
1565 UniformHandle fShininessUni; 1566 UniformHandle fShininessUni;
1566 }; 1567 };
1567 1568
1568 /////////////////////////////////////////////////////////////////////////////// 1569 ///////////////////////////////////////////////////////////////////////////////
1569 1570
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor); 1736 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
1736 fsBuilder->codeAppend(modulate.c_str()); 1737 fsBuilder->codeAppend(modulate.c_str());
1737 } 1738 }
1738 1739
1739 void GrGLLightingEffect::GenKey(const GrProcessor& proc, 1740 void GrGLLightingEffect::GenKey(const GrProcessor& proc,
1740 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b ) { 1741 const GrGLSLCaps& caps, GrProcessorKeyBuilder* b ) {
1741 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1742 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1742 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); 1743 b->add32(lighting.boundaryMode() << 2 | lighting.light()->type());
1743 } 1744 }
1744 1745
1745 void GrGLLightingEffect::onSetData(const GrGLProgramDataManager& pdman, 1746 void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
1746 const GrProcessor& proc) { 1747 const GrProcessor& proc) {
1747 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>(); 1748 const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
1748 GrTexture* texture = lighting.texture(0); 1749 GrTexture* texture = lighting.texture(0);
1749 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; 1750 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
1750 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight()); 1751 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he ight());
1751 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); 1752 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
1752 SkAutoTUnref<SkImageFilterLight> transformedLight( 1753 SkAutoTUnref<SkImageFilterLight> transformedLight(
1753 lighting.light()->transform(lighting .filterMatrix())); 1754 lighting.light()->transform(lighting .filterMatrix()));
1754 fLight->setData(pdman, transformedLight); 1755 fLight->setData(pdman, transformedLight);
1755 } 1756 }
1756 1757
(...skipping 20 matching lines...) Expand all
1777 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n" , kd); 1778 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n" , kd);
1778 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1 .0);\n"); 1779 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1 .0);\n");
1779 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType, 1780 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType,
1780 "light", 1781 "light",
1781 SK_ARRAY_COUNT(gLightArgs) , 1782 SK_ARRAY_COUNT(gLightArgs) ,
1782 gLightArgs, 1783 gLightArgs,
1783 lightBody.c_str(), 1784 lightBody.c_str(),
1784 funcName); 1785 funcName);
1785 } 1786 }
1786 1787
1787 void GrGLDiffuseLightingEffect::onSetData(const GrGLProgramDataManager& pdman, 1788 void GrGLDiffuseLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
1788 const GrProcessor& proc) { 1789 const GrProcessor& proc) {
1789 INHERITED::onSetData(pdman, proc); 1790 INHERITED::onSetData(pdman, proc);
1790 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>( ); 1791 const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>( );
1791 pdman.set1f(fKDUni, diffuse.kd()); 1792 pdman.set1f(fKDUni, diffuse.kd());
1792 } 1793 }
1793 1794
1794 /////////////////////////////////////////////////////////////////////////////// 1795 ///////////////////////////////////////////////////////////////////////////////
1795 1796
1796 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, 1797 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture,
1797 const SkImageFilterLight* lig ht, 1798 const SkImageFilterLight* lig ht,
1798 SkScalar surfaceScale, 1799 SkScalar surfaceScale,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\ n"); 1868 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\ n");
1868 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b)) ;\n"); 1869 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b)) ;\n");
1869 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType, 1870 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType,
1870 "light", 1871 "light",
1871 SK_ARRAY_COUNT(gLightArgs) , 1872 SK_ARRAY_COUNT(gLightArgs) ,
1872 gLightArgs, 1873 gLightArgs,
1873 lightBody.c_str(), 1874 lightBody.c_str(),
1874 funcName); 1875 funcName);
1875 } 1876 }
1876 1877
1877 void GrGLSpecularLightingEffect::onSetData(const GrGLProgramDataManager& pdman, 1878 void GrGLSpecularLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman ,
1878 const GrProcessor& effect) { 1879 const GrProcessor& effect) {
1879 INHERITED::onSetData(pdman, effect); 1880 INHERITED::onSetData(pdman, effect);
1880 const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect> (); 1881 const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect> ();
1881 pdman.set1f(fKSUni, spec.ks()); 1882 pdman.set1f(fKSUni, spec.ks());
1882 pdman.set1f(fShininessUni, spec.shininess()); 1883 pdman.set1f(fShininessUni, spec.shininess());
1883 } 1884 }
1884 1885
1885 /////////////////////////////////////////////////////////////////////////////// 1886 ///////////////////////////////////////////////////////////////////////////////
1886 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) { 1887 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) {
1887 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 1888 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
1888 kVec3f_GrSLType, kDefault_GrSLPrecision, 1889 kVec3f_GrSLType, kDefault_GrSLPrecision,
1889 "LightColor"); 1890 "LightColor");
1890 } 1891 }
1891 1892
1892 void GrGLLight::emitLightColor(GrGLFPBuilder* builder, const char *surfaceToLigh t) { 1893 void GrGLLight::emitLightColor(GrGLFPBuilder* builder, const char *surfaceToLigh t) {
1893 builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this ->lightColorUni())); 1894 builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this ->lightColorUni()));
1894 } 1895 }
1895 1896
1896 void GrGLLight::setData(const GrGLProgramDataManager& pdman, 1897 void GrGLLight::setData(const GrGLSLProgramDataManager& pdman,
1897 const SkImageFilterLight* light) const { 1898 const SkImageFilterLight* light) const {
1898 setUniformPoint3(pdman, fColorUni, 1899 setUniformPoint3(pdman, fColorUni,
1899 light->color().makeScale(SkScalarInvert(SkIntToScalar(255)) )); 1900 light->color().makeScale(SkScalarInvert(SkIntToScalar(255)) ));
1900 } 1901 }
1901 1902
1902 /////////////////////////////////////////////////////////////////////////////// 1903 ///////////////////////////////////////////////////////////////////////////////
1903 1904
1904 void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman, 1905 void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman,
1905 const SkImageFilterLight* light) const { 1906 const SkImageFilterLight* light) const {
1906 INHERITED::setData(pdman, light); 1907 INHERITED::setData(pdman, light);
1907 SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType); 1908 SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType);
1908 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh t); 1909 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh t);
1909 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); 1910 setUniformNormal3(pdman, fDirectionUni, distantLight->direction());
1910 } 1911 }
1911 1912
1912 void GrGLDistantLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { 1913 void GrGLDistantLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) {
1913 const char* dir; 1914 const char* dir;
1914 fDirectionUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility , 1915 fDirectionUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility ,
1915 kVec3f_GrSLType, kDefault_GrSLPrecision, 1916 kVec3f_GrSLType, kDefault_GrSLPrecision,
1916 "LightDirection", &dir); 1917 "LightDirection", &dir);
1917 builder->getFragmentShaderBuilder()->codeAppend(dir); 1918 builder->getFragmentShaderBuilder()->codeAppend(dir);
1918 } 1919 }
1919 1920
1920 /////////////////////////////////////////////////////////////////////////////// 1921 ///////////////////////////////////////////////////////////////////////////////
1921 1922
1922 void GrGLPointLight::setData(const GrGLProgramDataManager& pdman, 1923 void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman,
1923 const SkImageFilterLight* light) const { 1924 const SkImageFilterLight* light) const {
1924 INHERITED::setData(pdman, light); 1925 INHERITED::setData(pdman, light);
1925 SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType); 1926 SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType);
1926 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); 1927 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light);
1927 setUniformPoint3(pdman, fLocationUni, pointLight->location()); 1928 setUniformPoint3(pdman, fLocationUni, pointLight->location());
1928 } 1929 }
1929 1930
1930 void GrGLPointLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { 1931 void GrGLPointLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) {
1931 const char* loc; 1932 const char* loc;
1932 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 1933 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
1933 kVec3f_GrSLType, kDefault_GrSLPrecision, 1934 kVec3f_GrSLType, kDefault_GrSLPrecision,
1934 "LightLocation", &loc); 1935 "LightLocation", &loc);
1935 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 1936 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
1936 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", 1937 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))",
1937 loc, fsBuilder->fragmentPosition(), z); 1938 loc, fsBuilder->fragmentPosition(), z);
1938 } 1939 }
1939 1940
1940 /////////////////////////////////////////////////////////////////////////////// 1941 ///////////////////////////////////////////////////////////////////////////////
1941 1942
1942 void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman, 1943 void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman,
1943 const SkImageFilterLight* light) const { 1944 const SkImageFilterLight* light) const {
1944 INHERITED::setData(pdman, light); 1945 INHERITED::setData(pdman, light);
1945 SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType); 1946 SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType);
1946 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); 1947 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light);
1947 setUniformPoint3(pdman, fLocationUni, spotLight->location()); 1948 setUniformPoint3(pdman, fLocationUni, spotLight->location());
1948 pdman.set1f(fExponentUni, spotLight->specularExponent()); 1949 pdman.set1f(fExponentUni, spotLight->specularExponent());
1949 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); 1950 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle());
1950 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); 1951 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle());
1951 pdman.set1f(fConeScaleUni, spotLight->coneScale()); 1952 pdman.set1f(fConeScaleUni, spotLight->coneScale());
1952 setUniformNormal3(pdman, fSUni, spotLight->s()); 1953 setUniformNormal3(pdman, fSUni, spotLight->s());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2012 2013
2013 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 2014 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
2014 } 2015 }
2015 2016
2016 #endif 2017 #endif
2017 2018
2018 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 2019 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
2019 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 2020 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
2020 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 2021 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
2021 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 2022 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698