Loading...
Searching...
No Matches
VertexFallbackDefaults.hpp
1#pragma once
2
3#include <ossia/dataflow/geometry_port.hpp>
4
5#include <score_plugin_gfx_export.h>
6
7#include <array>
8#include <cstdint>
9#include <optional>
10#include <string_view>
11#include <vector>
12
13namespace score::gfx
14{
15
16// Packed neutral value for an optional VERTEX_INPUT whose upstream
17// attribute is absent. The renderer uploads these `stride_bytes` bytes
18// into a PerInstance step_rate=1 buffer of exactly one element and binds
19// it at the shader input's slot. Stride and format are driven by the
20// GLSL TYPE the shader declared — not the semantic's canonical width.
22{
23 // Values from the anonymous enum in ossia::geometry::attribute — we
24 // store as int to sidestep the "decltype on non-static member"
25 // boilerplate; callers cast back at the QRhi boundary the same way
26 // RenderedCSFNode.cpp already does.
27 int format{};
28 uint32_t stride_bytes{};
29 // First `stride_bytes` bytes are the payload (native float / int
30 // bytes). 64 bytes accommodate mat4 if mat4 VERTEX_INPUTS ever land
31 // (they don't today — the parser's location-bump is not mat4-aware).
32 std::array<uint8_t, 64> bytes{};
33};
34
35// Resolve a fallback for a shader-declared optional VERTEX_INPUT.
36//
37// `semantic` the resolved ossia semantic (from SEMANTIC field if
38// set, else from NAME via ossia::name_to_semantic).
39// Pass attribute_semantic::custom for unknown names.
40// `decl_type` the GLSL TYPE the shader declared, lowercased
41// ("float", "vec2", "vec3", "vec4"). mat4 / integer
42// types are unsupported in v1 — returns nullopt.
43// `user_default` the DEFAULT[] array from the JSON header (may be
44// empty). When non-empty, overrides the semantic
45// whitelist: numbers are packed into the payload in
46// declaration order, then truncated / zero-padded to
47// fit the declared type width.
48//
49// Returns `std::nullopt` when neither a user DEFAULT nor a whitelisted
50// semantic default applies — the caller is expected to fail the pipeline
51// build with a clear error referencing the input name.
52SCORE_PLUGIN_GFX_EXPORT std::optional<VertexFallbackSpec> resolveVertexFallback(
53 ossia::attribute_semantic semantic,
54 std::string_view decl_type,
55 const std::vector<double>& user_default) noexcept;
56
57// Stable hash of a fallback spec's byte payload. Used as part of the
58// VertexFallbackPool key so two shaders declaring the same semantic and
59// TYPE with different DEFAULT arrays don't share a buffer.
60SCORE_PLUGIN_GFX_EXPORT uint64_t
61hashVertexFallback(const VertexFallbackSpec& spec) noexcept;
62
63}
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
Definition VertexFallbackDefaults.hpp:22