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

Side by Side Diff: src/core/SkLights.cpp

Issue 2237493002: Added PointLights to SkLights::Light (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Added SkLights.cpp 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 unified diff | Download patch
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2016 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 #include "SkLights.h"
10 #include "SkReadBuffer.h"
11
12 SkLights::Light::Light(LightType type, const SkColor3f color, const SkVector3 di r) {
13 fType = type;
14 fColor = color;
15 fDirection = dir;
16 }
17
18 void SkLights::Builder::add(const SkLights::Light& light) {
19 if (fLights) {
20 fLights->fLights.push_back(light);
21 }
22 }
23
24 void SkLights::Builder::add(SkLights::Light&& light) {
25 if (fLights) {
26 fLights->fLights.push_back(std::move(light));
27 }
28 }
29
30 sk_sp<SkLights> SkLights::Builder::finish() {
31 return std::move(fLights);
32 }
33
34 int SkLights::numLights() const {
35 return fLights.count();
36 }
37
38 const SkLights::Light& SkLights::light(int index) const {
39 return fLights[index];
40 }
41
42 SkLights::Light& SkLights::light(int index) {
43 return fLights[index];
44 }
45
46 sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) {
47 int numLights = buf.readInt();
48
49 Builder builder;
50 for (int l = 0; l < numLights; ++l) {
51 bool isAmbient = buf.readBool();
52 bool isPoint = buf.readBool();
53
54 SkColor3f color;
55 if (!buf.readScalarArray(&color.fX, 3)) {
56 return nullptr;
57 }
58
59 if (isAmbient) {
60 builder.add(Light::MakeAmbient(color));
61 } else {
62 SkVector3 dirOrPos;
63 if (!buf.readScalarArray(&dirOrPos.fX, 3)) {
64 return nullptr;
65 }
66
67 sk_sp<SkImage> depthMap;
robertphillips 2016/08/12 13:34:48 Not all lights need to have a shadow map!
vjiaoblack 2016/08/12 14:12:10 Done.
68 if (!(depthMap = sk_ref_sp<SkImage>(buf.readImage()))) {
69 return nullptr;
70 }
71
72 if (isPoint) {
73 Light light = Light::MakePoint(color, dirOrPos);
74 light.setShadowMap(depthMap);
75 builder.add(light);
76 } else {
77 Light light = Light::MakeDirectional(color, dirOrPos);
78 light.setShadowMap(depthMap);
79 builder.add(light);
80 }
81 }
82 }
83
84 return builder.finish();
85 }
86
87 void SkLights::flatten(SkWriteBuffer& buf) const {
88
89 buf.writeInt(this->numLights());
90 for (int l = 0; l < this->numLights(); ++l) {
91 const Light& light = this->light(l);
92
93 bool isAmbient = Light::kAmbient_LightType == light.type();
94 bool isPoint = Light::kPoint_LightType == light.type();
95
96 buf.writeBool(isAmbient);
97 buf.writeBool(isPoint);
98 buf.writeScalarArray(&light.color().fX, 3);
99 if (!isAmbient) {
100 buf.writeScalarArray(&light.dir().fX, 3);
101 }
102
103 buf.writeImage(light.getShadowMap());
104 }
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698