Index: include/core/SkLights.h |
diff --git a/include/core/SkLights.h b/include/core/SkLights.h |
index 52e60c71a07a5fe3cae5f441f58e858617490251..a8f3d052dcc337c555cfc93908c333ab598cac18 100644 |
--- a/include/core/SkLights.h |
+++ b/include/core/SkLights.h |
@@ -20,7 +20,8 @@ public: |
public: |
enum LightType { |
kAmbient_LightType, // only 'fColor' is used |
- kDirectional_LightType |
+ kDirectional_LightType, |
+ kPoint_LightType |
}; |
Light(const Light& other) |
@@ -37,27 +38,34 @@ public: |
, fShadowMap(std::move(other.fShadowMap)) { |
} |
- Light(const SkColor3f& color) |
- : fType(kAmbient_LightType) |
- , fColor(color) { |
- fDirection.set(0.0f, 0.0f, 1.0f); |
+ static Light MakeAmbient(const SkColor3f& color) { |
robertphillips
2016/08/10 17:48:39
just "return Light(...);"
no need for the temporar
vjiaoblack
2016/08/11 14:27:23
Done.
|
+ Light light(kAmbient_LightType, color, SkVector3::Make(0.0f, 0.0f, 1.0f)); |
+ return light; |
} |
- Light(const SkColor3f& color, const SkVector3& dir) |
- : fType(kDirectional_LightType) |
- , fColor(color) |
- , fDirection(dir) { |
- if (!fDirection.normalize()) { |
- fDirection.set(0.0f, 0.0f, 1.0f); |
+ static Light MakeDirectional(const SkColor3f& color, const SkVector3& dir) { |
+ Light light(kDirectional_LightType, color, dir); |
+ if (!light.fDirection.normalize()) { |
+ light.fDirection.set(0.0f, 0.0f, 1.0f); |
} |
+ return light; |
+ } |
+ |
+ static Light MakePoint(const SkColor3f& color, const SkPoint3& pos) { |
robertphillips
2016/08/10 17:48:39
Same here
vjiaoblack
2016/08/11 14:27:23
Done.
|
+ Light light(kPoint_LightType, color, pos); |
+ return light; |
} |
LightType type() const { return fType; } |
const SkColor3f& color() const { return fColor; } |
const SkVector3& dir() const { |
- SkASSERT(kAmbient_LightType != fType); |
+ SkASSERT(kDirectional_LightType == fType); |
return fDirection; |
} |
+ const SkPoint3& pos() const { |
+ SkASSERT(kPoint_LightType == fType); |
+ return fDirection; |
+ } |
void setShadowMap(sk_sp<SkImage> shadowMap) { |
fShadowMap = std::move(shadowMap); |
@@ -85,6 +93,12 @@ public: |
SkVector3 fDirection; // direction towards the light (+Z is out of the screen). |
// If degenerate, it will be replaced with (0, 0, 1). |
sk_sp<SkImage> fShadowMap; |
+ |
+ Light(LightType type, const SkColor3f color, const SkVector3 dir) { |
robertphillips
2016/08/10 17:48:39
Don't need "this->" on member variables
vjiaoblack
2016/08/11 14:27:23
Done.
|
+ this->fType = type; |
+ this->fColor = color; |
+ this->fDirection = dir; |
+ } |
}; |
class Builder { |