diff options
author | Paul Olav Tvete <paul.tvete@qt.io> | 2020-06-16 17:03:47 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@qt.io> | 2020-06-17 17:42:01 +0200 |
commit | 83fb4f6743860bfb746e6243aad00513d498db4f (patch) | |
tree | 816bf1a1d509124c6bfb4fc34cce2a4ed885f40e /src/quickshapes | |
parent | 48e919e9647fd07351be37e1ad7efdda9c550be9 (diff) |
Clean up QT_CONFIG(opengl)
Accelerated graphics is now possible without OpenGL support. With
this change, a Qt build with -no-opengl can still run Qt Quick with
a Vulkan, Metal, or Direct3D backend.
Fixes: QTBUG-84027
Change-Id: Ib63c733d28cfdf7de16b138df136fa7628e1747b
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/quickshapes')
-rw-r--r-- | src/quickshapes/qquickshape.cpp | 13 | ||||
-rw-r--r-- | src/quickshapes/qquickshapegenericrenderer.cpp | 60 |
2 files changed, 11 insertions, 62 deletions
diff --git a/src/quickshapes/qquickshape.cpp b/src/quickshapes/qquickshape.cpp index b71e872841..3fa4a74a01 100644 --- a/src/quickshapes/qquickshape.cpp +++ b/src/quickshapes/qquickshape.cpp @@ -981,12 +981,6 @@ void QQuickShapePrivate::createRenderer() return; switch (ri->graphicsApi()) { -#if QT_CONFIG(opengl) - case QSGRendererInterface::OpenGL: - rendererType = QQuickShape::GeometryRenderer; - renderer = new QQuickShapeGenericRenderer(q); - break; -#endif case QSGRendererInterface::Software: rendererType = QQuickShape::SoftwareRenderer; renderer = new QQuickShapeSoftwareRenderer; @@ -1014,13 +1008,6 @@ QSGNode *QQuickShapePrivate::createNode() return node; switch (ri->graphicsApi()) { -#if QT_CONFIG(opengl) - case QSGRendererInterface::OpenGL: - node = new QQuickShapeGenericNode; - static_cast<QQuickShapeGenericRenderer *>(renderer)->setRootNode( - static_cast<QQuickShapeGenericNode *>(node)); - break; -#endif case QSGRendererInterface::Software: node = new QQuickShapeSoftwareRenderNode(q); static_cast<QQuickShapeSoftwareRenderer *>(renderer)->setNode( diff --git a/src/quickshapes/qquickshapegenericrenderer.cpp b/src/quickshapes/qquickshapegenericrenderer.cpp index 373a014a68..16831d59d3 100644 --- a/src/quickshapes/qquickshapegenericrenderer.cpp +++ b/src/quickshapes/qquickshapegenericrenderer.cpp @@ -40,18 +40,13 @@ #include "qquickshapegenericrenderer_p.h" #include <QtGui/private/qtriangulator_p.h> #include <QtGui/private/qtriangulatingstroker_p.h> +#include <QtGui/private/qrhi_p.h> #include <QSGVertexColorMaterial> #if QT_CONFIG(thread) #include <QThreadPool> #endif -#if QT_CONFIG(opengl) -#include <QOpenGLContext> -#include <QOffscreenSurface> -#include <private/qopenglextensions_p.h> -#endif - QT_BEGIN_NAMESPACE static const qreal TRI_SCALE = 1; @@ -114,47 +109,6 @@ void QQuickShapeGenericStrokeFillNode::activateMaterial(QQuickWindow *window, Ma setMaterial(m_material.data()); } -static bool q_supportsElementIndexUint(QSGRendererInterface::GraphicsApi api) -{ - static bool elementIndexUint = true; -#if QT_CONFIG(opengl) - if (api == QSGRendererInterface::OpenGL) { - static bool elementIndexUintChecked = false; - if (!elementIndexUintChecked) { - elementIndexUintChecked = true; - QOpenGLContext *context = QOpenGLContext::currentContext(); - const bool needsTempContext = !context; - QScopedPointer<QOpenGLContext> dummyContext; - QScopedPointer<QOffscreenSurface> dummySurface; - bool ok = true; - if (needsTempContext) { - dummyContext.reset(new QOpenGLContext); - dummyContext->create(); - context = dummyContext.data(); - dummySurface.reset(new QOffscreenSurface); - dummySurface->setFormat(context->format()); - dummySurface->create(); - ok = context->makeCurrent(dummySurface.data()); - } - if (ok) { - elementIndexUint = static_cast<QOpenGLExtensions *>(context->functions())->hasOpenGLExtension( - QOpenGLExtensions::ElementIndexUint); - - if (needsTempContext) { - // Must not let the temprary context be destroyed while current and - // the associated surface already gone, because some implementations - // (Mesa on drm) do not like that. - context->doneCurrent(); - } - } - } - } -#else - Q_UNUSED(api); -#endif - return elementIndexUint; -} - QQuickShapeGenericRenderer::~QQuickShapeGenericRenderer() { for (ShapePathData &d : m_sp) { @@ -338,6 +292,14 @@ void QQuickShapeGenericRenderer::endSync(bool async) pathWorkThreadPool->setMaxThreadCount(idealCount > 0 ? idealCount * 2 : 4); } #endif + auto testFeatureIndexUint = [](QQuickItem *item) -> bool { + if (auto *w = item->window()) { + if (auto *rhi = QQuickWindowPrivate::get(w)->rhi) + return rhi->isFeatureSupported(QRhi::ElementIndexUint); + } + return true; + }; + static bool supportsElementIndexUint = testFeatureIndexUint(m_item); if ((d.syncDirty & DirtyFillGeom) && d.fillColor.a) { d.path.setFillRule(d.fillRule); if (m_api == QSGRendererInterface::Unknown) @@ -350,7 +312,7 @@ void QQuickShapeGenericRenderer::endSync(bool async) d.pendingFill = r; r->path = d.path; r->fillColor = d.fillColor; - r->supportsElementIndexUint = q_supportsElementIndexUint(m_api); + r->supportsElementIndexUint = supportsElementIndexUint; // Unlikely in practice but in theory m_sp could be // resized. Therefore, capture 'i' instead of 'd'. QObject::connect(r, &QQuickShapeFillRunnable::done, qApp, [this, i](QQuickShapeFillRunnable *r) { @@ -375,7 +337,7 @@ void QQuickShapeGenericRenderer::endSync(bool async) pathWorkThreadPool->start(r); #endif } else { - triangulateFill(d.path, d.fillColor, &d.fillVertices, &d.fillIndices, &d.indexType, q_supportsElementIndexUint(m_api)); + triangulateFill(d.path, d.fillColor, &d.fillVertices, &d.fillIndices, &d.indexType, supportsElementIndexUint); } } |