Loading...
Searching...
No Matches
ExtractBuffer2.hpp
1#pragma once
2#include <Threedim/GeometryToBufferStrategies.hpp>
3
4#include <halp/buffer.hpp>
5#include <halp/controls.hpp>
6#include <halp/geometry.hpp>
7#include <halp/meta.hpp>
8
9namespace Threedim
10{
11// Name-based version of Threedim::ExtractBuffer, which enumerates a fixed list
12// of attribute slots and selects one through a combobox. This one takes a Mode
13// enum -- Attribute or Buffer -- and a free-form name interpreted per mode.
14//
15// Mode == Attribute extracts a single per-vertex attribute:
16// * "position" / "normal" / "tangent" / "bitangent" / "texcoord" or
17// "texcoord0".."texcoord7" / "uv" / "color" or "color0".."color3" match
18// against halp::attribute_semantic
19// * "<integer>" is the Nth entry in mesh.attributes[]
20// * anything else is a custom-name lookup in mesh.attributes[].name
21// The output uses the same Direct / Compute / Indexed strategies.
22//
23// Mode == Buffer extracts a whole raw buffer:
24// * "<integer>" is the Nth entry in mesh.buffers[]
25// * "index" is the buffer mesh.index points at
26// * a name matching mesh.auxiliary[].name, checked first since aux names may
27// shadow attribute names, returns that auxiliary's backing buffer with its
28// byte_offset and byte_size. This is how ScenePreprocessor's per-frame
29// auxiliaries reach a standalone gpu_buffer outlet for consumers that do
30// not want try_bind_from_geometry
31// * anything else looks up an attribute by semantic or custom name and
32// returns the buffer it lives in
33//
34// The source buffer handle is re-fetched from the mesh on every update(), so an
35// upstream that rebuilds its QRhiBuffer is reflected on the next frame.
37{
38public:
39 halp_meta(name, "Extract buffer (by name)")
40 halp_meta(category, "Visuals/Utilities")
41 halp_meta(c_name, "extract_buffer_by_name")
42 halp_meta(
43 manual_url, "https://ossia.io/score-docs/processes/extract-buffer.html")
44 halp_meta(uuid, "3c9d6c2b-1f04-4f7d-9bc2-a4b1d7c8e5f0")
45
46 enum Mode
47 {
48 Attribute,
49 Buffer
50 };
51
52 struct ins
53 {
54 struct
55 {
56 halp_meta(name, "Geometry");
57 halp::dynamic_gpu_geometry mesh;
58 float transform[16]{};
59 bool dirty_mesh = false;
60 bool dirty_transform = false;
61 } geometry;
62
63 halp::combobox_t<"Mode", Mode> mode;
64 struct : halp::lineedit<"Name / index", "position">
65 {
66 halp_meta(symbol, "name")
67 } name;
68 halp::toggle<"Pad vec3 to vec4"> pad_to_vec4;
69 } inputs;
70
71 struct
72 {
73 halp::gpu_buffer_output<"Buffer"> buffer;
74 } outputs;
75
77
78 void init(score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res);
79 void update(
80 score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res,
82 void release(score::gfx::RenderList& r);
83 void runInitialPasses(
84 score::gfx::RenderList& renderer, QRhiCommandBuffer& commands,
85 QRhiResourceUpdateBatch*& res, score::gfx::Edge& edge);
86 void operator()();
87
88private:
89 // Resolve the user's name string to an attribute_lookup, taking the
90 // active mesh into account. Returns nullopt on miss.
91 [[nodiscard]] static std::optional<attribute_lookup>
92 resolveAttribute(const halp::dynamic_gpu_geometry& mesh, std::string_view n) noexcept;
93
94 // Resolve the user's name string to a (buffer index, byte_offset, byte_size)
95 // triple suitable for DirectBufferReferenceStrategy. Returns -1 on miss.
96 struct BufferRef
97 {
98 int buffer_index{-1};
99 int64_t byte_offset{};
100 int64_t byte_size{};
101 };
102 [[nodiscard]] static BufferRef
103 resolveBuffer(const halp::dynamic_gpu_geometry& mesh, std::string_view n) noexcept;
104
105 // (Re)initialise m_strategy based on the current inputs and mesh.
106 void initStrategy(score::gfx::RenderList& renderer);
107 void updateOutput();
108
109 ExtractionStrategyVariant m_strategy;
110 Mode m_currentMode{Attribute};
111 std::string m_currentName{};
112 bool m_currentPadToVec4{false};
113};
114}
Definition ExtractBuffer2.hpp:37
List of nodes to be rendered to an output.
Definition RenderList.hpp:30
Definition ExtractBuffer2.hpp:53
Definition TinyObj.hpp:27
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:103