Loading...
Searching...
No Matches
InjectBuffer.hpp
1#pragma once
2#include <halp/buffer.hpp>
3#include <halp/controls.hpp>
4#include <halp/meta.hpp>
5
6#include <ossia/dataflow/geometry_port.hpp>
7
8#include <cstdint>
9#include <memory>
10#include <string>
11
12namespace Threedim
13{
14
15// Mid-pipeline aux-buffer injection. Takes a scene_spec passthrough cable
16// plus a live GPU buffer from an upstream producer (CSF output, another
17// aux node, etc.) and attaches it to the scene as a pending injection
18// under a caller-supplied name. ScenePreprocessor consumes
19// `scene_state::inject_buffers` at flatten-time and writes matching
20// `auxiliary_buffer` entries onto every output geometry — so the live
21// handle ends up bound to any downstream consumer shader that declares
22// an AUXILIARY entry with the same name (SSBO or UBO kind).
23//
24// Wiring:
25// CSFProducer → InjectBuffer(name="scene_params", is_uniform=true)
26// → ScenePreprocessor → classic_pbr_full
27//
28// Name collisions with existing auxes published by the scene producers
29// (e.g., ScenePreprocessor's own scene_lights / scene_materials) follow
30// last-wins — the injection appended after flatten overrides the
31// flatten-time entry. Use this to selectively replace standard auxes
32// with custom data without forking the preprocessor.
34{
35public:
36 halp_meta(name, "Inject Buffer")
37 halp_meta(category, "Visuals/3D/Scene")
38 halp_meta(c_name, "inject_buffer")
39 halp_meta(description, "Attach a live GPU buffer to a scene under a named auxiliary binding.")
40 halp_meta(authors, "ossia team")
41 halp_meta(
42 manual_url,
43 "https://ossia.io/score-docs/processes/inject-buffer.html")
44 halp_meta(uuid, "4f9a6e2d-7c83-4b5d-9e1f-8a3c5d6b2f4e")
45
46 struct ins
47 {
48 struct
49 {
50 halp_meta(name, "Scene In");
51 ossia::scene_spec scene;
52 uint8_t dirty{0};
53 } scene_in;
54
55 // Port-driven rebuild: aux_name triggers rebuild(). scene_in +
56 // buffer handle changes are detected in operator()() because they
57 // can change without a port-update event.
58 // Live GPU buffer from an upstream producer. Null handle → the
59 // injection is skipped (passthrough), so unwiring is safe.
60 halp::gpu_buffer_input<"Buffer"> buffer;
61
62 struct : halp::lineedit<"Aux name", "">
63 { void update(InjectBuffer& n) { n.rebuild(); } } aux_name;
64 } inputs;
65
66 struct outs
67 {
68 struct
69 {
70 halp_meta(name, "Scene Out");
71 ossia::scene_spec scene;
72 uint8_t dirty{0};
73 } scene_out;
74 } outputs;
75
76 void rebuild();
77 void operator()();
78
79 // Stable shared_ptr cached while inputs are unchanged — keeps
80 // ScenePreprocessor's fingerprint fast-path warm.
81 std::shared_ptr<const ossia::scene_state> m_cached_out;
82 uint8_t m_pending_dirty{0xFF};
83 const ossia::scene_state* m_cached_in_state{};
84 // -2 is a sentinel no live input can produce (a null input reads as
85 // -1): it forces the first tick's rebuild without needing
86 // `!m_cached_out` as a trigger — a null cached output is legitimate
87 // whenever the input scene is null, and using it as a rebuild trigger
88 // re-dirties every tick of an unwired node.
89 int64_t m_cached_in_version{-2};
90 std::string m_cached_name;
91 void* m_cached_handle{};
92 int64_t m_cached_byte_size{};
93 int64_t m_version_counter{0};
94};
95
96}
Definition InjectBuffer.hpp:34
Definition InjectBuffer.hpp:47
Definition InjectBuffer.hpp:67