cesium-native 0.44.2
Loading...
Searching...
No Matches
getOffsetFromOffsetsBuffer.h
1#pragma once
2
3#include <CesiumGltf/PropertyType.h>
4#include <CesiumUtility/Assert.h>
5#include <CesiumUtility/SpanHelper.h>
6
7#include <cstddef>
8#include <span>
9
10namespace CesiumGltf {
11static size_t getOffsetFromOffsetsBuffer(
12 size_t index,
13 const std::span<const std::byte>& offsetBuffer,
14 PropertyComponentType offsetType) noexcept {
15 switch (offsetType) {
17 CESIUM_ASSERT(index < offsetBuffer.size() / sizeof(uint8_t));
18 const uint8_t offset = *reinterpret_cast<const uint8_t*>(
19 offsetBuffer.data() + index * sizeof(uint8_t));
20 return static_cast<size_t>(offset);
21 }
23 CESIUM_ASSERT(index < offsetBuffer.size() / sizeof(uint16_t));
24 const uint16_t offset = *reinterpret_cast<const uint16_t*>(
25 offsetBuffer.data() + index * sizeof(uint16_t));
26 return static_cast<size_t>(offset);
27 }
29 CESIUM_ASSERT(index < offsetBuffer.size() / sizeof(uint32_t));
30 const uint32_t offset = *reinterpret_cast<const uint32_t*>(
31 offsetBuffer.data() + index * sizeof(uint32_t));
32 return static_cast<size_t>(offset);
33 }
35 CESIUM_ASSERT(index < offsetBuffer.size() / sizeof(uint64_t));
36 const uint64_t offset = *reinterpret_cast<const uint64_t*>(
37 offsetBuffer.data() + index * sizeof(uint64_t));
38 return static_cast<size_t>(offset);
39 }
40 default:
41 CESIUM_ASSERT(false && "Offset type is invalid");
42 return 0;
43 }
44}
45} // namespace CesiumGltf
Classes for working with glTF models.
PropertyComponentType
The possible types of a property component.
@ Uint32
A property component equivalent to a uint32_t.
@ Uint16
A property component equivalent to a uint16_t.
@ Uint8
A property component equivalent to a uint8_t.
@ Uint64
A property component equivalent to a uint32_t.