Loading...
Searching...
No Matches
BufferToGeometryCommon.hpp
1#pragma once
2
3#include "GeometryToBufferStrategies.hpp"
4
5#include <ossia/dataflow/geometry_port.hpp>
6
7#include <Threedim/Debug.hpp>
8
9#include <cstring>
10
11namespace Threedim
12{
13
14// Matches QRhiVertexInputAttribute::Format
15enum AttributeFormat
16{
17 Float4,
18 Float3,
19 Float2,
20 Float,
21 UNormByte4,
22 UNormByte2,
23 UNormByte,
24 UInt4,
25 UInt2,
26 UInt,
27 SInt4,
28 SInt2,
29 SInt,
30 Half4,
31 Half3,
32 Half2,
33 Half,
34 UShort4,
35 UShort2,
36 UShort,
37 SShort4,
38 SShort2,
39 SShort,
40};
41
42enum PrimitiveTopology
43{
44 Triangles,
45 TriangleStrip,
46 TriangleFan,
47 Lines,
48 LineStrip,
49 Points
50};
51
52enum CullMode
53{
54 None,
55 Front,
56 Back
57};
58
59enum FrontFace
60{
61 CounterClockwise,
62 Clockwise
63};
64
65enum IndexFormat
66{
67 UInt16,
68 UInt32
69};
70
71namespace
72{
73
74[[nodiscard]] constexpr int32_t attributeFormatSize(AttributeFormat fmt) noexcept
75{
76 return Threedim::attributeFormatSize((halp::attribute_format)fmt);
77}
78
79[[nodiscard]] constexpr halp::attribute_format toHalpFormat(AttributeFormat fmt) noexcept
80{
81 return static_cast<halp::attribute_format>(fmt);
82}
83
84[[nodiscard]] constexpr halp::primitive_topology
85toHalpTopology(PrimitiveTopology t) noexcept
86{
87 switch(t)
88 {
89 case PrimitiveTopology::Triangles:
90 return halp::primitive_topology::triangles;
91 case PrimitiveTopology::TriangleStrip:
92 return halp::primitive_topology::triangle_strip;
93 case PrimitiveTopology::TriangleFan:
94 return halp::primitive_topology::triangle_fan;
95 case PrimitiveTopology::Lines:
96 return halp::primitive_topology::lines;
97 case PrimitiveTopology::LineStrip:
98 return halp::primitive_topology::line_strip;
99 case PrimitiveTopology::Points:
100 return halp::primitive_topology::points;
101 }
102 return halp::primitive_topology::triangles;
103}
104
105[[nodiscard]] constexpr halp::cull_mode toHalpCullMode(CullMode c) noexcept
106{
107 switch(c)
108 {
109 case CullMode::None:
110 return halp::cull_mode::none;
111 case CullMode::Front:
112 return halp::cull_mode::front;
113 case CullMode::Back:
114 return halp::cull_mode::back;
115 }
116 return halp::cull_mode::none;
117}
118
119[[nodiscard]] constexpr halp::front_face toHalpFrontFace(FrontFace f) noexcept
120{
121 switch(f)
122 {
123 case FrontFace::CounterClockwise:
124 return halp::front_face::counter_clockwise;
125 case FrontFace::Clockwise:
126 return halp::front_face::clockwise;
127 }
128 return halp::front_face::counter_clockwise;
129}
130
131[[nodiscard]] constexpr halp::index_format toHalpIndexFormat(IndexFormat f) noexcept
132{
133 switch(f)
134 {
135 case IndexFormat::UInt16:
136 return halp::index_format::uint16;
137 case IndexFormat::UInt32:
138 return halp::index_format::uint32;
139 }
140 return halp::index_format::uint32;
141}
142
143[[nodiscard]] constexpr halp::binding_classification
144toHalpClassification(bool instanced) noexcept
145{
146 return instanced ? halp::binding_classification::per_instance
147 : halp::binding_classification::per_vertex;
148}
149
150// Resolve a user-provided semantic name to ossia::attribute_semantic.
151// Uses case-insensitive name_to_semantic; if unrecognized, returns custom.
152[[nodiscard]] inline int resolveSemanticFromName(const std::string& name) noexcept
153{
154 if(name.empty())
155 return static_cast<int>(ossia::attribute_semantic::custom);
156
157 auto sem = ossia::name_to_semantic(name);
158 return static_cast<int>(sem);
159}
160
161} // anonymous namespace
162
163}