Loading...
Searching...
No Matches
BufferToGeometry.hpp
1#pragma once
2#include <Threedim/TinyObj.hpp>
3#include <halp/buffer.hpp>
4#include <halp/controls.hpp>
5#include <halp/geometry.hpp>
6#include <halp/layout.hpp>
7#include <halp/meta.hpp>
8
9namespace Threedim
10{
11
13{
14public:
15 halp_meta(name, "Buffers to geometry")
16 halp_meta(category, "Visuals/3D")
17 halp_meta(c_name, "buffers_to_geometry")
18 halp_meta(manual_url, "https://ossia.io/score-docs/processes/buffers-to-geometry.html")
19 halp_meta(uuid, "d5dd3b9a-f57b-4546-9890-d5b5e351dcea")
20
21 // Matches QRhiVertexInputAttribute::Format
22 enum AttributeFormat
23 {
24 Float4,
25 Float3,
26 Float2,
27 Float,
28 UNormByte4,
29 UNormByte2,
30 UNormByte,
31 UInt4,
32 UInt2,
33 UInt,
34 SInt4,
35 SInt2,
36 SInt,
37 Half4,
38 Half3,
39 Half2,
40 Half,
41 UShort4,
42 UShort2,
43 UShort,
44 SShort4,
45 SShort2,
46 SShort,
47 };
48
49 enum PrimitiveTopology
50 {
51 Triangles,
52 TriangleStrip,
53 TriangleFan,
54 Lines,
55 LineStrip,
56 Points
57 };
58
59 enum CullMode
60 {
61 None,
62 Front,
63 Back
64 };
65
66 enum FrontFace
67 {
68 CounterClockwise,
69 Clockwise
70 };
71
72 enum IndexFormat
73 {
74 UInt16,
75 UInt32
76 };
77
78 struct ins
79 {
80 // Input buffers
81 halp::gpu_buffer_input<"Buffer 0"> buffer_0;
82 halp::gpu_buffer_input<"Buffer 1"> buffer_1;
83 halp::gpu_buffer_input<"Buffer 2"> buffer_2;
84 halp::gpu_buffer_input<"Buffer 3"> buffer_3;
85 halp::gpu_buffer_input<"Buffer 4"> buffer_4;
86 halp::gpu_buffer_input<"Buffer 5"> buffer_5;
87 halp::gpu_buffer_input<"Buffer 6"> buffer_6;
88 halp::gpu_buffer_input<"Buffer 7"> buffer_7;
89
90 // clang-format off
91#define ATTRIBUTE(i) \
92 halp::spinbox_i32<"Attr" #i " buffer", halp::irange{-1, 7, 0}> attribute_buffer_ ## i; \
93 halp::spinbox_i32<"Attr" #i " offset", halp::irange{0, 1000000, 0}> attribute_offset_ ## i; \
94 halp::spinbox_i32<"Attr" #i " stride", halp::irange{0, 1024, 0}> attribute_stride_ ## i; \
95 halp::combobox_t<"Attr" #i " format", AttributeFormat> format_ ## i; \
96 halp::spinbox_i32<"Attr" #i " location", halp::irange{0, 15, i}> location_ ## i; \
97 halp::toggle<"Attr" #i " instanced"> instanced_ ## i;
98
99 ATTRIBUTE(0)
100 ATTRIBUTE(1)
101 ATTRIBUTE(2)
102 ATTRIBUTE(3)
103 ATTRIBUTE(4)
104 ATTRIBUTE(5)
105 ATTRIBUTE(6)
106 ATTRIBUTE(7)
107#undef ATTRIBUTE
108 // clang-format on
109
110 // Index buffer
111 halp::spinbox_i32<"Index Buffer", halp::irange{-1, 7, 0}> index_buffer;
112 halp::combobox_t<"Index Format", IndexFormat> index_format;
113 halp::spinbox_i32<"Index Offset", halp::irange{0, 1000000, 0}> index_offset;
114
115 // Geometry settings
116 halp::spinbox_i32<"Vertices", halp::irange{0, 1000000000, 0}> vertices;
117 halp::spinbox_i32<"Instances", halp::irange{1, 1000000000, 1}> instances;
118 halp::combobox_t<"Topology", PrimitiveTopology> topology;
119 halp::combobox_t<"Cull Mode", CullMode> cull_mode;
120 halp::combobox_t<"Front Face", FrontFace> front_face;
121
122 // Transform
123 PositionControl position;
124 RotationControl rotation;
125 ScaleControl scale;
126 } inputs;
127
128 struct
129 {
130 struct
131 {
132 halp_meta(name, "Geometry");
133 halp::dynamic_gpu_geometry mesh;
134 float transform[16]{};
135 bool dirty_mesh = false;
136 bool dirty_transform = false;
137 } geometry;
138 } outputs;
139
140 BuffersToGeometry();
141 void operator()();
142
143 // Cache previous state to detect changes
145 {
146 bool enabled{};
147 int32_t buffer{};
148 int32_t offset{};
149 int32_t stride{};
150 AttributeFormat format{};
151 int32_t location{};
152 bool instanced{};
153 };
154
155 std::array<AttributeState, 8> m_prevAttributes{};
156 int32_t m_prevUseIndexBuffer{};
157 IndexFormat m_prevIndexFormat{};
158 int32_t m_prevIndexOffset{};
159 int32_t m_prevVertices{};
160 PrimitiveTopology m_prevTopology{};
161 CullMode m_prevCullMode{};
162 FrontFace m_prevFrontFace{};
163
164 struct ui
165 {
166 halp_meta(name, "Main")
167 halp_meta(layout, halp::layouts::hbox)
168 halp_meta(background, halp::colors::background_mid)
169
170 struct T
171 {
172 halp_meta(name, "Tabs")
173 halp_meta(layout, halp::layouts::tabs)
174 halp_meta(background, halp::colors::background_darker)
175 struct G
176 {
177 halp_meta(name, "Global")
178 halp_meta(layout, halp::layouts::hbox)
179 struct A
180 {
181 halp_meta(layout, halp::layouts::vbox)
182 halp::item<&ins::vertices> vertices;
183 halp::item<&ins::instances> instances;
184 halp::item<&ins::topology> topology;
185 halp::item<&ins::cull_mode> cull_mode;
186 halp::item<&ins::front_face> front_face;
187 } a;
188
189 struct B
190 {
191 halp_meta(layout, halp::layouts::vbox)
192 halp::item<&ins::position> p;
193 halp::item<&ins::rotation> r;
194 halp::item<&ins::scale> s;
195 } b;
196 } global;
197
198 struct A1
199 {
200 halp_meta(name, "0")
201 halp_meta(layout, halp::layouts::vbox)
202 halp::item<&ins::attribute_buffer_0> buffer;
203 halp::item<&ins::attribute_offset_0> offset;
204 halp::item<&ins::attribute_stride_0> stride;
205 halp::item<&ins::format_0> format;
206 halp::item<&ins::location_0> location;
207 halp::item<&ins::instanced_0> instanced;
208 } a0;
209 struct A2
210 {
211 halp_meta(name, "1")
212 halp_meta(layout, halp::layouts::vbox)
213 halp::item<&ins::attribute_buffer_1> buffer;
214 halp::item<&ins::attribute_offset_1> offset;
215 halp::item<&ins::attribute_stride_1> stride;
216 halp::item<&ins::format_1> format;
217 halp::item<&ins::location_1> location;
218 halp::item<&ins::instanced_1> instanced;
219 } a1;
220 struct
221 {
222 halp_meta(name, "2")
223 halp_meta(layout, halp::layouts::vbox)
224 halp::item<&ins::attribute_buffer_2> buffer;
225 halp::item<&ins::attribute_offset_2> offset;
226 halp::item<&ins::attribute_stride_2> stride;
227 halp::item<&ins::format_2> format;
228 halp::item<&ins::location_2> location;
229 halp::item<&ins::instanced_2> instanced;
230 } a2;
231 struct A3
232 {
233 halp_meta(name, "3")
234 halp_meta(layout, halp::layouts::vbox)
235 halp::item<&ins::attribute_buffer_3> buffer;
236 halp::item<&ins::attribute_offset_3> offset;
237 halp::item<&ins::attribute_stride_3> stride;
238 halp::item<&ins::format_3> format;
239 halp::item<&ins::location_3> location;
240 halp::item<&ins::instanced_3> instanced;
241 } a3;
242 struct A4
243 {
244 halp_meta(name, "4")
245 halp_meta(layout, halp::layouts::vbox)
246 halp::item<&ins::attribute_buffer_4> buffer;
247 halp::item<&ins::attribute_offset_4> offset;
248 halp::item<&ins::attribute_stride_4> stride;
249 halp::item<&ins::format_4> format;
250 halp::item<&ins::location_4> location;
251 halp::item<&ins::instanced_4> instanced;
252 } a4;
253 struct A5
254 {
255 halp_meta(name, "5")
256 halp_meta(layout, halp::layouts::vbox)
257 halp::item<&ins::attribute_buffer_5> buffer;
258 halp::item<&ins::attribute_offset_5> offset;
259 halp::item<&ins::attribute_stride_5> stride;
260 halp::item<&ins::format_5> format;
261 halp::item<&ins::location_5> location;
262 halp::item<&ins::instanced_5> instanced;
263 } a5;
264 struct A6
265 {
266 halp_meta(name, "6")
267 halp_meta(layout, halp::layouts::vbox)
268 halp::item<&ins::attribute_buffer_6> buffer;
269 halp::item<&ins::attribute_offset_6> offset;
270 halp::item<&ins::attribute_stride_6> stride;
271 halp::item<&ins::format_6> format;
272 halp::item<&ins::location_6> location;
273 halp::item<&ins::instanced_6> instanced;
274 } a6;
275 struct A7
276 {
277 halp_meta(name, "7")
278 halp_meta(layout, halp::layouts::vbox)
279 halp::item<&ins::attribute_buffer_7> buffer;
280 halp::item<&ins::attribute_offset_7> offset;
281 halp::item<&ins::attribute_stride_7> stride;
282 halp::item<&ins::format_7> format;
283 halp::item<&ins::location_7> location;
284 halp::item<&ins::instanced_7> instanced;
285 } a7;
286 struct
287 {
288 halp_meta(name, "Index")
289 halp_meta(layout, halp::layouts::vbox)
290 halp::item<&ins::index_buffer> buffer;
291 halp::item<&ins::index_offset> offset;
292 halp::item<&ins::index_format> format;
293 } index;
294 } tabs;
295 };
296};
297
298} // namespace Threedim
Definition BufferToGeometry.hpp:13
Definition BufferToGeometry.hpp:145
Definition BufferToGeometry.hpp:79
Definition BufferToGeometry.hpp:165
Definition TinyObj.hpp:64
Definition TinyObj.hpp:69
Definition TinyObj.hpp:73
Definition TinyObj.hpp:19