Skyscraper 2.0
XrSceneUnderstandingSerialization.hpp
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
7
8namespace xr::su {
14
15 inline std::vector<SceneFragment> GetSerializedSceneFragments(XrSceneMSFT scene) {
16 XrSceneComponentsGetInfoMSFT getInfo{XR_TYPE_SCENE_COMPONENTS_GET_INFO_MSFT};
17 getInfo.componentType = XR_SCENE_COMPONENT_TYPE_SERIALIZED_SCENE_FRAGMENT_MSFT;
18
19 XrSceneComponentsMSFT sceneComponents{XR_TYPE_SCENE_COMPONENTS_MSFT};
20 CHECK_XRCMD(xrGetSceneComponentsMSFT(scene, &getInfo, &sceneComponents));
21 const uint32_t count = sceneComponents.componentCountOutput;
22
23 std::vector<XrSceneComponentMSFT> components(count);
24 sceneComponents.componentCapacityInput = count;
25 sceneComponents.components = components.data();
26
27 CHECK_XRCMD(xrGetSceneComponentsMSFT(scene, &getInfo, &sceneComponents));
28
29 std::vector<SceneFragment> result(count);
30 for (uint32_t k = 0; k < count; k++) {
31 result[k].id = components[k].id;
32 result[k].updateTime = components[k].updateTime;
33 }
34 return result;
35 }
36
37 inline std::vector<uint8_t> ReadSceneFragmentData(XrSceneMSFT scene, const SceneFragment::Id& id) {
38 uint32_t readOutput = 0;
39 XrSerializedSceneFragmentDataGetInfoMSFT getInfo{XR_TYPE_SERIALIZED_SCENE_FRAGMENT_DATA_GET_INFO_MSFT};
40 getInfo.sceneFragmentId = static_cast<XrUuidMSFT>(id);
41 CHECK_XRCMD(xrGetSerializedSceneFragmentDataMSFT(scene, &getInfo, 0, &readOutput, nullptr));
42
43 std::vector<uint8_t> buffer(readOutput);
44 CHECK_XRCMD(xrGetSerializedSceneFragmentDataMSFT(scene, &getInfo, readOutput, &readOutput, buffer.data()));
45 return buffer;
46 }
47
48} // namespace xr::su
#define CHECK_XRCMD(cmd)
Definition XrError.h:14
std::vector< uint8_t > ReadSceneFragmentData(XrSceneMSFT scene, const SceneFragment::Id &id)
std::vector< SceneFragment > GetSerializedSceneFragments(XrSceneMSFT scene)