Chromium Code Reviews| 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 #ifndef SkLights_DEFINED | 9 #ifndef SkLights_DEFINED |
| 10 #define SkLights_DEFINED | 10 #define SkLights_DEFINED |
| 11 | 11 |
| 12 #include "SkPoint3.h" | 12 #include "SkPoint3.h" |
| 13 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
| 14 #include "../private/SkTDArray.h" | 14 #include "../private/SkTDArray.h" |
| 15 #include "SkImage.h" | |
| 15 | 16 |
| 16 class SK_API SkLights : public SkRefCnt { | 17 class SK_API SkLights : public SkRefCnt { |
| 17 public: | 18 public: |
| 18 class Light { | 19 class Light { |
| 19 public: | 20 public: |
| 20 enum LightType { | 21 enum LightType { |
| 21 kAmbient_LightType, // only 'fColor' is used | 22 kAmbient_LightType, // only 'fColor' is used |
| 22 kDirectional_LightType | 23 kDirectional_LightType |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 Light(const SkColor3f& color) | 26 Light(const SkColor3f& color) |
| 26 : fType(kAmbient_LightType) | 27 : fType(kAmbient_LightType) |
| 27 , fColor(color) { | 28 , fColor(color) |
| 29 , fShadowMap(nullptr) { | |
| 28 fDirection.set(0.0f, 0.0f, 1.0f); | 30 fDirection.set(0.0f, 0.0f, 1.0f); |
| 29 } | 31 } |
| 30 | 32 |
| 31 Light(const SkColor3f& color, const SkVector3& dir) | 33 Light(const SkColor3f& color, const SkVector3& dir) |
| 32 : fType(kDirectional_LightType) | 34 : fType(kDirectional_LightType) |
| 33 , fColor(color) | 35 , fColor(color) |
| 34 , fDirection(dir) { | 36 , fDirection(dir) |
| 37 , fShadowMap(nullptr) { | |
| 35 if (!fDirection.normalize()) { | 38 if (!fDirection.normalize()) { |
| 36 fDirection.set(0.0f, 0.0f, 1.0f); | 39 fDirection.set(0.0f, 0.0f, 1.0f); |
| 37 } | 40 } |
| 38 } | 41 } |
| 39 | 42 |
| 40 LightType type() const { return fType; } | 43 LightType type() const { return fType; } |
| 41 const SkColor3f& color() const { return fColor; } | 44 const SkColor3f& color() const { return fColor; } |
| 42 const SkVector3& dir() const { | 45 const SkVector3& dir() const { |
| 43 SkASSERT(kAmbient_LightType != fType); | 46 SkASSERT(kAmbient_LightType != fType); |
| 44 return fDirection; | 47 return fDirection; |
| 45 } | 48 } |
| 46 | 49 |
| 50 void setShadowMap(sk_sp<SkImage> shadowMap) { | |
| 51 fShadowMap = shadowMap.get(); | |
| 52 } | |
| 53 | |
| 47 private: | 54 private: |
| 48 LightType fType; | 55 LightType fType; |
| 49 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. | 56 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. |
| 50 SkVector3 fDirection; // direction towards the light (+Z is out of the screen). | 57 SkVector3 fDirection; // direction towards the light (+Z is out of the screen). |
| 51 // If degenerate, it will be replaced with (0, 0, 1). | 58 // If degenerate, it will be replaced with (0, 0, 1). |
| 59 SkImage* fShadowMap; // if we use an sk_sp, this freaking breaks because it's init to nullptr | |
| 52 }; | 60 }; |
| 53 | 61 |
| 54 class Builder { | 62 class Builder { |
| 55 public: | 63 public: |
| 56 Builder() : fLights(new SkLights) { } | 64 Builder() : fLights(new SkLights) { } |
| 57 | 65 |
| 58 void add(const Light& light) { | 66 void add(const Light& light) { |
| 59 if (fLights) { | 67 if (fLights) { |
| 60 *fLights->fLights.push() = light; | 68 *fLights->fLights.push() = light; |
| 61 } | 69 } |
| 62 } | 70 } |
| 63 | 71 |
| 64 sk_sp<SkLights> finish() { | 72 sk_sp<SkLights> finish() { |
| 65 return fLights; | 73 return fLights; |
| 66 } | 74 } |
| 67 | 75 |
| 68 private: | 76 private: |
| 69 sk_sp<SkLights> fLights; | 77 sk_sp<SkLights> fLights; |
| 70 }; | 78 }; |
| 71 | 79 |
| 72 int numLights() const { | 80 int numLights() const { |
| 73 return fLights.count(); | 81 return fLights.count(); |
| 74 } | 82 } |
| 75 | 83 |
| 76 const Light& light(int index) const { | 84 const Light& light(int index) const { |
| 77 return fLights[index]; | 85 return fLights[index]; |
| 78 } | 86 } |
| 79 | 87 |
| 88 Light& editLight(int index) { | |
|
jvanverth1
2016/07/18 15:02:26
You can just call this light() like the const vers
vjiaoblack
2016/07/18 16:51:06
Done.
| |
| 89 return fLights[index]; | |
| 90 } | |
| 91 | |
| 80 private: | 92 private: |
| 81 SkLights() {} | 93 SkLights() {} |
| 82 | 94 |
| 83 SkTDArray<Light> fLights; | 95 SkTDArray<Light> fLights; |
| 84 }; | 96 }; |
| 85 | 97 |
| 86 #endif | 98 #endif |
| OLD | NEW |