diff options
Diffstat (limited to 'tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp')
-rw-r--r-- | tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp b/tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp index 153bd2c37f..edbd048c63 100644 --- a/tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp +++ b/tests/manual/rhi/hellominimalcrossgfxtriangle/window.cpp @@ -1,8 +1,9 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "window.h" #include <QPlatformSurfaceEvent> +#include <QTimer> Window::Window(QRhi::Implementation graphicsApi) : m_graphicsApi(graphicsApi) @@ -10,14 +11,12 @@ Window::Window(QRhi::Implementation graphicsApi) switch (graphicsApi) { case QRhi::OpenGLES2: setSurfaceType(OpenGLSurface); -#if QT_CONFIG(opengl) - setFormat(QRhiGles2InitParams::adjustedFormat()); -#endif break; case QRhi::Vulkan: setSurfaceType(VulkanSurface); break; case QRhi::D3D11: + case QRhi::D3D12: setSurfaceType(Direct3DSurface); break; case QRhi::Metal: @@ -83,7 +82,7 @@ bool Window::event(QEvent *e) void Window::init() { - QRhi::Flags rhiFlags = QRhi::EnableDebugMarkers | QRhi::EnableProfiling; + QRhi::Flags rhiFlags = QRhi::EnableDebugMarkers; if (m_graphicsApi == QRhi::Null) { QRhiNullInitParams params; @@ -114,10 +113,14 @@ void Window::init() QRhiD3D11InitParams params; params.enableDebugLayer = true; m_rhi.reset(QRhi::create(QRhi::D3D11, ¶ms, rhiFlags)); + } else if (m_graphicsApi == QRhi::D3D12) { + QRhiD3D12InitParams params; + params.enableDebugLayer = true; + m_rhi.reset(QRhi::create(QRhi::D3D12, ¶ms, rhiFlags)); } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (m_graphicsApi == QRhi::Metal) { QRhiMetalInitParams params; m_rhi.reset(QRhi::create(QRhi::Metal, ¶ms, rhiFlags)); @@ -196,7 +199,20 @@ void Window::render() m_rhi->endFrame(m_sc.get()); + // Always request the next frame via requestUpdate(). On some platforms this is backed + // by a platform-specific solution, e.g. CVDisplayLink on macOS, which is potentially + // more efficient than a timer, queued metacalls, etc. + // + // However, the rendering behavior is identical no matter how the next round of + // rendering is triggered: the rendering thread is throttled to the presentation rate + // (either in beginFrame() or endFrame()) so the triangle should rotate at the exact + // same speed no matter which approach is taken here. + +#if 1 requestUpdate(); +#else + QTimer::singleShot(0, this, [this] { render(); }); +#endif } void Window::customInit() |