Debian Codegraph @

libs/opengl/src/TLightParameters.cpp

raw
1 /* +------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | https://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2026, Individual contributors, see AUTHORS file |
6 | See: https://www.mrpt.org/Authors - All rights reserved. |
7 | Released under BSD License. See: https://www.mrpt.org/License |
8 +------------------------------------------------------------------------+ */
9
10 #include "opengl-precomp.h" // Precompiled header
11 //
12 #include <mrpt/opengl/TLightParameters.h>
13 #include <mrpt/serialization/CArchive.h>
14
15 using namespace mrpt;
16 using namespace mrpt::opengl;
17 using namespace std;
18
19 void TLightParameters::writeToStream(mrpt::serialization::CArchive& out) const
20 {
21 const uint8_t version = 3;
22 out << version;
23
24 out << diffuse << ambient << specular << direction << color;
25 out << shadow_bias << shadow_bias_cam2frag << shadow_bias_normal; // v2
26 out << eyeDistance2lightShadowExtension << minimum_shadow_map_extension_ratio; // v3
27 }
28
29 void TLightParameters::readFromStream(mrpt::serialization::CArchive& in)
30 {
31 uint8_t version;
32 in >> version;
33
34 switch (version)
35 {
36 case 0:
37 {
38 mrpt::img::TColorf diffuseCol, ambientCol, specularCol;
39 in >> diffuseCol >> ambientCol >> specularCol >> direction;
40 ambient = ambientCol.R;
41 specular = specularCol.R;
42 diffuse = 1.0f;
43 color = diffuseCol;
44 }
45 break;
46 case 1:
47 case 2:
48 case 3:
49 in >> diffuse >> ambient >> specular >> direction >> color;
50 if (version >= 2) in >> shadow_bias >> shadow_bias_cam2frag >> shadow_bias_normal;
51 if (version >= 3)
52 in >> eyeDistance2lightShadowExtension >> minimum_shadow_map_extension_ratio;
53 break;
54 default:
55 MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version);
56 };
57 }
58
59 namespace mrpt::opengl
60 {
61 mrpt::serialization::CArchive& operator>>(
62 mrpt::serialization::CArchive& in, mrpt::opengl::TLightParameters& o)
63 {
64 o.readFromStream(in);
65 return in;
66 }
67 mrpt::serialization::CArchive& operator<<(
68 mrpt::serialization::CArchive& out, const mrpt::opengl::TLightParameters& o)
69 {
70 o.writeToStream(out);
71 return out;
72 }
73 } // namespace mrpt::opengl