Loading...
Searching...
No Matches
InjectTexture.hpp
1#pragma once
2#include <halp/controls.hpp>
3#include <halp/meta.hpp>
4#include <halp/texture.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-texture injection. Takes a scene_spec passthrough
16// cable plus a live GPU texture from an upstream producer (video node,
17// ISF output, CSF image, etc.) and attaches it under a caller-supplied
18// name. ScenePreprocessor consumes `scene_state::inject_textures` and
19// writes matching `auxiliary_texture` entries onto its output
20// geometry — so the live handle flows to any downstream consumer
21// shader that declares an AUXILIARY texture entry with the same name.
22//
23// Texture handles are routed via halp::gpu_texture_input, which goes
24// through the Graph's TextureInlet / updateInputTexture() path — a
25// fundamentally different mechanism from InjectBuffer's
26// halp::gpu_buffer_input (which goes through bufferForInput / Output).
27// Hence the split into two distinct node types.
28//
29// Wiring:
30// VideoProducer → InjectTexture(name="base_color_dyn0")
31// → ScenePreprocessor → classic_pbr_full
33{
34public:
35 halp_meta(name, "Inject Texture")
36 halp_meta(category, "Visuals/3D/Scene")
37 halp_meta(c_name, "inject_texture")
38 halp_meta(authors, "ossia team")
39 halp_meta(
40 manual_url,
41 "https://ossia.io/score-docs/processes/inject-texture.html")
42 halp_meta(uuid, "3b8d2f7c-9a5e-4f1d-a4c6-6e2d9c4f8a1b")
43
44 struct ins
45 {
46 struct
47 {
48 halp_meta(name, "Scene In");
49 ossia::scene_spec scene;
50 uint8_t dirty{0};
51 } scene_in;
52
53 // Port-driven rebuild: aux_name triggers rebuild(). scene_in +
54 // texture handle changes detected in operator()() (no port-update
55 // event fires when a native handle is swapped).
56 // Live GPU texture from an upstream producer. Null handle → the
57 // injection is skipped (passthrough).
58 halp::gpu_texture_input<"Texture"> texture;
59
60 struct : halp::lineedit<"Aux name", "">
61 { void update(InjectTexture& n) { n.rebuild(); } } aux_name;
62 } inputs;
63
64 struct outs
65 {
66 struct
67 {
68 halp_meta(name, "Scene Out");
69 ossia::scene_spec scene;
70 uint8_t dirty{0};
71 } scene_out;
72 } outputs;
73
74 void rebuild();
75 void operator()();
76
77 std::shared_ptr<const ossia::scene_state> m_cached_out;
78 uint8_t m_pending_dirty{0xFF};
79 const ossia::scene_state* m_cached_in_state{};
80 // -2 is a sentinel no live input can produce (a null input reads as
81 // -1): it forces the first tick's rebuild without needing
82 // `!m_cached_out` as a trigger — a null cached output is legitimate
83 // whenever the input scene is null, and using it as a rebuild trigger
84 // re-dirties every tick of an unwired node.
85 int64_t m_cached_in_version{-2};
86 std::string m_cached_name;
87 void* m_cached_handle{};
88 int64_t m_version_counter{0};
89};
90
91}
Definition InjectTexture.hpp:33
Definition InjectTexture.hpp:45
Definition InjectTexture.hpp:65