cesium-native 0.43.0
Loading...
Searching...
No Matches
getOffsetFromOffsetsBuffer.h
1#pragma once
2
3#include "CesiumGltf/PropertyType.h"
4
5#include <CesiumUtility/Assert.h>
6#include <CesiumUtility/SpanHelper.h>
7
8#include <cstddef>
9#include <span>
10
11namespace CesiumGltf {
12static size_t getOffsetFromOffsetsBuffer(
13 size_t index,
14 const std::span<const std::byte>& offsetBuffer,
15 PropertyComponentType offsetType) noexcept {
16 switch (offsetType) {
18 CESIUM_ASSERT(index < offsetBuffer.size() / sizeof(uint8_t));
19 const uint8_t offset = *reinterpret_cast<const uint8_t*>(
20 offsetBuffer.data() + index * sizeof(uint8_t));
21 return static_cast<size_t>(offset);
22 }
24 CESIUM_ASSERT(index < offsetBuffer.size() / sizeof(uint16_t));
25 const uint16_t offset = *reinterpret_cast<const uint16_t*>(
26 offsetBuffer.data() + index * sizeof(uint16_t));
27 return static_cast<size_t>(offset);
28 }
30 CESIUM_ASSERT(index < offsetBuffer.size() / sizeof(uint32_t));
31 const uint32_t offset = *reinterpret_cast<const uint32_t*>(
32 offsetBuffer.data() + index * sizeof(uint32_t));
33 return static_cast<size_t>(offset);
34 }
36 CESIUM_ASSERT(index < offsetBuffer.size() / sizeof(uint64_t));
37 const uint64_t offset = *reinterpret_cast<const uint64_t*>(
38 offsetBuffer.data() + index * sizeof(uint64_t));
39 return static_cast<size_t>(offset);
40 }
41 default:
42 CESIUM_ASSERT(false && "Offset type is invalid");
43 return 0;
44 }
45}
46} // 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.