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: the inlet is single-cable: it has no render target and reads the
19// texture the upstream publishes (textureForOutput), so the inlet's size and
20// format settings do not apply. Unwired, or fed by a node that publishes no
21// texture, the handle is null and the size 0x0.
23{
24public:
25 halp_meta(name, "Texture Info")
26 halp_meta(category, "Visuals/Utilities")
27 halp_meta(c_name, "texture_info")
28 halp_meta(description, "Report a GPU texture's dimensions, format and native handle as values and readable text.")
29 halp_meta(manual_url, "https://ossia.io/score-docs/processes/texture-info.html")
30 halp_meta(uuid, "5bd9c8e2-7f1a-4e3b-9c0d-2a4b6f8e1d72")
31
32 struct
33 {
34 struct : halp::gpu_texture_input<"Texture">
35 {
36 halp_flag(single_cable);
37 } texture;
38 } inputs;
39
40 struct
41 {
42 halp::val_port<"Width", int> width;
43 halp::val_port<"Height", int> height;
44 halp::val_port<"Format", std::string> format;
45 // Raw native handle as an opaque integer (a QRhiTexture* on every
46 // backend score supports today). Useful only for visual identity
47 // ("did the upstream rebuild this texture?").
48 halp::val_port<"Handle", int64_t> handle;
49 halp::val_port<"Readable", std::string> readable;
50 } outputs;
51
52 static std::string_view format_name(halp::gpu_texture::format_t f) noexcept
53 {
54 using F = halp::gpu_texture;
55 switch(f)
56 {
57 case F::RGBA8:
58 return "RGBA8";
59 case F::RGBA16F:
60 return "RGBA16F";
61 case F::RGBA32F:
62 return "RGBA32F";
63 case F::R8:
64 return "R8";
65 case F::R16:
66 return "R16";
67 case F::R16F:
68 return "R16F";
69 case F::R32F:
70 return "R32F";
71 default:
72 return "unknown";
73 }
74 }
75
76 void operator()()
77 {
78 const auto& t = inputs.texture.texture;
79 const auto fmt_name = format_name(t.format);
80
81 outputs.width.value = t.width;
82 outputs.height.value = t.height;
83 outputs.format.value = std::string{fmt_name};
84 outputs.handle.value = reinterpret_cast<std::int64_t>(t.handle);
85
86 auto& ret = outputs.readable.value;
87 ret.clear();
88 fmt::format_to(
89 std::back_inserter(ret), "{}x{} {} (handle=0x{:x})", t.width, t.height,
90 fmt_name, reinterpret_cast<std::uintptr_t>(t.handle));
91 }
92};
93}
Definition TextureInfo.hpp:23