Loading...
Searching...
No Matches
TextureInfo.hpp
1#pragma once
2#include <fmt/format.h>
3#include <halp/controls.hpp>
4#include <halp/meta.hpp>
5#include <halp/texture.hpp>
6
7#include <cstdint>
8#include <string>
9#include <string_view>
10
11namespace Threedim
12{
13// Tiny inspector node: takes a halp::gpu_texture_input -- a zero-copy
14// reference to the upstream's GPU texture -- and exposes its metadata
15// (width, height, format, native handle) on regular value-output ports
16// plus a single human-readable summary string.
17//
18// Wiring: when an Image-typed edge is connected to our Texture port,
19// score's CpuAnalysisNode (the GfxRenderer specialization for nodes
20// with no texture/buffer/geometry outputs) allocates a render target
21// at init time via texture_inputs_storage::init(), points the upstream
22// at it through renderTargetForInput(), and -- thanks to the
23// gpu_texture_port branch in that storage -- writes the resulting
24// QRhiTexture pointer plus its pixel size into our gpu_texture struct
25// (handle / width / height). The format enum is mapped from the
26// negotiated QRhiTexture::Format via gpp::qrhi::toTextureFormat. None of
27// the per-frame readback machinery used for halp::texture_input fires
28// for us.
30{
31public:
32 halp_meta(name, "Texture Info")
33 halp_meta(category, "Visuals/Utilities")
34 halp_meta(c_name, "texture_info")
35 halp_meta(manual_url, "https://ossia.io/score-docs/processes/texture-info.html")
36 halp_meta(uuid, "5bd9c8e2-7f1a-4e3b-9c0d-2a4b6f8e1d72")
37
38 struct
39 {
40 halp::gpu_texture_input<"Texture"> texture;
41 } inputs;
42
43 struct
44 {
45 halp::val_port<"Width", int> width;
46 halp::val_port<"Height", int> height;
47 halp::val_port<"Format", std::string> format;
48 // Raw native handle as an opaque integer (a QRhiTexture* on every
49 // backend score supports today). Useful only for visual identity
50 // ("did the upstream rebuild this texture?").
51 halp::val_port<"Handle", int64_t> handle;
52 halp::val_port<"Readable", std::string> readable;
53 } outputs;
54
55 static std::string_view format_name(halp::gpu_texture::format_t f) noexcept
56 {
57 using F = halp::gpu_texture;
58 switch(f)
59 {
60 case F::RGBA8:
61 return "RGBA8";
62 case F::RGBA16F:
63 return "RGBA16F";
64 case F::RGBA32F:
65 return "RGBA32F";
66 case F::R8:
67 return "R8";
68 case F::R16:
69 return "R16";
70 case F::R16F:
71 return "R16F";
72 case F::R32F:
73 return "R32F";
74 default:
75 return "unknown";
76 }
77 }
78
79 void operator()()
80 {
81 const auto& t = inputs.texture.texture;
82 const auto fmt_name = format_name(t.format);
83
84 outputs.width.value = t.width;
85 outputs.height.value = t.height;
86 outputs.format.value = std::string{fmt_name};
87 outputs.handle.value = reinterpret_cast<std::int64_t>(t.handle);
88
89 auto& ret = outputs.readable.value;
90 ret.clear();
91 fmt::format_to(
92 std::back_inserter(ret), "{}x{} {} (handle=0x{:x})", t.width, t.height,
93 fmt_name, reinterpret_cast<std::uintptr_t>(t.handle));
94 }
95};
96}
Definition TextureInfo.hpp:30