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(description, "Extract a named vertex attribute, raw buffer or auxiliary buffer from geometry.")
43 halp_meta(
44 manual_url, "https://ossia.io/score-docs/processes/extract-buffer.html")
45 halp_meta(uuid, "3c9d6c2b-1f04-4f7d-9bc2-a4b1d7c8e5f0")
46
47 enum Mode
48 {
49 Attribute,
50 Buffer
51 };
52
53 struct ins
54 {
55 struct
56 {
57 halp_meta(name, "Geometry");
58 halp::dynamic_gpu_geometry mesh;
59 float transform[16]{};
60 bool dirty_mesh = false;
61 bool dirty_transform = false;
62 } geometry;
63
64 halp::combobox_t<"Mode", Mode> mode;
65 struct : halp::lineedit<"Name / index", "position">
66 {
67 halp_meta(symbol, "name")
68 } name;
69 halp::toggle<"Pad vec3 to vec4"> pad_to_vec4;
70 } inputs;
71
72 struct
73 {
74 halp::gpu_buffer_output<"Buffer"> buffer;
75 } outputs;
76
78
79 void init(score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res);
80 void update(
81 score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res,
83 void release(score::gfx::RenderList& r);
84 void runInitialPasses(
85 score::gfx::RenderList& renderer, QRhiCommandBuffer& commands,
86 QRhiResourceUpdateBatch*& res, score::gfx::Edge& edge);
87 void operator()();
88
89private:
90 // Resolve the user's name string to an attribute_lookup, taking the
91 // active mesh into account. Returns nullopt on miss.
92 [[nodiscard]] static std::optional<attribute_lookup>
93 resolveAttribute(const halp::dynamic_gpu_geometry& mesh, std::string_view n) noexcept;
94
95 // Resolve the user's name string to a (buffer index, byte_offset, byte_size)
96 // triple suitable for DirectBufferReferenceStrategy. Returns -1 on miss.
97 struct BufferRef
98 {
99 int buffer_index{-1};
100 int64_t byte_offset{};
101 int64_t byte_size{};
102 };
103 [[nodiscard]] static BufferRef
104 resolveBuffer(const halp::dynamic_gpu_geometry& mesh, std::string_view n) noexcept;
105
106 // (Re)initialise m_strategy based on the current inputs and mesh.
107 void initStrategy(score::gfx::RenderList& renderer);
108 void updateOutput();
109
110 ExtractionStrategyVariant m_strategy;
111 Mode m_currentMode{Attribute};
112 std::string m_currentName{};
113 bool m_currentPadToVec4{false};
114};
115}
Definition ExtractBuffer2.hpp:37
List of nodes to be rendered to an output.
Definition RenderList.hpp:33
Definition ExtractBuffer2.hpp:54
Definition TinyObj.hpp:27
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:236