Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
CustomParamsKey.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <QLatin1Char>
7#include <QLatin1String>
8#include <QString>
9
10namespace PhosphorShaders {
11
19inline constexpr double kMinBufferScale = 0.125;
20inline constexpr double kMaxBufferScale = 1.0;
21
27inline constexpr int kMaxBufferPasses = 4;
28
39inline bool isValidWrapToken(const QString& wrap)
40{
41 return wrap == QLatin1String("clamp") || wrap == QLatin1String("repeat") || wrap == QLatin1String("mirror");
42}
43
48inline bool isValidFilterToken(const QString& filter)
49{
50 return filter == QLatin1String("linear") || filter == QLatin1String("nearest") || filter == QLatin1String("mipmap");
51}
52
79namespace CustomParams {
80
82inline constexpr int kVecCount = 8;
83
88inline constexpr int kFlatSlotCount = 4 * kVecCount;
89
95inline QString slotKey(int vec, char comp)
96{
97 // Same graceful-degradation contract as the flat slotKey(int) below: an
98 // out-of-range vec or a component outside {x,y,z,w} returns an empty string
99 // rather than fabricating a key that could collide with a valid one.
100 if (vec < 0 || vec >= kVecCount || (comp != 'x' && comp != 'y' && comp != 'z' && comp != 'w')) {
101 return {};
102 }
103 return QStringLiteral("customParams") + QString::number(vec + 1) + QLatin1Char('_') + QLatin1Char(comp);
104}
105
117inline QString slotKey(int slot)
118{
119 if (slot < 0 || slot >= kFlatSlotCount) {
120 return {};
121 }
122 static constexpr char kComponents[4] = {'x', 'y', 'z', 'w'};
123 return slotKey(slot / 4, kComponents[slot & 3]);
124}
125
133inline QString glslAccessor(int slot)
134{
135 if (slot < 0 || slot >= kFlatSlotCount) {
136 return {};
137 }
138 static constexpr char kComponents[4] = {'x', 'y', 'z', 'w'};
139 return QStringLiteral("customParams[") + QString::number(slot / 4) + QStringLiteral("].")
140 + QLatin1Char(kComponents[slot & 3]);
141}
142
143} // namespace CustomParams
144
172namespace CustomColors {
173
175inline constexpr int kColorCount = 16;
176
181inline QString colorKey(int slot)
182{
183 if (slot < 0 || slot >= kColorCount) {
184 return {};
185 }
186 return QStringLiteral("customColor") + QString::number(slot + 1);
187}
188
194inline QString glslAccessor(int slot)
195{
196 if (slot < 0 || slot >= kColorCount) {
197 return {};
198 }
199 return QStringLiteral("customColors[") + QString::number(slot) + QLatin1Char(']');
200}
201
202} // namespace CustomColors
203
204} // namespace PhosphorShaders
QString colorKey(int slot)
Format a customColor key from a 0-based slot index.
Definition CustomParamsKey.h:181
QString glslAccessor(int slot)
GLSL author-facing accessor for a color slot — the form a shader author reads in fragment source,...
Definition CustomParamsKey.h:194
constexpr int kColorCount
Number of color slots in BaseUniforms::customColors[16].
Definition CustomParamsKey.h:175
QString slotKey(int vec, char comp)
Format a customParams slot key from explicit (vec, comp) pair.
Definition CustomParamsKey.h:95
constexpr int kVecCount
Number of vec4 slots in BaseUniforms::customParams[8].
Definition CustomParamsKey.h:82
constexpr int kFlatSlotCount
Number of float sub-slots across all vec4s (4 × kVecCount).
Definition CustomParamsKey.h:88
QString glslAccessor(int slot)
GLSL author-facing accessor for a flat scalar sub-slot — the form a shader author reads in fragment s...
Definition CustomParamsKey.h:133
Definition ShaderEffect.h:33
constexpr double kMaxBufferScale
Definition CustomParamsKey.h:20
constexpr double kMinBufferScale
Lower / upper bounds on a multipass bufferScale (FBO downscale factor).
Definition CustomParamsKey.h:19
bool isValidFilterToken(const QString &filter)
The accepted buffer filter vocabulary: linear / nearest / mipmap.
Definition CustomParamsKey.h:48
constexpr int kMaxBufferPasses
Maximum number of multipass buffer passes a pack may declare.
Definition CustomParamsKey.h:27
bool isValidWrapToken(const QString &wrap)
The accepted texture / buffer wrap vocabulary, shared by every validation site across the shader regi...
Definition CustomParamsKey.h:39