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; | |
bsalomon
2016/07/20 16:25:54
std::move?
vjiaoblack
2016/07/20 20:15:03
Done.
| |
52 } | |
53 | |
54 sk_sp<SkImage> getShadowMap() const { | |
55 return fShadowMap; | |
56 } | |
57 | |
47 private: | 58 private: |
48 LightType fType; | 59 LightType fType; |
49 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. | 60 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). | 61 SkVector3 fDirection; // direction towards the light (+Z is out of the screen). |
51 // If degenerate, it will be replaced with (0, 0, 1). | 62 // If degenerate, it will be replaced with (0, 0, 1). |
63 sk_sp<SkImage> fShadowMap; | |
52 }; | 64 }; |
53 | 65 |
54 class Builder { | 66 class Builder { |
55 public: | 67 public: |
56 Builder() : fLights(new SkLights) { } | 68 Builder() : fLights(new SkLights) { } |
57 | 69 |
58 void add(const Light& light) { | 70 void add(const Light& light) { |
59 if (fLights) { | 71 if (fLights) { |
60 *fLights->fLights.push() = light; | 72 *fLights->fLights.push() = light; |
61 } | 73 } |
62 } | 74 } |
63 | 75 |
64 sk_sp<SkLights> finish() { | 76 sk_sp<SkLights> finish() { |
65 return fLights; | 77 return fLights; |
66 } | 78 } |
67 | 79 |
68 private: | 80 private: |
69 sk_sp<SkLights> fLights; | 81 sk_sp<SkLights> fLights; |
70 }; | 82 }; |
71 | 83 |
72 int numLights() const { | 84 int numLights() const { |
73 return fLights.count(); | 85 return fLights.count(); |
74 } | 86 } |
75 | 87 |
76 const Light& light(int index) const { | 88 const Light& light(int index) const { |
77 return fLights[index]; | 89 return fLights[index]; |
78 } | 90 } |
79 | 91 |
92 Light& light(int index) { | |
93 return fLights[index]; | |
94 } | |
95 | |
80 private: | 96 private: |
81 SkLights() {} | 97 SkLights() {} |
82 | 98 |
83 SkTDArray<Light> fLights; | 99 SkTDArray<Light> fLights; |
84 }; | 100 }; |
85 | 101 |
86 #endif | 102 #endif |
OLD | NEW |