diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 5 | ||||
-rw-r--r-- | src/quick/items/qquickwindow_p.h | 9 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgtexture.cpp | 38 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgtexture_platform.h | 4 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgplaintexture.cpp | 17 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgplaintexture_p.h | 9 |
6 files changed, 70 insertions, 12 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 37525d99d8..6a57553b21 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -4689,14 +4689,15 @@ QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image, CreateText QSGTexture *QQuickWindowPrivate::createTextureFromNativeTexture(quint64 nativeObjectHandle, int nativeLayout, const QSize &size, - QQuickWindow::CreateTextureOptions options) const + QQuickWindow::CreateTextureOptions options, + TextureFromNativeTextureFlags flags) const { if (!rhi) return nullptr; QSGPlainTexture *texture = new QSGPlainTexture; texture->setTextureFromNativeTexture(rhi, nativeObjectHandle, nativeLayout, - size, options.testFlag(QQuickWindow::TextureHasMipmaps)); + size, options, flags); texture->setHasAlphaChannel(options & QQuickWindow::TextureHasAlphaChannel); // note that the QRhiTexture does not (and cannot) own the native object texture->setOwnsTexture(true); // texture meaning the QRhiTexture here, not the native object diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index 67bce9f02c..869324c317 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -255,10 +255,16 @@ public: bool emitError(QQuickWindow::SceneGraphError error, const QString &msg); + enum TextureFromNativeTextureFlag { + NativeTextureIsExternalOES = 0x01 + }; + Q_DECLARE_FLAGS(TextureFromNativeTextureFlags, TextureFromNativeTextureFlag) + QSGTexture *createTextureFromNativeTexture(quint64 nativeObjectHandle, int nativeLayout, const QSize &size, - QQuickWindow::CreateTextureOptions options) const; + QQuickWindow::CreateTextureOptions options, + TextureFromNativeTextureFlags flags = {}) const; QQuickItem::UpdatePaintNodeData updatePaintNodeData; @@ -388,6 +394,7 @@ public: }; Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWindowPrivate::FocusOptions) +Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWindowPrivate::TextureFromNativeTextureFlags) QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgtexture.cpp b/src/quick/scenegraph/coreapi/qsgtexture.cpp index 898f8cbe33..f09ff9ad85 100644 --- a/src/quick/scenegraph/coreapi/qsgtexture.cpp +++ b/src/quick/scenegraph/coreapi/qsgtexture.cpp @@ -759,6 +759,44 @@ QSGTexture *QSGOpenGLTexture::fromNative(GLuint textureId, { return QQuickWindowPrivate::get(window)->createTextureFromNativeTexture(quint64(textureId), 0, size, options); } + +/*! + Creates a new QSGTexture wrapping an existing OpenGL texture object for + \a window. + + The native object specified in \a textureId is wrapped, but not owned, by + the resulting QSGTexture. The caller of the function is responsible for + deleting the returned QSGTexture, but that will not destroy the underlying + native object. + + This function is suitable only for textures that are meant to be + used with the \c{GL_TEXTURE_EXTERNAL_OES} target. + + \warning This function will return null if the scenegraph has not yet been + initialized. + + Use \a options to customize the texture attributes. Only the + TextureHasAlphaChannel and TextureHasMipmaps are taken into account here. + + \a size specifies the size in pixels. + + \note This function must be called on the scenegraph rendering thread. + + \since 6.1 + + \sa fromNative() + */ +QSGTexture *QSGOpenGLTexture::fromNativeExternalOES(GLuint textureId, + QQuickWindow *window, + const QSize &size, + QQuickWindow::CreateTextureOptions options) +{ + return QQuickWindowPrivate::get(window)->createTextureFromNativeTexture(quint64(textureId), + 0, + size, + options, + QQuickWindowPrivate::NativeTextureIsExternalOES); +} } // QNativeInterface GLuint QSGTexturePlatformOpenGL::nativeTexture() const diff --git a/src/quick/scenegraph/coreapi/qsgtexture_platform.h b/src/quick/scenegraph/coreapi/qsgtexture_platform.h index 69011c2605..d4d9ad50ed 100644 --- a/src/quick/scenegraph/coreapi/qsgtexture_platform.h +++ b/src/quick/scenegraph/coreapi/qsgtexture_platform.h @@ -67,6 +67,10 @@ struct Q_QUICK_EXPORT QSGOpenGLTexture QQuickWindow *window, const QSize &size, QQuickWindow::CreateTextureOptions options = {}); + static QSGTexture *fromNativeExternalOES(GLuint textureId, + QQuickWindow *window, + const QSize &size, + QQuickWindow::CreateTextureOptions options = {}); }; #endif diff --git a/src/quick/scenegraph/util/qsgplaintexture.cpp b/src/quick/scenegraph/util/qsgplaintexture.cpp index 030a496e33..6e59f9e607 100644 --- a/src/quick/scenegraph/util/qsgplaintexture.cpp +++ b/src/quick/scenegraph/util/qsgplaintexture.cpp @@ -101,14 +101,19 @@ void QSGPlainTexture::setTexture(QRhiTexture *texture) // RHI only } void QSGPlainTexture::setTextureFromNativeTexture(QRhi *rhi, - quint64 nativeObjectHandle, int nativeLayout, - const QSize &size, bool mipmap) + quint64 nativeObjectHandle, + int nativeLayout, + const QSize &size, + QQuickWindow::CreateTextureOptions options, + QQuickWindowPrivate::TextureFromNativeTextureFlags flags) { - QRhiTexture::Flags flags; - if (mipmap) - flags |= QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips; + QRhiTexture::Flags texFlags; + if (options.testFlag(QQuickWindow::TextureHasMipmaps)) + texFlags |= QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips; + if (flags.testFlag(QQuickWindowPrivate::NativeTextureIsExternalOES)) + texFlags |= QRhiTexture::ExternalOES; - QRhiTexture *t = rhi->newTexture(QRhiTexture::RGBA8, size, 1, flags); + QRhiTexture *t = rhi->newTexture(QRhiTexture::RGBA8, size, 1, texFlags); // ownership of the native object is never taken t->createFrom({nativeObjectHandle, nativeLayout}); diff --git a/src/quick/scenegraph/util/qsgplaintexture_p.h b/src/quick/scenegraph/util/qsgplaintexture_p.h index 33f47f7fa0..56e0492afa 100644 --- a/src/quick/scenegraph/util/qsgplaintexture_p.h +++ b/src/quick/scenegraph/util/qsgplaintexture_p.h @@ -53,7 +53,7 @@ #include <QtQuick/private/qtquickglobal_p.h> #include <QtQuick/private/qsgtexture_p.h> -#include <QtQuick/qquickwindow.h> +#include <QtQuick/private/qquickwindow_p.h> QT_BEGIN_NAMESPACE @@ -88,8 +88,11 @@ public: void setTexture(QRhiTexture *texture); void setTextureFromNativeTexture(QRhi *rhi, - quint64 nativeObjectHandle, int nativeLayout, - const QSize &size, bool mipmap); + quint64 nativeObjectHandle, + int nativeLayout, + const QSize &size, + QQuickWindow::CreateTextureOptions options, + QQuickWindowPrivate::TextureFromNativeTextureFlags flags); static QSGPlainTexture *fromImage(const QImage &image) { QSGPlainTexture *t = new QSGPlainTexture(); |