diff options
author | 2016-05-31 06:56:28 -0700 | |
---|---|---|
committer | 2016-05-31 06:56:28 -0700 | |
commit | 93966d88efb090f77f6109f0e19cc982b83d5da9 (patch) | |
tree | 3c3c50b70e6b2487e301c13fb1c59874cc6319a5 /include | |
parent | 019db3fe885848913645e2dda62c84744ad5ee65 (diff) |
Add SkLights class
The SkLights class is intended to be passed to the drawLitAtlas call (and then on to SkLightingShader).
This CL is calved off of https://codereview.chromium.org/1261433009/ (Add SkCanvas::drawLitAtlas call).
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1255133004
Review-Url: https://codereview.chromium.org/1255133004
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkLights.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/include/core/SkLights.h b/include/core/SkLights.h new file mode 100644 index 0000000000..0a4fb8153e --- /dev/null +++ b/include/core/SkLights.h @@ -0,0 +1,86 @@ + +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkLights_DEFINED +#define SkLights_DEFINED + +#include "SkPoint3.h" +#include "SkRefCnt.h" +#include "../private/SkTDArray.h" + +class SK_API SkLights : public SkRefCnt { +public: + class Light { + public: + enum LightType { + kAmbient_LightType, // only 'fColor' is used + kDirectional_LightType + }; + + Light(const SkColor3f& color) + : fType(kAmbient_LightType) + , fColor(color) { + fDirection.set(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); + } + } + + LightType type() const { return fType; } + const SkColor3f& color() const { return fColor; } + const SkVector3& dir() const { + SkASSERT(kAmbient_LightType != fType); + return fDirection; + } + + 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). + // If degenerate, it will be replaced with (0, 0, 1). + }; + + class Builder { + public: + Builder() : fLights(new SkLights) { } + + void add(const Light& light) { + if (fLights) { + *fLights->fLights.push() = light; + } + } + + const sk_sp<SkLights> finish() { + return fLights; + } + + private: + sk_sp<SkLights> fLights; + }; + + int numLights() const { + return fLights.count(); + } + + const Light& light(int index) const { + return fLights[index]; + } + +private: + SkLights() {} + + SkTDArray<Light> fLights; +}; + +#endif |