aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/scenegraph')
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp6
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h1
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp1
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp4
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h10
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp6
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h12
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h3
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp1
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp3
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp8
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h4
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp54
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h15
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp18
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer.h120
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h79
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer_p_p.h (renamed from src/quick/scenegraph/util/qsgengine_p.h)42
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp49
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h8
-rw-r--r--src/quick/scenegraph/coreapi/qsggeometry.h2
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialshader.cpp8
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialshader.h2
-rw-r--r--src/quick/scenegraph/coreapi/qsgnode.cpp2
-rw-r--r--src/quick/scenegraph/coreapi/qsgnode.h1
-rw-r--r--src/quick/scenegraph/coreapi/qsgrenderer.cpp6
-rw-r--r--src/quick/scenegraph/coreapi/qsgrenderer_p.h4
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendererinterface.cpp9
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendererinterface.h1
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendernode.cpp31
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendernode.h4
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendernode_p.h6
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture.cpp108
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture.h17
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture_p.h11
-rw-r--r--src/quick/scenegraph/qsgadaptationlayer.cpp2
-rw-r--r--src/quick/scenegraph/qsgadaptationlayer_p.h9
-rw-r--r--src/quick/scenegraph/qsgcontext.cpp2
-rw-r--r--src/quick/scenegraph/qsgcontext_p.h3
-rw-r--r--src/quick/scenegraph/qsgdefaultcontext.cpp14
-rw-r--r--src/quick/scenegraph/qsgdefaultcontext_p.h3
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p.cpp13
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p.h1
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p_p.h2
-rw-r--r--src/quick/scenegraph/qsgdefaultinternalimagenode.cpp4
-rw-r--r--src/quick/scenegraph/qsgdefaultrendercontext.cpp28
-rw-r--r--src/quick/scenegraph/qsgdefaultrendercontext_p.h2
-rw-r--r--src/quick/scenegraph/qsgdefaultspritenode.cpp4
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp2
-rw-r--r--src/quick/scenegraph/qsgopengldistancefieldglyphcache.cpp21
-rw-r--r--src/quick/scenegraph/qsgopengldistancefieldglyphcache_p.h8
-rw-r--r--src/quick/scenegraph/qsgopengllayer.cpp13
-rw-r--r--src/quick/scenegraph/qsgopengllayer_p.h10
-rw-r--r--src/quick/scenegraph/qsgrenderloop.cpp42
-rw-r--r--src/quick/scenegraph/qsgrenderloop_p.h3
-rw-r--r--src/quick/scenegraph/qsgrhilayer.cpp22
-rw-r--r--src/quick/scenegraph/qsgrhilayer_p.h15
-rw-r--r--src/quick/scenegraph/qsgrhishadereffectnode.cpp20
-rw-r--r--src/quick/scenegraph/qsgrhishadereffectnode_p.h6
-rw-r--r--src/quick/scenegraph/qsgrhisupport.cpp124
-rw-r--r--src/quick/scenegraph/qsgrhisupport_p.h12
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop.cpp13
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop_p.h2
-rw-r--r--src/quick/scenegraph/qsgwindowsrenderloop.cpp551
-rw-r--r--src/quick/scenegraph/qsgwindowsrenderloop_p.h129
-rw-r--r--src/quick/scenegraph/scenegraph.pri13
-rw-r--r--src/quick/scenegraph/util/qsgdefaultimagenode_p.h7
-rw-r--r--src/quick/scenegraph/util/qsgdefaultpainternode.cpp13
-rw-r--r--src/quick/scenegraph/util/qsgdefaultpainternode_p.h13
-rw-r--r--src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp8
-rw-r--r--src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h6
-rw-r--r--src/quick/scenegraph/util/qsgengine.cpp295
-rw-r--r--src/quick/scenegraph/util/qsgengine.h91
-rw-r--r--src/quick/scenegraph/util/qsgimagenode.cpp12
-rw-r--r--src/quick/scenegraph/util/qsgimagenode.h3
-rw-r--r--src/quick/scenegraph/util/qsgopenglatlastexture.cpp27
-rw-r--r--src/quick/scenegraph/util/qsgopenglatlastexture_p.h6
-rw-r--r--src/quick/scenegraph/util/qsgplaintexture.cpp119
-rw-r--r--src/quick/scenegraph/util/qsgplaintexture_p.h9
-rw-r--r--src/quick/scenegraph/util/qsgrhiatlastexture.cpp32
-rw-r--r--src/quick/scenegraph/util/qsgrhiatlastexture_p.h20
-rw-r--r--src/quick/scenegraph/util/qsgshadersourcebuilder.cpp4
-rw-r--r--src/quick/scenegraph/util/qsgsimplematerial.cpp258
-rw-r--r--src/quick/scenegraph/util/qsgsimplematerial.h226
-rw-r--r--src/quick/scenegraph/util/qsgsimplerectnode.cpp7
-rw-r--r--src/quick/scenegraph/util/qsgsimpletexturenode.cpp7
-rw-r--r--src/quick/scenegraph/util/qsgtexturematerial.cpp6
87 files changed, 663 insertions, 2255 deletions
diff --git a/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp b/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp
index ca620965a8..49151551b1 100644
--- a/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp
@@ -77,6 +77,12 @@ QSGSoftwareRenderableNode *QSGAbstractSoftwareRenderer::renderableNode(QSGNode *
return m_nodes.value(node, nullptr);
}
+// Used by GammaRay
+const QVector<QSGSoftwareRenderableNode*> &QSGAbstractSoftwareRenderer::renderableNodes() const
+{
+ return m_renderableNodes;
+}
+
void QSGAbstractSoftwareRenderer::addNodeMapping(QSGNode *node, QSGSoftwareRenderableNode *renderableNode)
{
m_nodes.insert(node, renderableNode);
diff --git a/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h b/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h
index e1b477ab97..d4bfb5a9f7 100644
--- a/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h
+++ b/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h
@@ -87,6 +87,7 @@ protected:
QRect backgroundRect();
// only known after calling optimizeRenderList()
bool isOpaque() const { return m_isOpaque; }
+ const QVector<QSGSoftwareRenderableNode*> &renderableNodes() const;
private:
void nodeAdded(QSGNode *node);
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp
index f1d0e28fc8..91c26780b1 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp
@@ -56,6 +56,7 @@
#include <QtGui/QWindow>
#include <QtQuick/private/qquickwindow_p.h>
+#include <QtQuick/private/qquickitem_p.h>
// Used for very high-level info about the renderering and gl context
// Includes GL_VERSION, type of render loop, atlas size, etc.
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp
index 683ccb60c2..ffeb55c7ef 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp
@@ -45,7 +45,7 @@
QT_BEGIN_NAMESPACE
QSGSoftwareLayer::QSGSoftwareLayer(QSGRenderContext *renderContext)
- : QSGLayer(*(new QSGSoftwareLayerPrivate))
+ : QSGLayer(*(new QSGTexturePrivate))
, m_item(nullptr)
, m_context(renderContext)
, m_renderer(nullptr)
@@ -70,7 +70,7 @@ int QSGSoftwareLayer::textureId() const
return 0;
}
-int QSGSoftwareLayerPrivate::comparisonKey() const
+int QSGSoftwareLayer::comparisonKey() const
{
return 0;
}
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h
index 1859e14514..4961c91c1c 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h
@@ -58,11 +58,9 @@
QT_BEGIN_NAMESPACE
class QSGSoftwarePixmapRenderer;
-class QSGSoftwareLayerPrivate;
class QSGSoftwareLayer : public QSGLayer
{
- Q_DECLARE_PRIVATE(QSGSoftwareLayer)
Q_OBJECT
public:
QSGSoftwareLayer(QSGRenderContext *renderContext);
@@ -72,6 +70,7 @@ public:
// QSGTexture interface
public:
+ int comparisonKey() const override;
int textureId() const override;
QSize textureSize() const override;
bool hasAlphaChannel() const override;
@@ -120,13 +119,6 @@ private:
bool m_dirtyTexture;
};
-class QSGSoftwareLayerPrivate : public QSGTexturePrivate
-{
- Q_DECLARE_PUBLIC(QSGSoftwareLayer)
-public:
- int comparisonKey() const override;
-};
-
QT_END_NAMESPACE
#endif // QSGSOFTWARELAYER_H
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp
index 82a48d80ca..7a3be61cc0 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp
@@ -43,7 +43,6 @@
QT_BEGIN_NAMESPACE
QSGSoftwarePixmapTexture::QSGSoftwarePixmapTexture(const QImage &image, uint flags)
- : QSGTexture(*(new QSGSoftwarePixmapTexturePrivate))
{
// Prevent pixmap format conversion to reduce memory consumption
// and surprises in calling code. (See QTBUG-47328)
@@ -57,8 +56,7 @@ QSGSoftwarePixmapTexture::QSGSoftwarePixmapTexture(const QImage &image, uint fla
}
QSGSoftwarePixmapTexture::QSGSoftwarePixmapTexture(const QPixmap &pixmap)
- : QSGTexture(*(new QSGSoftwarePixmapTexturePrivate)),
- m_pixmap(pixmap)
+ : m_pixmap(pixmap)
{
}
@@ -87,7 +85,7 @@ void QSGSoftwarePixmapTexture::bind()
Q_UNREACHABLE();
}
-int QSGSoftwarePixmapTexturePrivate::comparisonKey() const
+int QSGSoftwarePixmapTexture::comparisonKey() const
{
return 0;
}
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h
index baa62d93de..dda1358124 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h
@@ -56,16 +56,15 @@
QT_BEGIN_NAMESPACE
-class QSGSoftwarePixmapTexturePrivate;
-
class QSGSoftwarePixmapTexture : public QSGTexture
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QSGSoftwarePixmapTexture)
+
public:
QSGSoftwarePixmapTexture(const QImage &image, uint flags);
QSGSoftwarePixmapTexture(const QPixmap &pixmap);
+ int comparisonKey() const override;
int textureId() const override;
QSize textureSize() const override;
bool hasAlphaChannel() const override;
@@ -78,13 +77,6 @@ private:
QPixmap m_pixmap;
};
-class QSGSoftwarePixmapTexturePrivate : public QSGTexturePrivate
-{
- Q_DECLARE_PUBLIC(QSGSoftwarePixmapTexture)
-public:
- int comparisonKey() const override;
-};
-
QT_END_NAMESPACE
#endif // QSGSOFTWAREPIXMAPTEXTURE_H
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h
index 114137fb55..470bb73f78 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes_p.h
@@ -97,6 +97,9 @@ public:
void setMipmapFiltering(QSGTexture::Filtering) override { }
QSGTexture::Filtering mipmapFiltering() const override { return QSGTexture::None; }
+ void setAnisotropyLevel(QSGTexture::AnisotropyLevel) override { }
+ QSGTexture::AnisotropyLevel anisotropyLevel() const override { return QSGTexture::AnisotropyNone; }
+
void setTextureCoordinatesTransform(TextureCoordinatesTransformMode transformNode) override;
TextureCoordinatesTransformMode textureCoordinatesTransform() const override { return m_transformMode; }
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp
index c010e0cae5..ad1f9cacf4 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp
@@ -44,6 +44,7 @@
#include <QtCore/QCoreApplication>
#include <private/qquickwindow_p.h>
+#include <private/qquickitem_p.h>
#include <QElapsedTimer>
#include <private/qquickanimatorcontroller_p.h>
#include <private/qquickprofiler_p.h>
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
index f07cc28827..7075d3e1cb 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
@@ -43,6 +43,7 @@
#include <private/qsgrenderer_p.h>
#include <private/qquickwindow_p.h>
+#include <private/qquickitem_p.h>
#include <private/qquickprofiler_p.h>
#include <private/qquickanimatorcontroller_p.h>
#include <private/qquickprofiler_p.h>
@@ -423,7 +424,7 @@ void QSGSoftwareRenderThread::sync(bool inExpose)
qCDebug(QSG_RASTER_LOG_RENDERLOOP, "RT - sync");
mutex.lock();
- Q_ASSERT_X(renderLoop->lockedForSync, "QSGD3D12RenderThread::sync()", "sync triggered with gui not locked");
+ Q_ASSERT_X(renderLoop->lockedForSync, "QSGSoftwareRenderThread::sync()", "sync triggered with gui not locked");
if (exposedWindow) {
QQuickWindowPrivate *wd = QQuickWindowPrivate::get(exposedWindow);
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
index 7c98e2c1e1..ed37305374 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
@@ -43,13 +43,13 @@
#include <QtCore/QElapsedTimer>
#include <QtCore/QtMath>
-#include <QtGui/QOpenGLContext>
+#include <QOpenGLContext>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
#include <QtGui/QSurface>
#include <QtGui/QWindow>
-#include <QtGui/QOpenGLFunctions>
-#include <QtGui/QOpenGLTexture>
+#include <QOpenGLFunctions>
+#include <QOpenGLTexture>
#include <QDebug>
#include <private/qqmlglobal_p.h>
@@ -154,7 +154,7 @@ bool Texture::hasAlphaChannel() const
return !QSGCompressedTexture::formatIsOpaque(static_cast<Atlas*>(m_atlas)->format());
}
-QSGTexture *Texture::removedFromAtlas() const
+QSGTexture *Texture::removedFromAtlas(QRhiResourceUpdateBatch *) const
{
if (m_nonatlas_texture) {
m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h
index 78051778f5..a2d6d96dfe 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h
@@ -53,7 +53,7 @@
#include <QtCore/QSize>
-#include <QtGui/qopengl.h>
+#include <qopengl.h>
#include <QtQuick/QSGTexture>
#include <QtQuick/private/qsgareaallocator_p.h>
@@ -97,7 +97,7 @@ public:
QRectF normalizedTextureSubRect() const override { return m_texture_coords_rect; }
- QSGTexture *removedFromAtlas() const override;
+ QSGTexture *removedFromAtlas(QRhiResourceUpdateBatch *) const override;
const QByteArray &data() const { return m_data; }
int sizeInBytes() const { return m_dataLength; }
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp b/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp
index 65abb2a1af..59cc967167 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp
@@ -44,6 +44,7 @@
#include <QOpenGLFunctions>
#include <QDebug>
#include <QtQuick/private/qquickwindow_p.h>
+#include <QtQuick/private/qquickitem_p.h>
#include <QtGui/private/qrhi_p.h>
QT_BEGIN_NAMESPACE
@@ -51,7 +52,7 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(QSG_LOG_TEXTUREIO, "qt.scenegraph.textureio");
QSGCompressedTexture::QSGCompressedTexture(const QTextureFileData &texData)
- : QSGTexture(*(new QSGCompressedTexturePrivate)),
+ : QSGTexture(*(new QSGTexturePrivate)),
m_textureData(texData)
{
m_size = m_textureData.size();
@@ -89,18 +90,17 @@ int QSGCompressedTexture::textureId() const
return m_textureId;
}
-int QSGCompressedTexturePrivate::comparisonKey() const
+int QSGCompressedTexture::comparisonKey() const
{
- Q_Q(const QSGCompressedTexture);
// not textureId() as that would create an id when not yet done - that's not wanted here
- if (q->m_textureId)
- return q->m_textureId;
+ if (m_textureId)
+ return m_textureId;
- if (q->m_texture)
- return int(qintptr(q->m_texture));
+ if (m_texture)
+ return int(qintptr(m_texture));
// two textures (and so materials) with not-yet-created texture underneath are never equal
- return int(qintptr(q));
+ return int(qintptr(this));
}
QSize QSGCompressedTexture::textureSize() const
@@ -271,28 +271,26 @@ static QPair<QRhiTexture::Format, bool> toRhiCompressedFormat(uint glinternalfor
}
}
-QRhiTexture *QSGCompressedTexturePrivate::rhiTexture() const
+QRhiTexture *QSGCompressedTexture::rhiTexture() const
{
- Q_Q(const QSGCompressedTexture);
- return q->m_texture;
+ return m_texture;
}
-void QSGCompressedTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+void QSGCompressedTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
{
- Q_Q(QSGCompressedTexture);
- if (q->m_uploaded)
+ if (m_uploaded)
return;
- q->m_uploaded = true; // even if fails, no point in trying again
+ m_uploaded = true; // even if fails, no point in trying again
- if (!q->m_textureData.isValid()) {
- qCDebug(QSG_LOG_TEXTUREIO, "Invalid texture data for %s", q->m_textureData.logName().constData());
+ if (!m_textureData.isValid()) {
+ qCDebug(QSG_LOG_TEXTUREIO, "Invalid texture data for %s", m_textureData.logName().constData());
return;
}
- const QPair<QRhiTexture::Format, bool> fmt = toRhiCompressedFormat(q->m_textureData.glInternalFormat());
+ const QPair<QRhiTexture::Format, bool> fmt = toRhiCompressedFormat(m_textureData.glInternalFormat());
if (fmt.first == QRhiTexture::UnknownFormat) {
- qWarning("Unknown compressed format 0x%x", q->m_textureData.glInternalFormat());
+ qWarning("Unknown compressed format 0x%x", m_textureData.glInternalFormat());
return;
}
@@ -301,25 +299,25 @@ void QSGCompressedTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdate
texFlags |= QRhiTexture::sRGB;
if (!rhi->isTextureFormatSupported(fmt.first, texFlags)) {
- qWarning("Unsupported compressed format 0x%x", q->m_textureData.glInternalFormat());
+ qWarning("Unsupported compressed format 0x%x", m_textureData.glInternalFormat());
return;
}
- if (!q->m_texture) {
- q->m_texture = rhi->newTexture(fmt.first, q->m_size, 1, texFlags);
- if (!q->m_texture->build()) {
+ if (!m_texture) {
+ m_texture = rhi->newTexture(fmt.first, m_size, 1, texFlags);
+ if (!m_texture->build()) {
qWarning("Failed to create QRhiTexture for compressed data");
- delete q->m_texture;
- q->m_texture = nullptr;
+ delete m_texture;
+ m_texture = nullptr;
return;
}
}
// only upload mip level 0 since we never do mipmapping for compressed textures (for now?)
- resourceUpdates->uploadTexture(q->m_texture, QRhiTextureUploadEntry(0, 0,
- { q->m_textureData.data().constData() + q->m_textureData.dataOffset(), q->m_textureData.dataLength() }));
+ resourceUpdates->uploadTexture(m_texture, QRhiTextureUploadEntry(0, 0,
+ { m_textureData.data().constData() + m_textureData.dataOffset(), m_textureData.dataLength() }));
- q->m_textureData = QTextureFileData(); // Release this memory, not needed anymore
+ m_textureData = QTextureFileData(); // Release this memory, not needed anymore
}
QTextureFileData QSGCompressedTexture::textureData() const
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h b/src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h
index b858d8ddee..d584f0e2d4 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h
@@ -59,11 +59,8 @@
QT_BEGIN_NAMESPACE
-class QSGCompressedTexturePrivate;
-
class Q_QUICK_PRIVATE_EXPORT QSGCompressedTexture : public QSGTexture
{
- Q_DECLARE_PRIVATE(QSGCompressedTexture)
Q_OBJECT
public:
QSGCompressedTexture(const QTextureFileData& texData);
@@ -73,8 +70,11 @@ public:
bool hasAlphaChannel() const override;
bool hasMipmaps() const override;
+ int comparisonKey() const override;
int textureId() const override;
void bind() override;
+ QRhiTexture *rhiTexture() const override;
+ void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
QTextureFileData textureData() const;
@@ -93,15 +93,6 @@ namespace QSGOpenGLAtlasTexture {
class Manager;
}
-class QSGCompressedTexturePrivate : public QSGTexturePrivate
-{
- Q_DECLARE_PUBLIC(QSGCompressedTexture)
-public:
- int comparisonKey() const override;
- QRhiTexture *rhiTexture() const override;
- void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
-};
-
class Q_QUICK_PRIVATE_EXPORT QSGCompressedTextureFactory : public QQuickTextureFactory
{
public:
diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp b/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
index 62ed342244..502ee27e27 100644
--- a/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
@@ -37,26 +37,16 @@
**
****************************************************************************/
-#include "qsgabstractrenderer_p.h"
+#include "qsgabstractrenderer_p_p.h"
QT_BEGIN_NAMESPACE
/*!
\class QSGAbstractRenderer
- \brief QSGAbstractRenderer gives access to the scene graph nodes and rendering of a QSGEngine.
+ \brief QSGAbstractRenderer gives access to the scene graph nodes and rendering.
\inmodule QtQuick
\since 5.4
-
- A QSGAbstractRenderer created by a QSGEngine allows you to set your QSGNode
- tree through setRootNode() and control the rendering viewport through
- setDeviceRect(), setViewportRect() and setProjectionMatrixToRect().
- You can finally trigger the rendering to the desired framebuffer through
- renderScene().
-
- The QSGAbstractRenderer is only available when used with a QSGEngine
- and isn't exposed when used internally by QQuickWindow.
-
- \sa QSGEngine, QSGNode
+ \internal
*/
/*!
@@ -387,5 +377,3 @@ QSGAbstractRenderer::ClearMode QSGAbstractRenderer::clearMode() const
*/
QT_END_NAMESPACE
-
-#include "moc_qsgabstractrenderer.cpp"
diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer.h b/src/quick/scenegraph/coreapi/qsgabstractrenderer.h
deleted file mode 100644
index 258a5fed14..0000000000
--- a/src/quick/scenegraph/coreapi/qsgabstractrenderer.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGABSTRACTRENDERER_H
-#define QSGABSTRACTRENDERER_H
-
-#include <QtQuick/qsgnode.h>
-
-#ifndef GLuint
-#define GLuint uint
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class QSGAbstractRendererPrivate;
-
-class Q_QUICK_EXPORT QSGAbstractRenderer : public QObject
-{
- Q_OBJECT
-public:
- enum ClearModeBit
- {
- ClearColorBuffer = 0x0001,
- ClearDepthBuffer = 0x0002,
- ClearStencilBuffer = 0x0004
- };
- Q_DECLARE_FLAGS(ClearMode, ClearModeBit)
- Q_FLAG(ClearMode)
-
- enum MatrixTransformFlag
- {
- MatrixTransformFlipY = 0x01
- };
- Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag)
- Q_FLAG(MatrixTransformFlags)
-
- ~QSGAbstractRenderer() override;
-
- // just have a warning about becoming private, ifdefing the whole class is not feasible
-#if QT_DEPRECATED_SINCE(5, 15)
- QT_DEPRECATED_X("QSGAbstractRenderer is no longer going to be public in Qt 6.0. QSGEngine-based workflows are expected to migrate to QQuickRenderControl instead.")
-#endif
- void setRootNode(QSGRootNode *node);
- QSGRootNode *rootNode() const;
- void setDeviceRect(const QRect &rect);
- inline void setDeviceRect(const QSize &size) { setDeviceRect(QRect(QPoint(), size)); }
- QRect deviceRect() const;
-
- void setViewportRect(const QRect &rect);
- inline void setViewportRect(const QSize &size) { setViewportRect(QRect(QPoint(), size)); }
- QRect viewportRect() const;
-
- void setProjectionMatrixToRect(const QRectF &rect);
- void setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags);
- void setProjectionMatrix(const QMatrix4x4 &matrix);
- void setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix);
- QMatrix4x4 projectionMatrix() const;
- QMatrix4x4 projectionMatrixWithNativeNDC() const;
-
- void setClearColor(const QColor &color);
- QColor clearColor() const;
-
- void setClearMode(ClearMode mode);
- ClearMode clearMode() const;
-
- virtual void renderScene(GLuint fboId = 0) = 0;
-
-Q_SIGNALS:
- void sceneGraphChanged();
-
-protected:
- explicit QSGAbstractRenderer(QObject *parent = nullptr);
- virtual void nodeChanged(QSGNode *node, QSGNode::DirtyState state) = 0;
-
-private:
- Q_DECLARE_PRIVATE(QSGAbstractRenderer)
- friend class QSGRootNode;
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QSGAbstractRenderer::ClearMode)
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h b/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
index bbc4289b2c..5d48f18310 100644
--- a/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
@@ -51,37 +51,78 @@
// We mean it.
//
-#include "qsgabstractrenderer.h"
-
-#include "qsgnode.h"
-#include <qcolor.h>
-
-#include <QtCore/private/qobject_p.h>
#include <QtQuick/private/qtquickglobal_p.h>
+#include <QtQuick/qsgnode.h>
+
+#ifndef GLuint
+#define GLuint uint
+#endif
QT_BEGIN_NAMESPACE
-class Q_QUICK_PRIVATE_EXPORT QSGAbstractRendererPrivate : public QObjectPrivate
+class QSGAbstractRendererPrivate;
+
+class Q_QUICK_PRIVATE_EXPORT QSGAbstractRenderer : public QObject
{
- Q_DECLARE_PUBLIC(QSGAbstractRenderer)
+ Q_OBJECT
public:
- static const QSGAbstractRendererPrivate *get(const QSGAbstractRenderer *q) { return q->d_func(); }
+ enum ClearModeBit
+ {
+ ClearColorBuffer = 0x0001,
+ ClearDepthBuffer = 0x0002,
+ ClearStencilBuffer = 0x0004
+ };
+ Q_DECLARE_FLAGS(ClearMode, ClearModeBit)
+ Q_FLAG(ClearMode)
+
+ enum MatrixTransformFlag
+ {
+ MatrixTransformFlipY = 0x01
+ };
+ Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag)
+ Q_FLAG(MatrixTransformFlags)
+
+ ~QSGAbstractRenderer() override;
- QSGAbstractRendererPrivate();
- void updateProjectionMatrix();
+ void setRootNode(QSGRootNode *node);
+ QSGRootNode *rootNode() const;
+ void setDeviceRect(const QRect &rect);
+ inline void setDeviceRect(const QSize &size) { setDeviceRect(QRect(QPoint(), size)); }
+ QRect deviceRect() const;
- QSGRootNode *m_root_node;
- QColor m_clear_color;
- QSGAbstractRenderer::ClearMode m_clear_mode;
+ void setViewportRect(const QRect &rect);
+ inline void setViewportRect(const QSize &size) { setViewportRect(QRect(QPoint(), size)); }
+ QRect viewportRect() const;
- QRect m_device_rect;
- QRect m_viewport_rect;
+ void setProjectionMatrixToRect(const QRectF &rect);
+ void setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags);
+ void setProjectionMatrix(const QMatrix4x4 &matrix);
+ void setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix);
+ QMatrix4x4 projectionMatrix() const;
+ QMatrix4x4 projectionMatrixWithNativeNDC() const;
- QMatrix4x4 m_projection_matrix;
- QMatrix4x4 m_projection_matrix_native_ndc;
- uint m_mirrored : 1;
+ void setClearColor(const QColor &color);
+ QColor clearColor() const;
+
+ void setClearMode(ClearMode mode);
+ ClearMode clearMode() const;
+
+ virtual void renderScene(GLuint fboId = 0) = 0;
+
+Q_SIGNALS:
+ void sceneGraphChanged();
+
+protected:
+ explicit QSGAbstractRenderer(QObject *parent = nullptr);
+ virtual void nodeChanged(QSGNode *node, QSGNode::DirtyState state) = 0;
+
+private:
+ Q_DECLARE_PRIVATE(QSGAbstractRenderer)
+ friend class QSGRootNode;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QSGAbstractRenderer::ClearMode)
+
QT_END_NAMESPACE
#endif
diff --git a/src/quick/scenegraph/util/qsgengine_p.h b/src/quick/scenegraph/coreapi/qsgabstractrenderer_p_p.h
index 662c32d3d9..42e9acb437 100644
--- a/src/quick/scenegraph/util/qsgengine_p.h
+++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer_p_p.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QSGENGINE_P_H
-#define QSGENGINE_P_H
+#ifndef QSGABSTRACTRENDERER_P_P_H
+#define QSGABSTRACTRENDERER_P_P_H
//
// W A R N I N G
@@ -51,27 +51,37 @@
// We mean it.
//
-#include "qsgengine.h"
-#include <private/qobject_p.h>
+#include "qsgabstractrenderer_p.h"
-QT_BEGIN_NAMESPACE
+#include "qsgnode.h"
+#include <qcolor.h>
+
+#include <QtCore/private/qobject_p.h>
+#include <QtQuick/private/qtquickglobal_p.h>
-class QSGContext;
-class QSGRenderContext;
+QT_BEGIN_NAMESPACE
-#if QT_DEPRECATED_SINCE(5, 15)
-class QSGEnginePrivate : public QObjectPrivate
+class Q_QUICK_PRIVATE_EXPORT QSGAbstractRendererPrivate : public QObjectPrivate
{
- Q_DECLARE_PUBLIC(QSGEngine)
+ Q_DECLARE_PUBLIC(QSGAbstractRenderer)
public:
- static QSGEnginePrivate *get(QSGEngine *engine) { return engine->d_func(); }
- QSGEnginePrivate();
+ static const QSGAbstractRendererPrivate *get(const QSGAbstractRenderer *q) { return q->d_func(); }
+
+ QSGAbstractRendererPrivate();
+ void updateProjectionMatrix();
- QScopedPointer<QSGContext> sgContext;
- QScopedPointer<QSGRenderContext> sgRenderContext;
+ QSGRootNode *m_root_node;
+ QColor m_clear_color;
+ QSGAbstractRenderer::ClearMode m_clear_mode;
+
+ QRect m_device_rect;
+ QRect m_viewport_rect;
+
+ QMatrix4x4 m_projection_matrix;
+ QMatrix4x4 m_projection_matrix_native_ndc;
+ uint m_mirrored : 1;
};
-#endif
QT_END_NAMESPACE
-#endif // QSGENGINE_P_H
+#endif
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
index ce3c4aac4f..ed790fdc5c 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
@@ -50,10 +50,11 @@
#include <QtCore/QtNumeric>
#include <QtGui/QGuiApplication>
-#include <QtGui/QOpenGLFramebufferObject>
-#include <QtGui/QOpenGLVertexArrayObject>
-#include <QtGui/QOpenGLFunctions_1_0>
-#include <QtGui/QOpenGLFunctions_3_2_Core>
+#include <QOpenGLFramebufferObject>
+#include <QOpenGLVertexArrayObject>
+#include <QOpenGLFunctions_1_0>
+#include <QOpenGLFunctions_3_2_Core>
+#include <QOpenGLVersionFunctionsFactory>
#include <private/qnumeric_p.h>
#include <private/qquickprofiler_p.h>
@@ -138,6 +139,7 @@ struct QMatrix4x4_Accessor
static bool isScale(const QMatrix4x4 &m) { return ((const QMatrix4x4_Accessor &) m).flagBits <= 0x2; }
static bool is2DSafe(const QMatrix4x4 &m) { return ((const QMatrix4x4_Accessor &) m).flagBits < 0x8; }
};
+Q_STATIC_ASSERT(sizeof(QMatrix4x4_Accessor) == sizeof(QMatrix4x4));
const float OPAQUE_LIMIT = 0.999f;
@@ -480,8 +482,6 @@ Updater::Updater(Renderer *r)
m_roots.add(0);
m_combined_matrix_stack.add(&m_identityMatrix);
m_rootMatrices.add(m_identityMatrix);
-
- Q_ASSERT(sizeof(QMatrix4x4_Accessor) == sizeof(QMatrix4x4));
}
void Updater::updateStates(QSGNode *n)
@@ -2964,16 +2964,16 @@ void Renderer::updateLineWidth(QSGGeometry *g) // legacy (GL-only)
{
if (g->drawingMode() == GL_LINE_STRIP || g->drawingMode() == GL_LINE_LOOP || g->drawingMode() == GL_LINES)
glLineWidth(g->lineWidth());
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
else {
QOpenGLContext *ctx = m_context->openglContext();
if (!ctx->isOpenGLES() && g->drawingMode() == GL_POINTS) {
QOpenGLFunctions_1_0 *gl1funcs = nullptr;
QOpenGLFunctions_3_2_Core *gl3funcs = nullptr;
if (ctx->format().profile() == QSurfaceFormat::CoreProfile)
- gl3funcs = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>();
+ gl3funcs = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_2_Core>(ctx);
else
- gl1funcs = ctx->versionFunctions<QOpenGLFunctions_1_0>();
+ gl1funcs = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_1_0>(ctx);
Q_ASSERT(gl1funcs || gl3funcs);
if (gl1funcs)
gl1funcs->glPointSize(g->lineWidth());
@@ -3499,7 +3499,7 @@ void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms,
}
if (pd->textureBindingTable[binding] && pd->samplerBindingTable[binding]) {
- QRhiTexture *texture = QSGTexturePrivate::get(pd->textureBindingTable[binding])->rhiTexture();
+ QRhiTexture *texture = pd->textureBindingTable[binding]->rhiTexture();
// texture may be null if the update above failed for any reason,
// or if the QSGTexture chose to return null intentionally. This is
// valid and we still need to provide something to the shader.
@@ -4117,6 +4117,8 @@ void Renderer::renderBatches()
if (m_renderPassRecordingCallbacks.start)
m_renderPassRecordingCallbacks.start(m_renderPassRecordingCallbacks.userData);
+ cb->debugMarkBegin(QByteArrayLiteral("Qt Quick scene render"));
+
for (int i = 0, ie = opaqueRenderBatches.count(); i != ie; ++i) {
PreparedRenderBatch *renderBatch = &opaqueRenderBatches[i];
if (renderBatch->batch->merged)
@@ -4138,6 +4140,8 @@ void Renderer::renderBatches()
if (m_currentShader)
setActiveRhiShader(nullptr, nullptr);
+ cb->debugMarkEnd();
+
if (m_renderPassRecordingCallbacks.end)
m_renderPassRecordingCallbacks.end(m_renderPassRecordingCallbacks.userData);
@@ -4534,8 +4538,7 @@ bool Renderer::prepareRhiRenderNode(Batch *batch, PreparedRenderBatch *renderBat
opacity = opacity->parent();
}
- if (rd->m_prepareCallback)
- rd->m_prepareCallback();
+ e->renderNode->prepare();
renderBatch->batch = batch;
renderBatch->sms = nullptr;
@@ -4568,7 +4571,7 @@ void Renderer::renderRhiRenderNode(const Batch *batch) // split prepare-render (
const QSGRenderNode::StateFlags changes = e->renderNode->changedStates();
QRhiCommandBuffer *cb = commandBuffer();
- const bool needsExternal = rd->m_needsExternalRendering;
+ const bool needsExternal = !e->renderNode->flags().testFlag(QSGRenderNode::NoExternalRendering);
if (needsExternal)
cb->beginExternal();
e->renderNode->render(&state);
@@ -4612,6 +4615,22 @@ bool Renderer::hasCustomRenderModeWithContinuousUpdate() const
return m_visualizer->mode() == Visualizer::VisualizeOverdraw;
}
+void Renderer::invalidatePipelineCacheDependency(QRhiRenderPassDescriptor *rpDesc)
+{
+ if (!rpDesc)
+ return;
+
+ for (auto it = m_shaderManager->pipelineCache.begin(); it != m_shaderManager->pipelineCache.end(); ) {
+ if (it.key().compatibleRenderPassDescriptor == rpDesc) {
+ QRhiGraphicsPipeline *ps = it.value();
+ it = m_shaderManager->pipelineCache.erase(it);
+ ps->releaseAndDestroyLater(); // QRhi takes care of it in endFrame()
+ } else {
+ ++it;
+ }
+ }
+}
+
bool operator==(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW
{
return a.depthTest == b.depthTest
@@ -4634,7 +4653,7 @@ bool operator!=(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW
return !(a == b);
}
-uint qHash(const GraphicsState &s, uint seed) Q_DECL_NOTHROW
+size_t qHash(const GraphicsState &s, uint seed) Q_DECL_NOTHROW
{
// do not bother with all fields
return seed
@@ -4662,7 +4681,7 @@ bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKe
return !(a == b);
}
-uint qHash(const GraphicsPipelineStateKey &k, uint seed) Q_DECL_NOTHROW
+size_t qHash(const GraphicsPipelineStateKey &k, uint seed) Q_DECL_NOTHROW
{
// no srb and rp included due to their special comparison semantics and lack of hash keys
return qHash(k.state, seed) + qHash(k.sms->programRhi.program, seed);
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
index 878b63fc8c..3db93bee41 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
@@ -62,7 +62,7 @@
#include <QtCore/QBitArray>
#include <QtCore/QStack>
-#include <QtGui/QOpenGLFunctions>
+#include <QOpenGLFunctions>
#include <QtGui/private/qrhi_p.h>
@@ -645,7 +645,7 @@ struct GraphicsState
bool operator==(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW;
bool operator!=(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW;
-uint qHash(const GraphicsState &s, uint seed = 0) Q_DECL_NOTHROW;
+size_t qHash(const GraphicsState &s, uint seed = 0) Q_DECL_NOTHROW;
struct ShaderManagerShader;
@@ -659,7 +659,7 @@ struct GraphicsPipelineStateKey
bool operator==(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) Q_DECL_NOTHROW;
bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) Q_DECL_NOTHROW;
-uint qHash(const GraphicsPipelineStateKey &k, uint seed = 0) Q_DECL_NOTHROW;
+size_t qHash(const GraphicsPipelineStateKey &k, uint seed = 0) Q_DECL_NOTHROW;
struct ShaderManagerShader
{
@@ -847,6 +847,8 @@ private:
void setCustomRenderMode(const QByteArray &mode) override;
bool hasCustomRenderModeWithContinuousUpdate() const override;
+ void invalidatePipelineCacheDependency(QRhiRenderPassDescriptor *rpDesc) override;
+
QSGDefaultRenderContext *m_context;
QSet<Node *> m_taggedRoots;
QDataBuffer<Element *> m_opaqueRenderList;
diff --git a/src/quick/scenegraph/coreapi/qsggeometry.h b/src/quick/scenegraph/coreapi/qsggeometry.h
index d17915a842..9c60876597 100644
--- a/src/quick/scenegraph/coreapi/qsggeometry.h
+++ b/src/quick/scenegraph/coreapi/qsggeometry.h
@@ -41,7 +41,7 @@
#define QSGGEOMETRY_H
#include <QtQuick/qtquickglobal.h>
-#include <QtGui/qopengl.h>
+#include <qopengl.h>
#include <QtCore/QRectF>
QT_BEGIN_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp
index d614f9be4c..64956e2ca4 100644
--- a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp
+++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp
@@ -44,8 +44,8 @@
# include <private/qsgshadersourcebuilder_p.h>
# include <private/qsgdefaultcontext_p.h>
# include <private/qsgdefaultrendercontext_p.h>
-# include <QtGui/QOpenGLFunctions>
-# include <QtGui/QOpenGLContext>
+# include <QOpenGLFunctions>
+# include <QOpenGLContext>
#endif
QT_BEGIN_NAMESPACE
@@ -69,10 +69,6 @@ const char *QSGMaterialShaderPrivate::loadShaderSource(QOpenGLShader::ShaderType
\inmodule QtQuick
\ingroup qtquick-scenegraph-materials
- The QSGMaterialShader API is relatively low-level. A more convenient API,
- which provides almost all the same features, is available through
- QSGSimpleMaterialShader.
-
\warning This class is only functional when running with the legacy OpenGL
renderer of the Qt Quick scenegraph.
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.h b/src/quick/scenegraph/coreapi/qsgmaterialshader.h
index d7ee23384f..6783b3f890 100644
--- a/src/quick/scenegraph/coreapi/qsgmaterialshader.h
+++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.h
@@ -42,7 +42,7 @@
#include <QtQuick/qtquickglobal.h>
#if QT_CONFIG(opengl)
-# include <QtGui/qopenglshaderprogram.h>
+# include <qopenglshaderprogram.h>
#endif
#include <QtGui/QMatrix4x4>
#include <QtCore/QRect>
diff --git a/src/quick/scenegraph/coreapi/qsgnode.cpp b/src/quick/scenegraph/coreapi/qsgnode.cpp
index a35629d874..e22ffa10d2 100644
--- a/src/quick/scenegraph/coreapi/qsgnode.cpp
+++ b/src/quick/scenegraph/coreapi/qsgnode.cpp
@@ -850,7 +850,7 @@ void QSGBasicGeometryNode::setGeometry(QSGGeometry *geometry)
\note All classes with QSG prefix should be used solely on the scene graph's
rendering thread. See \l {Scene Graph and Rendering} for more information.
- \sa QSGGeometry, QSGMaterial, QSGSimpleMaterial
+ \sa QSGGeometry, QSGMaterial
*/
diff --git a/src/quick/scenegraph/coreapi/qsgnode.h b/src/quick/scenegraph/coreapi/qsgnode.h
index 5a7faed5e0..19b8cf9354 100644
--- a/src/quick/scenegraph/coreapi/qsgnode.h
+++ b/src/quick/scenegraph/coreapi/qsgnode.h
@@ -177,7 +177,6 @@ private:
int m_subtreeRenderableCount = 0;
Flags m_nodeFlags;
- DirtyState m_dirtyState; // Obsolete, remove in Qt 6
protected:
friend class QSGNodePrivate;
diff --git a/src/quick/scenegraph/coreapi/qsgrenderer.cpp b/src/quick/scenegraph/coreapi/qsgrenderer.cpp
index 90090e1cc0..cd16014d41 100644
--- a/src/quick/scenegraph/coreapi/qsgrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrenderer.cpp
@@ -40,9 +40,9 @@
#include "qsgrenderer_p.h"
#include "qsgnodeupdater_p.h"
#if QT_CONFIG(opengl)
-# include <QtGui/QOpenGLFramebufferObject>
-# include <QtGui/QOpenGLContext>
-# include <QtGui/QOpenGLFunctions>
+# include <QOpenGLFramebufferObject>
+# include <QOpenGLContext>
+# include <QOpenGLFunctions>
#endif
#include <private/qquickprofiler_p.h>
#include <qtquick_tracepoints_p.h>
diff --git a/src/quick/scenegraph/coreapi/qsgrenderer_p.h b/src/quick/scenegraph/coreapi/qsgrenderer_p.h
index c4ed0072f6..3f2154e3c1 100644
--- a/src/quick/scenegraph/coreapi/qsgrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgrenderer_p.h
@@ -51,8 +51,7 @@
// We mean it.
//
-#include "qsgabstractrenderer.h"
-#include "qsgabstractrenderer_p.h"
+#include "qsgabstractrenderer_p_p.h"
#include "qsgnode.h"
#include "qsgmaterial.h"
@@ -99,6 +98,7 @@ public:
virtual void setCustomRenderMode(const QByteArray &) { }
virtual bool hasCustomRenderModeWithContinuousUpdate() const { return false; }
virtual void releaseCachedResources() { }
+ virtual void invalidatePipelineCacheDependency(QRhiRenderPassDescriptor *) { }
void clearChangedFlag() { m_changed_emitted = false; }
diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
index 0fee1486cf..9b5701df5a 100644
--- a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
@@ -76,7 +76,6 @@ QT_BEGIN_NAMESPACE
\value Unknown An unknown graphics API is in use
\value Software The Qt Quick 2D Renderer is in use
\value OpenGL OpenGL ES 2.0 or higher
- \value Direct3D12 Direct3D 12
\value OpenVG OpenVG via EGL
\value OpenGLRhi OpenGL ES 2.0 or higher via a graphics abstraction layer. This value was introduced in Qt 5.14.
\value Direct3D11Rhi Direct3D 11 via a graphics abstraction layer. This value was introduced in Qt 5.14.
@@ -189,10 +188,10 @@ QSGRendererInterface::~QSGRendererInterface()
not supported or not available.
When successful, the returned pointer is either a direct pointer to an
- interface (and can be cast, for example, to \c{ID3D12Device *}) or a
- pointer to an opaque handle that needs to be dereferenced first (for
- example, \c{VkDevice dev = *static_cast<VkDevice *>(result)}). The latter
- is necessary since such handles may have sizes different from a pointer.
+ interface, or a pointer to an opaque handle that needs to be dereferenced
+ first (for example, \c{VkDevice dev = *static_cast<VkDevice
+ *>(result)}). The latter is necessary since such handles may have sizes
+ different from a pointer.
\note The ownership of the returned pointer is never transferred to the caller.
diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.h b/src/quick/scenegraph/coreapi/qsgrendererinterface.h
index 7aa7d0e769..6224e08e84 100644
--- a/src/quick/scenegraph/coreapi/qsgrendererinterface.h
+++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.h
@@ -53,7 +53,6 @@ public:
Unknown,
Software,
OpenGL,
- Direct3D12,
OpenVG,
OpenGLRhi,
Direct3D11Rhi,
diff --git a/src/quick/scenegraph/coreapi/qsgrendernode.cpp b/src/quick/scenegraph/coreapi/qsgrendernode.cpp
index 45ad49475f..ec8e3dda57 100644
--- a/src/quick/scenegraph/coreapi/qsgrendernode.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrendernode.cpp
@@ -77,8 +77,6 @@ QSGRenderNodePrivate::QSGRenderNodePrivate()
: m_matrix(nullptr)
, m_clip_list(nullptr)
, m_opacity(1)
- , m_needsExternalRendering(true)
- , m_prepareCallback(nullptr)
{
}
@@ -101,8 +99,8 @@ QSGRenderNodePrivate::QSGRenderNodePrivate()
With APIs other than OpenGL, the only relevant values are the ones that
correspond to dynamic state changes recorded on the command list/buffer.
- For example, RSSetViewports, RSSetScissorRects, OMSetBlendFactor,
- OMSetStencilRef in case of D3D12, or vkCmdSetViewport, vkCmdSetScissor,
+ For example, RSSetViewports, RSSetScissorRects, OMSetBlendState,
+ OMSetDepthStencilState in case of D3D11, or vkCmdSetViewport, vkCmdSetScissor,
vkCmdSetBlendConstants, vkCmdSetStencilRef in case of Vulkan, and only when
such commands were added to the scenegraph's command list queried via the
QSGRendererInterface::CommandList resource enum. States set in pipeline
@@ -137,6 +135,24 @@ QSGRenderNode::StateFlags QSGRenderNode::changedStates() const
}
/*!
+ Called from the frame preparation phase. There is a call to this function
+ before each invocation of render().
+
+ Unlike render(), this function is called before the scenegraph starts
+ recording the render pass for the current frame on the underlying command
+ buffer. This is useful when doing rendering with graphics APIs, such as
+ Vulkan, where copy type of operations will need to be recorded before the
+ render pass.
+
+ The default implementation is empty.
+
+ \since 6.0
+ */
+void QSGRenderNode::prepare()
+{
+}
+
+/*!
\fn void QSGRenderNode::render(const RenderState *state)
This function is called by the renderer and should paint this node with
@@ -301,6 +317,8 @@ void QSGRenderNode::releaseResources()
transparent pixels. Setting this flag can improve performance in some
cases.
+ \omitvalue NoExternalRendering
+
\sa render(), rect()
*/
@@ -383,11 +401,6 @@ QSGRenderNode::RenderState::~RenderState()
\return the current scissor rectangle when clipping is active. x and y are
the bottom left coordinates.
-
- \note Be aware of the differences between graphics APIs: for some the
- scissor rect is only active when scissoring is enabled (for example,
- OpenGL), while for others the scissor rect is equal to the viewport rect
- when there is no need to scissor away anything (for example, Direct3D 12).
*/
/*!
diff --git a/src/quick/scenegraph/coreapi/qsgrendernode.h b/src/quick/scenegraph/coreapi/qsgrendernode.h
index 0fb83b080c..2a5a5ce106 100644
--- a/src/quick/scenegraph/coreapi/qsgrendernode.h
+++ b/src/quick/scenegraph/coreapi/qsgrendernode.h
@@ -64,7 +64,8 @@ public:
enum RenderingFlag {
BoundedRectRendering = 0x01,
DepthAwareRendering = 0x02,
- OpaqueRendering = 0x04
+ OpaqueRendering = 0x04,
+ NoExternalRendering = 0x08
};
Q_DECLARE_FLAGS(RenderingFlags, RenderingFlag)
@@ -83,6 +84,7 @@ public:
~QSGRenderNode() override;
virtual StateFlags changedStates() const;
+ virtual void prepare();
virtual void render(const RenderState *state) = 0;
virtual void releaseResources();
virtual RenderingFlags flags() const;
diff --git a/src/quick/scenegraph/coreapi/qsgrendernode_p.h b/src/quick/scenegraph/coreapi/qsgrendernode_p.h
index 534d630f15..ca38f344ef 100644
--- a/src/quick/scenegraph/coreapi/qsgrendernode_p.h
+++ b/src/quick/scenegraph/coreapi/qsgrendernode_p.h
@@ -54,7 +54,6 @@
#include <QtQuick/private/qtquickglobal_p.h>
#include <QtQuick/qsgnode.h>
#include <QtQuick/qsgrendernode.h>
-#include <functional>
QT_BEGIN_NAMESPACE
@@ -68,11 +67,6 @@ public:
const QMatrix4x4 *m_matrix;
const QSGClipNode *m_clip_list;
qreal m_opacity;
-
- // ### Qt 6: change this into a value for flags()
- bool m_needsExternalRendering;
- // ### Qt 6: change this into a virtual prepare() function
- std::function<void()> m_prepareCallback;
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgtexture.cpp b/src/quick/scenegraph/coreapi/qsgtexture.cpp
index 418aaca605..25e02d8058 100644
--- a/src/quick/scenegraph/coreapi/qsgtexture.cpp
+++ b/src/quick/scenegraph/coreapi/qsgtexture.cpp
@@ -39,8 +39,8 @@
#include "qsgtexture_p.h"
#if QT_CONFIG(opengl)
-# include <QtGui/qopenglcontext.h>
-# include <QtGui/qopenglfunctions.h>
+# include <qopenglcontext.h>
+# include <qopenglfunctions.h>
#endif
#include <private/qqmlglobal_p.h>
#include <private/qsgmaterialshader_p.h>
@@ -83,7 +83,7 @@ bool operator!=(const QSGSamplerDescription &a, const QSGSamplerDescription &b)
return !(a == b);
}
-uint qHash(const QSGSamplerDescription &s, uint seed) Q_DECL_NOTHROW
+size_t qHash(const QSGSamplerDescription &s, uint seed) Q_DECL_NOTHROW
{
const int f = s.filtering;
const int m = s.mipmapFiltering;
@@ -453,11 +453,19 @@ QSGTexture::~QSGTexture()
Implementations of this function are recommended to return the same instance
for multiple calls to limit memory usage.
+ \a resourceUpdates is an optional resource update batch, on which texture
+ operations, if any, are enqueued. Materials can retrieve an instance from
+ QSGMaterialRhiShader::RenderState. When null, the removedFromAtlas()
+ implementation creates its own batch and submit it right away. However,
+ when a valid instance is specified, this function will not submit the
+ update batch.
+
\warning This function can only be called from the rendering thread.
*/
-QSGTexture *QSGTexture::removedFromAtlas() const
+QSGTexture *QSGTexture::removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates) const
{
+ Q_UNUSED(resourceUpdates);
Q_ASSERT_X(!isAtlasTexture(), "QSGTexture::removedFromAtlas()", "Called on a non-atlas texture");
return nullptr;
}
@@ -485,6 +493,8 @@ bool QSGTexture::isAtlasTexture() const
*/
/*!
+ \fn int QSGTexture::comparisonKey() const
+
Returns a key suitable for comparing textures. Typically used in
QSGMaterial::compare() implementations.
@@ -506,11 +516,6 @@ bool QSGTexture::isAtlasTexture() const
\since 5.14
*/
-int QSGTexture::comparisonKey() const
-{
- Q_D(const QSGTexture);
- return d->comparisonKey();
-}
/*!
\fn QSize QSGTexture::textureSize() const
@@ -727,6 +732,32 @@ void QSGTexture::updateBindOptions(bool force) // legacy (GL-only)
}
/*!
+ \return the QRhiTexture for this QSGTexture or null if there is none (either
+ because a valid texture has not been created internally yet, or because the
+ concept is not applicable to the scenegraph backend in use).
+
+ This function is not expected to create a new QRhiTexture in case there is
+ none. Just return null in that case. The expectation towards the renderer
+ is that a null texture leads to using a transparent, dummy texture instead.
+
+ \warning This function can only be called from the rendering thread.
+
+ \since 6.0
+ */
+QRhiTexture *QSGTexture::rhiTexture() const
+{
+ return nullptr;
+}
+
+QRhiTexture *QSGTexturePrivate::rhiTexture() const
+{
+ // Just calls the public API, this private function exists for internal
+ // source compatibility only until all Qt modules migrate away from it.
+ Q_Q(const QSGTexture);
+ return q->rhiTexture();
+}
+
+/*!
Call this function to enqueue image upload operations to \a
resourceUpdates, in case there are any pending ones. When there is no new
data (for example, because there was no setImage() since the last call to
@@ -735,17 +766,14 @@ void QSGTexture::updateBindOptions(bool force) // legacy (GL-only)
Materials involving \a rhi textures are expected to call this function from
their updateSampledImage() implementation, typically without any conditions.
- \note This function is only used when running the graphics API independent
- rendering path of the scene graph.
-
\warning This function can only be called from the rendering thread.
- \since 5.14
+ \since 6.0
*/
-void QSGTexture::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+void QSGTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
{
- Q_D(QSGTexture);
- d->updateRhiTexture(rhi, resourceUpdates);
+ Q_UNUSED(rhi);
+ Q_UNUSED(resourceUpdates);
}
/*!
@@ -762,23 +790,13 @@ void QSGTexture::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUp
*/
QSGTexture::NativeTexture QSGTexture::nativeTexture() const
{
- Q_D(const QSGTexture);
- if (auto *tex = d->rhiTexture()) {
+ if (auto *tex = rhiTexture()) {
auto nativeTexture = tex->nativeTexture();
return {nativeTexture.object, nativeTexture.layout};
}
return {};
}
-/*!
- \internal
- */
-void QSGTexture::setWorkResourceUpdateBatch(QRhiResourceUpdateBatch *resourceUpdates)
-{
- Q_D(QSGTexture);
- d->workResourceUpdateBatch = resourceUpdates;
-}
-
bool QSGTexturePrivate::hasDirtySamplerOptions() const
{
return wrapChanged || filteringChanged || anisotropyChanged;
@@ -789,42 +807,6 @@ void QSGTexturePrivate::resetDirtySamplerOptions()
wrapChanged = filteringChanged = anisotropyChanged = false;
}
-int QSGTexturePrivate::comparisonKey() const
-{
- // Must be overridden in subclasses but we cannot make this pure virtual
- // before Qt 6 because the simple QSGTexture ctor must be kept working.
- Q_Q(const QSGTexture);
- return q->textureId(); // this is semantically wrong but at least compatible with existing, non-RHI-aware subclasses
-}
-
-/*!
- \internal
-
- \return the QRhiTexture for this QSGTexture or null if there is none.
-
- Unlike textureId(), this function is not expected to create a new
- QRhiTexture in case there is none. Just return null in that case. The
- expectation towards the renderer is that a null texture leads to using a
- transparent, dummy texture instead.
-
- \note This function is only used when running the graphics API independent
- rendering path of the scene graph.
-
- \warning This function can only be called from the rendering thread.
-
- \since 5.14
- */
-QRhiTexture *QSGTexturePrivate::rhiTexture() const
-{
- return nullptr;
-}
-
-void QSGTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
-{
- Q_UNUSED(rhi);
- Q_UNUSED(resourceUpdates);
-}
-
/*!
\class QSGDynamicTexture
\brief The QSGDynamicTexture class serves as a baseclass for dynamically changing textures,
diff --git a/src/quick/scenegraph/coreapi/qsgtexture.h b/src/quick/scenegraph/coreapi/qsgtexture.h
index 207ef52f4e..b0f01b1933 100644
--- a/src/quick/scenegraph/coreapi/qsgtexture.h
+++ b/src/quick/scenegraph/coreapi/qsgtexture.h
@@ -85,7 +85,9 @@ public:
int layout;
};
+ virtual int comparisonKey() const = 0;
virtual int textureId() const = 0; // ### Qt 6: remove
+ virtual QRhiTexture *rhiTexture() const;
NativeTexture nativeTexture() const;
virtual QSize textureSize() const = 0;
virtual bool hasAlphaChannel() const = 0;
@@ -95,10 +97,12 @@ public:
virtual bool isAtlasTexture() const;
- virtual QSGTexture *removedFromAtlas() const;
+ virtual QSGTexture *removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates = nullptr) const;
- virtual void bind() = 0;
- void updateBindOptions(bool force = false);
+ virtual void bind() = 0; // ### Qt 6: remove
+ void updateBindOptions(bool force = false); // ### Qt 6: remove
+
+ virtual void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
void setMipmapFiltering(Filtering filter);
QSGTexture::Filtering mipmapFiltering() const;
@@ -117,13 +121,6 @@ public:
inline QRectF convertToNormalizedSourceRect(const QRectF &rect) const;
- // ### Qt 6: make these virtual
- int comparisonKey() const;
- void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
-
- // ### Qt 6: make this an argument for removedFromAtlas()
- void setWorkResourceUpdateBatch(QRhiResourceUpdateBatch *resourceUpdates);
-
protected:
QSGTexture(QSGTexturePrivate &dd);
};
diff --git a/src/quick/scenegraph/coreapi/qsgtexture_p.h b/src/quick/scenegraph/coreapi/qsgtexture_p.h
index cb59d32012..e24088229c 100644
--- a/src/quick/scenegraph/coreapi/qsgtexture_p.h
+++ b/src/quick/scenegraph/coreapi/qsgtexture_p.h
@@ -72,7 +72,7 @@ Q_DECLARE_TYPEINFO(QSGSamplerDescription, Q_MOVABLE_TYPE);
bool operator==(const QSGSamplerDescription &a, const QSGSamplerDescription &b) Q_DECL_NOTHROW;
bool operator!=(const QSGSamplerDescription &a, const QSGSamplerDescription &b) Q_DECL_NOTHROW;
-uint qHash(const QSGSamplerDescription &s, uint seed = 0) Q_DECL_NOTHROW;
+size_t qHash(const QSGSamplerDescription &s, uint seed = 0) Q_DECL_NOTHROW;
class Q_QUICK_PRIVATE_EXPORT QSGTexturePrivate : public QObjectPrivate
{
@@ -82,14 +82,7 @@ public:
static QSGTexturePrivate *get(QSGTexture *t) { return t->d_func(); }
void resetDirtySamplerOptions();
bool hasDirtySamplerOptions() const;
-
- virtual QRhiTexture *rhiTexture() const;
-
- // ### Qt 6: these should be virtuals in the public class instead
- virtual int comparisonKey() const; // ### Qt 6: pure virtual
- virtual void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
-
- QRhiResourceUpdateBatch *workResourceUpdateBatch = nullptr; // ### Qt 6: remove
+ QRhiTexture *rhiTexture() const;
uint wrapChanged : 1;
uint filteringChanged : 1;
diff --git a/src/quick/scenegraph/qsgadaptationlayer.cpp b/src/quick/scenegraph/qsgadaptationlayer.cpp
index eab0369be7..e0d9d5db68 100644
--- a/src/quick/scenegraph/qsgadaptationlayer.cpp
+++ b/src/quick/scenegraph/qsgadaptationlayer.cpp
@@ -329,7 +329,7 @@ void QSGDistanceFieldGlyphCache::updateRhiTexture(QRhiTexture *oldTex, QRhiTextu
}
#if defined(QSG_DISTANCEFIELD_CACHE_DEBUG)
-#include <QtGui/qopenglfunctions.h>
+#include <qopenglfunctions.h>
void QSGDistanceFieldGlyphCache::saveTexture(GLuint textureId, int width, int height) const
{
diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h
index 1db49feb5d..6376317427 100644
--- a/src/quick/scenegraph/qsgadaptationlayer_p.h
+++ b/src/quick/scenegraph/qsgadaptationlayer_p.h
@@ -299,7 +299,6 @@ public:
Q_SIGNALS:
void shaderCodePrepared(bool ok, ShaderInfo::Type typeHint, const QByteArray &src, ShaderInfo *result);
- void textureChanged();
void logAndStatusChanged();
};
@@ -307,8 +306,10 @@ Q_SIGNALS:
Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug debug, const QSGGuiThreadShaderEffectManager::ShaderInfo::Variable &v);
#endif
-class Q_QUICK_PRIVATE_EXPORT QSGShaderEffectNode : public QSGVisitableNode
+class Q_QUICK_PRIVATE_EXPORT QSGShaderEffectNode : public QObject, public QSGVisitableNode
{
+ Q_OBJECT
+
public:
enum DirtyShaderFlag {
DirtyShaders = 0x01,
@@ -355,12 +356,14 @@ public:
};
// Each ShaderEffect item has one node (render thread) and one manager (gui thread).
- QSGShaderEffectNode(QSGGuiThreadShaderEffectManager *) { }
virtual QRectF updateNormalizedTextureSubRect(bool supportsAtlasTextures) = 0;
virtual void syncMaterial(SyncData *syncData) = 0;
void accept(QSGNodeVisitorEx *visitor) override { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
+
+Q_SIGNALS:
+ void textureChanged();
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QSGShaderEffectNode::DirtyShaderFlags)
diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp
index e3c951e5ed..9baf530889 100644
--- a/src/quick/scenegraph/qsgcontext.cpp
+++ b/src/quick/scenegraph/qsgcontext.cpp
@@ -284,7 +284,7 @@ QSGGuiThreadShaderEffectManager *QSGContext::createGuiThreadShaderEffectManager(
valid as long as the backend does not claim SupportsShaderEffectNode or
ignoring ShaderEffect elements is acceptable.
*/
-QSGShaderEffectNode *QSGContext::createShaderEffectNode(QSGRenderContext *, QSGGuiThreadShaderEffectManager *)
+QSGShaderEffectNode *QSGContext::createShaderEffectNode(QSGRenderContext *)
{
return nullptr;
}
diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h
index d389420907..a2cb21a60c 100644
--- a/src/quick/scenegraph/qsgcontext_p.h
+++ b/src/quick/scenegraph/qsgcontext_p.h
@@ -128,8 +128,7 @@ public:
virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) = 0;
virtual QSGLayer *createLayer(QSGRenderContext *renderContext) = 0;
virtual QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager();
- virtual QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext,
- QSGGuiThreadShaderEffectManager *mgr);
+ virtual QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext);
#if QT_CONFIG(quick_sprite)
virtual QSGSpriteNode *createSpriteNode() = 0;
#endif
diff --git a/src/quick/scenegraph/qsgdefaultcontext.cpp b/src/quick/scenegraph/qsgdefaultcontext.cpp
index ea01b0a3b4..f7701d8f7f 100644
--- a/src/quick/scenegraph/qsgdefaultcontext.cpp
+++ b/src/quick/scenegraph/qsgdefaultcontext.cpp
@@ -57,10 +57,11 @@
#endif
#include <QtQuick/private/qsgrhishadereffectnode_p.h>
-#include <QtGui/QOpenGLContext>
-#include <QtGui/QOpenGLFramebufferObject>
+#include <QOpenGLContext>
+#include <QOpenGLFramebufferObject>
#include <QtQuick/private/qquickwindow_p.h>
+#include <QtQuick/private/qquickitem_p.h>
#include <private/qqmlglobal_p.h>
@@ -296,13 +297,10 @@ QSGGuiThreadShaderEffectManager *QSGDefaultContext::createGuiThreadShaderEffectM
return nullptr;
}
-QSGShaderEffectNode *QSGDefaultContext::createShaderEffectNode(QSGRenderContext *renderContext,
- QSGGuiThreadShaderEffectManager *mgr)
+QSGShaderEffectNode *QSGDefaultContext::createShaderEffectNode(QSGRenderContext *renderContext)
{
- if (QSGRhiSupport::instance()->isRhiEnabled()) {
- return new QSGRhiShaderEffectNode(static_cast<QSGDefaultRenderContext *>(renderContext),
- static_cast<QSGRhiGuiThreadShaderEffectManager *>(mgr));
- }
+ if (QSGRhiSupport::instance()->isRhiEnabled())
+ return new QSGRhiShaderEffectNode(static_cast<QSGDefaultRenderContext *>(renderContext));
return nullptr;
}
diff --git a/src/quick/scenegraph/qsgdefaultcontext_p.h b/src/quick/scenegraph/qsgdefaultcontext_p.h
index 8fdd29caee..414a4151f1 100644
--- a/src/quick/scenegraph/qsgdefaultcontext_p.h
+++ b/src/quick/scenegraph/qsgdefaultcontext_p.h
@@ -80,8 +80,7 @@ public:
QSGSpriteNode *createSpriteNode() override;
#endif
QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager() override;
- QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext,
- QSGGuiThreadShaderEffectManager *mgr) override;
+ QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext) override;
void setDistanceFieldEnabled(bool enabled);
bool isDistanceFieldEnabled() const;
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
index be6ef25feb..f73b64f537 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
@@ -451,8 +451,8 @@ bool QSGTextMaskRhiShader::updateUniformData(RenderState &state,
changed = true;
}
- QRhiTexture *oldRtex = oldMat ? QSGTexturePrivate::get(oldMat->texture())->rhiTexture() : nullptr;
- QRhiTexture *newRtex = QSGTexturePrivate::get(mat->texture())->rhiTexture();
+ QRhiTexture *oldRtex = oldMat ? oldMat->texture()->rhiTexture() : nullptr;
+ QRhiTexture *newRtex = mat->texture()->rhiTexture();
if (updated || !oldMat || oldRtex != newRtex) {
const QVector2D textureScale = QVector2D(1.0f / mat->rhiGlyphCache()->width(),
1.0f / mat->rhiGlyphCache()->height());
@@ -789,11 +789,12 @@ void QSGTextMaskMaterial::populate(const QPointF &p,
const QMargins &margins)
{
Q_ASSERT(m_font.isValid());
+ QPointF position(p.x(), p.y() - m_font.ascent());
QVector<QFixedPoint> fixedPointPositions;
const int glyphPositionsSize = glyphPositions.size();
fixedPointPositions.reserve(glyphPositionsSize);
for (int i=0; i < glyphPositionsSize; ++i)
- fixedPointPositions.append(QFixedPoint::fromPointF(glyphPositions.at(i)));
+ fixedPointPositions.append(QFixedPoint::fromPointF(position + glyphPositions.at(i)));
QTextureGlyphCache *cache = glyphCache();
@@ -815,18 +816,16 @@ void QSGTextMaskMaterial::populate(const QPointF &p,
Q_ASSERT(geometry->sizeOfVertex() == sizeof(QVector4D));
ushort *ip = geometry->indexDataAsUShort();
- QPointF position(p.x(), p.y() - m_font.ascent());
bool supportsSubPixelPositions = fontD->fontEngine->supportsSubPixelPositions();
for (int i=0; i<glyphIndexes.size(); ++i) {
+ QPointF glyphPosition = glyphPositions.at(i) + position;
QFixed subPixelPosition;
if (supportsSubPixelPositions)
- subPixelPosition = fontD->fontEngine->subPixelPositionForX(QFixed::fromReal(glyphPositions.at(i).x()));
+ subPixelPosition = fontD->fontEngine->subPixelPositionForX(QFixed::fromReal(glyphPosition.x()));
QTextureGlyphCache::GlyphAndSubPixelPosition glyph(glyphIndexes.at(i), subPixelPosition);
const QTextureGlyphCache::Coord &c = cache->coords.value(glyph);
- QPointF glyphPosition = glyphPositions.at(i) + position;
-
// On a retina screen the glyph positions are not pre-scaled (as opposed to
// eg. the raster paint engine). To ensure that we get the same behavior as
// the raster engine (and CoreText itself) when it comes to rounding of the
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.h b/src/quick/scenegraph/qsgdefaultglyphnode_p.h
index 4cff2d3d24..f70d51d1ee 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p.h
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.h
@@ -53,7 +53,6 @@
#include <private/qsgadaptationlayer_p.h>
#include <private/qsgbasicglyphnode_p.h>
-#include <qlinkedlist.h>
QT_BEGIN_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
index 7d2635794d..4ddef9af24 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
@@ -52,7 +52,7 @@
//
#include <qcolor.h>
-#include <QtGui/private/qopengltextureglyphcache_p.h>
+#include <private/qopengltextureglyphcache_p.h>
#include <QtQuick/qsgmaterial.h>
#include <QtQuick/qsgtexture.h>
#include <QtQuick/qsggeometry.h>
diff --git a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp
index 500d4e6e95..e609bea439 100644
--- a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp
+++ b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp
@@ -41,7 +41,7 @@
#include <private/qsgdefaultrendercontext_p.h>
#include <private/qsgmaterialshader_p.h>
#include <private/qsgtexturematerial_p.h>
-#include <QtGui/qopenglfunctions.h>
+#include <qopenglfunctions.h>
#include <QtCore/qmath.h>
#include <QtGui/private/qrhi_p.h>
@@ -254,7 +254,7 @@ bool QSGDefaultInternalImageNode::supportsWrap(const QSize &size) const
|| (isPowerOfTwo(size.width()) && isPowerOfTwo(size.height()));
} else {
QOpenGLContext *ctx = QOpenGLContext::currentContext();
-#ifndef QT_OPENGL_ES_2
+#if !QT_CONFIG(opengles2)
if (ctx->isOpenGLES())
#endif
{
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext.cpp b/src/quick/scenegraph/qsgdefaultrendercontext.cpp
index 1d18caa0b4..a5d352b7f1 100644
--- a/src/quick/scenegraph/qsgdefaultrendercontext.cpp
+++ b/src/quick/scenegraph/qsgdefaultrendercontext.cpp
@@ -40,7 +40,7 @@
#include "qsgdefaultrendercontext_p.h"
#include <QtGui/QGuiApplication>
-#include <QtGui/QOpenGLFramebufferObject>
+#include <QOpenGLFramebufferObject>
#include <QtQuick/private/qsgbatchrenderer_p.h>
#include <QtQuick/private/qsgrenderer_p.h>
@@ -69,6 +69,7 @@ QSGDefaultRenderContext::QSGDefaultRenderContext(QSGContext *context)
, m_rhiAtlasManager(nullptr)
, m_currentFrameCommandBuffer(nullptr)
, m_currentFrameRenderPass(nullptr)
+ , m_separateIndexBuffer(false)
{
}
@@ -92,6 +93,8 @@ void QSGDefaultRenderContext::initialize(const QSGRenderContext::InitParams *par
m_maxTextureSize = m_rhi->resourceLimit(QRhi::TextureSizeMax);
if (!m_rhiAtlasManager)
m_rhiAtlasManager = new QSGRhiAtlasTexture::Manager(this, m_initParams.initialSurfacePixelSize, m_initParams.maybeSurface);
+ // unlike OpenGL (and like WebGL), QRhi does not guarantee buffer usage types can be mixed
+ m_separateIndexBuffer = true;
} else {
QOpenGLFunctions *funcs = m_rhi ? nullptr : QOpenGLContext::currentContext()->functions();
funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize);
@@ -124,6 +127,15 @@ void QSGDefaultRenderContext::initialize(const QSGRenderContext::InitParams *par
if (!m_glAtlasManager)
m_glAtlasManager = new QSGOpenGLAtlasTexture::Manager(m_initParams.initialSurfacePixelSize);
+
+ // WebGL: A given WebGLBuffer object may only be bound to one of
+ // the ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target in its
+ // lifetime. An attempt to bind a buffer object to the other
+ // target will generate an INVALID_OPERATION error, and the
+ // current binding will remain untouched.
+ const bool isWebGL = (qGuiApp->platformName().compare(QLatin1String("webgl")) == 0
+ || qGuiApp->platformName().compare(QLatin1String("wasm")) == 0);
+ m_separateIndexBuffer = isWebGL;
}
m_sg->renderContextInitialized(this);
@@ -377,7 +389,7 @@ QString QSGDefaultRenderContext::fontKey(const QRawFont &font)
{
QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine;
if (!fe->faceId().filename.isEmpty()) {
- QByteArray keyName = fe->faceId().filename;
+ QByteArray keyName = fe->faceId().filename + ' ' + QByteArray::number(fe->faceId().index);
if (font.style() != QFont::StyleNormal)
keyName += QByteArray(" I");
if (font.weight() != QFont::Normal)
@@ -417,17 +429,7 @@ QSGDefaultRenderContext *QSGDefaultRenderContext::from(QOpenGLContext *context)
bool QSGDefaultRenderContext::separateIndexBuffer() const
{
- if (m_rhi)
- return true;
-
- // WebGL: A given WebGLBuffer object may only be bound to one of
- // the ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target in its
- // lifetime. An attempt to bind a buffer object to the other
- // target will generate an INVALID_OPERATION error, and the
- // current binding will remain untouched.
- static const bool isWebGL = (qGuiApp->platformName().compare(QLatin1String("webgl")) == 0
- || qGuiApp->platformName().compare(QLatin1String("wasm")) == 0);
- return isWebGL;
+ return m_separateIndexBuffer;
}
QSGDistanceFieldGlyphCache *QSGDefaultRenderContext::distanceFieldGlyphCache(const QRawFont &font)
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext_p.h b/src/quick/scenegraph/qsgdefaultrendercontext_p.h
index 97ed681f9a..be83f5a9f5 100644
--- a/src/quick/scenegraph/qsgdefaultrendercontext_p.h
+++ b/src/quick/scenegraph/qsgdefaultrendercontext_p.h
@@ -69,6 +69,7 @@ class QSGMaterialRhiShader;
class QOpenGLFramebufferObject;
class QSGDepthStencilBufferManager;
class QSGDepthStencilBuffer;
+class QSurface;
namespace QSGOpenGLAtlasTexture {
class Manager;
@@ -179,6 +180,7 @@ protected:
QRhiCommandBuffer *m_currentFrameCommandBuffer;
QRhiRenderPassDescriptor *m_currentFrameRenderPass;
qreal m_currentDevicePixelRatio;
+ bool m_separateIndexBuffer;
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdefaultspritenode.cpp b/src/quick/scenegraph/qsgdefaultspritenode.cpp
index 6422a252d9..b179838576 100644
--- a/src/quick/scenegraph/qsgdefaultspritenode.cpp
+++ b/src/quick/scenegraph/qsgdefaultspritenode.cpp
@@ -40,7 +40,7 @@
#include "qsgdefaultspritenode_p.h"
#include <QtQuick/QSGMaterial>
-#include <QtGui/QOpenGLShaderProgram>
+#include <QOpenGLShaderProgram>
QT_BEGIN_NAMESPACE
@@ -199,7 +199,7 @@ void SpriteMaterialRhiShader::updateSampledImage(RenderState &state, int binding
QQuickSpriteMaterial *mat = static_cast<QQuickSpriteMaterial *>(newMaterial);
QSGTexture *t = mat->texture;
- t->updateRhiTexture(state.rhi(), state.resourceUpdateBatch());
+ t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
*texture = t;
}
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
index e8e9f76d04..a25daa6070 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
@@ -39,7 +39,7 @@
#include "qsgdistancefieldglyphnode_p_p.h"
#include "qsgrhidistancefieldglyphcache_p.h"
-#include <QtGui/qopenglfunctions.h>
+#include <qopenglfunctions.h>
#include <QtGui/qsurface.h>
#include <QtGui/qwindow.h>
#include <qmath.h>
diff --git a/src/quick/scenegraph/qsgopengldistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgopengldistancefieldglyphcache.cpp
index b6b6f3b057..04dd6d64ad 100644
--- a/src/quick/scenegraph/qsgopengldistancefieldglyphcache.cpp
+++ b/src/quick/scenegraph/qsgopengldistancefieldglyphcache.cpp
@@ -45,16 +45,17 @@
#include <QtQml/qqmlfile.h>
#include <QtGui/private/qdistancefield_p.h>
-#include <QtGui/private/qopenglcontext_p.h>
+#include <private/qopenglcontext_p.h>
#include <QtQml/private/qqmlglobal_p.h>
#include <qopenglfunctions.h>
+#include <qopenglversionfunctionsfactory.h>
#include <qopenglframebufferobject.h>
#include <qmath.h>
#include "qsgcontext_p.h"
-#if !defined(QT_OPENGL_ES_2)
-#include <QtGui/qopenglfunctions_3_2_core.h>
+#if !QT_CONFIG(opengles2)
+#include <qopenglfunctions_3_2_core.h>
#endif
QT_BEGIN_NAMESPACE
@@ -77,7 +78,7 @@ QSGOpenGLDistanceFieldGlyphCache::QSGOpenGLDistanceFieldGlyphCache(QOpenGLContex
, m_blitBuffer(QOpenGLBuffer::VertexBuffer)
, m_fboGuard(nullptr)
, m_funcs(c->functions())
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
, m_coreFuncs(nullptr)
#endif
{
@@ -222,7 +223,7 @@ void QSGOpenGLDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField> &
}
}
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
const GLenum format = isCoreProfile() ? GL_RED : GL_ALPHA;
#else
const GLenum format = GL_ALPHA;
@@ -291,7 +292,7 @@ void QSGOpenGLDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
if (!QOpenGLContext::currentContext()->isOpenGLES())
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
const GLint internalFormat = isCoreProfile() ? GL_R8 : GL_ALPHA;
@@ -337,13 +338,13 @@ void QSGOpenGLDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int w
updateTexture(oldTexture, texInfo->texture, texInfo->size);
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
if (isCoreProfile() && !useTextureResizeWorkaround()) {
// For an OpenGL Core Profile we can use http://www.opengl.org/wiki/Framebuffer#Blitting
// to efficiently copy the contents of the old texture to the new texture
// TODO: Use ARB_copy_image if available of if we have >=4.3 context
if (!m_coreFuncs) {
- m_coreFuncs = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>();
+ m_coreFuncs = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_2_Core>(ctx);
Q_ASSERT(m_coreFuncs);
m_coreFuncs->initializeOpenGLFunctions();
}
@@ -388,7 +389,7 @@ void QSGOpenGLDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int w
m_funcs->glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
m_funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
const GLenum format = isCoreProfile() ? GL_RED : GL_ALPHA;
#else
const GLenum format = GL_ALPHA;
@@ -434,7 +435,7 @@ void QSGOpenGLDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int w
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
if (!ctx->isOpenGLES())
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
#endif
diff --git a/src/quick/scenegraph/qsgopengldistancefieldglyphcache_p.h b/src/quick/scenegraph/qsgopengldistancefieldglyphcache_p.h
index 66d1b52f86..b095fc94a0 100644
--- a/src/quick/scenegraph/qsgopengldistancefieldglyphcache_p.h
+++ b/src/quick/scenegraph/qsgopengldistancefieldglyphcache_p.h
@@ -52,17 +52,17 @@
//
#include "qsgadaptationlayer_p.h"
-#include <QtGui/qopenglfunctions.h>
+#include <qopenglfunctions.h>
#include <qopenglshaderprogram.h>
#include <qopenglbuffer.h>
#include <qopenglvertexarrayobject.h>
-#include <QtGui/private/qopenglengineshadersource_p.h>
+#include <private/qopenglengineshadersource_p.h>
#include <private/qsgareaallocator_p.h>
QT_BEGIN_NAMESPACE
class QOpenGLSharedResourceGuard;
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
class QOpenGLFunctions_3_2_Core;
#endif
@@ -154,7 +154,7 @@ private:
QOpenGLSharedResourceGuard *m_fboGuard;
QOpenGLFunctions *m_funcs;
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
QOpenGLFunctions_3_2_Core *m_coreFuncs;
#endif
};
diff --git a/src/quick/scenegraph/qsgopengllayer.cpp b/src/quick/scenegraph/qsgopengllayer.cpp
index ae5032231d..c585cd05f8 100644
--- a/src/quick/scenegraph/qsgopengllayer.cpp
+++ b/src/quick/scenegraph/qsgopengllayer.cpp
@@ -42,9 +42,9 @@
#include <private/qsgrenderer_p.h>
#include <private/qsgdefaultrendercontext_p.h>
-#include <QtGui/QOpenGLFramebufferObject>
-#include <QtGui/QOpenGLFunctions>
-#include <QtGui/private/qopenglextensions_p.h>
+#include <QOpenGLFramebufferObject>
+#include <QOpenGLFunctions>
+#include <private/qopenglextensions_p.h>
#include <QtQuick/private/qsgdepthstencilbuffer_p.h>
@@ -89,7 +89,7 @@ namespace
}
QSGOpenGLLayer::QSGOpenGLLayer(QSGRenderContext *context)
- : QSGLayer(*(new QSGOpenGLLayerPrivate))
+ : QSGLayer(*(new QSGTexturePrivate))
, m_item(nullptr)
, m_device_pixel_ratio(1)
, m_format(GL_RGBA)
@@ -141,10 +141,9 @@ int QSGOpenGLLayer::textureId() const
return m_fbo ? m_fbo->texture() : 0;
}
-int QSGOpenGLLayerPrivate::comparisonKey() const
+int QSGOpenGLLayer::comparisonKey() const
{
- Q_Q(const QSGOpenGLLayer);
- return q->m_fbo ? q->m_fbo->texture() : 0;
+ return m_fbo ? m_fbo->texture() : 0;
}
bool QSGOpenGLLayer::hasAlphaChannel() const
diff --git a/src/quick/scenegraph/qsgopengllayer_p.h b/src/quick/scenegraph/qsgopengllayer_p.h
index c6246843e2..e54571e311 100644
--- a/src/quick/scenegraph/qsgopengllayer_p.h
+++ b/src/quick/scenegraph/qsgopengllayer_p.h
@@ -62,11 +62,9 @@ QT_BEGIN_NAMESPACE
class QOpenGLFramebufferObject;
class QSGDepthStencilBuffer;
class QSGDefaultRenderContext;
-class QSGOpenGLLayerPrivate;
class Q_QUICK_PRIVATE_EXPORT QSGOpenGLLayer : public QSGLayer
{
- Q_DECLARE_PRIVATE(QSGOpenGLLayer)
Q_OBJECT
public:
QSGOpenGLLayer(QSGRenderContext *context);
@@ -92,6 +90,7 @@ public:
bool hasMipmaps() const override;
int textureId() const override;
QSize textureSize() const override { return m_size; }
+ int comparisonKey() const override;
GLenum format() const { return m_format; }
void setFormat(GLenum format) override;
@@ -157,13 +156,6 @@ private:
uint m_mirrorVertical : 1;
};
-class QSGOpenGLLayerPrivate : public QSGTexturePrivate
-{
- Q_DECLARE_PUBLIC(QSGOpenGLLayer)
-public:
- int comparisonKey() const override;
-};
-
QT_END_NAMESPACE
#endif // QSGOPENGLLAYER_P_H
diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp
index 94f15b55d4..aa956fda9e 100644
--- a/src/quick/scenegraph/qsgrenderloop.cpp
+++ b/src/quick/scenegraph/qsgrenderloop.cpp
@@ -39,7 +39,6 @@
#include "qsgrenderloop_p.h"
#include "qsgthreadedrenderloop_p.h"
-#include "qsgwindowsrenderloop_p.h"
#include "qsgrhisupport_p.h"
#include <private/qquickanimatorcontroller_p.h>
@@ -57,6 +56,7 @@
#include <QtQuick/QQuickWindow>
#include <QtQuick/private/qquickwindow_p.h>
+#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qsgcontext_p.h>
#include <QtQuick/private/qsgrenderer_p.h>
#include <private/qquickprofiler_p.h>
@@ -65,7 +65,7 @@
#include <private/qsgrhishadereffectnode_p.h>
#if QT_CONFIG(opengl)
-#include <QtGui/QOpenGLContext>
+#include <QOpenGLContext>
#if QT_CONFIG(quick_shadereffect)
#include <private/qquickopenglshadereffectnode_p.h>
#endif
@@ -125,7 +125,7 @@ void QSGRenderLoop::cleanup()
s_instance = nullptr;
#ifdef ENABLE_DEFAULT_BACKEND
- QSGRhiSupport::instance()->cleanup();
+ QSGRhiSupport::cleanupVulkanInstance();
QSGRhiProfileConnection::instance()->cleanup();
#endif
}
@@ -237,13 +237,10 @@ QSGRenderLoop *QSGRenderLoop::instance()
} else {
loopType = BasicRenderLoop;
#ifdef Q_OS_WIN
- // With desktop OpenGL (opengl32.dll), use threaded. Otherwise (ANGLE) use windows.
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL
&& QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL))
{
loopType = ThreadedRenderLoop;
- } else {
- loopType = WindowsRenderLoop;
}
#else
if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL))
@@ -270,10 +267,6 @@ QSGRenderLoop *QSGRenderLoop::instance()
default:
break;
}
-
- // no 'windows' because that's not yet ported to the rhi
- if (loopType == WindowsRenderLoop)
- loopType = BasicRenderLoop;
}
// The environment variables can always override. This is good
@@ -287,12 +280,14 @@ QSGRenderLoop *QSGRenderLoop::instance()
if (Q_UNLIKELY(qEnvironmentVariableIsSet("QSG_RENDER_LOOP"))) {
const QByteArray loopName = qgetenv("QSG_RENDER_LOOP");
- if (loopName == "windows")
- loopType = WindowsRenderLoop;
- else if (loopName == "basic")
+ if (loopName == "windows") {
+ qWarning("The 'windows' render loop is no longer supported. Using 'basic' instead.");
+ loopType = BasicRenderLoop;
+ } else if (loopName == "basic") {
loopType = BasicRenderLoop;
- else if (loopName == "threaded")
+ } else if (loopName == "threaded") {
loopType = ThreadedRenderLoop;
+ }
}
switch (loopType) {
@@ -302,12 +297,8 @@ QSGRenderLoop *QSGRenderLoop::instance()
s_instance = new QSGThreadedRenderLoop();
break;
#endif
- case WindowsRenderLoop:
- qCDebug(QSG_LOG_INFO, "windows render loop");
- s_instance = new QSGWindowsRenderLoop();
- break;
default:
- qCDebug(QSG_LOG_INFO, "QSG: basic render loop");
+ qCDebug(QSG_LOG_INFO, "basic render loop");
s_instance = new QSGGuiThreadRenderLoop();
break;
}
@@ -473,6 +464,15 @@ void QSGGuiThreadRenderLoop::handleDeviceLoss()
void QSGGuiThreadRenderLoop::releaseSwapchain(QQuickWindow *window)
{
QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window);
+
+ // Unlike the threaded render loop, this one reuses the same rendercontext
+ // for all QQuickWindows for the entire lifetime of the render loop.
+ // Therefore the renderer, if there is one, needs to be notified about the
+ // destruction of certain resources because they may be referenced from
+ // per-rendercontext data structures.
+ if (wd->renderer)
+ wd->renderer->invalidatePipelineCacheDependency(wd->rpDescForSwapchain);
+
delete wd->rpDescForSwapchain;
wd->rpDescForSwapchain = nullptr;
delete wd->swapchain;
@@ -703,6 +703,8 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
emit window->afterAnimating();
+ emit window->beforeFrameBegin();
+
// Begin the frame before syncing -> sync is where we may invoke
// updatePaintNode() on the items and they may want to do resource updates.
// Also relevant for applications that connect to the before/afterSynchronizing
@@ -798,6 +800,8 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
if (needsPresent)
cd->fireFrameSwapped();
+ emit window->afterFrameEnd();
+
qint64 swapTime = 0;
if (profileFrames)
swapTime = renderTimer.nsecsElapsed();
diff --git a/src/quick/scenegraph/qsgrenderloop_p.h b/src/quick/scenegraph/qsgrenderloop_p.h
index 9fd0ab02f5..e9357f2061 100644
--- a/src/quick/scenegraph/qsgrenderloop_p.h
+++ b/src/quick/scenegraph/qsgrenderloop_p.h
@@ -126,8 +126,7 @@ private:
enum QSGRenderLoopType
{
BasicRenderLoop,
- ThreadedRenderLoop,
- WindowsRenderLoop
+ ThreadedRenderLoop
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgrhilayer.cpp b/src/quick/scenegraph/qsgrhilayer.cpp
index 952279a3ff..003ffaf5ea 100644
--- a/src/quick/scenegraph/qsgrhilayer.cpp
+++ b/src/quick/scenegraph/qsgrhilayer.cpp
@@ -44,7 +44,7 @@
#include <private/qsgdefaultrendercontext_p.h>
QSGRhiLayer::QSGRhiLayer(QSGRenderContext *context)
- : QSGLayer(*(new QSGRhiLayerPrivate))
+ : QSGLayer(*(new QSGTexturePrivate))
, m_mipmap(false)
, m_live(true)
, m_recursive(false)
@@ -72,10 +72,9 @@ void QSGRhiLayer::invalidated()
m_renderer = nullptr;
}
-int QSGRhiLayerPrivate::comparisonKey() const
+int QSGRhiLayer::comparisonKey() const
{
- Q_Q(const QSGRhiLayer);
- return int(qintptr(q->m_texture));
+ return int(qintptr(m_texture));
}
bool QSGRhiLayer::hasAlphaChannel() const
@@ -99,13 +98,12 @@ void QSGRhiLayer::bind()
Q_ASSERT_X(false, "QSGRhiLayer::bind()", "Not implemented for RHI");
}
-QRhiTexture *QSGRhiLayerPrivate::rhiTexture() const
+QRhiTexture *QSGRhiLayer::rhiTexture() const
{
- Q_Q(const QSGRhiLayer);
- return q->m_texture;
+ return m_texture;
}
-void QSGRhiLayerPrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+void QSGRhiLayer::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
{
Q_UNUSED(rhi);
Q_UNUSED(resourceUpdates);
@@ -227,8 +225,12 @@ void QSGRhiLayer::releaseResources()
delete m_rt;
m_rt = nullptr;
- delete m_rtRp;
- m_rtRp = nullptr;
+ if (m_rtRp) {
+ if (m_renderer)
+ m_renderer->invalidatePipelineCacheDependency(m_rtRp);
+ delete m_rtRp;
+ m_rtRp = nullptr;
+ }
delete m_ds;
m_ds = nullptr;
diff --git a/src/quick/scenegraph/qsgrhilayer_p.h b/src/quick/scenegraph/qsgrhilayer_p.h
index 6c4953ce17..ba0567c737 100644
--- a/src/quick/scenegraph/qsgrhilayer_p.h
+++ b/src/quick/scenegraph/qsgrhilayer_p.h
@@ -58,12 +58,11 @@
QT_BEGIN_NAMESPACE
class QSGDefaultRenderContext;
-class QSGRhiLayerPrivate;
class Q_QUICK_PRIVATE_EXPORT QSGRhiLayer : public QSGLayer
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QSGRhiLayer)
+
public:
QSGRhiLayer(QSGRenderContext *context);
~QSGRhiLayer();
@@ -76,6 +75,9 @@ public:
void bind() override;
int textureId() const override;
+ int comparisonKey() const override;
+ QRhiTexture *rhiTexture() const override;
+ void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
void setItem(QSGNode *item) override;
void setRect(const QRectF &rect) override;
@@ -129,15 +131,6 @@ private:
uint m_mirrorVertical : 1;
};
-class QSGRhiLayerPrivate : public QSGTexturePrivate
-{
- Q_DECLARE_PUBLIC(QSGRhiLayer)
-public:
- int comparisonKey() const override;
- QRhiTexture *rhiTexture() const override;
- void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
-};
-
QT_END_NAMESPACE
#endif // QSGRHILAYER_P_H
diff --git a/src/quick/scenegraph/qsgrhishadereffectnode.cpp b/src/quick/scenegraph/qsgrhishadereffectnode.cpp
index e86dae7c09..5d3b158de8 100644
--- a/src/quick/scenegraph/qsgrhishadereffectnode.cpp
+++ b/src/quick/scenegraph/qsgrhishadereffectnode.cpp
@@ -185,9 +185,9 @@ struct QSGRhiShaderMaterialTypeCache
QHash<Key, QSGMaterialType *> m_types;
};
-uint qHash(const QSGRhiShaderMaterialTypeCache::Key &key, uint seed = 0)
+size_t qHash(const QSGRhiShaderMaterialTypeCache::Key &key, uint seed = 0)
{
- uint hash = seed;
+ size_t hash = seed;
for (int i = 0; i < 2; ++i)
hash = hash * 31337 + qHash(key.blob[i]);
return hash;
@@ -393,7 +393,7 @@ void QSGRhiShaderEffectMaterialShader::updateSampledImage(RenderState &state, in
QSGTextureProvider *tp = mat->m_textureProviders.at(binding);
if (tp) {
if (QSGTexture *t = tp->texture()) {
- t->updateRhiTexture(state.rhi(), state.resourceUpdateBatch());
+ t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
if (t->isAtlasTexture() && !mat->m_geometryUsesTextureSubRect) {
// Why the hassle with the batch: while removedFromAtlas() is
// able to operate with its own resource update batch (which is
@@ -402,9 +402,7 @@ void QSGRhiShaderEffectMaterialShader::updateSampledImage(RenderState &state, in
// committed operations to state.resourceUpdateBatch()... The
// only safe way then is to use the same batch the atlas'
// updateRhiTexture() used.
- t->setWorkResourceUpdateBatch(state.resourceUpdateBatch());
- QSGTexture *newTexture = t->removedFromAtlas();
- t->setWorkResourceUpdateBatch(nullptr);
+ QSGTexture *newTexture = t->removedFromAtlas(state.resourceUpdateBatch());
if (newTexture)
t = newTexture;
}
@@ -421,7 +419,7 @@ void QSGRhiShaderEffectMaterialShader::updateSampledImage(RenderState &state, in
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
img.fill(0);
mat->m_dummyTexture->setImage(img);
- mat->m_dummyTexture->updateRhiTexture(state.rhi(), state.resourceUpdateBatch());
+ mat->m_dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
}
*texture = mat->m_dummyTexture;
}
@@ -570,10 +568,8 @@ void QSGRhiShaderEffectMaterial::updateTextureProviders(bool layoutChange)
}
}
-QSGRhiShaderEffectNode::QSGRhiShaderEffectNode(QSGDefaultRenderContext *rc, QSGRhiGuiThreadShaderEffectManager *mgr)
- : QSGShaderEffectNode(mgr),
- m_rc(rc),
- m_mgr(mgr),
+QSGRhiShaderEffectNode::QSGRhiShaderEffectNode(QSGDefaultRenderContext *rc)
+ : m_rc(rc),
m_material(this)
{
setFlag(UsePreprocess, true);
@@ -751,7 +747,7 @@ void QSGRhiShaderEffectNode::syncMaterial(SyncData *syncData)
void QSGRhiShaderEffectNode::handleTextureChange()
{
markDirty(QSGNode::DirtyMaterial);
- emit m_mgr->textureChanged();
+ emit textureChanged();
}
void QSGRhiShaderEffectNode::handleTextureProviderDestroyed(QObject *object)
diff --git a/src/quick/scenegraph/qsgrhishadereffectnode_p.h b/src/quick/scenegraph/qsgrhishadereffectnode_p.h
index 26460d24b2..fb98bbf10e 100644
--- a/src/quick/scenegraph/qsgrhishadereffectnode_p.h
+++ b/src/quick/scenegraph/qsgrhishadereffectnode_p.h
@@ -59,7 +59,6 @@ QT_BEGIN_NAMESPACE
class QSGDefaultRenderContext;
class QSGPlainTexture;
class QSGRhiShaderEffectNode;
-class QSGRhiGuiThreadShaderEffectManager;
class QFileSelector;
class QSGRhiShaderLinker
@@ -121,12 +120,12 @@ public:
QSGPlainTexture *m_dummyTexture = nullptr;
};
-class QSGRhiShaderEffectNode : public QObject, public QSGShaderEffectNode
+class QSGRhiShaderEffectNode : public QSGShaderEffectNode
{
Q_OBJECT
public:
- QSGRhiShaderEffectNode(QSGDefaultRenderContext *rc, QSGRhiGuiThreadShaderEffectManager *mgr);
+ QSGRhiShaderEffectNode(QSGDefaultRenderContext *rc);
QRectF updateNormalizedTextureSubRect(bool supportsAtlasTextures) override;
void syncMaterial(SyncData *syncData) override;
@@ -140,7 +139,6 @@ private Q_SLOTS:
private:
QSGDefaultRenderContext *m_rc;
- QSGRhiGuiThreadShaderEffectManager *m_mgr;
QSGRhiShaderEffectMaterial m_material;
};
diff --git a/src/quick/scenegraph/qsgrhisupport.cpp b/src/quick/scenegraph/qsgrhisupport.cpp
index 0df19c247f..b86667a972 100644
--- a/src/quick/scenegraph/qsgrhisupport.cpp
+++ b/src/quick/scenegraph/qsgrhisupport.cpp
@@ -42,12 +42,17 @@
#if QT_CONFIG(opengl)
# include "qsgdefaultrendercontext_p.h"
#endif
-#include <QtGui/qwindow.h>
+#include <QtQuick/private/qquickitem_p.h>
+#include <QtQuick/private/qquickwindow_p.h>
+
+#include <QtGui/qwindow.h>
#if QT_CONFIG(vulkan)
#include <QtGui/qvulkaninstance.h>
#endif
+#include <QOperatingSystemVersion>
+
QT_BEGIN_NAMESPACE
#if QT_CONFIG(vulkan)
@@ -91,7 +96,7 @@ QVulkanInstance *QSGRhiSupport::vulkanInstance()
#endif
}
-void QSGRhiSupport::cleanup()
+void QSGRhiSupport::cleanupVulkanInstance()
{
#if QT_CONFIG(vulkan)
delete s_vulkanInstance;
@@ -100,7 +105,7 @@ void QSGRhiSupport::cleanup()
}
QSGRhiSupport::QSGRhiSupport()
- : m_set(false),
+ : m_settingsApplied(false),
m_enableRhi(false),
m_debugLayer(false),
m_profile(false),
@@ -111,7 +116,7 @@ QSGRhiSupport::QSGRhiSupport()
void QSGRhiSupport::applySettings()
{
- m_set = true;
+ m_settingsApplied = true;
// This is also done when creating the renderloop but we may be before that
// in case we get here due to a setScenegraphBackend() -> configure() early
@@ -121,7 +126,7 @@ void QSGRhiSupport::applySettings()
if (m_requested.valid) {
// explicit rhi backend request from C++ (e.g. via QQuickWindow)
- m_enableRhi = m_requested.rhi;
+ m_enableRhi = true;
switch (m_requested.api) {
case QSGRendererInterface::OpenGLRhi:
m_rhiBackend = QRhi::OpenGLES2;
@@ -143,8 +148,11 @@ void QSGRhiSupport::applySettings()
break;
}
} else {
+
+ // New Qt 6 default: enable RHI, unless QSG_NO_RHI is set
+ m_enableRhi = !qEnvironmentVariableIsSet("QSG_NO_RHI");
+
// check env.vars., fall back to platform-specific defaults when backend is not set
- m_enableRhi = uint(qEnvironmentVariableIntValue("QSG_RHI"));
const QByteArray rhiBackend = qgetenv("QSG_RHI_BACKEND");
if (rhiBackend == QByteArrayLiteral("gl")
|| rhiBackend == QByteArrayLiteral("gles2")
@@ -172,12 +180,23 @@ void QSGRhiSupport::applySettings()
m_rhiBackend = QRhi::OpenGLES2;
#endif
// Vulkan has to be requested explicitly
+
+ // Now that we established our initial choice, we may want to opt
+ // for another backend under certain special circumstances.
+ if (m_enableRhi) // guard because this may do actual graphics calls on some platforms
+ adjustToPlatformQuirks();
}
}
if (!m_enableRhi)
return;
+ // At this point the RHI backend is fixed, it cannot be changed once we
+ // return from this function. This is because things like the QWindow
+ // (QQuickWindow) may depend on the graphics API as well (surfaceType
+ // f.ex.), and all that is based on what we report from here. So further
+ // adjustments are not possible (or, at minimum, not safe and portable).
+
// validation layers (Vulkan) or debug layer (D3D)
m_debugLayer = uint(qEnvironmentVariableIntValue("QSG_RHI_DEBUG_LAYER"));
@@ -200,6 +219,39 @@ void QSGRhiSupport::applySettings()
qCDebug(QSG_LOG_INFO, "Prioritizing software renderers");
}
+void QSGRhiSupport::adjustToPlatformQuirks()
+{
+#if defined(Q_OS_WIN)
+ // Temporary Windows 7 workaround: no D3D. Just stick with OpenGL like Qt 5
+ // would. Can be removed when Win 7 support is finally dropped from Qt 6.
+ // (but as long as we have a Win 7 CI, this is mandatory)
+ if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::Windows7) {
+ if (m_rhiBackend == QRhi::D3D11) {
+ qCDebug(QSG_LOG_INFO, "D3D on Windows 7 is not supported. Trying OpenGL instead.");
+ m_rhiBackend = QRhi::OpenGLES2;
+ }
+ }
+#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+
+ // ### For now just create a throwaway QRhi instance. This will be replaced
+ // by a more lightweight way, once a helper function is added gui/rhi.
+
+ // A macOS VM may not have Metal support at all. We have to decide at this
+ // point, it will be too late afterwards, and the only way is to see if
+ // MTLCreateSystemDefaultDevice succeeds.
+ if (m_rhiBackend == QRhi::Metal) {
+ QRhiMetalInitParams rhiParams;
+ QRhi *tempRhi = QRhi::create(m_rhiBackend, &rhiParams, {});
+ if (!tempRhi) {
+ m_rhiBackend = QRhi::OpenGLES2;
+ qCDebug(QSG_LOG_INFO, "Metal does not seem to be supported. Falling back to OpenGL.");
+ } else {
+ delete tempRhi;
+ }
+ }
+#endif
+}
+
QSGRhiSupport *QSGRhiSupport::staticInst()
{
static QSGRhiSupport inst;
@@ -217,20 +269,15 @@ void QSGRhiSupport::configure(QSGRendererInterface::GraphicsApi api)
{
Q_ASSERT(QSGRendererInterface::isApiRhiBased(api));
QSGRhiSupport *inst = staticInst();
- if (inst->m_set) {
- qWarning("QRhi is already configured, request ignored");
- return;
- }
inst->m_requested.valid = true;
inst->m_requested.api = api;
- inst->m_requested.rhi = true;
inst->applySettings();
}
QSGRhiSupport *QSGRhiSupport::instance()
{
QSGRhiSupport *inst = staticInst();
- if (!inst->m_set)
+ if (!inst->m_settingsApplied)
inst->applySettings();
return inst;
}
@@ -483,11 +530,10 @@ QOffscreenSurface *QSGRhiSupport::maybeCreateOffscreenSurface(QWindow *window)
}
// must be called on the render thread
-QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurface)
+QRhi *QSGRhiSupport::createRhi(QQuickWindow *window, QOffscreenSurface *offscreenSurface)
{
-#if !QT_CONFIG(opengl) && !QT_CONFIG(vulkan)
- Q_UNUSED(window);
-#endif
+ const QQuickGraphicsDevice &customDev(QQuickWindowPrivate::get(window)->customDeviceObjects);
+ const QQuickGraphicsDevicePrivate *customDevD = QQuickGraphicsDevicePrivate::get(&customDev);
QRhi *rhi = nullptr;
@@ -509,7 +555,14 @@ QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurf
rhiParams.format = format;
rhiParams.fallbackSurface = offscreenSurface;
rhiParams.window = window;
- rhi = QRhi::create(backend, &rhiParams, flags);
+ if (customDevD->type == QQuickGraphicsDevicePrivate::Type::OpenGLContext) {
+ QRhiGles2NativeHandles importDev;
+ importDev.context = customDevD->u.context;
+ qCDebug(QSG_LOG_INFO, "Using existing QOpenGLContext %p", importDev.context);
+ rhi = QRhi::create(backend, &rhiParams, flags, &importDev);
+ } else {
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
}
#else
Q_UNUSED(offscreenSurface);
@@ -520,8 +573,19 @@ QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurf
rhiParams.inst = window->vulkanInstance();
if (!rhiParams.inst)
qWarning("No QVulkanInstance set for QQuickWindow, this is wrong.");
- rhiParams.window = window;
- rhi = QRhi::create(backend, &rhiParams, flags);
+ if (window->handle()) // only used for vkGetPhysicalDeviceSurfaceSupportKHR and that implies having a valid native window
+ rhiParams.window = window;
+ if (customDevD->type == QQuickGraphicsDevicePrivate::Type::DeviceObjects) {
+ QRhiVulkanNativeHandles importDev;
+ importDev.physDev = reinterpret_cast<VkPhysicalDevice>(customDevD->u.deviceObjects.physicalDevice);
+ importDev.dev = reinterpret_cast<VkDevice>(customDevD->u.deviceObjects.device);
+ importDev.gfxQueueFamilyIdx = customDevD->u.deviceObjects.queueFamilyIndex;
+ qCDebug(QSG_LOG_INFO, "Using existing native Vulkan physical device %p device %p graphics queue family index %d",
+ importDev.physDev, importDev.dev, importDev.gfxQueueFamilyIdx);
+ rhi = QRhi::create(backend, &rhiParams, flags, &importDev);
+ } else {
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
}
#endif
#ifdef Q_OS_WIN
@@ -532,13 +596,31 @@ QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurf
rhiParams.framesUntilKillingDeviceViaTdr = m_killDeviceFrameCount;
rhiParams.repeatDeviceKill = true;
}
- rhi = QRhi::create(backend, &rhiParams, flags);
+ if (customDevD->type == QQuickGraphicsDevicePrivate::Type::DeviceAndContext) {
+ QRhiD3D11NativeHandles importDev;
+ importDev.dev = customDevD->u.deviceAndContext.device;
+ importDev.context = customDevD->u.deviceAndContext.context;
+ qCDebug(QSG_LOG_INFO, "Using existing native D3D11 device %p and context %p",
+ importDev.dev, importDev.context);
+ rhi = QRhi::create(backend, &rhiParams, flags, &importDev);
+ } else {
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
}
#endif
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
if (backend == QRhi::Metal) {
QRhiMetalInitParams rhiParams;
- rhi = QRhi::create(backend, &rhiParams, flags);
+ if (customDevD->type == QQuickGraphicsDevicePrivate::Type::DeviceAndCommandQueue) {
+ QRhiMetalNativeHandles importDev;
+ importDev.dev = customDevD->u.deviceAndCommandQueue.device;
+ importDev.cmdQueue = customDevD->u.deviceAndCommandQueue.cmdQueue;
+ qCDebug(QSG_LOG_INFO, "Using existing native Metal device %p and command queue %p",
+ importDev.dev, importDev.cmdQueue);
+ rhi = QRhi::create(backend, &rhiParams, flags, &importDev);
+ } else {
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
}
#endif
diff --git a/src/quick/scenegraph/qsgrhisupport_p.h b/src/quick/scenegraph/qsgrhisupport_p.h
index 0a95a09ad2..ec7ebbbfd1 100644
--- a/src/quick/scenegraph/qsgrhisupport_p.h
+++ b/src/quick/scenegraph/qsgrhisupport_p.h
@@ -91,7 +91,7 @@ class QOffscreenSurface;
// Opting in/out of QRhi and choosing the default/requested backend is managed
// by this singleton. This is because this information may be needed before
// creating a render loop. A well-written render loop sets up its QRhi and
-// related machinery based on the settings queriable from here.
+// related machinery using the helper functions in here.
//
// cleanup() must be called to perform global (not per thread) cleanup, such
// as, destroying the QVulkanInstance (if one was created in vulkanInstance()).
@@ -99,13 +99,13 @@ class QOffscreenSurface;
// In addition, the class provides handy conversion and query stuff for the
// renderloop and the QSGRendererInterface implementations.
//
-class QSGRhiSupport
+class Q_QUICK_PRIVATE_EXPORT QSGRhiSupport
{
public:
static void configure(QSGRendererInterface::GraphicsApi api);
static QSGRhiSupport *instance();
static QVulkanInstance *vulkanInstance();
- void cleanup();
+ static void cleanupVulkanInstance();
bool isRhiEnabled() const { return m_enableRhi; }
QRhi::Implementation rhiBackend() const { return m_rhiBackend; }
@@ -124,7 +124,7 @@ public:
int chooseSampleCountForWindowWithRhi(QWindow *window, QRhi *rhi);
QOffscreenSurface *maybeCreateOffscreenSurface(QWindow *window);
- QRhi *createRhi(QWindow *window, QOffscreenSurface *offscreenSurface);
+ QRhi *createRhi(QQuickWindow *window, QOffscreenSurface *offscreenSurface);
QImage grabAndBlockInCurrentFrame(QRhi *rhi, QRhiSwapChain *swapchain);
@@ -133,15 +133,15 @@ public:
private:
QSGRhiSupport();
void applySettings();
+ void adjustToPlatformQuirks();
static QSGRhiSupport *staticInst();
struct {
bool valid = false;
QSGRendererInterface::GraphicsApi api;
- uint rhi : 1;
} m_requested;
QRhi::Implementation m_rhiBackend = QRhi::Null;
int m_killDeviceFrameCount;
- uint m_set : 1;
+ uint m_settingsApplied : 1;
uint m_enableRhi : 1;
uint m_debugLayer : 1;
uint m_profile : 1;
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
index 9b288029b4..0a62f85388 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp
+++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
@@ -53,6 +53,7 @@
#include <QtQuick/QQuickWindow>
#include <private/qquickwindow_p.h>
+#include <private/qquickitem_p.h>
#include <QtQuick/private/qsgrenderer_p.h>
@@ -712,6 +713,8 @@ void QSGRenderThread::syncAndRender(QImage *grabImage)
if (!grabRequested)
pendingUpdate = 0;
+ emit window->beforeFrameBegin();
+
QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
// Begin the frame before syncing -> sync is where we may invoke
// updatePaintNode() on the items and they may want to do resource updates.
@@ -790,12 +793,16 @@ void QSGRenderThread::syncAndRender(QImage *grabImage)
&& !(pendingUpdate & RepaintRequest) // may have been set in sync()
&& sgrc->isValid()
&& !grabRequested
- && (gl || (rhi && !rhi->isRecordingFrame())))
+ && (gl || rhi))
{
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- no changes, render aborted");
+ if (rhi && rhi->isRecordingFrame())
+ rhi->endFrame(cd->swapchain, QRhi::SkipPresent);
+
int waitTime = vsyncDelta - (int) waitTimer.elapsed();
if (waitTime > 0)
msleep(waitTime);
+
return;
}
@@ -882,6 +889,8 @@ void QSGRenderThread::syncAndRender(QImage *grabImage)
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering done");
+ emit window->afterFrameEnd();
+
// Though it would be more correct to put this block directly after
// fireFrameSwapped in the if (current) branch above, we don't do
// that to avoid blocking the GUI thread in the case where it
@@ -1404,7 +1413,7 @@ bool QSGThreadedRenderLoop::eventFilter(QObject *watched, QEvent *event)
QQuickWindow *window = qobject_cast<QQuickWindow *>(watched);
if (window) {
Window *w = windowFor(m_windows, window);
- if (w) {
+ if (w && w->thread->isRunning()) {
w->thread->mutex.lock();
w->thread->postEvent(new WMReleaseSwapchainEvent(window));
w->thread->waitCondition.wait(&w->thread->mutex);
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop_p.h b/src/quick/scenegraph/qsgthreadedrenderloop_p.h
index e5e9fa8b48..d805c91d79 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop_p.h
+++ b/src/quick/scenegraph/qsgthreadedrenderloop_p.h
@@ -52,7 +52,7 @@
//
#include <QtCore/QThread>
-#include <QtGui/QOpenGLContext>
+#include <QOpenGLContext>
#include <private/qsgcontext_p.h>
#include "qsgrenderloop_p.h"
diff --git a/src/quick/scenegraph/qsgwindowsrenderloop.cpp b/src/quick/scenegraph/qsgwindowsrenderloop.cpp
deleted file mode 100644
index 20d7c4557f..0000000000
--- a/src/quick/scenegraph/qsgwindowsrenderloop.cpp
+++ /dev/null
@@ -1,551 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qsgwindowsrenderloop_p.h"
-#include <QtCore/QCoreApplication>
-#include <QtCore/QLibraryInfo>
-#include <QtCore/QThread>
-
-#include <QtGui/QScreen>
-#include <QtGui/QGuiApplication>
-#include <QtGui/QOffscreenSurface>
-
-#include <QtQuick/private/qsgcontext_p.h>
-#include <QtQuick/private/qquickwindow_p.h>
-#include <QtQuick/private/qsgrenderer_p.h>
-#include <QtQuick/private/qsgdefaultrendercontext_p.h>
-
-#include <QtQuick/QQuickWindow>
-
-#include <private/qquickprofiler_p.h>
-#include <private/qquickanimatorcontroller_p.h>
-
-#if QT_CONFIG(quick_shadereffect) && QT_CONFIG(opengl)
-#include <private/qquickopenglshadereffectnode_p.h>
-#endif
-
-#include <qtquick_tracepoints_p.h>
-
-QT_BEGIN_NAMESPACE
-
-// Single-threaded render loop with a custom animation driver. Like a
-// combination of basic+threaded but still working on the main thread. Only
-// compatible with direct OpenGL, no RHI support here.
-
-extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
-
-#define RLDEBUG(x) qCDebug(QSG_LOG_RENDERLOOP, x)
-
-static QElapsedTimer qsg_render_timer;
-#define QSG_LOG_TIME_SAMPLE(sampleName) \
- qint64 sampleName = 0; \
- if (QSG_LOG_TIME_RENDERLOOP().isDebugEnabled()) \
- sampleName = qsg_render_timer.nsecsElapsed(); \
-
-#define QSG_RENDER_TIMING_SAMPLE(frameType, sampleName, position) \
- QSG_LOG_TIME_SAMPLE(sampleName) \
- Q_QUICK_SG_PROFILE_RECORD(frameType, position);
-
-
-QSGWindowsRenderLoop::QSGWindowsRenderLoop()
- : m_gl(nullptr)
- , m_sg(QSGContext::createDefaultContext())
- , m_updateTimer(0)
- , m_animationTimer(0)
-{
- m_rc = static_cast<QSGDefaultRenderContext *>(m_sg->createRenderContext());
-
- m_vsyncDelta = 1000 / QGuiApplication::primaryScreen()->refreshRate();
- if (m_vsyncDelta <= 0)
- m_vsyncDelta = 16;
-
- RLDEBUG("Windows Render Loop created");
-
- m_animationDriver = m_sg->createAnimationDriver(m_sg);
- connect(m_animationDriver, SIGNAL(started()), this, SLOT(started()));
- connect(m_animationDriver, SIGNAL(stopped()), this, SLOT(stopped()));
- m_animationDriver->install();
-
- qsg_render_timer.start();
-}
-
-QSGWindowsRenderLoop::~QSGWindowsRenderLoop()
-{
- delete m_rc;
- delete m_sg;
-}
-
-bool QSGWindowsRenderLoop::interleaveIncubation() const
-{
- return m_animationDriver->isRunning() && anyoneShowing();
-}
-
-QSGWindowsRenderLoop::WindowData *QSGWindowsRenderLoop::windowData(QQuickWindow *window)
-{
- for (int i=0; i<m_windows.size(); ++i) {
- WindowData &wd = m_windows[i];
- if (wd.window == window)
- return &wd;
- }
- return nullptr;
-}
-
-void QSGWindowsRenderLoop::maybePostUpdateTimer()
-{
- if (!m_updateTimer) {
- RLDEBUG(" - posting event");
- m_updateTimer = startTimer(m_vsyncDelta / 3);
- }
-}
-
-/*
- * If no windows are showing, start ticking animations using a timer,
- * otherwise, start rendering
- */
-void QSGWindowsRenderLoop::started()
-{
- RLDEBUG("Animations started...");
- if (!anyoneShowing()) {
- if (m_animationTimer == 0) {
- RLDEBUG(" - starting non-visual animation timer");
- m_animationTimer = startTimer(m_vsyncDelta);
- }
- } else {
- maybePostUpdateTimer();
- }
-}
-
-void QSGWindowsRenderLoop::stopped()
-{
- RLDEBUG("Animations stopped...");
- if (m_animationTimer) {
- RLDEBUG(" - stopping non-visual animation timer");
- killTimer(m_animationTimer);
- m_animationTimer = 0;
- }
-}
-
-void QSGWindowsRenderLoop::show(QQuickWindow *window)
-{
- RLDEBUG("show");
- if (windowData(window) != nullptr)
- return;
-
- // This happens before the platform window is shown, but after
- // it is created. Creating the GL context takes a lot of time
- // (hundreds of milliseconds) and will prevent us from rendering
- // the first frame in time for the initial show on screen.
- // By preparing the GL context here, it is feasible (if the app
- // is quick enough) to have a perfect first frame.
- if (!m_gl) {
- RLDEBUG(" - creating GL context");
- m_gl = new QOpenGLContext();
- m_gl->setFormat(window->requestedFormat());
- m_gl->setScreen(window->screen());
- if (qt_gl_global_share_context())
- m_gl->setShareContext(qt_gl_global_share_context());
- bool created = m_gl->create();
- if (!created) {
- delete m_gl;
- m_gl = nullptr;
- handleContextCreationFailure(window);
- return;
- }
-
- QQuickWindowPrivate::get(window)->fireOpenGLContextCreated(m_gl);
-
- RLDEBUG(" - making current");
- bool current = m_gl->makeCurrent(window);
- RLDEBUG(" - initializing SG");
- if (current) {
- QSGDefaultRenderContext::InitParams rcParams;
- rcParams.sampleCount = qMax(1, m_gl->format().samples());
- rcParams.openGLContext = m_gl;
- rcParams.initialSurfacePixelSize = window->size() * window->effectiveDevicePixelRatio();
- rcParams.maybeSurface = window;
- m_rc->initialize(&rcParams);
- }
- }
-
- WindowData data;
- data.window = window;
- data.pendingUpdate = false;
- m_windows << data;
-
- RLDEBUG(" - done with show");
-}
-
-void QSGWindowsRenderLoop::hide(QQuickWindow *window)
-{
- RLDEBUG("hide");
- // The expose event is queued while hide is sent synchronously, so
- // the value might not be updated yet. (plus that the windows plugin
- // sends exposed=true when it goes to hidden, so it is doubly broken)
- // The check is made here, after the removal from m_windows, so
- // anyoneShowing will report the right value.
- if (window->isExposed())
- handleObscurity();
- if (!m_gl)
- return;
- QQuickWindowPrivate::get(window)->fireAboutToStop();
-}
-
-void QSGWindowsRenderLoop::windowDestroyed(QQuickWindow *window)
-{
- RLDEBUG("windowDestroyed");
- for (int i=0; i<m_windows.size(); ++i) {
- if (m_windows.at(i).window == window) {
- m_windows.removeAt(i);
- break;
- }
- }
-
- hide(window);
-
- QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
-
- bool current = false;
- QScopedPointer<QOffscreenSurface> offscreenSurface;
- if (m_gl) {
- QSurface *surface = window;
- // There may be no platform window if the window got closed.
- if (!window->handle()) {
- offscreenSurface.reset(new QOffscreenSurface);
- offscreenSurface->setFormat(m_gl->format());
- offscreenSurface->create();
- surface = offscreenSurface.data();
- }
- current = m_gl->makeCurrent(surface);
- }
- if (Q_UNLIKELY(!current))
- RLDEBUG("cleanup without an OpenGL context");
-
-#if QT_CONFIG(quick_shadereffect) && QT_CONFIG(opengl)
- if (current)
- QQuickOpenGLShaderEffectMaterial::cleanupMaterialCache();
-#endif
-
- d->cleanupNodesOnShutdown();
- if (m_windows.size() == 0) {
- d->context->invalidate();
- delete m_gl;
- m_gl = nullptr;
- } else if (m_gl && current) {
- m_gl->doneCurrent();
- }
-
- d->animationController.reset();
-}
-
-bool QSGWindowsRenderLoop::anyoneShowing() const
-{
- for (const WindowData &wd : qAsConst(m_windows))
- if (wd.window->isVisible() && wd.window->isExposed() && wd.window->size().isValid())
- return true;
- return false;
-}
-
-void QSGWindowsRenderLoop::exposureChanged(QQuickWindow *window)
-{
-
- if (windowData(window) == nullptr)
- return;
-
- if (window->isExposed() && window->isVisible()) {
-
- // Stop non-visual animation timer as we now have a window rendering
- if (m_animationTimer && anyoneShowing()) {
- RLDEBUG(" - stopping non-visual animation timer");
- killTimer(m_animationTimer);
- m_animationTimer = 0;
- }
-
- RLDEBUG("exposureChanged - exposed");
- WindowData *wd = windowData(window);
- wd->pendingUpdate = true;
-
- // If we have a pending timer and we get an expose, we need to stop it.
- // Otherwise we get two frames and two animation ticks in the same time-interval.
- if (m_updateTimer) {
- RLDEBUG(" - killing pending update timer");
- killTimer(m_updateTimer);
- m_updateTimer = 0;
- }
- render();
- } else {
- handleObscurity();
- }
-}
-
-void QSGWindowsRenderLoop::handleObscurity()
-{
- RLDEBUG("handleObscurity");
- // Potentially start the non-visual animation timer if nobody is rendering
- if (m_animationDriver->isRunning() && !anyoneShowing() && !m_animationTimer) {
- RLDEBUG(" - starting non-visual animation timer");
- m_animationTimer = startTimer(m_vsyncDelta);
- }
-}
-
-QImage QSGWindowsRenderLoop::grab(QQuickWindow *window)
-{
- RLDEBUG("grab");
- if (!m_gl)
- return QImage();
-
- m_gl->makeCurrent(window);
-
- QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
- d->polishItems();
- d->syncSceneGraph();
- d->renderSceneGraph(window->size());
-
- bool alpha = window->format().alphaBufferSize() > 0 && window->color().alpha() != 255;
- QImage image = qt_gl_read_framebuffer(window->size() * window->effectiveDevicePixelRatio(), alpha, alpha);
- image.setDevicePixelRatio(window->effectiveDevicePixelRatio());
- return image;
-}
-
-void QSGWindowsRenderLoop::update(QQuickWindow *window)
-{
- RLDEBUG("update");
- maybeUpdate(window);
-}
-
-void QSGWindowsRenderLoop::maybeUpdate(QQuickWindow *window)
-{
- RLDEBUG("maybeUpdate");
-
- WindowData *wd = windowData(window);
- if (!wd || !anyoneShowing())
- return;
-
- wd->pendingUpdate = true;
- maybePostUpdateTimer();
-}
-
-QSGRenderContext *QSGWindowsRenderLoop::createRenderContext(QSGContext *) const
-{
- return m_rc;
-}
-
-bool QSGWindowsRenderLoop::event(QEvent *event)
-{
- switch (event->type()) {
- case QEvent::Timer: {
- QTimerEvent *te = static_cast<QTimerEvent *>(event);
- if (te->timerId() == m_animationTimer) {
- RLDEBUG("event : animation tick while nothing is showing");
- m_animationDriver->advance();
- } else if (te->timerId() == m_updateTimer) {
- RLDEBUG("event : update");
- killTimer(m_updateTimer);
- m_updateTimer = 0;
- render();
- }
- return true; }
- default:
- break;
- }
-
- return QObject::event(event);
-}
-
-/*
- * Go through all windows we control and render them in turn.
- * Then tick animations if active.
- */
-void QSGWindowsRenderLoop::render()
-{
- RLDEBUG("render");
- Q_TRACE(QSG_render_entry);
- bool rendered = false;
- for (const WindowData &wd : qAsConst(m_windows)) {
- if (wd.pendingUpdate) {
- const_cast<WindowData &>(wd).pendingUpdate = false;
- renderWindow(wd.window);
- rendered = true;
- }
- }
-
- if (!rendered) {
- RLDEBUG("no changes, sleep");
- QThread::msleep(m_vsyncDelta);
- }
-
- Q_TRACE(QSG_render_exit);
-
- if (m_animationDriver->isRunning()) {
- RLDEBUG("advancing animations");
- QSG_LOG_TIME_SAMPLE(time_start);
- Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphWindowsAnimations);
- Q_TRACE(QSG_animations_entry);
- m_animationDriver->advance();
- RLDEBUG("animations advanced");
-
- qCDebug(QSG_LOG_TIME_RENDERLOOP,
- "animations ticked in %dms",
- int((qsg_render_timer.nsecsElapsed() - time_start)/1000000));
-
- Q_TRACE(QSG_animations_exit);
- Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphWindowsAnimations, 1);
-
- // It is not given that animations triggered another maybeUpdate()
- // and thus another render pass, so to keep things running,
- // make sure there is another frame pending.
- maybePostUpdateTimer();
-
- emit timeToIncubate();
- }
-}
-
-/*
- * Render the contents of this window. First polish, then sync, render
- * then finally swap.
- *
- * Note: This render function does not implement aborting
- * the render call when sync step results in no scene graph changes,
- * like the threaded renderer does.
- */
-void QSGWindowsRenderLoop::renderWindow(QQuickWindow *window)
-{
- RLDEBUG("renderWindow");
- QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
-
- if (!d->isRenderable())
- return;
-
- if (!m_gl->makeCurrent(window)) {
- // Check for context loss.
- if (!m_gl->isValid()) {
- d->cleanupNodesOnShutdown();
- m_rc->invalidate();
- if (m_gl->create() && m_gl->makeCurrent(window)) {
- QSGDefaultRenderContext::InitParams rcParams;
- rcParams.sampleCount = qMax(1, m_gl->format().samples());
- rcParams.openGLContext = m_gl;
- rcParams.initialSurfacePixelSize = window->size() * window->effectiveDevicePixelRatio();
- rcParams.maybeSurface = window;
- m_rc->initialize(&rcParams);
- } else {
- return;
- }
- }
- }
-
- bool lastDirtyWindow = true;
- for (int i=0; i<m_windows.size(); ++i) {
- if ( m_windows[i].pendingUpdate) {
- lastDirtyWindow = false;
- break;
- }
- }
-
- d->flushFrameSynchronousEvents();
- // Event delivery or processing has caused the window to stop rendering.
- if (!windowData(window))
- return;
-
- Q_TRACE_SCOPE(QSG_renderWindow);
-
- QSG_LOG_TIME_SAMPLE(time_start);
- Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphPolishFrame);
- Q_TRACE(QSG_polishItems_entry);
-
- RLDEBUG(" - polishing");
- d->polishItems();
- QSG_LOG_TIME_SAMPLE(time_polished);
- Q_TRACE(QSG_polishItems_exit);
- Q_QUICK_SG_PROFILE_SWITCH(QQuickProfiler::SceneGraphPolishFrame,
- QQuickProfiler::SceneGraphRenderLoopFrame,
- QQuickProfiler::SceneGraphPolishPolish);
- Q_TRACE(QSG_sync_entry);
-
- emit window->afterAnimating();
-
- RLDEBUG(" - syncing");
- d->syncSceneGraph();
- if (lastDirtyWindow)
- m_rc->endSync();
- Q_TRACE(QSG_sync_exit);
- QSG_RENDER_TIMING_SAMPLE(QQuickProfiler::SceneGraphRenderLoopFrame, time_synced,
- QQuickProfiler::SceneGraphRenderLoopSync);
- Q_TRACE(QSG_render_entry);
-
- RLDEBUG(" - rendering");
- d->renderSceneGraph(window->size());
- Q_TRACE(QSG_render_exit);
- QSG_RENDER_TIMING_SAMPLE(QQuickProfiler::SceneGraphRenderLoopFrame, time_rendered,
- QQuickProfiler::SceneGraphRenderLoopRender);
- Q_TRACE(QSG_swap_entry);
-
- RLDEBUG(" - swapping");
- if (!d->customRenderStage || !d->customRenderStage->swap())
- m_gl->swapBuffers(window);
- Q_TRACE(QSG_swap_exit);
- QSG_RENDER_TIMING_SAMPLE(QQuickProfiler::SceneGraphRenderLoopFrame, time_swapped,
- QQuickProfiler::SceneGraphRenderLoopSwap);
-
- RLDEBUG(" - frameDone");
- d->fireFrameSwapped();
-
- qCDebug(QSG_LOG_TIME_RENDERLOOP()).nospace()
- << "Frame rendered with 'windows' renderloop in: " << (time_swapped - time_start) / 1000000 << "ms"
- << ", polish=" << (time_polished - time_start) / 1000000
- << ", sync=" << (time_synced - time_polished) / 1000000
- << ", render=" << (time_rendered - time_synced) / 1000000
- << ", swap=" << (time_swapped - time_rendered) / 1000000
- << " - " << window;
-
- Q_QUICK_SG_PROFILE_REPORT(QQuickProfiler::SceneGraphRenderLoopFrame,
- QQuickProfiler::SceneGraphRenderLoopSwap);
-}
-
-void QSGWindowsRenderLoop::releaseResources(QQuickWindow *w)
-{
- // No full invalidation of the rendercontext, just clear some caches.
- RLDEBUG("releaseResources");
- QQuickWindowPrivate *d = QQuickWindowPrivate::get(w);
- if (d->renderer)
- d->renderer->releaseCachedResources();
-}
-
-QT_END_NAMESPACE
-
-#include "moc_qsgwindowsrenderloop_p.cpp"
diff --git a/src/quick/scenegraph/qsgwindowsrenderloop_p.h b/src/quick/scenegraph/qsgwindowsrenderloop_p.h
deleted file mode 100644
index a1188fed8a..0000000000
--- a/src/quick/scenegraph/qsgwindowsrenderloop_p.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGWINDOWSRENDERLOOP_P_H
-#define QSGWINDOWSRENDERLOOP_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/QObject>
-#include <QtCore/QElapsedTimer>
-
-#include <QtGui/QOpenGLContext>
-
-#include "qsgrenderloop_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QSGRenderContext;
-class QSGDefaultRenderContext;
-
-class QSGWindowsRenderLoop : public QSGRenderLoop
-{
- Q_OBJECT
-public:
- explicit QSGWindowsRenderLoop();
- ~QSGWindowsRenderLoop();
-
- void show(QQuickWindow *window) override;
- void hide(QQuickWindow *window) override;
-
- void windowDestroyed(QQuickWindow *window) override;
-
- void exposureChanged(QQuickWindow *window) override;
- QImage grab(QQuickWindow *window) override;
-
- void update(QQuickWindow *window) override;
- void maybeUpdate(QQuickWindow *window) override;
-
- QAnimationDriver *animationDriver() const override { return m_animationDriver; }
-
- QSGContext *sceneGraphContext() const override { return m_sg; }
- QSGRenderContext *createRenderContext(QSGContext *) const override;
-
- void releaseResources(QQuickWindow *) override;
-
- void render();
- void renderWindow(QQuickWindow *window);
-
- bool event(QEvent *event) override;
- bool anyoneShowing() const;
-
- bool interleaveIncubation() const override;
-
-public Q_SLOTS:
- void started();
- void stopped();
-
-private:
- struct WindowData {
- QQuickWindow *window;
- bool pendingUpdate;
- };
-
- void handleObscurity();
- void maybePostUpdateTimer();
- WindowData *windowData(QQuickWindow *window);
-
- QList<WindowData> m_windows;
-
- QOpenGLContext *m_gl;
- QSGContext *m_sg;
- QSGDefaultRenderContext *m_rc;
-
- QAnimationDriver *m_animationDriver;
-
- int m_updateTimer;
- int m_animationTimer;
-
- int m_vsyncDelta;
-};
-
-QT_END_NAMESPACE
-
-#endif // QSGWINDOWSRENDERLOOP_P_H
diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri
index b12f57d8ef..87146dcac8 100644
--- a/src/quick/scenegraph/scenegraph.pri
+++ b/src/quick/scenegraph/scenegraph.pri
@@ -12,8 +12,8 @@ HEADERS += \
$$PWD/coreapi/qsgnode.h \
$$PWD/coreapi/qsgnode_p.h \
$$PWD/coreapi/qsgnodeupdater_p.h \
- $$PWD/coreapi/qsgabstractrenderer.h \
$$PWD/coreapi/qsgabstractrenderer_p.h \
+ $$PWD/coreapi/qsgabstractrenderer_p_p.h \
$$PWD/coreapi/qsgrenderer_p.h \
$$PWD/coreapi/qsgrendernode.h \
$$PWD/coreapi/qsgrendernode_p.h \
@@ -50,14 +50,11 @@ qtConfig(opengl(es1|es2)?) {
# Util API
HEADERS += \
$$PWD/util/qsgareaallocator_p.h \
- $$PWD/util/qsgengine.h \
- $$PWD/util/qsgengine_p.h \
$$PWD/util/qsgplaintexture_p.h \
$$PWD/util/qsgsimplerectnode.h \
$$PWD/util/qsgsimpletexturenode.h \
$$PWD/util/qsgtextureprovider.h \
$$PWD/util/qsgflatcolormaterial.h \
- $$PWD/util/qsgsimplematerial.h \
$$PWD/util/qsgtexturematerial.h \
$$PWD/util/qsgtexturematerial_p.h \
$$PWD/util/qsgvertexcolormaterial.h \
@@ -67,13 +64,11 @@ HEADERS += \
SOURCES += \
$$PWD/util/qsgareaallocator.cpp \
- $$PWD/util/qsgengine.cpp \
$$PWD/util/qsgplaintexture.cpp \
$$PWD/util/qsgsimplerectnode.cpp \
$$PWD/util/qsgsimpletexturenode.cpp \
$$PWD/util/qsgtextureprovider.cpp \
$$PWD/util/qsgflatcolormaterial.cpp \
- $$PWD/util/qsgsimplematerial.cpp \
$$PWD/util/qsgtexturematerial.cpp \
$$PWD/util/qsgvertexcolormaterial.cpp \
$$PWD/util/qsgrectanglenode.cpp \
@@ -142,8 +137,7 @@ qtConfig(opengl(es1|es2)?) {
$$PWD/util/qsgdefaultrectanglenode.cpp \
$$PWD/util/qsgdefaultimagenode.cpp \
$$PWD/util/qsgdefaultninepatchnode.cpp \
- $$PWD/qsgopengllayer.cpp \
- $$PWD/qsgwindowsrenderloop.cpp
+ $$PWD/qsgopengllayer.cpp
HEADERS += \
$$PWD/qsgdefaultglyphnode_p.h \
$$PWD/qsgopengldistancefieldglyphcache_p.h \
@@ -158,8 +152,7 @@ qtConfig(opengl(es1|es2)?) {
$$PWD/util/qsgdefaultrectanglenode_p.h \
$$PWD/util/qsgdefaultimagenode_p.h \
$$PWD/util/qsgdefaultninepatchnode_p.h \
- $$PWD/qsgopengllayer_p.h \
- $$PWD/qsgwindowsrenderloop_p.h
+ $$PWD/qsgopengllayer_p.h
qtConfig(thread) {
SOURCES += \
diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
index 7b26daf541..5fc91b44d3 100644
--- a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
+++ b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
@@ -79,16 +79,15 @@ public:
void setMipmapFiltering(QSGTexture::Filtering filtering) override;
QSGTexture::Filtering mipmapFiltering() const override;
+ void setAnisotropyLevel(QSGTexture::AnisotropyLevel level) override;
+ QSGTexture::AnisotropyLevel anisotropyLevel() const override;
+
void setTextureCoordinatesTransform(TextureCoordinatesTransformMode mode) override;
TextureCoordinatesTransformMode textureCoordinatesTransform() const override;
void setOwnsTexture(bool owns) override;
bool ownsTexture() const override;
- // QSGImageNode now being a public class does not allow any additional virtual methods. Placing these here, non-virtual.
- void setAnisotropyLevel(QSGTexture::AnisotropyLevel level);
- QSGTexture::AnisotropyLevel anisotropyLevel() const;
-
private:
QSGGeometry m_geometry;
QSGOpaqueTextureMaterial m_opaque_material;
diff --git a/src/quick/scenegraph/util/qsgdefaultpainternode.cpp b/src/quick/scenegraph/util/qsgdefaultpainternode.cpp
index f15ea67b46..cd8426db97 100644
--- a/src/quick/scenegraph/util/qsgdefaultpainternode.cpp
+++ b/src/quick/scenegraph/util/qsgdefaultpainternode.cpp
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
#define QT_MINIMUM_DYNAMIC_FBO_SIZE 64U
QSGPainterTexture::QSGPainterTexture()
- : QSGPlainTexture(*(new QSGPainterTexturePrivate))
+ : QSGPlainTexture(*(new QSGPlainTexturePrivate))
{
m_retain_image = true;
}
@@ -73,14 +73,13 @@ void QSGPainterTexture::bind()
m_dirty_rect = QRect();
}
-void QSGPainterTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+void QSGPainterTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
{
- Q_Q(QSGPainterTexture);
- if (!q->m_dirty_rect.isNull()) {
- q->setImage(q->m_image);
- q->m_dirty_rect = QRect();
+ if (!m_dirty_rect.isNull()) {
+ setImage(m_image);
+ m_dirty_rect = QRect();
}
- QSGPlainTexturePrivate::updateRhiTexture(rhi, resourceUpdates);
+ QSGPlainTexture::commitTextureOperations(rhi, resourceUpdates);
}
QSGDefaultPainterNode::QSGDefaultPainterNode(QQuickPaintedItem *item)
diff --git a/src/quick/scenegraph/util/qsgdefaultpainternode_p.h b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
index a86f7397be..b2402dc70e 100644
--- a/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
+++ b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
@@ -64,29 +64,21 @@ QT_BEGIN_NAMESPACE
class QOpenGLFramebufferObject;
class QOpenGLPaintDevice;
class QSGDefaultRenderContext;
-class QSGPainterTexturePrivate;
class Q_QUICK_PRIVATE_EXPORT QSGPainterTexture : public QSGPlainTexture
{
- Q_DECLARE_PRIVATE(QSGPainterTexture)
public:
QSGPainterTexture();
void setDirtyRect(const QRect &rect) { m_dirty_rect = rect; }
void bind() override;
+ void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
private:
QRect m_dirty_rect;
};
-class QSGPainterTexturePrivate : public QSGPlainTexturePrivate
-{
- Q_DECLARE_PUBLIC(QSGPainterTexture)
-public:
- void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
-};
-
class Q_QUICK_PRIVATE_EXPORT QSGDefaultPainterNode : public QSGPainterNode
{
public:
@@ -159,9 +151,6 @@ private:
QSize m_textureSize;
QRect m_dirtyRect;
QColor m_fillColor;
-#if QT_VERSION >= 0x060000
-#warning "Remove m_contentsScale and assume 1 everywhere"
-#endif
qreal m_contentsScale;
bool m_dirtyContents : 1;
diff --git a/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp b/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp
index 1154c06d7c..907dbdfd0e 100644
--- a/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp
+++ b/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp
@@ -112,7 +112,7 @@ QSGDefaultDepthStencilBuffer::QSGDefaultDepthStencilBuffer(QOpenGLContext *conte
m_functions.glGenRenderbuffers(1, &m_depthBuffer);
m_functions.glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
if (format.samples && m_functions.hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)) {
-#if defined(QT_OPENGL_ES_2)
+#if QT_CONFIG(opengles2)
m_functions.glRenderbufferStorageMultisample(GL_RENDERBUFFER, format.samples,
GL_DEPTH24_STENCIL8_OES, width, height);
#else
@@ -120,7 +120,7 @@ QSGDefaultDepthStencilBuffer::QSGDefaultDepthStencilBuffer(QOpenGLContext *conte
GL_DEPTH24_STENCIL8, width, height);
#endif
} else {
-#if defined(QT_OPENGL_ES_2)
+#if QT_CONFIG(opengles2)
m_functions.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height);
#else
m_functions.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
@@ -145,7 +145,7 @@ QSGDefaultDepthStencilBuffer::QSGDefaultDepthStencilBuffer(QOpenGLContext *conte
if (!m_stencilBuffer && (format.attachments & StencilAttachment)) {
m_functions.glGenRenderbuffers(1, &m_stencilBuffer);
m_functions.glBindRenderbuffer(GL_RENDERBUFFER, m_stencilBuffer);
-#ifdef QT_OPENGL_ES
+#if QT_CONFIG(opengles2)
const GLenum internalFormat = GL_STENCIL_INDEX8;
#else
const GLenum internalFormat = context->isOpenGLES() ? GL_STENCIL_INDEX8 : GL_STENCIL_INDEX;
@@ -207,7 +207,7 @@ void QSGDepthStencilBufferManager::insertBuffer(const QSharedPointer<QSGDepthSte
m_buffers.insert(buffer->m_format, buffer.toWeakRef());
}
-uint qHash(const QSGDepthStencilBuffer::Format &format)
+size_t qHash(const QSGDepthStencilBuffer::Format &format)
{
return qHash(qMakePair(format.size.width(), format.size.height()))
^ (uint(format.samples) << 12) ^ (uint(format.attachments) << 28);
diff --git a/src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h b/src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h
index f7c6923021..dfcd854fc2 100644
--- a/src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h
+++ b/src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h
@@ -52,8 +52,8 @@
//
#include <QtCore/qsize.h>
-#include <QtGui/private/qopenglcontext_p.h>
-#include <QtGui/private/qopenglextensions_p.h>
+#include <private/qopenglcontext_p.h>
+#include <private/qopenglextensions_p.h>
#include <QtCore/qsharedpointer.h>
#include <QtCore/qhash.h>
@@ -140,7 +140,7 @@ private:
friend class QSGDepthStencilBuffer;
};
-extern uint qHash(const QSGDepthStencilBuffer::Format &format);
+extern size_t qHash(const QSGDepthStencilBuffer::Format &format);
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgengine.cpp b/src/quick/scenegraph/util/qsgengine.cpp
deleted file mode 100644
index aec981871b..0000000000
--- a/src/quick/scenegraph/util/qsgengine.cpp
+++ /dev/null
@@ -1,295 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qsgengine_p.h"
-
-#include <QtQuick/qsgtexture.h>
-#include <private/qsgcontext_p.h>
-#include <private/qsgrenderer_p.h>
-#include <private/qsgplaintexture_p.h>
-
-#if QT_CONFIG(opengl)
-# include <QtGui/QOpenGLContext>
-# include <private/qsgdefaultrendercontext_p.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-#if QT_DEPRECATED_SINCE(5, 15)
-
-/*!
- \class QSGEngine
- \brief The QSGEngine class allows low level rendering of a scene graph.
- \inmodule QtQuick
- \since 5.4
-
- \deprecated
-
- A QSGEngine can be used to render a tree of QSGNode directly on a QWindow
- or QOpenGLFramebufferObject without any integration with QML, QQuickWindow
- or QQuickItem and the convenience that they provide.
-
- This means that you must handle event propagation, animation timing,
- and node lifetime yourself.
-
- \note This class is for very low level access to an independent scene graph.
- Most of the time you will instead want to subclass QQuickItem and insert
- your QSGNode in a normal QtQuick scene by overriding QQuickItem::updatePaintNode().
-
- \warning This class is only suitable when working directly with OpenGL. It
- is not compatible with the \l{Scene Graph Adaptations}{RHI-based rendering
- path}.
-
- \sa QSGAbstractRenderer
- */
-
-/*!
- \enum QSGEngine::CreateTextureOption
-
- The CreateTextureOption enums are used to customize how a texture is wrapped.
-
- \value TextureHasAlphaChannel The texture has an alpha channel and should
- be drawn using blending.
-
- \value TextureOwnsGLTexture The texture object owns the texture id and
- will delete the GL texture when the texture object is deleted.
-
- \value TextureCanUseAtlas The image can be uploaded into a texture atlas.
-
- \value TextureIsOpaque The texture object is opaque.
- */
-
-QSGEnginePrivate::QSGEnginePrivate()
- : sgContext(QSGContext::createDefaultContext())
- , sgRenderContext(sgContext.data()->createRenderContext())
-{
-}
-
-/*!
- Constructs a new QSGEngine with its \a parent
- */
-QSGEngine::QSGEngine(QObject *parent)
- : QObject(*(new QSGEnginePrivate), parent)
-{
-}
-
-/*!
- Destroys the engine
- */
-QSGEngine::~QSGEngine()
-{
-}
-
-/*!
- Initialize the engine with \a context.
-
- \warning You have to make sure that you call
- QOpenGLContext::makeCurrent() on \a context before calling this.
- */
-void QSGEngine::initialize(QOpenGLContext *context)
-{
- Q_D(QSGEngine);
-#if QT_CONFIG(opengl)
- if (context && QOpenGLContext::currentContext() != context) {
- qWarning("WARNING: The context must be current before calling QSGEngine::initialize.");
- return;
- }
-#endif
- if (d->sgRenderContext && !d->sgRenderContext->isValid()) {
- d->sgRenderContext->setAttachToGraphicsContext(false);
-#if QT_CONFIG(opengl)
- QSGDefaultRenderContext *rc = qobject_cast<QSGDefaultRenderContext *>(d->sgRenderContext.data());
- if (rc) {
- QSGDefaultRenderContext::InitParams params;
- params.sampleCount = qMax(1, context->format().samples());
- params.openGLContext = context;
- // leave the size hint and surface unset, we do not know, that's fine
- rc->initialize(&params);
- } else {
- d->sgRenderContext->initialize(nullptr);
- }
-#else
- d->sgRenderContext->initialize(nullptr);
-#endif
-#if QT_CONFIG(opengl)
- if (context)
- connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &QSGEngine::invalidate);
-#endif
- }
-
-#if !QT_CONFIG(opengl)
- Q_UNUSED(context);
-#endif
-}
-
-/*!
- Invalidate the engine releasing its resources
-
- You will have to call initialize() and createRenderer() if you
- want to use it again.
- */
-void QSGEngine::invalidate()
-{
- Q_D(QSGEngine);
- d->sgRenderContext->invalidate();
-}
-
-/*!
- Returns a renderer that can be used to render a QSGNode tree
-
- You call initialize() first with the QOpenGLContext that you
- want to use with this renderer. This will return a null
- renderer otherwise.
- */
-QSGAbstractRenderer *QSGEngine::createRenderer() const
-{
- Q_D(const QSGEngine);
- if (!d->sgRenderContext->isValid())
- return nullptr;
-
- QSGRenderer *renderer = d->sgRenderContext->createRenderer();
- renderer->setCustomRenderMode(qgetenv("QSG_VISUALIZE"));
- return renderer;
-}
-
-/*!
- Creates a texture using the data of \a image
-
- Valid \a options are TextureCanUseAtlas and TextureIsOpaque.
-
- The caller takes ownership of the texture and the
- texture should only be used with this engine.
-
- \sa createTextureFromId(), QSGSimpleTextureNode::setOwnsTexture(), QQuickWindow::createTextureFromImage()
- */
-QSGTexture *QSGEngine::createTextureFromImage(const QImage &image, CreateTextureOptions options) const
-{
- Q_D(const QSGEngine);
- if (!d->sgRenderContext->isValid())
- return nullptr;
- uint flags = 0;
- if (options & TextureCanUseAtlas) flags |= QSGRenderContext::CreateTexture_Atlas;
- if (!(options & TextureIsOpaque)) flags |= QSGRenderContext::CreateTexture_Alpha;
- return d->sgRenderContext->createTexture(image, flags);
-}
-
-/*!
- Creates a texture object that wraps the GL texture \a id uploaded with \a size
-
- Valid \a options are TextureHasAlphaChannel and TextureOwnsGLTexture
-
- The caller takes ownership of the texture object and the
- texture should only be used with this engine.
-
- \sa createTextureFromImage(), QSGSimpleTextureNode::setOwnsTexture(), QQuickWindow::createTextureFromId()
- */
-QSGTexture *QSGEngine::createTextureFromId(uint id, const QSize &size, CreateTextureOptions options) const
-{
- Q_D(const QSGEngine);
- if (d->sgRenderContext->isValid()) {
- QSGPlainTexture *texture = new QSGPlainTexture();
- texture->setTextureId(id);
- texture->setHasAlphaChannel(options & TextureHasAlphaChannel);
- texture->setOwnsTexture(options & TextureOwnsGLTexture);
- texture->setTextureSize(size);
- return texture;
- }
- return nullptr;
-}
-
-/*!
- Returns the current renderer interface if there is one. Otherwise null is returned.
-
- \sa QSGRenderNode, QSGRendererInterface
- \since 5.8
- */
-QSGRendererInterface *QSGEngine::rendererInterface() const
-{
- Q_D(const QSGEngine);
- return d->sgRenderContext->isValid()
- ? d->sgRenderContext->sceneGraphContext()->rendererInterface(d->sgRenderContext.data())
- : nullptr;
-}
-
-/*!
- Creates a simple rectangle node. When the scenegraph is not initialized, the return value is null.
-
- This is cross-backend alternative to constructing a QSGSimpleRectNode directly.
-
- \since 5.8
- \sa QSGRectangleNode
- */
-QSGRectangleNode *QSGEngine::createRectangleNode() const
-{
- Q_D(const QSGEngine);
- return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createRectangleNode() : nullptr;
-}
-
-/*!
- Creates a simple image node. When the scenegraph is not initialized, the return value is null.
-
- This is cross-backend alternative to constructing a QSGSimpleTextureNode directly.
-
- \since 5.8
- \sa QSGImageNode
- */
-
-QSGImageNode *QSGEngine::createImageNode() const
-{
- Q_D(const QSGEngine);
- return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createImageNode() : nullptr;
-}
-
-/*!
- Creates a nine patch node. When the scenegraph is not initialized, the return value is null.
-
- \since 5.8
- */
-
-QSGNinePatchNode *QSGEngine::createNinePatchNode() const
-{
- Q_D(const QSGEngine);
- return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createNinePatchNode() : nullptr;
-}
-
-#endif
-
-QT_END_NAMESPACE
-
-#include "moc_qsgengine.cpp"
diff --git a/src/quick/scenegraph/util/qsgengine.h b/src/quick/scenegraph/util/qsgengine.h
deleted file mode 100644
index f00b7a0b6f..0000000000
--- a/src/quick/scenegraph/util/qsgengine.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGENGINE_H
-#define QSGENGINE_H
-
-#include <QtCore/QObject>
-#include <QtQuick/qtquickglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenGLContext;
-class QSGAbstractRenderer;
-class QSGEnginePrivate;
-class QSGTexture;
-class QSGRendererInterface;
-class QSGRectangleNode;
-class QSGImageNode;
-class QSGNinePatchNode;
-
-#if QT_DEPRECATED_SINCE(5, 15)
-class Q_QUICK_EXPORT QSGEngine : public QObject
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QSGEngine)
-public:
- enum CreateTextureOption {
- TextureHasAlphaChannel = 0x0001,
- TextureOwnsGLTexture = 0x0004,
- TextureCanUseAtlas = 0x0008,
- TextureIsOpaque = 0x0010
- };
- Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption)
- Q_FLAG(CreateTextureOptions)
-
- explicit QSGEngine(QObject *parent = nullptr);
- ~QSGEngine() override;
-
- QT_DEPRECATED_X("QSGEngine is going to be removed in Qt 6.0. Use QQuickRenderControl instead.")
- void initialize(QOpenGLContext *context);
- void invalidate();
-
- QSGAbstractRenderer *createRenderer() const;
- QSGTexture *createTextureFromImage(const QImage &image, CreateTextureOptions options = CreateTextureOption()) const;
- QSGTexture *createTextureFromId(uint id, const QSize &size, CreateTextureOptions options = CreateTextureOption()) const;
- QSGRendererInterface *rendererInterface() const;
- QSGRectangleNode *createRectangleNode() const;
- QSGImageNode *createImageNode() const;
- QSGNinePatchNode *createNinePatchNode() const;
-};
-#endif
-
-QT_END_NAMESPACE
-
-#endif // QSGENGINE_H
diff --git a/src/quick/scenegraph/util/qsgimagenode.cpp b/src/quick/scenegraph/util/qsgimagenode.cpp
index b154023247..a94e3e0a5d 100644
--- a/src/quick/scenegraph/util/qsgimagenode.cpp
+++ b/src/quick/scenegraph/util/qsgimagenode.cpp
@@ -143,6 +143,18 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn void QSGImageNode::setAnisotropyLevel(QSGTexture::AnisotropyLevel level)
+
+ Sets this image node's anistropy level to \a level.
+*/
+
+/*!
+ \fn QSGTexture::AnisotropyLevel QSGImageNode::anisotropyLevel() const
+
+ Returns this image node's anistropy level.
+*/
+
+/*!
\enum QSGImageNode::TextureCoordinatesTransformFlag
The TextureCoordinatesTransformFlag enum is used to specify the mode used
diff --git a/src/quick/scenegraph/util/qsgimagenode.h b/src/quick/scenegraph/util/qsgimagenode.h
index 3b78f78a0e..45962415fc 100644
--- a/src/quick/scenegraph/util/qsgimagenode.h
+++ b/src/quick/scenegraph/util/qsgimagenode.h
@@ -67,7 +67,8 @@ public:
virtual void setMipmapFiltering(QSGTexture::Filtering filtering) = 0;
virtual QSGTexture::Filtering mipmapFiltering() const = 0;
- // ### Qt6: Add anisotropy support here, and possibly a virtual hook or another mean to extend this class.
+ virtual void setAnisotropyLevel(QSGTexture::AnisotropyLevel level) = 0;
+ virtual QSGTexture::AnisotropyLevel anisotropyLevel() const = 0;
enum TextureCoordinatesTransformFlag {
NoTransform = 0x00,
diff --git a/src/quick/scenegraph/util/qsgopenglatlastexture.cpp b/src/quick/scenegraph/util/qsgopenglatlastexture.cpp
index 18c72286d1..aa5ee3d7b8 100644
--- a/src/quick/scenegraph/util/qsgopenglatlastexture.cpp
+++ b/src/quick/scenegraph/util/qsgopenglatlastexture.cpp
@@ -43,9 +43,9 @@
#include <QtCore/QElapsedTimer>
#include <QtCore/QtMath>
-#include <QtGui/QOpenGLContext>
-#include <QtGui/QOpenGLTexture>
-#include <QtGui/QOpenGLFunctions>
+#include <QOpenGLContext>
+#include <QOpenGLTexture>
+#include <QOpenGLFunctions>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
#include <QtGui/QSurface>
@@ -222,7 +222,7 @@ void AtlasBase::bind(QSGTexture::Filtering filtering)
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-#if !defined(QT_OPENGL_ES_2)
+#if !QT_CONFIG(opengles2)
if (!QOpenGLContext::currentContext()->isOpenGLES())
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
#endif
@@ -295,7 +295,7 @@ Atlas::Atlas(const QSize &size)
m_internalFormat = GL_RGBA;
m_externalFormat = GL_BGRA;
-#ifndef QT_OPENGL_ES
+#if !QT_CONFIG(opengles2)
if (QOpenGLContext::currentContext()->isOpenGLES()) {
#endif
@@ -332,7 +332,7 @@ Atlas::Atlas(const QSize &size)
m_internalFormat = m_externalFormat = GL_RGBA;
}
-#ifndef QT_OPENGL_ES
+#if !QT_CONFIG(opengles2)
}
#endif
@@ -516,6 +516,19 @@ TextureBase::~TextureBase()
m_atlas->remove(this);
}
+int TextureBase::comparisonKey() const
+{
+ // We need special care here: a typical comparisonKey() implementation
+ // returns a unique result when there is no underlying texture yet. This is
+ // not quite ideal for atlasing however since textures with the same atlas
+ // should be considered equal regardless of the state of the underlying
+ // graphics resources.
+
+ // base the comparison on the atlas ptr; this way textures for the same
+ // atlas are considered equal
+ return int(qintptr(m_atlas));
+}
+
void TextureBase::bind()
{
m_atlas->bind(filtering());
@@ -542,7 +555,7 @@ Texture::~Texture()
delete m_nonatlas_texture;
}
-QSGTexture *Texture::removedFromAtlas() const
+QSGTexture *Texture::removedFromAtlas(QRhiResourceUpdateBatch *) const
{
if (m_nonatlas_texture) {
m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());
diff --git a/src/quick/scenegraph/util/qsgopenglatlastexture_p.h b/src/quick/scenegraph/util/qsgopenglatlastexture_p.h
index f8dd7cdf02..a81c62ad63 100644
--- a/src/quick/scenegraph/util/qsgopenglatlastexture_p.h
+++ b/src/quick/scenegraph/util/qsgopenglatlastexture_p.h
@@ -53,7 +53,7 @@
#include <QtCore/QSize>
-#include <QtGui/qopengl.h>
+#include <qopengl.h>
#include <QtQuick/QSGTexture>
#include <QtQuick/private/qsgplaintexture_p.h>
@@ -103,6 +103,7 @@ public:
void invalidate();
+ int comparisonKey() const { return m_texture_id; }
int textureId() const;
void bind(QSGTexture::Filtering filtering);
@@ -158,6 +159,7 @@ public:
TextureBase(AtlasBase *atlas, const QRect &textureRect);
~TextureBase();
+ int comparisonKey() const override;
int textureId() const override { return m_atlas->textureId(); }
bool isAtlasTexture() const override { return true; }
@@ -187,7 +189,7 @@ public:
QRect atlasSubRect() const { return m_allocated_rect; }
QRect atlasSubRectWithoutPadding() const { return m_allocated_rect.adjusted(1, 1, -1, -1); }
- QSGTexture *removedFromAtlas() const override;
+ QSGTexture *removedFromAtlas(QRhiResourceUpdateBatch *) const override;
void releaseImage() { m_image = QImage(); }
const QImage &image() const { return m_image; }
diff --git a/src/quick/scenegraph/util/qsgplaintexture.cpp b/src/quick/scenegraph/util/qsgplaintexture.cpp
index f00918bb4e..037cf8c254 100644
--- a/src/quick/scenegraph/util/qsgplaintexture.cpp
+++ b/src/quick/scenegraph/util/qsgplaintexture.cpp
@@ -45,9 +45,9 @@
#include <QtGui/qguiapplication.h>
#include <QtGui/qpa/qplatformnativeinterface.h>
#if QT_CONFIG(opengl)
-# include <QtGui/qopenglcontext.h>
-# include <QtGui/qopenglfunctions.h>
-# include <QtGui/private/qopengltextureuploader_p.h>
+# include <qopenglcontext.h>
+# include <qopenglfunctions.h>
+# include <private/qopengltextureuploader_p.h>
# include <private/qsgdefaultrendercontext_p.h>
#endif
#include <QtGui/private/qrhi_p.h>
@@ -304,81 +304,78 @@ void QSGPlainTexture::setTextureFromNativeObject(QRhi *rhi, QQuickWindow::Native
setTexture(t);
}
-int QSGPlainTexturePrivate::comparisonKey() const
+int QSGPlainTexture::comparisonKey() const
{
- Q_Q(const QSGPlainTexture);
-
// not textureId() as that would create an id when not yet done - that's not wanted here
- if (q->m_texture_id)
- return q->m_texture_id;
+ if (m_texture_id)
+ return m_texture_id;
- if (q->m_texture)
- return int(qintptr(q->m_texture));
+ if (m_texture)
+ return int(qintptr(m_texture));
// two textures (and so materials) with not-yet-created texture underneath are never equal
- return int(qintptr(q));
+ return int(qintptr(this));
}
-QRhiTexture *QSGPlainTexturePrivate::rhiTexture() const
+QRhiTexture *QSGPlainTexture::rhiTexture() const
{
- Q_Q(const QSGPlainTexture);
- return q->m_texture;
+ return m_texture;
}
-void QSGPlainTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+void QSGPlainTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
{
- Q_Q(QSGPlainTexture);
+ Q_D(QSGPlainTexture);
- const bool hasMipMaps = q->mipmapFiltering() != QSGTexture::None;
- const bool mipmappingChanged = q->m_texture && ((hasMipMaps && !q->m_texture->flags().testFlag(QRhiTexture::MipMapped)) // did not have it before
- || (!hasMipMaps && q->m_texture->flags().testFlag(QRhiTexture::MipMapped))); // does not have it anymore
+ const bool hasMipMaps = mipmapFiltering() != QSGTexture::None;
+ const bool mipmappingChanged = m_texture && ((hasMipMaps && !m_texture->flags().testFlag(QRhiTexture::MipMapped)) // did not have it before
+ || (!hasMipMaps && m_texture->flags().testFlag(QRhiTexture::MipMapped))); // does not have it anymore
- if (!q->m_dirty_texture) {
- if (!q->m_texture)
+ if (!m_dirty_texture) {
+ if (!m_texture)
return;
- if (q->m_texture && !mipmappingChanged) {
- if (hasMipMaps && !q->m_mipmaps_generated) {
- resourceUpdates->generateMips(q->m_texture);
- q->m_mipmaps_generated = true;
+ if (m_texture && !mipmappingChanged) {
+ if (hasMipMaps && !m_mipmaps_generated) {
+ resourceUpdates->generateMips(m_texture);
+ m_mipmaps_generated = true;
}
return;
}
}
- if (q->m_image.isNull()) {
- if (!q->m_dirty_texture && mipmappingChanged) {
+ if (m_image.isNull()) {
+ if (!m_dirty_texture && mipmappingChanged) {
// Full Mipmap Panic!
- if (!q->m_mipmap_warned) {
+ if (!m_mipmap_warned) {
qWarning("QSGPlainTexture: Mipmap settings changed without having image data available. "
"Call setImage() again or enable m_retain_image. "
"Falling back to previous mipmap filtering mode.");
- q->m_mipmap_warned = true;
+ m_mipmap_warned = true;
}
// leave the texture valid and rather ignore the mipmap mode change attempt
- q->setMipmapFiltering(m_last_mipmap_filter);
+ setMipmapFiltering(d->m_last_mipmap_filter);
return;
}
- if (q->m_texture && q->m_owns_texture)
- delete q->m_texture;
+ if (m_texture && m_owns_texture)
+ delete m_texture;
- q->m_texture = nullptr;
- q->m_texture_size = QSize();
- q->m_has_alpha = false;
+ m_texture = nullptr;
+ m_texture_size = QSize();
+ m_has_alpha = false;
- q->m_dirty_texture = false;
+ m_dirty_texture = false;
return;
}
- q->m_dirty_texture = false;
+ m_dirty_texture = false;
QImage tmp;
bool bgra = false;
bool needsConvert = false;
- if (q->m_image.format() == QImage::Format_RGB32 || q->m_image.format() == QImage::Format_ARGB32_Premultiplied) {
+ if (m_image.format() == QImage::Format_RGB32 || m_image.format() == QImage::Format_ARGB32_Premultiplied) {
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
if (rhi->isTextureFormatSupported(QRhiTexture::BGRA8)) {
- tmp = q->m_image;
+ tmp = m_image;
bgra = true;
} else {
needsConvert = true;
@@ -386,14 +383,14 @@ void QSGPlainTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch
#else
needsConvert = true;
#endif
- } else if (q->m_image.format() == QImage::Format_RGBX8888 || q->m_image.format() == QImage::Format_RGBA8888_Premultiplied) {
- tmp = q->m_image;
+ } else if (m_image.format() == QImage::Format_RGBX8888 || m_image.format() == QImage::Format_RGBA8888_Premultiplied) {
+ tmp = m_image;
} else {
needsConvert = true;
}
if (needsConvert)
- tmp = q->m_image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
+ tmp = m_image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
// Downscale the texture to fit inside the max texture limit if it is too big.
// It would be better if the image was already downscaled to the right size,
@@ -405,45 +402,45 @@ void QSGPlainTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch
const int max = rhi->resourceLimit(QRhi::TextureSizeMax);
if (tmp.width() > max || tmp.height() > max) {
tmp = tmp.scaled(qMin(max, tmp.width()), qMin(max, tmp.height()), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- q->m_texture_size = tmp.size();
+ m_texture_size = tmp.size();
}
- if ((q->mipmapFiltering() != QSGTexture::None
- || q->horizontalWrapMode() != QSGTexture::ClampToEdge
- || q->verticalWrapMode() != QSGTexture::ClampToEdge)
+ if ((mipmapFiltering() != QSGTexture::None
+ || horizontalWrapMode() != QSGTexture::ClampToEdge
+ || verticalWrapMode() != QSGTexture::ClampToEdge)
&& !rhi->isFeatureSupported(QRhi::NPOTTextureRepeat))
{
const int w = qNextPowerOfTwo(tmp.width() - 1);
const int h = qNextPowerOfTwo(tmp.height() - 1);
if (tmp.width() != w || tmp.height() != h) {
tmp = tmp.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- q->m_texture_size = tmp.size();
+ m_texture_size = tmp.size();
}
}
- bool needsRebuild = q->m_texture && q->m_texture->pixelSize() != q->m_texture_size;
+ bool needsRebuild = m_texture && m_texture->pixelSize() != m_texture_size;
if (mipmappingChanged) {
- QRhiTexture::Flags f = q->m_texture->flags();
+ QRhiTexture::Flags f = m_texture->flags();
f.setFlag(QRhiTexture::MipMapped, hasMipMaps);
f.setFlag(QRhiTexture::UsedWithGenerateMips, hasMipMaps);
- q->m_texture->setFlags(f);
+ m_texture->setFlags(f);
needsRebuild = true;
}
- if (!q->m_texture) {
+ if (!m_texture) {
QRhiTexture::Flags f;
if (hasMipMaps)
f |= QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips;
- q->m_texture = rhi->newTexture(bgra ? QRhiTexture::BGRA8 : QRhiTexture::RGBA8, q->m_texture_size, 1, f);
+ m_texture = rhi->newTexture(bgra ? QRhiTexture::BGRA8 : QRhiTexture::RGBA8, m_texture_size, 1, f);
needsRebuild = true;
}
if (needsRebuild) {
- if (!q->m_texture->build()) {
+ if (!m_texture->build()) {
qWarning("Failed to build texture for QSGPlainTexture (size %dx%d)",
- q->m_texture_size.width(), q->m_texture_size.height());
+ m_texture_size.width(), m_texture_size.height());
return;
}
}
@@ -451,18 +448,18 @@ void QSGPlainTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch
if (tmp.width() * 4 != tmp.bytesPerLine())
tmp = tmp.copy();
- resourceUpdates->uploadTexture(q->m_texture, tmp);
+ resourceUpdates->uploadTexture(m_texture, tmp);
if (hasMipMaps) {
- resourceUpdates->generateMips(q->m_texture);
- q->m_mipmaps_generated = true;
+ resourceUpdates->generateMips(m_texture);
+ m_mipmaps_generated = true;
}
- m_last_mipmap_filter = q->mipmapFiltering();
- q->m_texture_rect = QRectF(0, 0, 1, 1);
+ d->m_last_mipmap_filter = mipmapFiltering();
+ m_texture_rect = QRectF(0, 0, 1, 1);
- if (!q->m_retain_image)
- q->m_image = QImage();
+ if (!m_retain_image)
+ m_image = QImage();
}
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgplaintexture_p.h b/src/quick/scenegraph/util/qsgplaintexture_p.h
index 1eb0b59d2e..4bde505ec4 100644
--- a/src/quick/scenegraph/util/qsgplaintexture_p.h
+++ b/src/quick/scenegraph/util/qsgplaintexture_p.h
@@ -83,8 +83,13 @@ public:
void setImage(const QImage &image);
const QImage &image() { return m_image; }
+ int comparisonKey() const override;
+
void bind() override;
+ QRhiTexture *rhiTexture() const override;
+ void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
+
void setTexture(QRhiTexture *texture);
void setTextureFromNativeObject(QRhi *rhi, QQuickWindow::NativeObjectType type,
const void *nativeObjectPtr, int nativeLayout,
@@ -119,10 +124,6 @@ class QSGPlainTexturePrivate : public QSGTexturePrivate
{
Q_DECLARE_PUBLIC(QSGPlainTexture)
public:
- int comparisonKey() const override;
- QRhiTexture *rhiTexture() const override;
- void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
-
QSGTexture::Filtering m_last_mipmap_filter = QSGTexture::None;
};
diff --git a/src/quick/scenegraph/util/qsgrhiatlastexture.cpp b/src/quick/scenegraph/util/qsgrhiatlastexture.cpp
index 6b5f1aec4f..172cfc4791 100644
--- a/src/quick/scenegraph/util/qsgrhiatlastexture.cpp
+++ b/src/quick/scenegraph/util/qsgrhiatlastexture.cpp
@@ -184,7 +184,7 @@ void AtlasBase::invalidate()
m_texture = nullptr;
}
-void AtlasBase::updateRhiTexture(QRhiResourceUpdateBatch *resourceUpdates)
+void AtlasBase::commitTextureOperations(QRhiResourceUpdateBatch *resourceUpdates)
{
if (!m_allocated) {
m_allocated = true;
@@ -381,7 +381,7 @@ void Atlas::enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resour
}
TextureBase::TextureBase(AtlasBase *atlas, const QRect &textureRect)
- : QSGTexture(*(new TextureBasePrivate))
+ : QSGTexture(*(new QSGTexturePrivate))
, m_allocated_rect(textureRect)
, m_atlas(atlas)
{
@@ -392,16 +392,8 @@ TextureBase::~TextureBase()
m_atlas->remove(this);
}
-QRhiResourceUpdateBatch *TextureBase::workResourceUpdateBatch() const
+int TextureBase::comparisonKey() const
{
- Q_D(const TextureBase);
- return d->workResourceUpdateBatch;
-}
-
-int TextureBasePrivate::comparisonKey() const
-{
- Q_Q(const TextureBase);
-
// We need special care here: a typical comparisonKey() implementation
// returns a unique result when there is no underlying texture yet. This is
// not quite ideal for atlasing however since textures with the same atlas
@@ -410,23 +402,21 @@ int TextureBasePrivate::comparisonKey() const
// base the comparison on the atlas ptr; this way textures for the same
// atlas are considered equal
- return int(qintptr(q->m_atlas));
+ return int(qintptr(m_atlas));
}
-QRhiTexture *TextureBasePrivate::rhiTexture() const
+QRhiTexture *TextureBase::rhiTexture() const
{
- Q_Q(const TextureBase);
- return q->m_atlas->m_texture;
+ return m_atlas->m_texture;
}
-void TextureBasePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+void TextureBase::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
{
- Q_Q(TextureBase);
#ifdef QT_NO_DEBUG
Q_UNUSED(rhi);
#endif
- Q_ASSERT(rhi == q->m_atlas->m_rhi);
- q->m_atlas->updateRhiTexture(resourceUpdates);
+ Q_ASSERT(rhi == m_atlas->m_rhi);
+ m_atlas->commitTextureOperations(resourceUpdates);
}
Texture::Texture(Atlas *atlas, const QRect &textureRect, const QImage &image)
@@ -449,7 +439,7 @@ Texture::~Texture()
delete m_nonatlas_texture;
}
-QSGTexture *Texture::removedFromAtlas() const
+QSGTexture *Texture::removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates) const
{
if (!m_nonatlas_texture) {
m_nonatlas_texture = new QSGPlainTexture;
@@ -465,7 +455,7 @@ QSGTexture *Texture::removedFromAtlas() const
QRhiTexture *extractTex = rhi->newTexture(m_atlas->texture()->format(), r.size());
if (extractTex->build()) {
bool ownResUpd = false;
- QRhiResourceUpdateBatch *resUpd = workResourceUpdateBatch(); // ### Qt 6: should be an arg to this function
+ QRhiResourceUpdateBatch *resUpd = resourceUpdates;
if (!resUpd) {
ownResUpd = true;
resUpd = rhi->nextResourceUpdateBatch();
diff --git a/src/quick/scenegraph/util/qsgrhiatlastexture_p.h b/src/quick/scenegraph/util/qsgrhiatlastexture_p.h
index 50d7b2a53f..739498f137 100644
--- a/src/quick/scenegraph/util/qsgrhiatlastexture_p.h
+++ b/src/quick/scenegraph/util/qsgrhiatlastexture_p.h
@@ -71,7 +71,6 @@ namespace QSGRhiAtlasTexture
class Texture;
class TextureBase;
-class TextureBasePrivate;
class Atlas;
class Manager : public QObject
@@ -105,7 +104,7 @@ public:
~AtlasBase();
void invalidate();
- void updateRhiTexture(QRhiResourceUpdateBatch *resourceUpdates);
+ void commitTextureOperations(QRhiResourceUpdateBatch *resourceUpdates);
void remove(TextureBase *t);
QSGDefaultRenderContext *renderContext() const { return m_rc; }
@@ -153,34 +152,25 @@ private:
class TextureBase : public QSGTexture
{
- Q_DECLARE_PRIVATE(TextureBase)
Q_OBJECT
public:
TextureBase(AtlasBase *atlas, const QRect &textureRect);
~TextureBase();
+ int comparisonKey() const override;
int textureId() const override { return 0; } // not used
void bind() override { } // not used
+ QRhiTexture *rhiTexture() const override;
+ void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
bool isAtlasTexture() const override { return true; }
QRect atlasSubRect() const { return m_allocated_rect; }
- QRhiResourceUpdateBatch *workResourceUpdateBatch() const;
-
protected:
QRect m_allocated_rect;
AtlasBase *m_atlas;
};
-class TextureBasePrivate : public QSGTexturePrivate
-{
- Q_DECLARE_PUBLIC(TextureBase)
-public:
- int comparisonKey() const override;
- QRhiTexture *rhiTexture() const override;
- void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
-};
-
class Texture : public TextureBase
{
Q_OBJECT
@@ -198,7 +188,7 @@ public:
QRect atlasSubRect() const { return m_allocated_rect; }
QRect atlasSubRectWithoutPadding() const { return m_allocated_rect.adjusted(1, 1, -1, -1); }
- QSGTexture *removedFromAtlas() const override;
+ QSGTexture *removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates) const override;
void releaseImage() { m_image = QImage(); }
const QImage &image() const { return m_image; }
diff --git a/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp b/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
index 93fc213f2e..77fded6c21 100644
--- a/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
+++ b/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
@@ -39,8 +39,8 @@
#include "qsgshadersourcebuilder_p.h"
-#include <QtGui/qopenglcontext.h>
-#include <QtGui/qopenglshaderprogram.h>
+#include <qopenglcontext.h>
+#include <qopenglshaderprogram.h>
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
diff --git a/src/quick/scenegraph/util/qsgsimplematerial.cpp b/src/quick/scenegraph/util/qsgsimplematerial.cpp
deleted file mode 100644
index 4bbc2b17ba..0000000000
--- a/src/quick/scenegraph/util/qsgsimplematerial.cpp
+++ /dev/null
@@ -1,258 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \class QSGSimpleMaterialShader
-
- \brief The QSGSimpleMaterialShader class provides a convenient way of
- building custom OpenGL-based materials for the scene graph.
-
- \inmodule QtQuick
- \ingroup qtquick-scenegraph-materials
-
- \deprecated
-
- \warning This utility class is only functional when running with the legacy
- OpenGL renderer of the Qt Quick scenegraph. Its usage is not recommended in
- new application code.
-
- Where the QSGMaterial and QSGMaterialShader API requires a bit of
- boilerplate code to create a functioning material, the
- QSGSimpleMaterialShader tries to hide some of this through the use
- of templates.
-
- QSGSimpleMaterialShader::vertexShader() and
- QSGSimpleMaterialShader::fragmentShader() are used to specify the
- actual shader source code. The names of the vertex attributes
- should be listed in the QSGSimpleMaterialShader::attributes()
-
- QSGSimpleMaterialShader::updateState() is used to push the material
- state to the OpenGL shader program.
-
- The actual OpenGL shader program is accessible through the
- QSGSimpleMaterialShader::program() function.
-
- Each QSGSimpleMaterialShader implementation operates on a unique
- state struct. The state struct must be declared using the
- \c {QSG_DECLARE_SIMPLE_SHADER} macro.
-
- Here is a simple example of a custom solid-color:
-
- \code
- struct Color
- {
- float r, g, b, a;
- };
-
- class MinimalShader : public QSGSimpleMaterialShader<Color>
- {
- QSG_DECLARE_SIMPLE_SHADER(MinimalShader, Color)
- public:
-
- const char *vertexShader() const {
- return
- "attribute highp vec4 vertex; \n"
- "uniform highp mat4 qt_Matrix; \n"
- "void main() { \n"
- " gl_Position = qt_Matrix * vertex; \n"
- "}";
- }
-
- const char *fragmentShader() const {
- return
- "uniform lowp float qt_Opacity; \n"
- "uniform lowp vec4 color; \n"
- "void main() { \n"
- " gl_FragColor = color * qt_Opacity; \n"
- "}";
- }
-
- QList<QByteArray> attributes() const {
- return QList<QByteArray>() << "vertex";
- }
-
- void updateState(const Color *color, const Color *) {
- program()->setUniformValue("color", color->r, color->g, color->b, color->a);
- }
-
- };
- \endcode
-
- Instances of materials using this shader can be created using the
- createMaterial() function which will be defined by the
- QSG_DECLARE_SIMPLE_SHADER macro.
-
- \code
- QSGSimpleMaterial<Color> *material = MinimalShader::createMaterial();
- material->state()->r = 1;
- material->state()->g = 0;
- material->state()->b = 0;
- material->state()->a = 1;
-
- node->setMaterial(material);
- \endcode
-
- The scene graph will often try to find materials that have the
- same or at least similar state so that these can be batched
- together inside the renderer, which gives better performance. To
- specify sortable material states, use
- QSG_DECLARE_SIMPLE_COMPARABLE_SHADER instead of
- QSG_DECLARE_SIMPLE_SHADER. The state struct must then also define
- the function:
-
- \code
- int compare(const Type *other) const;
- \endcode
-
- \warning The QSGSimpleMaterialShader relies on template
- instantiation to create a QSGMaterialType which the scene graph
- renderer internally uses to identify this shader. For this reason,
- the unique QSGSimpleMaterialShader implementation must be
- instantiated with a unique C++ type.
-
- \note All classes with QSG prefix should be used solely on the scene graph's
- rendering thread. See \l {Scene Graph and Rendering} for more information.
-
- \sa {Scene Graph - Simple Material}
- */
-
-/*!
- \macro QSG_DECLARE_SIMPLE_SHADER(Shader, State)
- \relates QSGSimpleMaterialShader
-
- This macro is used to declare a QSGMaterialType and a \c
- createMaterial() function for \a Shader with the given \a State.
- */
-
-/*!
- \macro QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State)
- \relates QSGSimpleMaterialShader
-
- This macro is used to declare a QSGMaterialType and a \c
- createMaterial() function for \a Shader with the given \a State,
- where the \a State class must define a compare function on the
- form:
-
- \code
- int compare(const State *other) const;
- \endcode
-*/
-
-
-/*!
- \fn template <typename State> char const *const *QSGSimpleMaterialShader<State>::attributeNames() const
- \internal
- */
-
-/*!
- \fn template <typename State> void QSGSimpleMaterialShader<State>::initialize()
- \internal
- */
-
-/*!
- \fn template <typename State> void QSGSimpleMaterialShader<State>::resolveUniforms()
-
- Reimplement this function to resolve the location of named uniforms
- in the shader program.
-
- This function is called when the material shader is initialized.
- */
-
-/*!
- \fn template <typename State> const char *QSGSimpleMaterialShader<State>::uniformMatrixName() const
-
- Returns the name for the transform matrix uniform of this item.
- The default value is \c qt_Matrix.
- */
-
-/*!
- \fn template <typename State> const char *QSGSimpleMaterialShader<State>::uniformOpacityName() const
-
- Returns the name for the opacity uniform of this item.
- The default value is \c qt_Opacity.
- */
-
-/*!
- \fn template <typename State> void QSGSimpleMaterialShader<State>::updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
- \internal
- */
-
-
-/*!
- \fn template <typename State> QList<QByteArray> QSGSimpleMaterialShader<State>::attributes() const
-
- Returns a list of names, declaring the vertex attributes in the
- vertex shader.
-*/
-
-/*!
- \fn template <typename State> void QSGSimpleMaterialShader<State>::updateState(const State *newState, const State *oldState)
-
- Called whenever the state of this shader should be updated from
- \a oldState to \a newState, typical for each new set of
- geometries being drawn.
-
- Both the old and the new state are passed in so that the
- implementation can compare and minimize the state changes when
- applicable.
-*/
-
-/*!
- \class QSGSimpleMaterial
-
- \deprecated
-
- \inmodule QtQuick
- \ingroup qtquick-scenegraph-materials
-
- \brief The QSGSimpleMaterial class is a template generated class
- used to store the state used with a QSGSimpleMateralShader.
-
- The state of the material is accessible through the template
- generated state() function.
-
- \inmodule QtQuick
-
- \note All classes with QSG prefix should be used solely on the scene graph's
- rendering thread. See \l {Scene Graph and Rendering} for more information.
-
- \sa QSGSimpleMaterialShader
-*/
-
-
diff --git a/src/quick/scenegraph/util/qsgsimplematerial.h b/src/quick/scenegraph/util/qsgsimplematerial.h
deleted file mode 100644
index 78cd05f2d8..0000000000
--- a/src/quick/scenegraph/util/qsgsimplematerial.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSGSIMPLEMATERIAL_H
-#define QSGSIMPLEMATERIAL_H
-
-#include <QtQuick/qsgmaterial.h>
-
-QT_BEGIN_NAMESPACE
-
-#if QT_DEPRECATED_SINCE(5, 15)
-
-template <typename State>
-class QSGSimpleMaterialShader : public QSGMaterialShader
-{
-public:
- void initialize() override {
- QSGMaterialShader::initialize();
-#if QT_CONFIG(opengl)
- m_id_matrix = program()->uniformLocation(uniformMatrixName());
- if (m_id_matrix < 0) {
- qFatal("QSGSimpleMaterialShader does not implement 'uniform highp mat4 %s;' in its vertex shader",
- uniformMatrixName());
- }
-
- const char *opacity = uniformOpacityName();
- if (opacity) {
- m_id_opacity = program()->uniformLocation(uniformOpacityName());
- if (m_id_opacity < 0) {
- qFatal("QSGSimpleMaterialShader does not implement 'uniform lowp float %s' in its fragment shader",
- uniformOpacityName());
- }
- } else {
- m_id_opacity = -1;
- }
-#endif
- resolveUniforms();
- }
-
- // ### Qt 6: make both virtual and fix docs
- const char *uniformMatrixName() const { return "qt_Matrix"; }
- const char *uniformOpacityName() const { return "qt_Opacity"; }
-
- void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
-
- QT_DEPRECATED_X("QSGSimpleMaterialShader is going to be removed in Qt 6.0. Use QSGMaterialShader instead.")
- virtual void updateState(const State *newState, const State *oldState) = 0;
-
- virtual void resolveUniforms() {}
-
- virtual QList<QByteArray> attributes() const = 0;
-
- char const *const *attributeNames() const override
- {
- if (m_attribute_pointers.size())
- return m_attribute_pointers.constData();
-
- QList<QByteArray> names = attributes();
-
- // Calculate the total number of bytes needed, so we don't get rellocs and
- // bad pointers while copying over the individual names.
- // Add an extra byte pr entry for the '\0' char.
- int total = 0;
- for (int i=0; i<names.size(); ++i)
- total += names.at(i).size() + 1;
- m_attribute_name_data.reserve(total);
-
- // Copy over the names
- for (int i=0; i<names.size(); ++i) {
- m_attribute_pointers << m_attribute_name_data.constData() + m_attribute_name_data.size();
- m_attribute_name_data.append(names.at(i));
- m_attribute_name_data.append('\0');
- }
-
- // Append the "null" terminator
- m_attribute_pointers << 0;
-
- return m_attribute_pointers.constData();
- }
-
-private:
- int m_id_matrix;
- int m_id_opacity;
-
- mutable QByteArray m_attribute_name_data;
- mutable QVector<const char *> m_attribute_pointers;
-};
-
-#define QSG_DECLARE_SIMPLE_SHADER(Shader, State) \
-static QSGMaterialShader *createShader() \
-{ \
- return new Shader; \
-} \
-public: \
-static QSGSimpleMaterial<State> *createMaterial() \
-{ \
- return new QSGSimpleMaterial<State>(createShader); \
-}
-
-
-typedef QSGMaterialShader *(*PtrShaderCreateFunc)();
-
-
-template <typename State>
-class QSGSimpleMaterial : public QSGMaterial
-{
-public:
-#ifndef Q_CLANG_QDOC
- QT_DEPRECATED_X("QSGSimpleMaterial is going to be removed in Qt 6.0. Use QSGMaterial instead.")
- QSGSimpleMaterial(const State &aState, PtrShaderCreateFunc func)
- : m_state(aState)
- , m_func(func)
- {
- }
-
- QT_DEPRECATED_X("QSGSimpleMaterial is going to be removed in Qt 6.0. Use QSGMaterial instead.")
- QSGSimpleMaterial(PtrShaderCreateFunc func)
- : m_func(func)
- {
- }
-
- QSGMaterialShader *createShader() const override { return m_func(); }
- QSGMaterialType *type() const override { return &m_type; }
-
- State *state() { return &m_state; }
- const State *state() const { return &m_state; }
-#endif
-
-private:
- static QSGMaterialType m_type;
- State m_state;
- PtrShaderCreateFunc m_func;
-};
-
-#define QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State) \
-static QSGMaterialShader *createShader() \
-{ \
- return new Shader; \
-} \
-public: \
-static QSGSimpleMaterialComparableMaterial<State> *createMaterial() \
-{ \
- return new QSGSimpleMaterialComparableMaterial<State>(createShader); \
-}
-
-template <typename State>
-class QSGSimpleMaterialComparableMaterial : public QSGSimpleMaterial<State>
-{
-
-public:
- QSGSimpleMaterialComparableMaterial(const State &state, PtrShaderCreateFunc func)
- : QSGSimpleMaterial<State>(state, func) {}
-
- QSGSimpleMaterialComparableMaterial(PtrShaderCreateFunc func)
- : QSGSimpleMaterial<State>(func) {}
-
- int compare(const QSGMaterial *other) const override {
- return QSGSimpleMaterialComparableMaterial<State>::state()->compare(static_cast<const QSGSimpleMaterialComparableMaterial<State> *>(other)->state());
- }
-};
-
-
-template <typename State>
-QSGMaterialType QSGSimpleMaterial<State>::m_type;
-
-
-template <typename State>
-Q_INLINE_TEMPLATE void QSGSimpleMaterialShader<State>::updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
-{
-#if QT_CONFIG(opengl)
- if (state.isMatrixDirty())
- program()->setUniformValue(m_id_matrix, state.combinedMatrix());
- if (state.isOpacityDirty() && m_id_opacity >= 0)
- program()->setUniformValue(m_id_opacity, state.opacity());
-#else
- Q_UNUSED(state)
-#endif
- State *ns = static_cast<QSGSimpleMaterial<State> *>(newMaterial)->state();
- State *old = nullptr;
- if (oldMaterial)
- old = static_cast<QSGSimpleMaterial<State> *>(oldMaterial)->state();
- updateState(ns, old);
-}
-
-#endif
-
-QT_END_NAMESPACE
-
-
-#endif
diff --git a/src/quick/scenegraph/util/qsgsimplerectnode.cpp b/src/quick/scenegraph/util/qsgsimplerectnode.cpp
index 7b96a3fdde..de961d4f26 100644
--- a/src/quick/scenegraph/util/qsgsimplerectnode.cpp
+++ b/src/quick/scenegraph/util/qsgsimplerectnode.cpp
@@ -51,10 +51,9 @@ QT_BEGIN_NAMESPACE
\warning This utility class is only functional when running with the default
or software backends of the Qt Quick scenegraph. As an alternative, prefer
- using QSGRectangleNode via QQuickWindow::createRectangleNode() or
- QSGEngine::createRectangleNode().
-
- \deprecated
+ using QSGRectangleNode via QQuickWindow::createRectangleNode(). However, this
+ standalone class is still useful when used via subclassing and the
+ application knows that no special scenegraph backends will be involved.
*/
diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
index 1d0a423aa9..8dbfcad38b 100644
--- a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
+++ b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
@@ -99,10 +99,9 @@ static void qsgsimpletexturenode_update(QSGGeometry *g,
\warning This utility class is only functional when running with the default
or software backends of the Qt Quick scenegraph. As an alternative, prefer
- using QSGImageNode via QQuickWindow::createImageNode() or
- QSGEngine::createImageNode().
-
- \deprecated
+ using QSGImageNode via QQuickWindow::createImageNode(). However, this
+ standalone class is still useful when used via subclassing and the
+ application knows that no special scenegraph backends will be involved.
*/
/*!
diff --git a/src/quick/scenegraph/util/qsgtexturematerial.cpp b/src/quick/scenegraph/util/qsgtexturematerial.cpp
index 67b8748119..e6311fc652 100644
--- a/src/quick/scenegraph/util/qsgtexturematerial.cpp
+++ b/src/quick/scenegraph/util/qsgtexturematerial.cpp
@@ -40,8 +40,8 @@
#include "qsgtexturematerial_p.h"
#include <private/qsgtexture_p.h>
#if QT_CONFIG(opengl)
-# include <QtGui/qopenglshaderprogram.h>
-# include <QtGui/qopenglfunctions.h>
+# include <qopenglshaderprogram.h>
+# include <qopenglfunctions.h>
#endif
#include <QtGui/private/qrhi_p.h>
@@ -168,7 +168,7 @@ void QSGOpaqueTextureMaterialRhiShader::updateSampledImage(RenderState &state, i
}
}
- t->updateRhiTexture(state.rhi(), state.resourceUpdateBatch());
+ t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
*texture = t;
}