candlewick 0.6.0
A tiny cross-platform renderer based on SDL3
Loading...
Searching...
No Matches
MeshDataView.h
Go to the documentation of this file.
1#pragma once
2
3#include <span>
4#include "MeshData.h"
5
6namespace candlewick {
7struct MeshDataView : MeshDataBase<MeshDataView> {
9 SDL_GPUPrimitiveType primitiveType;
11 std::span<const char> vertexData;
12 std::span<const IndexType> indexData;
13
14 explicit MeshDataView(const MeshData &meshData);
15
16 template <IsVertexType V>
17 MeshDataView(SDL_GPUPrimitiveType primitiveType, std::span<const V> vertices,
18 std::span<const IndexType> indices = {});
19
20 template <IsVertexType V, size_t N, size_t M>
21 MeshDataView(SDL_GPUPrimitiveType primitiveType, const V (&vertices)[N],
22 const IndexType (&indices)[M]);
23
24 MeshDataView(SDL_GPUPrimitiveType primitiveType, const MeshLayout &layout,
25 std::span<const char> vertices,
26 std::span<const IndexType> indices = {});
27
29};
30
31template <IsVertexType V>
33 std::span<const V> vertices,
34 std::span<const IndexType> indices)
36 , layout(meshLayoutFor<V>())
37 , vertexData(reinterpret_cast<const char *>(vertices.data()),
38 vertices.size() * sizeof(V))
39 , indexData(indices) {}
40
41template <IsVertexType V, size_t N, size_t M>
43 const V (&vertices)[N],
44 const IndexType (&indices)[M])
45 : MeshDataView(primitiveType, std::span<const V>{vertices},
46 std::span<const IndexType>{indices}) {}
47
48} // namespace candlewick
A class to store type-erased vertex data and index data.
Definition MeshData.h:33
Uint32 IndexType
Definition MeshData.h:40
This class defines the layout of a mesh's vertices.
Definition MeshLayout.h:98
Definition Camera.h:8
MeshLayout meshLayoutFor()
Shortcut for extracting layout from compile-time struct.
Definition MeshLayout.h:211
Definition MeshData.h:16
MeshDataView(SDL_GPUPrimitiveType primitiveType, const MeshLayout &layout, std::span< const char > vertices, std::span< const IndexType > indices={})
std::span< const IndexType > indexData
Definition MeshDataView.h:12
std::span< const char > vertexData
Definition MeshDataView.h:11
MeshDataView(const MeshData &meshData)
MeshData toOwned() const
MeshData::IndexType IndexType
Definition MeshDataView.h:8
MeshLayout layout
Definition MeshDataView.h:10
SDL_GPUPrimitiveType primitiveType
Definition MeshDataView.h:9