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

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: Actually add SkLights.h Created 5 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 unified diff | Download patch
« no previous file with comments | « gyp/effects.gypi ('k') | include/core/SkPoint3.h » ('j') | 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 "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 kInfinite_LightType
bsalomon 2015/08/05 14:58:38 directional?
robertphillips 2015/08/05 15:40:24 Done.
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(kInfinite_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 Editor {
bsalomon 2015/08/05 14:58:38 Maybe just have a builder and immutable light set?
robertphillips 2015/08/05 15:40:24 Done.
55 public:
56 Editor(SkAutoTUnref<SkLights>* lights) {
57 if (!(*lights)->unique()) {
58 SkLights* copy = SkNEW(SkLights);
59 copy->copy(**lights);
60 lights->reset(copy);
61 }
62 fLights = *lights;
63 }
64
65 void add(const Light& light) {
66 *fLights->fLights.push() = light;
67 }
68
69 private:
70 SkLights* fLights;
71 };
72
73 int numLights() const {
74 return fLights.count();
75 }
76
77 const Light& light(int index) const {
78 return fLights[index];
79 }
80
81 private:
82 void copy(const SkLights& src) {
83 fLights.setCount(src.numLights());
84 src.fLights.copy(fLights.begin());
85 }
86
87 SkTDArray<Light> fLights;
88 };
89
90 #endif
OLDNEW
« no previous file with comments | « gyp/effects.gypi ('k') | include/core/SkPoint3.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698