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

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: fixed serialization bug 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
« no previous file with comments | « src/core/SkLightingShader.cpp ('k') | src/core/SkShadowShader.cpp » ('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 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 sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) {
13 int numLights = buf.readInt();
14
15 Builder builder;
16 for (int l = 0; l < numLights; ++l) {
17 bool isAmbient = buf.readBool();
18 bool isPoint = buf.readBool();
19
20 SkColor3f color;
21 if (!buf.readScalarArray(&color.fX, 3)) {
22 return nullptr;
23 }
24
25 if (isAmbient) {
26 builder.add(Light::MakeAmbient(color));
27 } else {
28 SkVector3 dirOrPos;
29 if (!buf.readScalarArray(&dirOrPos.fX, 3)) {
30 return nullptr;
31 }
32
33 sk_sp<SkImage> depthMap;
34 bool hasShadowMap = buf.readBool();
35 if (hasShadowMap) {
36 if (!(depthMap = buf.readImage())) {
37 return nullptr;
38 }
39 }
40
41 if (isPoint) {
42 Light light = Light::MakePoint(color, dirOrPos);
43 light.setShadowMap(depthMap);
44 builder.add(light);
45 } else {
46 Light light = Light::MakeDirectional(color, dirOrPos);
47 light.setShadowMap(depthMap);
48 builder.add(light);
49 }
50 }
51 }
52
53 return builder.finish();
54 }
55
56 void SkLights::flatten(SkWriteBuffer& buf) const {
57
58 buf.writeInt(this->numLights());
59 for (int l = 0; l < this->numLights(); ++l) {
60 const Light& light = this->light(l);
61
62 bool isAmbient = Light::kAmbient_LightType == light.type();
63 bool isPoint = Light::kPoint_LightType == light.type();
64
65 buf.writeBool(isAmbient);
66 buf.writeBool(isPoint);
67 buf.writeScalarArray(&light.color().fX, 3);
68 if (!isAmbient) {
69 buf.writeScalarArray(&light.dir().fX, 3);
70 bool hasShadowMap = light.getShadowMap() != nullptr;
71 buf.writeBool(hasShadowMap);
72 if (hasShadowMap) {
73 buf.writeImage(light.getShadowMap());
74 }
75 }
76 }
77 }
OLDNEW
« no previous file with comments | « src/core/SkLightingShader.cpp ('k') | src/core/SkShadowShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698