aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-01-11 15:41:39 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2021-01-14 10:12:13 +0100
commitc2c180e4ee58f8cfc104207b3b56e83ddcb7e79a (patch)
tree9473794cc5d112ee383032380a48aaad6901c670 /src/quick/scenegraph
parent653d5a4745ad2f20ae924527b7b31580eedc651b (diff)
Enable importing OpenGL textures for the GL_TEXTURE_EXTERNAL_OES target
Introduce a QSGOpenGLTexture::fromNativeExternalOES() function which internally passes in the flag QRhiTexture::ExternalOES when creating the wrapping QRhiTexture. Change-Id: I919e2539304d3aeaa6bc8e5953d96adc810abb12 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/scenegraph')
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture.cpp38
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture_platform.h4
-rw-r--r--src/quick/scenegraph/util/qsgplaintexture.cpp17
-rw-r--r--src/quick/scenegraph/util/qsgplaintexture_p.h9
4 files changed, 59 insertions, 9 deletions
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();