diff options
Diffstat (limited to 'tests/manual/rhi/stereo')
-rw-r--r-- | tests/manual/rhi/stereo/main.cpp | 4 | ||||
-rw-r--r-- | tests/manual/rhi/stereo/window.cpp | 65 | ||||
-rw-r--r-- | tests/manual/rhi/stereo/window.h | 6 |
3 files changed, 63 insertions, 12 deletions
diff --git a/tests/manual/rhi/stereo/main.cpp b/tests/manual/rhi/stereo/main.cpp index 7ab1448217..cae25c8d24 100644 --- a/tests/manual/rhi/stereo/main.cpp +++ b/tests/manual/rhi/stereo/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2022 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 // This is a demo showing stereoscopic rendering. // For now, the backend is hardcoded to be OpenGL, because that's the only @@ -22,7 +22,7 @@ int main(int argc, char **argv) QSurfaceFormat::setDefaultFormat(fmt); - Window w; + Window w{QRhi::Vulkan}; w.resize(1280, 720); w.setTitle(QCoreApplication::applicationName()); w.show(); diff --git a/tests/manual/rhi/stereo/window.cpp b/tests/manual/rhi/stereo/window.cpp index 391e8b75fc..18e1ecc409 100644 --- a/tests/manual/rhi/stereo/window.cpp +++ b/tests/manual/rhi/stereo/window.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2022 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> @@ -8,9 +8,25 @@ #include <rhi/qshader.h> #include "../shared/cube.h" -Window::Window() +Window::Window(QRhi::Implementation graphicsApi) + :m_graphicsApi(graphicsApi) { - setSurfaceType(OpenGLSurface); + switch (graphicsApi) { + default: + case QRhi::OpenGLES2: + setSurfaceType(OpenGLSurface); + break; + case QRhi::Vulkan: + instance.setLayers({ "VK_LAYER_KHRONOS_validation" }); + instance.create(); + setVulkanInstance(&instance); + setSurfaceType(VulkanSurface); + break; + case QRhi::D3D11: + case QRhi::D3D12: + setSurfaceType(Direct3DSurface); + break; + } } void Window::exposeEvent(QExposeEvent *) @@ -57,11 +73,44 @@ void Window::init() { QRhi::Flags rhiFlags = QRhi::EnableDebugMarkers; - m_fallbackSurface.reset(QRhiGles2InitParams::newFallbackSurface()); - QRhiGles2InitParams params; - params.fallbackSurface = m_fallbackSurface.get(); - params.window = this; - m_rhi.reset(QRhi::create(QRhi::OpenGLES2, ¶ms, rhiFlags)); + switch (m_graphicsApi) { + case QRhi::Vulkan: + { + QRhiVulkanInitParams params; + params.window = this; + params.inst = vulkanInstance(); + m_rhi.reset(QRhi::create(QRhi::Vulkan, ¶ms, rhiFlags)); + break; + } + case QRhi::Null: + case QRhi::Metal: + case QRhi::OpenGLES2: + { + m_fallbackSurface.reset(QRhiGles2InitParams::newFallbackSurface()); + QRhiGles2InitParams params; + params.fallbackSurface = m_fallbackSurface.get(); + params.window = this; + m_rhi.reset(QRhi::create(QRhi::OpenGLES2, ¶ms, rhiFlags)); + break; + } +#ifdef Q_OS_WIN + case QRhi::D3D11: + { + QRhiD3D11InitParams params; + m_rhi.reset(QRhi::create(QRhi::D3D11, ¶ms, rhiFlags)); + break; + } + case QRhi::D3D12: + { + QRhiD3D12InitParams params; + params.enableDebugLayer = true; + m_rhi.reset(QRhi::create(QRhi::D3D12, ¶ms, rhiFlags)); + break; + } +#endif + default: + break; + } m_sc.reset(m_rhi->newSwapChain()); m_ds.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, diff --git a/tests/manual/rhi/stereo/window.h b/tests/manual/rhi/stereo/window.h index ea35040a7a..0a175e31a0 100644 --- a/tests/manual/rhi/stereo/window.h +++ b/tests/manual/rhi/stereo/window.h @@ -1,5 +1,5 @@ // Copyright (C) 2022 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 #ifndef WINDOW_H #define WINDOW_H @@ -11,17 +11,19 @@ class Window : public QWindow { public: - Window(); + Window(QRhi::Implementation graphicsApi); void releaseSwapChain(); protected: + QVulkanInstance instance; std::unique_ptr<QOffscreenSurface> m_fallbackSurface; std::unique_ptr<QRhi> m_rhi; std::unique_ptr<QRhiSwapChain> m_sc; std::unique_ptr<QRhiRenderBuffer> m_ds; std::unique_ptr<QRhiRenderPassDescriptor> m_rp; + QRhi::Implementation m_graphicsApi; bool m_hasSwapChain = false; QMatrix4x4 m_proj; |