summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhigles2.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-03-25 12:39:02 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2021-05-19 17:35:35 +0200
commit8827cd657d12a037deb3e6f4f76271ee0bbd0b13 (patch)
tree6acbccb6ceda0714740a813da14a6f1abd139672 /src/gui/rhi/qrhigles2.cpp
parent2d9cc639a4a7a5e97979a6034364bd67dfa10c23 (diff)
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 <andy.nichols@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhigles2.cpp')
-rw-r--r--src/gui/rhi/qrhigles2.cpp33
1 files changed, 32 insertions, 1 deletions
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;
}