From fb54be25ecf0048687d7f72ccff87ee787fd2d20 Mon Sep 17 00:00:00 2001 From: ubuntu1804 Date: Tue, 11 Nov 2025 09:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=94=81=E5=B1=8F=E5=B8=A7?= =?UTF-8?q?=E7=9A=84=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shaders/background.frag | 13 +- src/shaders_spirv/background.frag.spv | Bin 2624 -> 2812 bytes src/shaders_spirv/background_frag.inc | 170 +++++++++++++------------- src/vulkanrenderer.cpp | 1 + src/vulkanrenderer.h | 3 +- src/vulkanwidget.cpp | 15 ++- 6 files changed, 112 insertions(+), 90 deletions(-) diff --git a/shaders/background.frag b/shaders/background.frag index 1a4bea3..51c0d7e 100644 --- a/shaders/background.frag +++ b/shaders/background.frag @@ -12,11 +12,19 @@ layout(binding = 0, std140) uniform UniformBufferObject { float resY; // offset 8 float rotation; // offset 12 float wavePhase; // offset 16 - float padding1; // offset 20 - float padding2; // offset 24 + float paintingEnabled; // offset 20 (0.0 = locked, 1.0 = normal) + float padding1; // offset 24 } ubo; void main() { + // Check if painting is disabled (locked state) + if (ubo.paintingEnabled < 0.5) { + // Locked state: dark gray background (matching CustomWidget) + outColor = vec4(0.157, 0.157, 0.157, 1.0); // RGB(40, 40, 40) + return; + } + + // Normal state: animated gradient background // Normalize position to 0-1 range vec2 uv = (fragPosition + 1.0) * 0.5; @@ -39,4 +47,3 @@ void main() { outColor = vec4(finalColor, 1.0); } - diff --git a/src/shaders_spirv/background.frag.spv b/src/shaders_spirv/background.frag.spv index 97bc5520d8e4299e54b48c663a96559fad6ab87b..a5ad5d487a694afbabd2402460fc4d68d2557c15 100644 GIT binary patch literal 2812 zcmZ{lO>cWqe zzrdX<_bgmnE_CP4-@yvY(kh?l&h2=MDsNTS>G$nE-F^D>nd$BtdMHWuB>R%R$)`!@ zJD7CAByh!aonO4VIJ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ASnmaPdn6y{T}1!;{-3jfm%xAgd}r z-x={N^|2x zT(O38V0qtH)bJX5)Sx|TIFIhT)E+g=p!;^US%Whr7d6bH+nd01=++r{9^IHKUG-fq zAjasY&798VLar~eUqTl7ADqb*#CcgpBInyVA9cS2mUF%$ZWY})-*d#hhb|v+@1x5Z z7x%r4Za!_+=9`c+hxK1UtT*rn=++!(Ttzn~?t2YgE@YUOZJz6h|AGIlInAT5XI9y@ z#~C-!<*wwj`3bt5E4WY5<;)q}XE`^(UggF5UAl=FufO*Fh-dm8)AkP;&LjT(m_height); m_ubo.rotation = static_cast(rotationAngle); m_ubo.wavePhase = static_cast(wavePhase); + m_ubo.paintingEnabled = paintingEnabled ? 1.0f : 0.0f; diff --git a/src/vulkanrenderer.h b/src/vulkanrenderer.h index a450983..7d2d1aa 100644 --- a/src/vulkanrenderer.h +++ b/src/vulkanrenderer.h @@ -44,7 +44,8 @@ struct UniformBufferObject { float resolution[2]; // 分辨率 (width, height) float rotation; // 旋转角度 float wavePhase; // 波浪相位 - float padding[2]; // 对齐到 16 字节边界 + float paintingEnabled; // 是否启用绘制(0.0 = 锁屏,1.0 = 正常) + float padding[1]; // 对齐到 16 字节边界 }; /** diff --git a/src/vulkanwidget.cpp b/src/vulkanwidget.cpp index dbf6485..946b8ea 100644 --- a/src/vulkanwidget.cpp +++ b/src/vulkanwidget.cpp @@ -639,10 +639,13 @@ bool VulkanWidget::recreateSwapchain() void VulkanWidget::renderFrame() { - if (!m_initialized || !m_renderingEnabled) { + if (!m_initialized) { return; } + // 关键修复:即使 renderingEnabled=false 也继续渲染,以显示锁屏状态 + // 只是传递不同的 paintingEnabled 参数给 renderer + // Wait for previous frame vkWaitForFences(m_device, 1, &m_inFlightFences[m_currentFrame], VK_TRUE, UINT64_MAX); @@ -912,7 +915,10 @@ void VulkanWidget::setRenderingEnabled(bool enabled) if (m_renderingEnabled) { qDebug() << "Vulkan rendering ENABLED - Resuming animations"; - m_renderTimer->start(16); // ~60 FPS + // 定时器始终运行,无需重新启动 + if (!m_renderTimer->isActive()) { + m_renderTimer->start(16); // ~60 FPS + } // Unlocked: calculate lock duration if (m_lastLockTime.isValid()) { @@ -926,8 +932,9 @@ void VulkanWidget::setRenderingEnabled(bool enabled) m_startTime = QDateTime::currentDateTime(); } else { - qDebug() << "Vulkan rendering DISABLED - Stopping animations"; - m_renderTimer->stop(); + qDebug() << "Vulkan rendering DISABLED - Showing locked state"; + // 关键修复:不停止定时器,继续渲染以显示锁屏界面 + // 只是不更新动画参数(在 onRenderTimer 中处理) // Locked: record lock time m_pauseTime = QDateTime::currentDateTime();