Zero-copy rendering with Qt FBO and dmabuf EGLImage – Shared context issue
-
I am building a zero-copy rendering pipeline on RK3568 (Mali-G52, Qt 5.x with EGL backend).
The idea is:
- Import a dmabuf into an
EGLImageKHR - Bind it to a GL texture
- Render Qt UI (
QOpenGLFramebufferObject) directly into this texture
The problem:
- To create an
EGLImageKHR, I need a validEGLDisplay. - Qt’s
QOpenGLContextdoes not expose the underlyingEGLDisplay. - In Qt5,
QOpenGLContext::nativeHandle()always returnsQVariant(null). - Even if I try
setNativeHandle(), it only echoes back what I set — Qt still creates its own internal EGL context.
Minimal test code:
QOpenGLContext* ctx = new QOpenGLContext; ctx->create(); qDebug() << ctx->nativeHandle(); // always null QVariant nativeHandle = QVariant::fromValue<void*>(eglGetCurrentContext()); ctx->setNativeHandle(nativeHandle); qDebug() << ctx->nativeHandle(); // echoes back, but not really usedThis results in two isolated contexts:
- Qt’s internal context (used by QPainter / QFBO rendering)
- My native EGLContext (used to create
EGLImageKHRfrom dmabuf)
Since these are not shared, Qt cannot render directly into the dmabuf-backed texture. That breaks the zero-copy requirement, because the only fallback is copying with
glBlitFramebufferor PBOs.My question:
Is there any supported way in Qt5 to:- Make
QOpenGLContextshare resources with an existing nativeEGLContext, or - Retrieve the actual
EGLDisplay/EGLContextfrom Qt so that I can create theEGLImageKHRinside the same context?
Goal: Render Qt FBO content directly into dmabuf (via EGLImage), without extra copies.
- Import a dmabuf into an
-
makeQCurrent();
eglDisplay_ = eglGetCurrentDisplay();
eglCtx_ = eglGetCurrentContext();
if (eglDisplay_ == EGL_NO_DISPLAY || eglCtx_ == EGL_NO_CONTEXT) {
fprintf(stderr, "[Core] Cannot get native EGL resources form qt.\n");
}
doneQCurrent();
————————————————
版权声明:本文为CSDN博主「SweerItTer」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40087136/article/details/151912946 -
S SweerItTer marked this topic as a regular topic on
-
S SweerItTer marked this topic as a question on
-
S SweerItTer has marked this topic as solved on