Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ZoneShaderCommon.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
7
8#include <QColor>
9#include <QRectF>
10#include <QVector>
11#include <QVector4D>
12
13#include <cstddef>
14
15namespace PhosphorRendering {
16
20constexpr int MaxZones = 64;
21
33struct alignas(16) ZoneShaderUniforms
34{
35 // ── Base region (PhosphorShaders::BaseUniforms) ────────────────────
37
38 // ── Zone extension region ────────────────────────────────────────
43
44 // Logical-to-device scale for the lengths carried in zoneParams (corner
45 // radius, border width). The GLSL counterpart is `uZoneScale` at the tail
46 // of the ZoneUniforms block in data/overlays/shared/common.glsl. std140
47 // places a float directly after the preceding vec4 array, so no leading
48 // pad is needed; the three trailing floats round the block out to the
49 // 16-byte boundary std140 requires.
50 // Defaulted to identity for the same reason ZoneUniformExtension's
51 // constructor seeds it: a value-initialised `ZoneShaderUniforms u = {}`
52 // would otherwise carry a zero scale, and a zero scale multiplies every
53 // corner radius and border width to nothing, so zones render square and
54 // border-less rather than failing visibly. The two structs are asserted
55 // binary-identical below, so both need the safe default.
56 float zoneScale = 1.0f;
57 float _pad_after_zoneScale[3] = {};
58};
59
64inline constexpr std::size_t kZoneExtensionBytes = 4 * sizeof(float[MaxZones][4]) + 4 * sizeof(float);
65
66// Exact, not a bound. Every member offset below is pinned exactly, so a loose
67// `<= 8192` would be the one assert that let an accidental growth through.
69 "ZoneShaderUniforms must be BaseUniforms plus the zone extension region");
70static_assert(offsetof(ZoneShaderUniforms, base) == 0, "base must be at offset 0");
71static_assert(offsetof(ZoneShaderUniforms, zoneRects) == sizeof(PhosphorShaders::BaseUniforms),
72 "zoneRects must follow BaseUniforms with no gap");
73// std140 puts a scalar directly after a vec4 array — pin that, because an
74// accidental pad here shifts uZoneScale and every overlay pack silently reads
75// garbage as its logical-to-device scale (corners round by a random factor).
76static_assert(offsetof(ZoneShaderUniforms, zoneScale)
77 == offsetof(ZoneShaderUniforms, zoneParams) + sizeof(float[MaxZones][4]),
78 "zoneScale must follow zoneParams with no gap (std140 scalar after vec4 array)");
79
84{
85 QRectF rect;
86 QColor fillColor;
88 float borderRadius = 0.0f;
89 float borderWidth = 2.0f;
90 bool isHighlighted = false;
91 int zoneNumber = 0;
92};
93
98{
99 float x = 0.0f;
100 float y = 0.0f;
101 float width = 0.0f;
102 float height = 0.0f;
103 int zoneNumber = 0;
104 bool highlighted = false;
105 // 0, matching ZoneData::borderRadius on the same path. An 8 px default here
106 // would be exactly the per-pack corner floor the shared zoneSdf() removed:
107 // a configured radius of 0 has to mean square corners, not "round by 8".
108 float borderRadius = 0.0f;
109 float borderWidth = 2.0f;
110};
111
116{
117 float r = 0.0f;
118 float g = 0.0f;
119 float b = 0.0f;
120 float a = 1.0f;
121
122 ZoneColor() = default;
123 ZoneColor(float red, float green, float blue, float alpha = 1.0f)
124 : r(red)
125 , g(green)
126 , b(blue)
127 , a(alpha)
128 {
129 }
130
131 static ZoneColor fromQColor(const QColor& color)
132 {
133 return ZoneColor(static_cast<float>(color.redF()), static_cast<float>(color.greenF()),
134 static_cast<float>(color.blueF()), static_cast<float>(color.alphaF()));
135 }
136
137 QVector4D toVector4D() const
138 {
139 return QVector4D(r, g, b, a);
140 }
141};
142
147{
148 QVector<ZoneRect> rects;
149 QVector<ZoneColor> fillColors;
150 QVector<ZoneColor> borderColors;
151 int zoneCount = 0;
153 int version = 0;
154};
155
156} // namespace PhosphorRendering
Definition ShaderCompiler.h:15
constexpr int MaxZones
Maximum number of zones the zone-aware UBO supports.
Definition ZoneShaderCommon.h:20
constexpr std::size_t kZoneExtensionBytes
Size of the zone extension region: four vec4[MaxZones] arrays, plus the uZoneScale scalar and the std...
Definition ZoneShaderCommon.h:64
Parsed zone color data for shader rendering.
Definition ZoneShaderCommon.h:116
float a
Definition ZoneShaderCommon.h:120
ZoneColor(float red, float green, float blue, float alpha=1.0f)
Definition ZoneShaderCommon.h:123
float g
Definition ZoneShaderCommon.h:118
float r
Definition ZoneShaderCommon.h:117
static ZoneColor fromQColor(const QColor &color)
Definition ZoneShaderCommon.h:131
float b
Definition ZoneShaderCommon.h:119
QVector4D toVector4D() const
Definition ZoneShaderCommon.h:137
Thread-safe zone data snapshot for the render thread.
Definition ZoneShaderCommon.h:147
int highlightedCount
Definition ZoneShaderCommon.h:152
QVector< ZoneColor > borderColors
Definition ZoneShaderCommon.h:150
int version
Definition ZoneShaderCommon.h:153
QVector< ZoneColor > fillColors
Definition ZoneShaderCommon.h:149
int zoneCount
Definition ZoneShaderCommon.h:151
QVector< ZoneRect > rects
Definition ZoneShaderCommon.h:148
Per-zone payload pushed into the UBO each frame.
Definition ZoneShaderCommon.h:84
float borderWidth
Definition ZoneShaderCommon.h:89
QRectF rect
Definition ZoneShaderCommon.h:85
QColor borderColor
Definition ZoneShaderCommon.h:87
int zoneNumber
Definition ZoneShaderCommon.h:91
QColor fillColor
Definition ZoneShaderCommon.h:86
float borderRadius
Definition ZoneShaderCommon.h:88
bool isHighlighted
Definition ZoneShaderCommon.h:90
Parsed zone rectangle data for shader rendering.
Definition ZoneShaderCommon.h:98
bool highlighted
Definition ZoneShaderCommon.h:104
float borderWidth
Definition ZoneShaderCommon.h:109
float width
Definition ZoneShaderCommon.h:101
float height
Definition ZoneShaderCommon.h:102
int zoneNumber
Definition ZoneShaderCommon.h:103
float y
Definition ZoneShaderCommon.h:100
float x
Definition ZoneShaderCommon.h:99
float borderRadius
Definition ZoneShaderCommon.h:108
GPU uniform buffer layout — BaseUniforms + zone extension.
Definition ZoneShaderCommon.h:34
float _pad_after_zoneScale[3]
Definition ZoneShaderCommon.h:57
float zoneParams[MaxZones][4]
Definition ZoneShaderCommon.h:42
float zoneScale
Definition ZoneShaderCommon.h:56
float zoneFillColors[MaxZones][4]
Definition ZoneShaderCommon.h:40
PhosphorShaders::BaseUniforms base
Definition ZoneShaderCommon.h:36
float zoneRects[MaxZones][4]
Definition ZoneShaderCommon.h:39
float zoneBorderColors[MaxZones][4]
Definition ZoneShaderCommon.h:41
GPU uniform buffer layout following std140 rules (base region).
Definition BaseUniforms.h:37