From 8827cd657d12a037deb3e6f4f76271ee0bbd0b13 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 25 Mar 2021 12:39:02 +0100 Subject: rhi: gl: Add support for importing an existing renderbuffer object Normally we only allow creating wrappers for texture objects. These can then be used with a QRhiTextureRenderTarget to allow rendering into an externally created texture. With OpenGL (ES), there are additional, special cases, especially on embedded. Consider EGLImages for example. An EGLImageKHR can be bound to a renderbuffer object (glEGLImageTargetRenderbufferStorageOES), which can then be associated with a framebuffer object to allow rendering into the external buffer represented by the EGLImage. To implement the same via QRhi one needs a way to create a wrapping QRhiRenderBuffer for the native OpenGL renderbuffer object. Here we add a createFrom() to QRhiRenderBuffer, while providing a dummy, default implementation. The only real implementation is in the OpenGL backend, which simply takes a renderbuffer id, without taking ownership. Task-number: QTBUG-92116 Change-Id: I4e68e665fb35a7d7803b7780db901c8bed5740e2 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhigles2.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/gui/rhi/qrhigles2.cpp') diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 43569d3752..8a5361b29a 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -1011,6 +1011,8 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const return caps.programBinary; case QRhi::ImageDataStride: return !caps.gles || caps.ctxMajor >= 3; + case QRhi::RenderBufferImport: + return true; default: Q_UNREACHABLE(); return false; @@ -4287,7 +4289,8 @@ void QGles2RenderBuffer::destroy() stencilRenderbuffer = 0; QRHI_RES_RHI(QRhiGles2); - rhiD->releaseQueue.append(e); + if (owns) + rhiD->releaseQueue.append(e); QRHI_PROF; QRHI_PROF_F(releaseRenderBuffer(this)); rhiD->unregisterResource(this); @@ -4375,6 +4378,34 @@ bool QGles2RenderBuffer::create() break; } + owns = true; + rhiD->registerResource(this); + return true; +} + +bool QGles2RenderBuffer::createFrom(NativeRenderBuffer src) +{ + if (!src.object) + return false; + + if (renderbuffer) + destroy(); + + QRHI_RES_RHI(QRhiGles2); + samples = rhiD->effectiveSampleCount(m_sampleCount); + + if (m_flags.testFlag(UsedWithSwapChainOnly)) + qWarning("RenderBuffer: UsedWithSwapChainOnly is meaningless when importing an existing native object"); + + if (!rhiD->ensureContext()) + return false; + + renderbuffer = src.object; + + QRHI_PROF; + QRHI_PROF_F(newRenderBuffer(this, false, false, samples)); + + owns = false; rhiD->registerResource(this); return true; } -- cgit v1.2.3