Loading...
Searching...
No Matches
BufferToGeometry.hpp
1#pragma once
2#include "BufferToGeometryCommon.hpp"
3#include "TransformHelper.hpp"
4
5#include <Threedim/TinyObj.hpp>
6#include <halp/buffer.hpp>
7#include <halp/controls.hpp>
8#include <halp/geometry.hpp>
9#include <halp/layout.hpp>
10#include <halp/meta.hpp>
11
12#include <climits>
13#include <cstdint>
14namespace Threedim
15{
16
18{
19public:
20 // "(v1)", not plain "Buffers to geometry": BuffersToGeometry2 in
21 // BufferToGeometry2.hpp carries the same name, so a document holding one of
22 // each would show two identical headers. Matches the c_name pair
23 // (buffers_to_geometry / buffers_to_geometry_v2); the uuid is unchanged, so
24 // existing documents still load.
25 halp_meta(name, "Buffers to geometry (v1)")
26 halp_meta(category, "Visuals/Utilities")
27 halp_meta(description, "Assemble GPU buffers into drawable geometry using the legacy attribute configuration.")
28 halp_meta(c_name, "buffers_to_geometry")
29 halp_meta(manual_url, "https://ossia.io/score-docs/processes/buffers-to-geometry.html")
30 halp_meta(uuid, "d5dd3b9a-f57b-4546-9890-d5b5e351dcea")
31 halp_flag(deprecated);
32
33 struct ins
34 {
35 // Input buffers
36 halp::gpu_buffer_input<"Buffer 0"> buffer_0;
37 halp::gpu_buffer_input<"Buffer 1"> buffer_1;
38 halp::gpu_buffer_input<"Buffer 2"> buffer_2;
39 halp::gpu_buffer_input<"Buffer 3"> buffer_3;
40 halp::gpu_buffer_input<"Buffer 4"> buffer_4;
41 halp::gpu_buffer_input<"Buffer 5"> buffer_5;
42 halp::gpu_buffer_input<"Buffer 6"> buffer_6;
43 halp::gpu_buffer_input<"Buffer 7"> buffer_7;
44
45 // clang-format off
46#define ATTRIBUTE(i) \
47 halp::spinbox_i32<"Attr" #i " buffer", halp::irange{-1, 7, -1}> attribute_buffer_ ## i; \
48 halp::spinbox_i32<"Attr" #i " offset", halp::irange{0, INT32_MAX, 0}> attribute_offset_ ## i; \
49 halp::spinbox_i32<"Attr" #i " stride", halp::irange{0, 1024, 0}> attribute_stride_ ## i; \
50 halp::combobox_t<"Attr" #i " format", AttributeFormat> format_ ## i; \
51 halp::spinbox_i32<"Attr" #i " location", halp::irange{0, 15, i}> location_ ## i; \
52 halp::toggle<"Attr" #i " instanced"> instanced_ ## i;
53
54 ATTRIBUTE(0)
55 ATTRIBUTE(1)
56 ATTRIBUTE(2)
57 ATTRIBUTE(3)
58 ATTRIBUTE(4)
59 ATTRIBUTE(5)
60 ATTRIBUTE(6)
61 ATTRIBUTE(7)
62#undef ATTRIBUTE
63 // clang-format on
64
65 // Index buffer
66 halp::spinbox_i32<"Index Buffer", halp::irange{-1, 7, -1}> index_buffer;
67 halp::combobox_t<"Index Format", IndexFormat> index_format;
68 halp::spinbox_i32<"Index Offset", halp::irange{0, 1000000, 0}> index_offset;
69
70 // Geometry settings
71 halp::spinbox_i32<"Vertices", halp::irange{0, 1000000000, 0}> vertices;
72 halp::spinbox_i32<"Instances", halp::irange{1, 1000000000, 1}> instances;
73 halp::combobox_t<"Topology", PrimitiveTopology> topology;
74 halp::combobox_t<"Cull Mode", CullMode> cull_mode;
75 halp::combobox_t<"Front Face", FrontFace> front_face;
76
77 // Transform
78 PositionControl position;
79 RotationControl rotation;
80 ScaleControl scale;
81 } inputs;
82
83 struct
84 {
85 struct
86 {
87 halp_meta(name, "Geometry");
88 halp::dynamic_gpu_geometry mesh;
89 float transform[16]{};
90 bool dirty_mesh = false;
91 bool dirty_transform = false;
92 } geometry;
93 } outputs;
94
95 BuffersToGeometry();
96 void operator()();
97
98 // Cache previous state to detect changes
100 {
101 bool enabled{};
102 int32_t buffer{};
103 int32_t offset{};
104 int32_t stride{};
105 AttributeFormat format{};
106 int32_t location{};
107 bool instanced{};
108 };
109
110 std::array<AttributeState, 8> m_prevAttributes{};
111 std::array<halp::gpu_buffer, 8> m_prevBuffers;
112 int32_t m_prevUseIndexBuffer{};
113 IndexFormat m_prevIndexFormat{};
114 int32_t m_prevIndexOffset{};
115 int32_t m_prevVertices{};
116 int32_t m_prevInstances{};
117 PrimitiveTopology m_prevTopology{};
118 CullMode m_prevCullMode{};
119 FrontFace m_prevFrontFace{};
120 CachedTRS m_cachedTRS{};
121
122 struct ui
123 {
124 halp_meta(name, "Main")
125 halp_meta(layout, halp::layouts::hbox)
126 halp_meta(background, halp::colors::background_mid)
127
128 struct T
129 {
130 halp_meta(name, "Tabs")
131 halp_meta(layout, halp::layouts::tabs)
132 halp_meta(background, halp::colors::background_darker)
133 struct G
134 {
135 halp_meta(name, "Global")
136 halp_meta(layout, halp::layouts::hbox)
137 struct A
138 {
139 halp_meta(layout, halp::layouts::vbox)
140 halp::item<&ins::vertices> vertices;
141 halp::item<&ins::instances> instances;
142 halp::item<&ins::topology> topology;
143 halp::item<&ins::cull_mode> cull_mode;
144 halp::item<&ins::front_face> front_face;
145 } a;
146
147 struct B
148 {
149 halp_meta(layout, halp::layouts::vbox)
150 halp::item<&ins::position> p;
151 halp::item<&ins::rotation> r;
152 halp::item<&ins::scale> s;
153 } b;
154 } global;
155
156 struct A1
157 {
158 halp_meta(name, "0")
159 halp_meta(layout, halp::layouts::vbox)
160 halp::item<&ins::attribute_buffer_0> buffer;
161 halp::item<&ins::attribute_offset_0> offset;
162 halp::item<&ins::attribute_stride_0> stride;
163 halp::item<&ins::format_0> format;
164 halp::item<&ins::location_0> location;
165 halp::item<&ins::instanced_0> instanced;
166 } a0;
167 struct A2
168 {
169 halp_meta(name, "1")
170 halp_meta(layout, halp::layouts::vbox)
171 halp::item<&ins::attribute_buffer_1> buffer;
172 halp::item<&ins::attribute_offset_1> offset;
173 halp::item<&ins::attribute_stride_1> stride;
174 halp::item<&ins::format_1> format;
175 halp::item<&ins::location_1> location;
176 halp::item<&ins::instanced_1> instanced;
177 } a1;
178 struct
179 {
180 halp_meta(name, "2")
181 halp_meta(layout, halp::layouts::vbox)
182 halp::item<&ins::attribute_buffer_2> buffer;
183 halp::item<&ins::attribute_offset_2> offset;
184 halp::item<&ins::attribute_stride_2> stride;
185 halp::item<&ins::format_2> format;
186 halp::item<&ins::location_2> location;
187 halp::item<&ins::instanced_2> instanced;
188 } a2;
189 struct A3
190 {
191 halp_meta(name, "3")
192 halp_meta(layout, halp::layouts::vbox)
193 halp::item<&ins::attribute_buffer_3> buffer;
194 halp::item<&ins::attribute_offset_3> offset;
195 halp::item<&ins::attribute_stride_3> stride;
196 halp::item<&ins::format_3> format;
197 halp::item<&ins::location_3> location;
198 halp::item<&ins::instanced_3> instanced;
199 } a3;
200 struct A4
201 {
202 halp_meta(name, "4")
203 halp_meta(layout, halp::layouts::vbox)
204 halp::item<&ins::attribute_buffer_4> buffer;
205 halp::item<&ins::attribute_offset_4> offset;
206 halp::item<&ins::attribute_stride_4> stride;
207 halp::item<&ins::format_4> format;
208 halp::item<&ins::location_4> location;
209 halp::item<&ins::instanced_4> instanced;
210 } a4;
211 struct A5
212 {
213 halp_meta(name, "5")
214 halp_meta(layout, halp::layouts::vbox)
215 halp::item<&ins::attribute_buffer_5> buffer;
216 halp::item<&ins::attribute_offset_5> offset;
217 halp::item<&ins::attribute_stride_5> stride;
218 halp::item<&ins::format_5> format;
219 halp::item<&ins::location_5> location;
220 halp::item<&ins::instanced_5> instanced;
221 } a5;
222 struct A6
223 {
224 halp_meta(name, "6")
225 halp_meta(layout, halp::layouts::vbox)
226 halp::item<&ins::attribute_buffer_6> buffer;
227 halp::item<&ins::attribute_offset_6> offset;
228 halp::item<&ins::attribute_stride_6> stride;
229 halp::item<&ins::format_6> format;
230 halp::item<&ins::location_6> location;
231 halp::item<&ins::instanced_6> instanced;
232 } a6;
233 struct A7
234 {
235 halp_meta(name, "7")
236 halp_meta(layout, halp::layouts::vbox)
237 halp::item<&ins::attribute_buffer_7> buffer;
238 halp::item<&ins::attribute_offset_7> offset;
239 halp::item<&ins::attribute_stride_7> stride;
240 halp::item<&ins::format_7> format;
241 halp::item<&ins::location_7> location;
242 halp::item<&ins::instanced_7> instanced;
243 } a7;
244 struct
245 {
246 halp_meta(name, "Index")
247 halp_meta(layout, halp::layouts::vbox)
248 halp::item<&ins::index_buffer> buffer;
249 halp::item<&ins::index_offset> offset;
250 halp::item<&ins::index_format> format;
251 } index;
252 } tabs;
253 };
254};
255
256} // namespace Threedim
Definition BufferToGeometry.hpp:18
Definition BufferToGeometry.hpp:100
Definition BufferToGeometry.hpp:34
Definition BufferToGeometry.hpp:123
Definition TinyObj.hpp:98
Definition TinyObj.hpp:103
Definition TinyObj.hpp:107
Definition TinyObj.hpp:27