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