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
36inline constexpr double kMinBufferScale = 0.0078125;
37inline constexpr double kMaxBufferScale = 1.0;
38
68inline constexpr int kMaxBufferPasses = 8;
69
84inline bool isValidWrapToken(const QString& wrap)
85{
86 return wrap == QLatin1String("clamp") || wrap == QLatin1String("repeat") || wrap == QLatin1String("mirror");
87}
88
94inline bool isValidFilterToken(const QString& filter)
95{
96 return filter == QLatin1String("linear") || filter == QLatin1String("nearest") || filter == QLatin1String("mipmap");
97}
98
124namespace CustomParams {
125
127inline constexpr int kVecCount = 8;
128
133inline constexpr int kFlatSlotCount = 4 * kVecCount;
134
140inline QString slotKey(int vec, char comp)
141{
142 // Same graceful-degradation contract as the flat slotKey(int) below: an
143 // out-of-range vec or a component outside {x,y,z,w} returns an empty string
144 // rather than fabricating a key that could collide with a valid one.
145 if (vec < 0 || vec >= kVecCount || (comp != 'x' && comp != 'y' && comp != 'z' && comp != 'w')) {
146 return {};
147 }
148 return QStringLiteral("customParams") + QString::number(vec + 1) + QLatin1Char('_') + QLatin1Char(comp);
149}
150
162inline QString slotKey(int slot)
163{
164 if (slot < 0 || slot >= kFlatSlotCount) {
165 return {};
166 }
167 static constexpr char kComponents[4] = {'x', 'y', 'z', 'w'};
168 return slotKey(slot / 4, kComponents[slot & 3]);
169}
170
178inline QString glslAccessor(int slot)
179{
180 if (slot < 0 || slot >= kFlatSlotCount) {
181 return {};
182 }
183 static constexpr char kComponents[4] = {'x', 'y', 'z', 'w'};
184 return QStringLiteral("customParams[") + QString::number(slot / 4) + QStringLiteral("].")
185 + QLatin1Char(kComponents[slot & 3]);
186}
187
188} // namespace CustomParams
189
215namespace CustomColors {
216
218inline constexpr int kColorCount = 16;
219
224inline QString colorKey(int slot)
225{
226 if (slot < 0 || slot >= kColorCount) {
227 return {};
228 }
229 return QStringLiteral("customColor") + QString::number(slot + 1);
230}
231
237inline QString glslAccessor(int slot)
238{
239 if (slot < 0 || slot >= kColorCount) {
240 return {};
241 }
242 return QStringLiteral("customColors[") + QString::number(slot) + QLatin1Char(']');
243}
244
245} // namespace CustomColors
246
247} // namespace PhosphorShaders
Canonical key format for the customColors[N] slots in BaseUniforms.
Definition CustomParamsKey.h:215
QString colorKey(int slot)
Format a customColor key from a 0-based slot index.
Definition CustomParamsKey.h:224
QString glslAccessor(int slot)
GLSL author-facing accessor for a color slot — the form a shader author reads in fragment source,...
Definition CustomParamsKey.h:237
constexpr int kColorCount
Number of color slots in BaseUniforms::customColors[16].
Definition CustomParamsKey.h:218
Canonical key format for the customParams[N].
Definition CustomParamsKey.h:124
QString slotKey(int vec, char comp)
Format a customParams slot key from explicit (vec, comp) pair.
Definition CustomParamsKey.h:140
constexpr int kVecCount
Number of vec4 slots in BaseUniforms::customParams[8].
Definition CustomParamsKey.h:127
constexpr int kFlatSlotCount
Number of float sub-slots across all vec4s (4 × kVecCount).
Definition CustomParamsKey.h:133
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:178
Definition ShaderProfile.h:21
constexpr double kMaxBufferScale
Definition CustomParamsKey.h:37
constexpr double kMinBufferScale
Lower / upper bounds on a multipass bufferScale (FBO downscale factor).
Definition CustomParamsKey.h:36
bool isValidFilterToken(const QString &filter)
The accepted buffer filter vocabulary: linear / nearest / mipmap.
Definition CustomParamsKey.h:94
constexpr int kMaxBufferPasses
Maximum number of multipass buffer passes a pack may declare.
Definition CustomParamsKey.h:68
bool isValidWrapToken(const QString &wrap)
The accepted texture / buffer wrap vocabulary, shared by every validation site across the shader regi...
Definition CustomParamsKey.h:84