score
Home
Classes
Namespaces
Files
Geometry.hpp
1
#pragma once
2
/*
3
#include <Gfx/Graph/Mesh.hpp>
4
5
#include <avnd/concepts/gfx.hpp>
6
7
namespace avnd
8
{
9
}
10
namespace Crousti
11
{
12
template<avnd::geometry_port T>
13
struct MeshMapper : public score::gfx::Mesh
14
{
15
public:
16
T geom;
17
18
explicit MeshMapper(T& geometry)
19
: geom{geometry}
20
{
21
avnd::for_each_field_ref(
22
typename T::bindings{},
23
[this] (auto& binding) {
24
QRhiVertexInputBinding b{binding.stride};
25
if constexpr(requires { binding.per_instance; })
26
b.setClassification(QRhiVertexInputBinding::PerInstance);
27
if constexpr(requires { binding.step_rate; })
28
b.setInstanceStepRate(binding.step_rate);
29
vertexBindings.push_back(b);
30
});
31
32
int k = 0;
33
avnd::for_each_field_ref(
34
typename T::attributes{},
35
[this, &k] <typename A> (A& attr) {
36
QRhiVertexInputAttribute a{};
37
a.setLocation(k++);
38
39
if constexpr(requires { attr.binding; })
40
a.setBinding(attr.binding);
41
42
if constexpr(requires { attr.offset; })
43
a.setOffset(attr.offset);
44
45
using tp = typename A::datatype;
46
if constexpr(std::is_same_v<tp, float>)
47
a.setFormt(QRhiVertexInputAttribute::Float);
48
else if constexpr(std::is_same_v<tp, float[2]>)
49
a.setFormt(QRhiVertexInputAttribute::Float2);
50
else if constexpr(std::is_same_v<tp, float[3]>)
51
a.setFormt(QRhiVertexInputAttribute::Float3);
52
else if constexpr(std::is_same_v<tp, float[4]>)
53
a.setFormt(QRhiVertexInputAttribute::Float4);
54
else if constexpr(std::is_same_v<tp, uint8_t> || std::is_same_v<tp, unsigned char>)
55
a.setFormt(QRhiVertexInputAttribute::UNormByte);
56
else if constexpr(std::is_same_v<tp, uint16_t>)
57
a.setFormt(QRhiVertexInputAttribute::UNormByte2);
58
else if constexpr(std::is_same_v<tp, uint32_t>)
59
a.setFormt(QRhiVertexInputAttribute::UNormByte4);
60
});
61
}
62
63
void update(tcb::span<const float> vtx, int count)
64
{
65
vertexArray = vtx;
66
vertexCount = count;
67
}
68
69
void setupBindings(QRhiBuffer& vtxData, QRhiBuffer* idxData, QRhiCommandBuffer& cb) const noexcept override
70
{
71
static constexpr auto sz = avnd::pfr::tuple_size<decltype(T{}.vertex_input)>{};
72
73
QRhiCommandBuffer::VertexInput bindings[sz];
74
75
int i = 0;
76
avnd::for_each_field_ref(
77
geom.vertex_input,
78
[&] (auto& vi) {
79
bindings[i++] = { &vtxData, vi.offset };
80
});
81
82
// TODO index
83
cb.setVertexInput(0, sz, bindings);
84
}
85
86
const char* defaultVertexShader() const noexcept override
87
{
88
return "";
89
}
90
};
91
92
}
93
94
*/