Loading...
Searching...
No Matches
PipelineStateHelpers.hpp
1#pragma once
2#include <isf.hpp>
3
4#include <QtGui/private/qrhi_p.h>
5
6#include <score_plugin_gfx_export.h>
7
8#include <string_view>
9
10namespace score::gfx
11{
12
13// --- String → Qt RHI enum mappers ----------------------------------------
14//
15// All mappers are case-insensitive and accept common synonyms
16// (e.g. "lequal" / "less_equal" both map to CompareOp::LessOrEqual).
17// Unknown strings fall back to a sensible default (documented per function).
18
19SCORE_PLUGIN_GFX_EXPORT
20QRhiGraphicsPipeline::CompareOp toCompareOp(std::string_view s) noexcept;
21
22SCORE_PLUGIN_GFX_EXPORT
23QRhiGraphicsPipeline::CullMode toCullMode(std::string_view s) noexcept;
24
25SCORE_PLUGIN_GFX_EXPORT
26QRhiGraphicsPipeline::FrontFace toFrontFace(std::string_view s) noexcept;
27
28SCORE_PLUGIN_GFX_EXPORT
29QRhiGraphicsPipeline::PolygonMode toPolygonMode(std::string_view s) noexcept;
30
31SCORE_PLUGIN_GFX_EXPORT
32QRhiGraphicsPipeline::BlendFactor toBlendFactor(std::string_view s) noexcept;
33
34SCORE_PLUGIN_GFX_EXPORT
35QRhiGraphicsPipeline::BlendOp toBlendOp(std::string_view s) noexcept;
36
37SCORE_PLUGIN_GFX_EXPORT
38QRhiGraphicsPipeline::StencilOp toStencilOp(std::string_view s) noexcept;
39
40SCORE_PLUGIN_GFX_EXPORT
41QRhiGraphicsPipeline::ColorMask toColorMask(std::string_view s) noexcept;
42
43// Depth-attachment clear value to pair with a declared DEPTH_COMPARE.
44//
45// Depth after the viewport transform is in [0, 1], so a clear value only
46// admits fragments on one side of it: 0.0 works with `greater` / `greater_equal`
47// (the project-wide reverse-Z convention documented in CameraMath.hpp) and
48// rejects every fragment under `less` / `less_equal`.
49SCORE_PLUGIN_GFX_EXPORT
50float depthClearForCompare(QRhiGraphicsPipeline::CompareOp compare) noexcept;
51
52// The same, for a shader's declared state: uses its DEPTH_COMPARE when it set
53// one, and otherwise the project-wide reverse-Z default.
54//
55// Every path that opens a pass with a depth attachment must go through this.
56// Picking the clear independently of the compare is not a cosmetic mismatch --
57// it silently discards the whole draw, because a clear of 0.0 admits nothing
58// under `less`.
59SCORE_PLUGIN_GFX_EXPORT
60float depthClearForState(const isf::pipeline_state& state) noexcept;
61
62// --- Conversion helpers ---------------------------------------------------
63
64SCORE_PLUGIN_GFX_EXPORT
65QRhiGraphicsPipeline::TargetBlend toTargetBlend(const isf::blend_attachment& b) noexcept;
66
67SCORE_PLUGIN_GFX_EXPORT
68QRhiGraphicsPipeline::StencilOpState toStencilOpState(const isf::stencil_op_state& s) noexcept;
69
70// --- pipeline_state manipulation ------------------------------------------
71
72// Merge two pipeline_states: every field that is set in `over` wins, otherwise
73// `base`'s field is kept. Used to combine the descriptor's global state with a
74// per-pass override_state.
75SCORE_PLUGIN_GFX_EXPORT
76isf::pipeline_state mergeState(isf::pipeline_state base, const isf::pipeline_state& over);
77
78// Returns true if the state has any field set (i.e. would affect a pipeline).
79SCORE_PLUGIN_GFX_EXPORT
80bool stateAffectsPipeline(const isf::pipeline_state&) noexcept;
81
82// Apply the state to a graphics pipeline.
83// - `colorAttachmentCount`: used to size per-attachment blend vectors.
84// - `depthAttachmentAvailable`: true when the target RT has a depth attachment;
85// depth-test/write are forced off otherwise.
86// - `wantsDepthByDefault`: when state.depth_test is nullopt and this is false,
87// depth test/write are force-disabled; callers pass
88// `renderer.anyNodeRequiresDepth()`.
89//
90// Only fields explicitly set in `state` are overridden. Cull, front-face,
91// polygon mode, blend, and stencil all preserve whatever the caller (or
92// `mesh.preparePipeline()`) configured before this call. The caller is
93// responsible for seeding sensible defaults (e.g. premul-alpha blend) before
94// invoking this, so that shaders declaring partial pipeline_state don't
95// silently lose unrelated defaults.
96SCORE_PLUGIN_GFX_EXPORT
97void applyPipelineState(
98 QRhiGraphicsPipeline& pip,
99 const isf::pipeline_state& state,
100 int colorAttachmentCount,
101 bool depthAttachmentAvailable,
102 bool wantsDepthByDefault) noexcept;
103
104}
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11