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", "int", "ivec2..4",
42// "uint", "uvec2..4"). mat4 is unsupported — returns
43// nullopt. An integer type needs a user DEFAULT, except
44// instance_draw_id, which defaults to 0.
45// `user_default` the DEFAULT[] array from the JSON header (may be
46// empty). When non-empty, overrides the semantic
47// whitelist: numbers are packed into the payload in
48// declaration order, then truncated / zero-padded to
49// fit the declared type width.
50//
51// Returns `std::nullopt` when neither a user DEFAULT nor a whitelisted
52// semantic default applies — the caller is expected to fail the pipeline
53// build with a clear error referencing the input name.
54SCORE_PLUGIN_GFX_EXPORT std::optional<VertexFallbackSpec> resolveVertexFallback(
55 ossia::attribute_semantic semantic,
56 std::string_view decl_type,
57 const std::vector<double>& user_default) noexcept;
58
59// Stable hash of a fallback spec's byte payload. Used as part of the
60// VertexFallbackPool key so two shaders declaring the same semantic and
61// TYPE with different DEFAULT arrays don't share a buffer.
62SCORE_PLUGIN_GFX_EXPORT uint64_t
63hashVertexFallback(const VertexFallbackSpec& spec) noexcept;
64
65}
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
Definition VertexFallbackDefaults.hpp:22