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

Side by Side Diff: include/core/SkLights.h

Issue 1255133004: Add SkLights class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rm Lingering SkNEW Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « gyp/core.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2015 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #ifndef SkLights_DEFINED
10 #define SkLights_DEFINED
11
12 #include "SkPoint3.h"
13 #include "SkRefCnt.h"
14 #include "../private/SkTDArray.h"
15
16 class SK_API SkLights : public SkRefCnt {
17 public:
18 class Light {
19 public:
20 enum LightType {
21 kAmbient_LightType, // only 'fColor' is used
22 kDirectional_LightType
23 };
24
25 Light(const SkColor3f& color)
26 : fType(kAmbient_LightType)
27 , fColor(color) {
28 fDirection.set(0.0f, 0.0f, 1.0f);
29 }
30
31 Light(const SkColor3f& color, const SkVector3& dir)
32 : fType(kDirectional_LightType)
33 , fColor(color)
34 , fDirection(dir) {
35 if (!fDirection.normalize()) {
36 fDirection.set(0.0f, 0.0f, 1.0f);
37 }
38 }
39
40 LightType type() const { return fType; }
41 const SkColor3f& color() const { return fColor; }
42 const SkVector3& dir() const {
43 SkASSERT(kAmbient_LightType != fType);
44 return fDirection;
45 }
46
47 private:
48 LightType fType;
49 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).
51 // If degenerate, it will be replaced with (0, 0, 1).
52 };
53
54 class Builder {
55 public:
56 Builder() : fLights(new SkLights) { }
57
58 void add(const Light& light) {
59 if (fLights) {
60 *fLights->fLights.push() = light;
61 }
62 }
63
64 const sk_sp<SkLights> finish() {
65 return fLights;
66 }
67
68 private:
69 sk_sp<SkLights> fLights;
70 };
71
72 int numLights() const {
73 return fLights.count();
74 }
75
76 const Light& light(int index) const {
77 return fLights[index];
78 }
79
80 private:
81 SkLights() {}
82
83 SkTDArray<Light> fLights;
84 };
85
86 #endif
OLDNEW
« no previous file with comments | « gyp/core.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698