OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2016 Google Inc. | 3 * Copyright 2016 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkLights.h" | 9 #include "SkLights.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 sk_sp<SkImage> depthMap; | 37 sk_sp<SkImage> depthMap; |
38 bool hasShadowMap = buf.readBool(); | 38 bool hasShadowMap = buf.readBool(); |
39 if (hasShadowMap) { | 39 if (hasShadowMap) { |
40 if (!(depthMap = buf.readImage())) { | 40 if (!(depthMap = buf.readImage())) { |
41 return nullptr; | 41 return nullptr; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
| 45 bool isRadial = buf.readBool(); |
45 if (isPoint) { | 46 if (isPoint) { |
46 SkScalar intensity = 0.0f; | 47 SkScalar intensity; |
47 intensity = buf.readScalar(); | 48 intensity = buf.readScalar(); |
48 Light light = Light::MakePoint(color, dirOrPos, intensity); | 49 Light light = Light::MakePoint(color, dirOrPos, intensity, isRadial)
; |
49 light.setShadowMap(depthMap); | 50 light.setShadowMap(depthMap); |
50 builder.add(light); | 51 builder.add(light); |
51 } else { | 52 } else { |
52 Light light = Light::MakeDirectional(color, dirOrPos); | 53 Light light = Light::MakeDirectional(color, dirOrPos, isRadial); |
53 light.setShadowMap(depthMap); | 54 light.setShadowMap(depthMap); |
54 builder.add(light); | 55 builder.add(light); |
55 } | 56 } |
56 } | 57 } |
57 | 58 |
58 return builder.finish(); | 59 return builder.finish(); |
59 } | 60 } |
60 | 61 |
61 void SkLights::flatten(SkWriteBuffer& buf) const { | 62 void SkLights::flatten(SkWriteBuffer& buf) const { |
62 buf.writeScalarArray(&this->ambientLightColor().fX, 3); | 63 buf.writeScalarArray(&this->ambientLightColor().fX, 3); |
63 | 64 |
64 buf.writeInt(this->numLights()); | 65 buf.writeInt(this->numLights()); |
65 for (int l = 0; l < this->numLights(); ++l) { | 66 for (int l = 0; l < this->numLights(); ++l) { |
66 const Light& light = this->light(l); | 67 const Light& light = this->light(l); |
67 | 68 |
68 bool isPoint = Light::kPoint_LightType == light.type(); | 69 bool isPoint = Light::kPoint_LightType == light.type(); |
69 | 70 |
70 buf.writeBool(isPoint); | 71 buf.writeBool(isPoint); |
71 buf.writeScalarArray(&light.color().fX, 3); | 72 buf.writeScalarArray(&light.color().fX, 3); |
72 buf.writeScalarArray(&light.dir().fX, 3); | 73 buf.writeScalarArray(&light.dir().fX, 3); |
| 74 |
73 bool hasShadowMap = light.getShadowMap() != nullptr; | 75 bool hasShadowMap = light.getShadowMap() != nullptr; |
74 buf.writeBool(hasShadowMap); | 76 buf.writeBool(hasShadowMap); |
| 77 |
| 78 bool isRadial = light.isRadial(); |
| 79 buf.writeBool(isRadial); |
| 80 |
75 if (hasShadowMap) { | 81 if (hasShadowMap) { |
76 buf.writeImage(light.getShadowMap()); | 82 buf.writeImage(light.getShadowMap()); |
77 } | 83 } |
78 if (isPoint) { | 84 if (isPoint) { |
79 buf.writeScalar(light.intensity()); | 85 buf.writeScalar(light.intensity()); |
80 } | 86 } |
81 } | 87 } |
82 } | 88 } |
OLD | NEW |