Index: include/core/SkLights.h |
diff --git a/include/core/SkLights.h b/include/core/SkLights.h |
index 52e60c71a07a5fe3cae5f441f58e858617490251..cfa89c6d84f4f0392654faf144f1236c14f1d483 100644 |
--- a/include/core/SkLights.h |
+++ b/include/core/SkLights.h |
@@ -9,10 +9,13 @@ |
#ifndef SkLights_DEFINED |
#define SkLights_DEFINED |
+#include "../private/SkTArray.h" |
#include "SkPoint3.h" |
#include "SkRefCnt.h" |
-#include "../private/SkTArray.h" |
-#include "SkImage.h" |
+ |
+class SkReadBuffer; |
+class SkWriteBuffer; |
+class SkImage; |
class SK_API SkLights : public SkRefCnt { |
public: |
@@ -20,7 +23,8 @@ public: |
public: |
enum LightType { |
kAmbient_LightType, // only 'fColor' is used |
- kDirectional_LightType |
+ kDirectional_LightType, |
+ kPoint_LightType |
}; |
Light(const Light& other) |
@@ -37,26 +41,31 @@ 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) { |
+ return Light(kAmbient_LightType, color, SkVector3::Make(0.0f, 0.0f, 1.0f)); |
} |
- 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) { |
+ return Light(kPoint_LightType, color, pos); |
} |
LightType type() const { return fType; } |
const SkColor3f& color() const { return fColor; } |
- const SkVector3& dir() const { |
- SkASSERT(kAmbient_LightType != fType); |
- return fDirection; |
+ const SkVector3& dir() const { |
+ SkASSERT(kDirectional_LightType == fType); |
+ return fDirection; |
+ } |
+ const SkPoint3& pos() const { |
+ SkASSERT(kPoint_LightType == fType); |
+ return fDirection; |
} |
void setShadowMap(sk_sp<SkImage> shadowMap) { |
@@ -78,56 +87,45 @@ public: |
fShadowMap = b.fShadowMap; |
return *this; |
} |
- |
private: |
LightType fType; |
SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. |
- SkVector3 fDirection; // direction towards the light (+Z is out of the screen). |
+ SkVector3 fDirection; // For directional lights, holds the direction towards the |
+ // light (+Z is out of the screen). |
// If degenerate, it will be replaced with (0, 0, 1). |
+ // For point lights, holds location of point light |
sk_sp<SkImage> fShadowMap; |
+ |
robertphillips
2016/08/12 13:34:48
const SkColor3f& color, const SkVector3& dir);
vjiaoblack
2016/08/12 14:12:10
Done.
|
+ Light(LightType type, const SkColor3f color, const SkVector3 dir); |
}; |
class Builder { |
public: |
Builder() : fLights(new SkLights) { } |
- void add(const Light& light) { |
- if (fLights) { |
- fLights->fLights.push_back(light); |
- } |
- } |
+ void add(const Light& light); |
- void add(Light&& light) { |
- if (fLights) { |
- fLights->fLights.push_back(std::move(light)); |
- } |
- } |
+ void add(Light&& light); |
- sk_sp<SkLights> finish() { |
- return std::move(fLights); |
- } |
+ sk_sp<SkLights> finish(); |
private: |
sk_sp<SkLights> fLights; |
}; |
- int numLights() const { |
robertphillips
2016/08/12 13:34:48
Why out line these ?
|
- return fLights.count(); |
- } |
+ int numLights() const; |
- const Light& light(int index) const { |
- return fLights[index]; |
- } |
+ const Light& light(int index) const; |
- Light& light(int index) { |
- return fLights[index]; |
- } |
+ Light& light(int index); |
-private: |
- SkLights() {} |
+ static sk_sp<SkLights> MakeFromBuffer(SkReadBuffer& buf); |
- SkTArray<Light> fLights; |
+ void flatten(SkWriteBuffer& buf) const; |
+private: |
robertphillips
2016/08/12 13:34:48
no ';' needed
vjiaoblack
2016/08/12 14:12:10
Done.
|
+ SkLights() {}; |
+ SkTArray<Light> fLights; |
typedef SkRefCnt INHERITED; |
}; |