| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtGui/qtguiglobal.h> |
| 5 | #if QT_CONFIG(opengl) |
| 6 | #include <QtGui/qoffscreensurface.h> |
| 7 | #endif |
| 8 | |
| 9 | #include "commonutils_p.h" |
| 10 | |
| 11 | #include <rhi/qrhi.h> |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | static qreal s_maxTextureSize = 0.; |
| 16 | |
| 17 | qreal CommonUtils::maxTextureSize() |
| 18 | { |
| 19 | // Query maximum texture size only once |
| 20 | if (!s_maxTextureSize) { |
| 21 | std::unique_ptr<QRhi> rhi; |
| 22 | #if defined(Q_OS_WIN) |
| 23 | QRhiD3D12InitParams params; |
| 24 | rhi.reset(QRhi::create(QRhi::D3D12, ¶ms)); |
| 25 | #elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) |
| 26 | QRhiMetalInitParams params; |
| 27 | rhi.reset(QRhi::create(QRhi::Metal, ¶ms)); |
| 28 | #elif QT_CONFIG(opengl) |
| 29 | QRhiGles2InitParams params; |
| 30 | params.fallbackSurface = QRhiGles2InitParams::newFallbackSurface(); |
| 31 | rhi.reset(p: QRhi::create(impl: QRhi::OpenGLES2, params: ¶ms)); |
| 32 | #elif QT_CONFIG(vulkan) |
| 33 | if (!qEnvironmentVariable("QSG_RHI_BACKEND").compare( "vulkan")) { |
| 34 | QVulkanInstance inst; |
| 35 | inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); |
| 36 | if (inst.create()) { |
| 37 | QRhiVulkanInitParams params; |
| 38 | params.inst = &inst; |
| 39 | rhi.reset(QRhi::create(QRhi::Vulkan, ¶ms)); |
| 40 | } else { |
| 41 | qWarning("Failed to create Vulkan instance"); |
| 42 | } |
| 43 | } |
| 44 | #endif |
| 45 | if (rhi) |
| 46 | s_maxTextureSize = qreal(rhi->resourceLimit(limit: QRhi::TextureSizeMax)); |
| 47 | else |
| 48 | s_maxTextureSize = gradientTextureWidth; |
| 49 | } |
| 50 | |
| 51 | return s_maxTextureSize; |
| 52 | } |
| 53 | |
| 54 | QT_END_NAMESPACE |
| 55 |
