Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
ShaderEffect.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#include <PhosphorRendering/phosphorrendering_export.h>
8
12
13#include <QColor>
14#include <QImage>
15#include <QMutex>
16#include <QPointF>
17#include <QQuickItem>
18#include <QSizeF>
19#include <QStringList>
20#include <QUrl>
21#include <QVariantMap>
22#include <QVector4D>
23
24#include <QPointer>
25#include <array>
26#include <atomic>
27#include <functional>
28#include <memory>
29#include <mutex>
30
31QT_BEGIN_NAMESPACE
32class QSGNode;
33QT_END_NAMESPACE
34
35namespace PhosphorShaders {
37}
38
39namespace PhosphorRendering {
40
41class ShaderNodeRhi;
42
49
52inline constexpr int kDefaultUserTextureSvgSize = 1024;
53
66PHOSPHORRENDERING_EXPORT QVariant peelQmlVariant(const QVariant& value);
67
82class PHOSPHORRENDERING_EXPORT ShaderEffect : public QQuickItem
83{
84 Q_OBJECT
85
86 // ── Shadertoy-compatible animation uniforms ──────────────────────
87 Q_PROPERTY(qreal iTime READ iTime WRITE setITime NOTIFY iTimeChanged FINAL)
88 Q_PROPERTY(qreal iTimeDelta READ iTimeDelta WRITE setITimeDelta NOTIFY iTimeDeltaChanged FINAL)
89 Q_PROPERTY(int iFrame READ iFrame WRITE setIFrame NOTIFY iFrameChanged FINAL)
90 Q_PROPERTY(QSizeF iResolution READ iResolution WRITE setIResolution NOTIFY iResolutionChanged FINAL)
91 Q_PROPERTY(QPointF iMouse READ iMouse WRITE setIMouse NOTIFY iMouseChanged FINAL)
92 Q_PROPERTY(bool isReversed READ isReversed WRITE setIsReversed NOTIFY isReversedChanged FINAL)
93
94
110 Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged FINAL)
111
112 // ── Shader source ────────────────────────────────────────────────
113 Q_PROPERTY(QUrl shaderSource READ shaderSource WRITE setShaderSource NOTIFY shaderSourceChanged FINAL)
114 Q_PROPERTY(QUrl vertexShaderUrl READ vertexShaderUrl WRITE setVertexShaderUrl NOTIFY vertexShaderUrlChanged FINAL)
115 Q_PROPERTY(QVariantMap shaderParams READ shaderParams WRITE setShaderParams NOTIFY shaderParamsChanged FINAL)
116 Q_PROPERTY(QString paramPreamble READ paramPreamble WRITE setParamPreamble NOTIFY paramPreambleChanged FINAL)
117 Q_PROPERTY(QQuickItem* sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged FINAL)
118
119 // ── Multipass ────────────────────────────────────────────────────
120 Q_PROPERTY(
122 Q_PROPERTY(QStringList bufferShaderPaths READ bufferShaderPaths WRITE setBufferShaderPaths NOTIFY
124 Q_PROPERTY(bool bufferFeedback READ bufferFeedback WRITE setBufferFeedback NOTIFY bufferFeedbackChanged FINAL)
125 Q_PROPERTY(qreal bufferScale READ bufferScale WRITE setBufferScale NOTIFY bufferScaleChanged FINAL)
126 Q_PROPERTY(QVariantList bufferScales READ bufferScales WRITE setBufferScales NOTIFY bufferScalesChanged FINAL)
127 Q_PROPERTY(
129 Q_PROPERTY(QString bufferWrap READ bufferWrap WRITE setBufferWrap NOTIFY bufferWrapChanged FINAL)
130 Q_PROPERTY(QStringList bufferWraps READ bufferWraps WRITE setBufferWraps NOTIFY bufferWrapsChanged FINAL)
131 Q_PROPERTY(QString bufferFilter READ bufferFilter WRITE setBufferFilter NOTIFY bufferFilterChanged FINAL)
132 Q_PROPERTY(QStringList bufferFilters READ bufferFilters WRITE setBufferFilters NOTIFY bufferFiltersChanged FINAL)
133
134 // ── Custom parameters (32 floats in 8 vec4s) ────────────────────
135 Q_PROPERTY(QVector4D customParams1 READ customParams1 WRITE setCustomParams1 NOTIFY customParamsChanged FINAL)
136 Q_PROPERTY(QVector4D customParams2 READ customParams2 WRITE setCustomParams2 NOTIFY customParamsChanged FINAL)
137 Q_PROPERTY(QVector4D customParams3 READ customParams3 WRITE setCustomParams3 NOTIFY customParamsChanged FINAL)
138 Q_PROPERTY(QVector4D customParams4 READ customParams4 WRITE setCustomParams4 NOTIFY customParamsChanged FINAL)
139 Q_PROPERTY(QVector4D customParams5 READ customParams5 WRITE setCustomParams5 NOTIFY customParamsChanged FINAL)
140 Q_PROPERTY(QVector4D customParams6 READ customParams6 WRITE setCustomParams6 NOTIFY customParamsChanged FINAL)
141 Q_PROPERTY(QVector4D customParams7 READ customParams7 WRITE setCustomParams7 NOTIFY customParamsChanged FINAL)
142 Q_PROPERTY(QVector4D customParams8 READ customParams8 WRITE setCustomParams8 NOTIFY customParamsChanged FINAL)
143
144 // ── Custom colors (16 color slots) ───────────────────────────────
145 Q_PROPERTY(QColor customColor1 READ customColor1 WRITE setCustomColor1 NOTIFY customColorsChanged FINAL)
146 Q_PROPERTY(QColor customColor2 READ customColor2 WRITE setCustomColor2 NOTIFY customColorsChanged FINAL)
147 Q_PROPERTY(QColor customColor3 READ customColor3 WRITE setCustomColor3 NOTIFY customColorsChanged FINAL)
148 Q_PROPERTY(QColor customColor4 READ customColor4 WRITE setCustomColor4 NOTIFY customColorsChanged FINAL)
149 Q_PROPERTY(QColor customColor5 READ customColor5 WRITE setCustomColor5 NOTIFY customColorsChanged FINAL)
150 Q_PROPERTY(QColor customColor6 READ customColor6 WRITE setCustomColor6 NOTIFY customColorsChanged FINAL)
151 Q_PROPERTY(QColor customColor7 READ customColor7 WRITE setCustomColor7 NOTIFY customColorsChanged FINAL)
152 Q_PROPERTY(QColor customColor8 READ customColor8 WRITE setCustomColor8 NOTIFY customColorsChanged FINAL)
153 Q_PROPERTY(QColor customColor9 READ customColor9 WRITE setCustomColor9 NOTIFY customColorsChanged FINAL)
154 Q_PROPERTY(QColor customColor10 READ customColor10 WRITE setCustomColor10 NOTIFY customColorsChanged FINAL)
155 Q_PROPERTY(QColor customColor11 READ customColor11 WRITE setCustomColor11 NOTIFY customColorsChanged FINAL)
156 Q_PROPERTY(QColor customColor12 READ customColor12 WRITE setCustomColor12 NOTIFY customColorsChanged FINAL)
157 Q_PROPERTY(QColor customColor13 READ customColor13 WRITE setCustomColor13 NOTIFY customColorsChanged FINAL)
158 Q_PROPERTY(QColor customColor14 READ customColor14 WRITE setCustomColor14 NOTIFY customColorsChanged FINAL)
159 Q_PROPERTY(QColor customColor15 READ customColor15 WRITE setCustomColor15 NOTIFY customColorsChanged FINAL)
160 Q_PROPERTY(QColor customColor16 READ customColor16 WRITE setCustomColor16 NOTIFY customColorsChanged FINAL)
161
162 // ── Textures ─────────────────────────────────────────────────────
163 Q_PROPERTY(QVariant audioSpectrum READ audioSpectrumVariant WRITE setAudioSpectrumVariant NOTIFY
165 Q_PROPERTY(QVariant wallpaperTexture READ wallpaperTextureVariant WRITE setWallpaperTextureVariant NOTIFY
167 Q_PROPERTY(bool useWallpaper READ useWallpaper WRITE setUseWallpaper NOTIFY useWallpaperChanged FINAL)
168 Q_PROPERTY(bool useDepthBuffer READ useDepthBuffer WRITE setUseDepthBuffer NOTIFY useDepthBufferChanged FINAL)
172 Q_PROPERTY(
174
175 // ── Status ───────────────────────────────────────────────────────
176 Q_PROPERTY(Status status READ status NOTIFY statusChanged FINAL)
177 Q_PROPERTY(QString errorLog READ errorLog NOTIFY errorLogChanged FINAL)
178
179public:
183 enum class Status {
184 Null,
185 Loading,
186 Ready,
187 Error,
188 };
189 Q_ENUM(Status)
190
191
197 static constexpr int kMaxSvgDimension = 2048;
198
202 static constexpr int kMinSvgDimension = 64;
203
210 static constexpr qint64 kMaxSvgPixelBytes = 16LL * 1024 * 1024;
211
212 explicit ShaderEffect(QQuickItem* parent = nullptr);
213 ~ShaderEffect() override;
214
215 // ── Uniform extension ────────────────────────────────────────────
216
226 virtual void setUniformExtension(std::shared_ptr<PhosphorShaders::IUniformExtension> extension);
227 std::shared_ptr<PhosphorShaders::IUniformExtension> uniformExtension() const;
228
229 // ── Shadertoy uniforms ───────────────────────────────────────────
230
231 qreal iTime() const
232 {
233 return m_iTime;
234 }
235 void setITime(qreal time);
236
237 qreal iTimeDelta() const
238 {
239 return m_iTimeDelta;
240 }
241 void setITimeDelta(qreal delta);
242
243 int iFrame() const
244 {
245 return m_iFrame;
246 }
247 void setIFrame(int frame);
248
249 bool isPlaying() const
250 {
251 return m_playing;
252 }
253 void setPlaying(bool playing);
254
255 bool isReversed() const
256 {
257 return m_isReversed;
258 }
259
263 void setIsReversed(bool reverse);
264
265 QSizeF iResolution() const
266 {
267 return m_iResolution;
268 }
269 void setIResolution(const QSizeF& resolution);
270
271 QPointF iMouse() const
272 {
273 return m_iMouse;
274 }
275 void setIMouse(const QPointF& mouse);
276
277 // ── Shader source ────────────────────────────────────────────────
278
279 QUrl shaderSource() const
280 {
281 return m_shaderSource;
282 }
283 void setShaderSource(const QUrl& source);
284
285 QUrl vertexShaderUrl() const
286 {
287 return m_vertexShaderUrl;
288 }
289 void setVertexShaderUrl(const QUrl& source);
290
291 QVariantMap shaderParams() const
292 {
293 return m_shaderParams;
294 }
295
345 virtual void setShaderParams(const QVariantMap& params);
346
359 static QImage loadUserTextureFile(const QString& path, int svgMaxDim);
360
383 QQuickItem* sourceItem() const
384 {
385 return m_sourceItem.data();
386 }
387 void setSourceItem(QQuickItem* item);
388
389 // ── Multipass ────────────────────────────────────────────────────
390
391 QString bufferShaderPath() const
392 {
393 return m_bufferShaderPath;
394 }
395 void setBufferShaderPath(const QString& path);
396
397 QStringList bufferShaderPaths() const
398 {
399 return m_bufferShaderPaths;
400 }
401 void setBufferShaderPaths(const QStringList& paths);
402
403 bool bufferFeedback() const
404 {
405 return m_bufferFeedback;
406 }
407 void setBufferFeedback(bool enable);
408
409 qreal bufferScale() const
410 {
411 return m_bufferScale;
412 }
413 void setBufferScale(qreal scale);
414
420 QVariantList bufferScales() const
421 {
422 return m_bufferScales;
423 }
424 void setBufferScales(const QVariantList& scales);
425
426 bool halfFloatBuffers() const
427 {
428 return m_halfFloatBuffers;
429 }
430 void setHalfFloatBuffers(bool enable);
431
432 QString bufferWrap() const
433 {
434 return m_bufferWrap;
435 }
436 void setBufferWrap(const QString& wrap);
437
438 QStringList bufferWraps() const
439 {
440 return m_bufferWraps;
441 }
442 void setBufferWraps(const QStringList& wraps);
443
444 QString bufferFilter() const
445 {
446 return m_bufferFilter;
447 }
448 void setBufferFilter(const QString& filter);
449
450 QStringList bufferFilters() const
451 {
452 return m_bufferFilters;
453 }
454 void setBufferFilters(const QStringList& filters);
455
456 // ── Custom parameters (32 float slots in 8 vec4s) ────────────────
457
458 QVector4D customParams1() const
459 {
460 return m_customParams[0];
461 }
462 void setCustomParams1(const QVector4D& params);
463 QVector4D customParams2() const
464 {
465 return m_customParams[1];
466 }
467 void setCustomParams2(const QVector4D& params);
468 QVector4D customParams3() const
469 {
470 return m_customParams[2];
471 }
472 void setCustomParams3(const QVector4D& params);
473 QVector4D customParams4() const
474 {
475 return m_customParams[3];
476 }
477 void setCustomParams4(const QVector4D& params);
478 QVector4D customParams5() const
479 {
480 return m_customParams[4];
481 }
482 void setCustomParams5(const QVector4D& params);
483 QVector4D customParams6() const
484 {
485 return m_customParams[5];
486 }
487 void setCustomParams6(const QVector4D& params);
488 QVector4D customParams7() const
489 {
490 return m_customParams[6];
491 }
492 void setCustomParams7(const QVector4D& params);
493 QVector4D customParams8() const
494 {
495 return m_customParams[7];
496 }
497 void setCustomParams8(const QVector4D& params);
498
499 // ── Custom colors (16 color slots) ───────────────────────────────
500
501 QColor customColor1() const
502 {
503 return m_customColors[0];
504 }
505 void setCustomColor1(const QColor& color);
506 QColor customColor2() const
507 {
508 return m_customColors[1];
509 }
510 void setCustomColor2(const QColor& color);
511 QColor customColor3() const
512 {
513 return m_customColors[2];
514 }
515 void setCustomColor3(const QColor& color);
516 QColor customColor4() const
517 {
518 return m_customColors[3];
519 }
520 void setCustomColor4(const QColor& color);
521 QColor customColor5() const
522 {
523 return m_customColors[4];
524 }
525 void setCustomColor5(const QColor& color);
526 QColor customColor6() const
527 {
528 return m_customColors[5];
529 }
530 void setCustomColor6(const QColor& color);
531 QColor customColor7() const
532 {
533 return m_customColors[6];
534 }
535 void setCustomColor7(const QColor& color);
536 QColor customColor8() const
537 {
538 return m_customColors[7];
539 }
540 void setCustomColor8(const QColor& color);
541 QColor customColor9() const
542 {
543 return m_customColors[8];
544 }
545 void setCustomColor9(const QColor& color);
546 QColor customColor10() const
547 {
548 return m_customColors[9];
549 }
550 void setCustomColor10(const QColor& color);
551 QColor customColor11() const
552 {
553 return m_customColors[10];
554 }
555 void setCustomColor11(const QColor& color);
556 QColor customColor12() const
557 {
558 return m_customColors[11];
559 }
560 void setCustomColor12(const QColor& color);
561 QColor customColor13() const
562 {
563 return m_customColors[12];
564 }
565 void setCustomColor13(const QColor& color);
566 QColor customColor14() const
567 {
568 return m_customColors[13];
569 }
570 void setCustomColor14(const QColor& color);
571 QColor customColor15() const
572 {
573 return m_customColors[14];
574 }
575 void setCustomColor15(const QColor& color);
576 QColor customColor16() const
577 {
578 return m_customColors[15];
579 }
580 void setCustomColor16(const QColor& color);
581
582 // ── Indexed accessors (avoid per-slot function-pointer tables at call sites) ──
587 QVector4D customParamAt(int index) const;
595 void setCustomParamAt(int index, const QVector4D& params);
596
601 QColor customColorAt(int index) const;
606 void setCustomColorAt(int index, const QColor& color);
607
608 // ── Textures ─────────────────────────────────────────────────────
609
610 QVariant audioSpectrumVariant() const;
611 void setAudioSpectrumVariant(const QVariant& spectrum);
613 void setAudioSpectrum(const QVector<float>& spectrum);
614
631 void setUserTexture(int slot, const QImage& image);
633 void setUserTextureWrap(int slot, const QString& wrap);
634
635 QImage wallpaperTexture() const;
636
670 QVariant wallpaperTextureVariant() const;
671 void setWallpaperTexture(const QImage& image);
678 void setWallpaperTextureVariant(const QVariant& texture);
679
680 bool useWallpaper() const
681 {
682 return m_useWallpaper;
683 }
684 void setUseWallpaper(bool use);
685
686 bool useDepthBuffer() const
687 {
688 return m_useDepthBuffer;
689 }
690 void setUseDepthBuffer(bool use);
691
693 {
694 return m_gridSubdivisions;
695 }
696 void setGridSubdivisions(int subdivisions);
697
698 // ── Shader include paths ─────────────────────────────────────────
699
701 void setShaderIncludePaths(const QStringList& paths);
702 QStringList shaderIncludePaths() const
703 {
704 return m_shaderIncludePaths;
705 }
706
707 // ── Parameter preamble (T1.1: generated `#define p_<id> ...`) ─────
708
714 void setParamPreamble(const QString& preamble);
715 QString paramPreamble() const
716 {
717 return m_paramPreamble;
718 }
719
720 // ── Entry-point scaffold (T1.4: harness-generated `main()`) ────────
721
728 void setEntryScaffold(const QString& prologue, const QList<PhosphorShaders::EntryCandidate>& candidates);
729
730 // ── Status ───────────────────────────────────────────────────────
731
733 {
734 return m_status.load(std::memory_order_acquire);
735 }
736 QString errorLog() const
737 {
738 QMutexLocker lock(&m_errorLogMutex);
739 return m_errorLog;
740 }
741
742 // ── Actions ──────────────────────────────────────────────────────
743
745 Q_INVOKABLE void reloadShader();
746
768
769Q_SIGNALS:
817
818protected:
819 QSGNode* updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* data) override;
820 void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
821 void componentComplete() override;
822 void itemChange(ItemChange change, const ItemChangeData& value) override;
823
841
855
865 {
866 return m_shaderDirty.exchange(false);
867 }
868
881
900
901 void setError(const QString& error);
902 void setStatus(Status newStatus);
903 static QString localShaderPath(const QUrl& url);
904
905private:
906 // ── Auto-tick (playing=true) plumbing ────────────────────────────
910 void updatePlayingConnection();
913 void onPlayingTick();
914
915 // ── Output-scale plumbing ────────────────────────────────────────
939 void updateScaleConnections();
940
941 // ── Animation state ──────────────────────────────────────────────
942 // Field order minimises padding: 8-byte (qreal/QSizeF/QPointF) members
943 // grouped together, followed by 4-byte (int), trailing 1-byte bool.
944 // qreal-bool-int interleaving wastes 7 bytes via alignment padding.
945 qreal m_iTime = 0.0;
946 qreal m_iTimeDelta = 0.0;
947 qreal m_playingLastFrameSeconds = 0.0;
948 QSizeF m_iResolution;
949 QPointF m_iMouse;
950 int m_iFrame = 0;
951 bool m_isReversed = false;
952 bool m_playing = false;
953 QMetaObject::Connection m_playingConnection;
956 QMetaObject::Connection m_scaleConnection;
963 QMetaObject::Connection m_screenDprConnection;
964
965 // ── Shader source ────────────────────────────────────────────────
966 QUrl m_shaderSource;
967 QUrl m_vertexShaderUrl;
968 QVariantMap m_shaderParams;
969 QStringList m_shaderIncludePaths;
970 QString m_paramPreamble;
971 QString m_entryPrologue;
972 QList<PhosphorShaders::EntryCandidate> m_entryCandidates;
973
974 // QPointer because the source item is owned by the QML scene, not
975 // the ShaderEffect — a torn-down source must auto-null rather than
976 // leave a dangling pointer that the per-frame textureProvider()
977 // lookup would dereference.
978 QPointer<QQuickItem> m_sourceItem;
982 bool m_warnedSelfSourceItem = false;
983
984 // ── Multipass ────────────────────────────────────────────────────
985 QString m_bufferShaderPath;
986 QStringList m_bufferShaderPaths;
987 bool m_bufferFeedback = false;
988 qreal m_bufferScale = 1.0;
989 QVariantList m_bufferScales;
990 bool m_halfFloatBuffers = true;
991 QString m_bufferWrap = QStringLiteral("clamp");
992 QStringList m_bufferWraps;
993 QString m_bufferFilter = QStringLiteral("linear");
994 QStringList m_bufferFilters;
995
996 // ── Custom parameters (kVecCount vec4s, -1.0 "unset" sentinel) ─────────
997 // Sized from the shared budget, not a literal: the sync loop indexes these
998 // by the same constants, so a drifted literal would be an out-of-bounds write.
999 std::array<QVector4D, PhosphorShaders::CustomParams::kVecCount> m_customParams = {{
1000 QVector4D(-1.0f, -1.0f, -1.0f, -1.0f),
1001 QVector4D(-1.0f, -1.0f, -1.0f, -1.0f),
1002 QVector4D(-1.0f, -1.0f, -1.0f, -1.0f),
1003 QVector4D(-1.0f, -1.0f, -1.0f, -1.0f),
1004 QVector4D(-1.0f, -1.0f, -1.0f, -1.0f),
1005 QVector4D(-1.0f, -1.0f, -1.0f, -1.0f),
1006 QVector4D(-1.0f, -1.0f, -1.0f, -1.0f),
1007 QVector4D(-1.0f, -1.0f, -1.0f, -1.0f),
1008 }};
1009
1010 // ── Custom colors (16 colors) ────────────────────────────────────
1011 std::array<QColor, PhosphorShaders::CustomColors::kColorCount> m_customColors = {{
1012 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1013 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1014 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1015 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1016 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1017 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1018 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1019 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1020 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1021 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1022 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1023 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1024 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1025 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1026 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1027 QColor::fromRgbF(0.0f, 0.0f, 0.0f, 0.0f),
1028 }};
1029
1030 // ── Textures ─────────────────────────────────────────────────────
1031 QVector<float> m_audioSpectrum;
1032 std::array<QImage, kMaxUserTextureSlots> m_userTextureImages;
1033 // Filled with "clamp" by the constructor rather than a brace list, exactly like
1034 // m_userTextureSvgSizes below and for the same reason: the count is the binding
1035 // table's, so a literal list stops covering the array the moment the table
1036 // grows a slot. Filled at all because setShaderParams string-compares these,
1037 // so a null default reads as a change and fires a spurious update().
1038 std::array<QString, kMaxUserTextureSlots> m_userTextureWraps;
1044 std::array<QString, kMaxUserTextureSlots> m_userTexturePaths;
1051 // Filled with kDefaultUserTextureSvgSize by the constructor rather than a
1052 // brace list, so bumping kMaxUserTextureSlots cannot silently zero-fill the
1053 // new slots (qBound would then rasterise them at the 64 px floor).
1054 std::array<int, kMaxUserTextureSlots> m_userTextureSvgSizes{};
1064 bool m_userTexturesDirectlyOverridden = false;
1065 QImage m_wallpaperTexture;
1066 mutable QMutex m_wallpaperTextureMutex;
1067 bool m_useWallpaper = false;
1068 bool m_useDepthBuffer = false;
1069 int m_gridSubdivisions = 0;
1070
1071 // ── Uniform extension ────────────────────────────────────────────
1072 std::shared_ptr<PhosphorShaders::IUniformExtension> m_uniformExtension;
1073
1074 // ── Status ───────────────────────────────────────────────────────
1075 // Atomic because setStatus is called from updatePaintNode (render
1076 // thread under threaded render loop) while onPlayingTick reads it on
1077 // the GUI thread. A torn read would only matter at status
1078 // transitions, but the gate at `m_status != Status::Ready` would
1079 // skip-or-tick spuriously around the boundary. Acquire/release
1080 // semantics suffice — there's no associated data we need to publish
1081 // alongside.
1082 std::atomic<Status> m_status{Status::Null};
1090 mutable QMutex m_errorLogMutex;
1091 QString m_errorLog;
1092
1093 // ── Render node tracking ─────────────────────────────────────────
1105 std::shared_ptr<ShaderNodeLiveness> m_renderNodeLink;
1110 mutable std::mutex m_renderNodeMutex;
1114 std::shared_ptr<ShaderNodeLiveness> trackedNodeLink() const;
1118 void withTrackedNode(const std::function<void(ShaderNodeRhi*)>& fn) const;
1119 // QPointer defends against reparent/teardown storms where the window is
1120 // destroyed out from under us before windowChanged(nullptr) fires.
1121 QPointer<QQuickWindow> m_connectedWindow;
1134 struct SelfToken
1135 {
1136 std::mutex mutex;
1137 ShaderEffect* effect = nullptr;
1138 };
1139 std::shared_ptr<SelfToken> m_selfToken = std::make_shared<SelfToken>();
1140
1144 void notifyOnGuiThread(void (ShaderEffect::*signal)());
1145
1146 // ── Thread-safe dirty flags for main -> render thread sync ───────
1147 std::atomic<bool> m_shaderDirty{false};
1148};
1149
1150} // namespace PhosphorRendering
void reloadShader()
Force reload of shader from source (callable from QML).
qreal effectiveResolutionScale() const
The factor the GPU-bound iResolution is multiplied by.
QColor customColor4() const
Definition ShaderEffect.h:516
QVariant wallpaperTextureVariant() const
QML-facing form of wallpaperTexture, and the reason the Q_PROPERTY is a QVariant rather than a QImage...
void setCustomParams4(const QVector4D &params)
void setCustomParams6(const QVector4D &params)
QVariant audioSpectrumVariant() const
void setUserTexture(int slot, const QImage &image)
Set a user texture (slots 0-3, bindings 11-14) directly from a QImage, bypassing the path-driven load...
void setUserTextureWrap(int slot, const QString &wrap)
Set user texture wrap mode (slots 0-3).
void setShaderSource(const QUrl &source)
void setIResolution(const QSizeF &resolution)
QColor customColorAt(int index) const
Read a customColor slot by index.
virtual void setUniformExtension(std::shared_ptr< PhosphorShaders::IUniformExtension > extension)
Attach a uniform extension that appends custom data after BaseUniforms.
static constexpr int kMinSvgDimension
Floor of the same clamp.
Definition ShaderEffect.h:202
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
QVariantMap shaderParams() const
Definition ShaderEffect.h:291
QString paramPreamble() const
Definition ShaderEffect.h:715
void setCustomColor3(const QColor &color)
void releaseIdleGraphicsResources()
Release the render node's RHI resources (buffer FBOs, pipelines, uploaded textures) while the item si...
bool useDepthBuffer() const
Definition ShaderEffect.h:686
void setBufferShaderPath(const QString &path)
void setCustomColor7(const QColor &color)
QVector4D customParams7() const
Definition ShaderEffect.h:488
QVector4D customParams4() const
Definition ShaderEffect.h:473
void setBufferFilters(const QStringList &filters)
QPointF iMouse() const
Definition ShaderEffect.h:271
void setCustomColor2(const QColor &color)
void setBufferFeedback(bool enable)
void setCustomColor11(const QColor &color)
QColor customColor15() const
Definition ShaderEffect.h:571
void setCustomColor10(const QColor &color)
void statusChanged()
Emitted when status() transitions.
qreal bufferScale() const
Definition ShaderEffect.h:409
bool isReversed() const
Definition ShaderEffect.h:255
QUrl shaderSource() const
Definition ShaderEffect.h:279
QColor customColor1() const
Definition ShaderEffect.h:501
void setStatus(Status newStatus)
void setAudioSpectrumVariant(const QVariant &spectrum)
bool halfFloatBuffers() const
Definition ShaderEffect.h:426
void setCustomColor15(const QColor &color)
bool useWallpaper() const
Definition ShaderEffect.h:680
void setCustomColorAt(int index, const QColor &color)
Write a customColor slot by index.
QColor customColor16() const
Definition ShaderEffect.h:576
void setBufferShaderPaths(const QStringList &paths)
void setPlaying(bool playing)
void setBufferWrap(const QString &wrap)
QUrl vertexShaderUrl() const
Definition ShaderEffect.h:285
void errorLogChanged()
Emitted from setError().
void setCustomParams2(const QVector4D &params)
void setCustomColor9(const QColor &color)
QColor customColor13() const
Definition ShaderEffect.h:561
QVector4D customParams3() const
Definition ShaderEffect.h:468
void setCustomParams7(const QVector4D &params)
QVector4D customParams1() const
Definition ShaderEffect.h:458
void setCustomColor4(const QColor &color)
static QString localShaderPath(const QUrl &url)
URL to loader path; see the definition.
QColor customColor14() const
Definition ShaderEffect.h:566
void setParamPreamble(const QString &preamble)
Set the generated named-parameter preamble spliced after #version into the fragment source at load ti...
QColor customColor7() const
Definition ShaderEffect.h:531
void setGridSubdivisions(int subdivisions)
void setBufferFilter(const QString &filter)
void registerRenderNode(ShaderNodeRhi *node)
Register the live render node for base-class teardown coverage.
QSGNode * updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override
QVector4D customParamAt(int index) const
Read a customParams slot by index.
void setIMouse(const QPointF &mouse)
qreal iTime() const
Definition ShaderEffect.h:231
void setCustomParamAt(int index, const QVector4D &params)
Write a customParams slot by index.
QVector4D customParams8() const
Definition ShaderEffect.h:493
QStringList bufferFilters() const
Definition ShaderEffect.h:450
void setCustomColor6(const QColor &color)
void setCustomColor13(const QColor &color)
void setCustomParams5(const QVector4D &params)
bool bufferFeedback() const
Definition ShaderEffect.h:403
QString bufferWrap() const
Definition ShaderEffect.h:432
void setCustomParams3(const QVector4D &params)
bool isPlaying() const
Definition ShaderEffect.h:249
void syncBasePropertiesToNode(ShaderNodeRhi *node)
Sync base properties (time, params, colors, audio, multipass, depth, wallpaper, user textures,...
void setBufferWraps(const QStringList &wraps)
QVector4D customParams5() const
Definition ShaderEffect.h:478
QColor customColor3() const
Definition ShaderEffect.h:511
QVariantList bufferScales() const
Per-pass render-target scales, positionally aligned with bufferShaderPaths (a pack's bufferScales),...
Definition ShaderEffect.h:420
QString bufferFilter() const
Definition ShaderEffect.h:444
Status status() const
Definition ShaderEffect.h:732
QColor customColor2() const
Definition ShaderEffect.h:506
virtual ShaderNodeRhi * createShaderNode()
Factory hook for the render node updatePaintNode() will create.
QStringList bufferWraps() const
Definition ShaderEffect.h:438
void setCustomColor8(const QColor &color)
QColor customColor8() const
Definition ShaderEffect.h:536
QVector4D customParams2() const
Definition ShaderEffect.h:463
QColor customColor11() const
Definition ShaderEffect.h:551
Status
Auto-tick mode.
Definition ShaderEffect.h:183
QStringList bufferShaderPaths() const
Definition ShaderEffect.h:397
void setCustomColor5(const QColor &color)
int iFrame() const
Definition ShaderEffect.h:243
QVector4D customParams6() const
Definition ShaderEffect.h:483
void setShaderIncludePaths(const QStringList &paths)
Set directories to search for include directives in shaders.
void itemChange(ItemChange change, const ItemChangeData &value) override
void setAudioSpectrum(const QVector< float > &spectrum)
Direct setter from C++ avoiding QVariantList round-trip.
void setCustomColor16(const QColor &color)
void setHalfFloatBuffers(bool enable)
QString errorLog() const
Definition ShaderEffect.h:736
ShaderEffect(QQuickItem *parent=nullptr)
void setCustomColor1(const QColor &color)
void setCustomColor14(const QColor &color)
static constexpr qint64 kMaxSvgPixelBytes
Hard cap on the byte budget for a single rasterised SVG (16 MiB — matches RGBA8 at kMaxSvgDimension ×...
Definition ShaderEffect.h:210
void setWallpaperTexture(const QImage &image)
void setCustomParams8(const QVector4D &params)
QSizeF iResolution() const
Definition ShaderEffect.h:265
void setEntryScaffold(const QString &prologue, const QList< PhosphorShaders::EntryCandidate > &candidates)
Install the entry-point scaffold forwarded to the render node: when the fragment source defines no ma...
void setITimeDelta(qreal delta)
QColor customColor5() const
Definition ShaderEffect.h:521
QColor customColor6() const
Definition ShaderEffect.h:526
void setIsReversed(bool reverse)
Direction signal forwarded to ShaderNodeRhi → BaseUniforms::iIsReversed.
virtual void setShaderParams(const QVariantMap &params)
Push a parameter map onto the shader.
void setSourceItem(QQuickItem *item)
void setCustomColor12(const QColor &color)
static QImage loadUserTextureFile(const QString &path, int svgMaxDim)
Static helper that loads a user-texture file (PNG/JPG/etc.
QColor customColor12() const
Definition ShaderEffect.h:556
void setError(const QString &error)
void setBufferScale(qreal scale)
static constexpr int kMaxSvgDimension
Hard ceiling on the per-axis SVG rasterisation dimension applied by setShaderParams to the uTexture<N...
Definition ShaderEffect.h:197
void setCustomParams1(const QVector4D &params)
void setBufferScales(const QVariantList &scales)
QStringList shaderIncludePaths() const
Definition ShaderEffect.h:702
QColor customColor10() const
Definition ShaderEffect.h:546
QString bufferShaderPath() const
Definition ShaderEffect.h:391
int gridSubdivisions() const
Definition ShaderEffect.h:692
std::shared_ptr< PhosphorShaders::IUniformExtension > uniformExtension() const
void setVertexShaderUrl(const QUrl &source)
void setWallpaperTextureVariant(const QVariant &texture)
Accepts a QImage, a null, an undefined, an absent key, or an invalid QVariant — a host with nothing b...
qreal iTimeDelta() const
Definition ShaderEffect.h:237
QQuickItem * sourceItem() const
Live texture-provider source bound to SRB binding 11 (uTexture0).
Definition ShaderEffect.h:383
QColor customColor9() const
Definition ShaderEffect.h:541
bool consumeShaderDirty()
Atomically read-and-clear the shader-dirty flag.
Definition ShaderEffect.h:864
QSGRenderNode for fullscreen-quad shader rendering via Qt RHI (Vulkan / OpenGL).
Definition ShaderNodeRhi.h:158
Interface for appending custom uniform data after the base UBO layout.
Definition IUniformExtension.h:18
Definition AnimationShaderItemConfig.h:10
PHOSPHORRENDERING_EXPORT QVariant peelQmlVariant(const QVariant &value)
Peel the QML delivery wrappers off a property value and return the inner QVariant.
constexpr int kMaxUserTextureSlots
Public mirror of PhosphorRendering::kMaxUserTextures (4 user-texture slots at SRB bindings 11....
Definition ShaderEffect.h:48
constexpr int kDefaultUserTextureSvgSize
Default per-axis rasterisation size for an SVG user texture, used until a slot's shader param overrid...
Definition ShaderEffect.h:52
constexpr int kUserTextureCount
Definition ShaderBindings.h:43
Definition ShaderProfile.h:21