Avara3D 0.2.0
C++ API reference
VertexAccess.h
1//
2// VertexAccess.h
3// avara3d
4//
5// Created by Morgan Davis on 1/5/26.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_MESH_VERTEXACCESS_H
10#define AVARA3D_MESH_VERTEXACCESS_H
11
12#include <cstddef>
13#include <cstdint>
14#include <optional>
15#include <span>
16
17#include "a3d/Math.h"
18#include "a3d/mesh/VertexLayout.h"
19#include "a3d/mesh/VertexLayoutDesc.h"
20
21namespace a3d {
22
23 class MeshElement;
24
25 struct VertexStreamView {
26 const std::byte* base = nullptr;
27 uint32_t count = 0;
28 uint16_t offset = 0; // attribute offset
29 VertexLayout layout = VertexLayout::None;
30 };
31
32 inline uint16_t VertexStreamStride(const VertexStreamView& v) {
33 return GetVertexLayoutDesc(v.layout).stride;
34 }
35
36 inline const std::byte* VertexBaseAt(const VertexStreamView& v, uint32_t i) {
37 return v.base + std::size_t(i) * std::size_t(VertexStreamStride(v));
38 }
39
40 struct VertexAccess {
41
42 static const VertexAttribDesc* FindAttrib(const VertexLayoutDesc& desc, VertexSemantic semantic);
43 static const VertexAttribDesc* GetPositionAttribF32x3(VertexLayout layout);
44 static math::vec3 ReadVec3(const std::byte* base, uint16_t offset);
45 static void WriteVec3(std::byte* base, uint16_t offset, const math::vec3& vec);
46 static std::optional<VertexStreamView> GetStreamView(const MeshElement& element,
47 VertexSemantic semantic,
48 VertexAttribFormat expectedFormat);
49
50 static std::optional<VertexStreamView> GetPositionStreamView(const MeshElement& element);
51 };
52
53}
54
55#endif // AVARA3D_MESH_VERTEXACCESS_H