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

Unified Diff: include/core/SkLights.h

Issue 2237493002: Added PointLights to SkLights::Light (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 4 months 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 side-by-side diff with in-line comments
Download patch
Index: include/core/SkLights.h
diff --git a/include/core/SkLights.h b/include/core/SkLights.h
index 52e60c71a07a5fe3cae5f441f58e858617490251..066623648672be1bbed96c6ffdaa7be205ad4f4a 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,43 @@ public:
, fShadowMap(std::move(other.fShadowMap)) {
}
robertphillips 2016/08/10 16:34:37 We could have a private Light(type, color, vec3) c
- Light(const SkColor3f& color)
- : fType(kAmbient_LightType)
- , fColor(color) {
- fDirection.set(0.0f, 0.0f, 1.0f);
+ static Light MakeAmbientLight(const SkColor3f& color) {
+ Light light;
+ light.fType = kAmbient_LightType;
+ light.fColor = color;
+ light.fDirection.set(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 MakeDirectionalLight(const SkColor3f& color, const SkVector3& dir) {
+ Light light;
+ light.fType = kDirectional_LightType;
+ light.fColor = color;
+ light.fDirection = dir;
+ if (!light.fDirection.normalize()) {
+ light.fDirection.set(0.0f, 0.0f, 1.0f);
}
+ return light;
+ }
+
robertphillips 2016/08/10 16:34:37 SkPoint3 for pos. Right now they are typedefed to
+ static Light MakePointLight(const SkColor3f& color, const SkVector3& pos) {
+ Light light;
+ light.fType = kPoint_LightType;
+ light.fColor = color;
+ light.fDirection = 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;
}
robertphillips 2016/08/10 16:34:37 SkPoint3
+ const SkVector3& pos() const {
+ SkASSERT(kPoint_LightType == fType);
+ return fDirection;
+ }
void setShadowMap(sk_sp<SkImage> shadowMap) {
fShadowMap = std::move(shadowMap);
@@ -85,6 +102,8 @@ 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() {}
};
class Builder {

Powered by Google App Engine
This is Rietveld 408576698