From e723636f9a6070c5fa6862dfe2206997b48c3a30 Mon Sep 17 00:00:00 2001 From: ubuntu1804 Date: Tue, 11 Nov 2025 13:39:17 +0800 Subject: [PATCH] Pass elapsed time to renderer and use for time UBO --- src/vulkanrenderer.cpp | 3 ++- src/vulkanrenderer.h | 2 ++ src/vulkanwidget.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/vulkanrenderer.cpp b/src/vulkanrenderer.cpp index f8cd9ba..55da196 100644 --- a/src/vulkanrenderer.cpp +++ b/src/vulkanrenderer.cpp @@ -483,6 +483,7 @@ void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex, VkImageView imageView, int frameCount, + double elapsedTime, double rotationAngle, double wavePhase, bool paintingEnabled, @@ -553,7 +554,7 @@ void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer, } // Update uniform buffer - m_ubo.time = static_cast(frameCount); + m_ubo.time = static_cast(elapsedTime); m_ubo.resolution[0] = static_cast(m_width); m_ubo.resolution[1] = static_cast(m_height); m_ubo.rotation = static_cast(rotationAngle); diff --git a/src/vulkanrenderer.h b/src/vulkanrenderer.h index 7d2d1aa..35d1fa2 100644 --- a/src/vulkanrenderer.h +++ b/src/vulkanrenderer.h @@ -103,6 +103,7 @@ public: * @param imageIndex 交换链图像索引 * @param imageView 交换链图像视图 * @param frameCount 当前帧数 + * @param elapsedTime 运行时间(秒) * @param rotationAngle 旋转角度 * @param wavePhase 波浪相位 * @param paintingEnabled 是否启用绘制 @@ -112,6 +113,7 @@ public: uint32_t imageIndex, VkImageView imageView, int frameCount, + double elapsedTime, double rotationAngle, double wavePhase, bool paintingEnabled, diff --git a/src/vulkanwidget.cpp b/src/vulkanwidget.cpp index b0ff484..5390942 100644 --- a/src/vulkanwidget.cpp +++ b/src/vulkanwidget.cpp @@ -866,8 +866,13 @@ void VulkanWidget::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t i .arg(m_lockCount); } + // Calculate elapsed time in seconds + QDateTime now = QDateTime::currentDateTime(); + qint64 elapsedTime = m_startTime.secsTo(now); + m_renderer->recordCommandBuffer(commandBuffer, imageIndex, imageView, - m_frameCount, m_rotationAngle, m_wavePhase, + m_frameCount, static_cast(elapsedTime), + m_rotationAngle, m_wavePhase, m_renderingEnabled, lockInfo.toStdString()); return; }