Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
PhosphorShaders Namespace Reference

Namespaces

namespace  CustomColors
 Canonical key format for the customColors[N] slots in BaseUniforms.
 
namespace  CustomParams
 Canonical key format for the customParams[N].
 
namespace  UboRegions
 UBO region offsets and sizes for partial updates (reduces GPU bandwidth).
 

Classes

struct  BaseUniforms
 GPU uniform buffer layout following std140 rules (base region). More...
 
struct  EntryCandidate
 One candidate entry function the author may define, paired with the void main() the harness generates when that function is present and the source defines no main() of its own (T1.4). More...
 
class  IUniformExtension
 Interface for appending custom uniform data after the base UBO layout. More...
 
class  IWallpaperProvider
 Abstract wallpaper provider interface. More...
 
struct  PreambleParam
 One declared shader parameter, in metadata declaration order, as fed to buildParamPreamble. More...
 
class  ShaderIncludeResolver
 Resolves #include directives in GLSL shader source. More...
 
class  ShaderRegistry
 Registry of available shader effects. More...
 

Functions

PHOSPHORSHADERS_EXPORT std::unique_ptr< IWallpaperProvidercreateWallpaperProvider ()
 Create the default wallpaper provider for the current desktop environment.
 
PHOSPHORSHADERS_EXPORT bool definesMain (const QString &expandedSource)
 True if expandedSource defines void main() at top level.
 
PHOSPHORSHADERS_EXPORT bool definesFunction (const QString &expandedSource, const QString &functionName)
 True if expandedSource defines a function named functionName.
 
PHOSPHORSHADERS_EXPORT QString composeEntryPoint (const QString &expandedSource, const QList< EntryCandidate > &candidates)
 Compose the fragment entry point (T1.4).
 
PHOSPHORSHADERS_EXPORT QString assembleEntryPoint (const QString &raw, const QString &prologue, const QList< EntryCandidate > &candidates)
 Convenience wrapper for the full assembly: when candidates is empty or raw already defines main(), returns raw unchanged; otherwise returns composeEntryPoint(prologue + raw, candidates).
 
PHOSPHORSHADERS_EXPORT QString stripGlslComments (const QString &source)
 Strip GLSL line (//…) and block (/* … *&zwj;/) comments from source, preserving newlines inside block comments so line numbers are unchanged.
 
PHOSPHORSHADERS_EXPORT QString buildParamPreamble (const QList< PreambleParam > &params)
 Build the generated #define p_<id> <glsl-accessor> preamble for a shader's declared parameters.
 
PHOSPHORSHADERS_EXPORT bool isValidParamId (const QString &id)
 True if id is a valid GLSL identifier body ([A-Za-z0-9_], non-empty) — the p_ prefix supplies the leading character, so a leading digit is fine.
 
PHOSPHORSHADERS_EXPORT QString spliceAfterVersion (const QString &source, const QString &block)
 Splice block into source immediately after its #version line, then emit a #line <n> 0 directive so the author's subsequent lines keep their original numbers (source string 0) despite the inserted block.
 

Variables

constexpr double kShaderTimeWrap = 1024.0
 Time wrap period for float32 precision preservation.
 

Function Documentation

◆ assembleEntryPoint()

PHOSPHORSHADERS_EXPORT QString PhosphorShaders::assembleEntryPoint ( const QString &  raw,
const QString &  prologue,
const QList< EntryCandidate > &  candidates 
)

Convenience wrapper for the full assembly: when candidates is empty or raw already defines main(), returns raw unchanged; otherwise returns composeEntryPoint(prologue + raw, candidates).

This is the single assembly entry point shared by the daemon bake layer and the kwin-effect path so both produce the identical pre-expansion source for an entry-only pack. Apply it to RAW (pre-expansion) source so the prologue's #include is then resolved. Entry-function detection therefore sees only the author's inline body — by convention the entry function (pZone/pImage/pTransition, or a hand-written main()) is authored directly, never pulled from an #include — which is why this wraps RAW rather than the expanded source composeEntryPoint expects.

◆ buildParamPreamble()

PHOSPHORSHADERS_EXPORT QString PhosphorShaders::buildParamPreamble ( const QList< PreambleParam > &  params)

Build the generated #define p_<id> <glsl-accessor> preamble for a shader's declared parameters.

Auto-numbers each pool independently in declaration order for params whose explicitSlot < 0. Returns an empty string for an empty list. A param whose id isn't a valid GLSL identifier body, or whose resolved slot is out of range, is emitted as a // p: skipped ... comment rather than a broken #define, so the block always compiles.

The returned block is newline-terminated and contains no #version or #line directive — the caller splices it after the shader's #version line and is responsible for any #line fixup that restores author line numbers (see the include resolver's #line contract).

◆ composeEntryPoint()

PHOSPHORSHADERS_EXPORT QString PhosphorShaders::composeEntryPoint ( const QString &  expandedSource,
const QList< EntryCandidate > &  candidates 
)

Compose the fragment entry point (T1.4).

• If expandedSource already defines void main(), it is returned unchanged — the author keeps full control (the escape hatch every existing pack uses today). • Otherwise the first candidate whose functionName is defined has its generatedMain appended (separated by a newline) and the result returned. • If no main() and no candidate matches, expandedSource is returned unchanged; the compiler then surfaces the missing-main() error, which the offline validator (T1.2) maps back to the author's file via the resolver's #line legend.

Splice the T1.1 param preamble (spliceAfterVersion) AFTER this, or before — they don't overlap (the preamble sits just after #version; the wrapper is appended at the end), but compose on the include-expanded source so definesMain / definesFunction see any entry point arriving from an include.

◆ createWallpaperProvider()

PHOSPHORSHADERS_EXPORT std::unique_ptr< IWallpaperProvider > PhosphorShaders::createWallpaperProvider ( )

Create the default wallpaper provider for the current desktop environment.

Detects KDE, Hyprland, Sway, GNOME and returns the appropriate implementation. Returns a fallback provider (empty path) if no supported DE is detected.

◆ definesFunction()

PHOSPHORSHADERS_EXPORT bool PhosphorShaders::definesFunction ( const QString &  expandedSource,
const QString &  functionName 
)

True if expandedSource defines a function named functionName.

Matches a definition — <name> ( <params> ) { — not a call: the trailing { distinguishes vec4 pZone(ZoneCtx z) { … } from return pZone(z);. Comments are stripped first. functionName is matched as a whole word. Parameter lists spanning multiple lines are handled.

◆ definesMain()

PHOSPHORSHADERS_EXPORT bool PhosphorShaders::definesMain ( const QString &  expandedSource)

True if expandedSource defines void main() at top level.

Comments are stripped first so a main inside a // or block comment never false-matches, and the match requires the () signature followed by { so a stray main identifier or a forward reference can't trip it. Run on the include-expanded source: a main() can legitimately arrive from an include, and the harness must treat that exactly like an inline one.

◆ isValidParamId()

PHOSPHORSHADERS_EXPORT bool PhosphorShaders::isValidParamId ( const QString &  id)

True if id is a valid GLSL identifier body ([A-Za-z0-9_], non-empty) — the p_ prefix supplies the leading character, so a leading digit is fine.

Shared so the metadata parser's auto-slot assignment skips exactly the same params buildParamPreamble skips, keeping the two lane-numberings identical.

◆ spliceAfterVersion()

PHOSPHORSHADERS_EXPORT QString PhosphorShaders::spliceAfterVersion ( const QString &  source,
const QString &  block 
)

Splice block into source immediately after its #version line, then emit a #line <n> 0 directive so the author's subsequent lines keep their original numbers (source string 0) despite the inserted block.

source is expected to be already include-expanded — the resolver's own #line bracketing uses the raw line positions, so injecting before expansion would corrupt its math; injecting here, after expansion, composes cleanly (the fixup re-anchors source string 0; the resolver's later #line directives are untouched). block must be newline-terminated (as buildParamPreamble returns). An empty block returns source unchanged. If source has no #version line the block is prepended best-effort (such source is not valid GLSL anyway).

◆ stripGlslComments()

PHOSPHORSHADERS_EXPORT QString PhosphorShaders::stripGlslComments ( const QString &  source)

Strip GLSL line (//…) and block (/* … *&zwj;/) comments from source, preserving newlines inside block comments so line numbers are unchanged.

Exposed for the detection helpers and for tests; GLSL has no string literals so there is no quoting context to preserve.

Variable Documentation

◆ kShaderTimeWrap

constexpr double PhosphorShaders::kShaderTimeWrap = 1024.0
constexpr

Time wrap period for float32 precision preservation.