summaryrefslogtreecommitdiffstats
path: root/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp')
-rw-r--r--src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp
index 4ec929b6e..ecaa12d8b 100644
--- a/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp
+++ b/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp
@@ -93,6 +93,40 @@ QT_BEGIN_NAMESPACE
namespace Qt3DRender {
namespace Render {
+
+class TextureExtRendererLocker
+{
+public:
+ static void lock(GLTexture *tex)
+ {
+ if (!tex->isExternalRenderingEnabled())
+ return;
+ if (s_lockHash.keys().contains(tex)) {
+ ++s_lockHash[tex];
+ } else {
+ tex->externalRenderingLock()->lock();
+ s_lockHash[tex] = 1;
+ }
+ }
+ static void unlock(GLTexture *tex)
+ {
+ if (!tex->isExternalRenderingEnabled())
+ return;
+ if (!s_lockHash.keys().contains(tex))
+ return;
+
+ --s_lockHash[tex];
+ if (s_lockHash[tex] == 0) {
+ s_lockHash.remove(tex);
+ tex->externalRenderingLock()->unlock();
+ }
+ }
+private:
+ static QHash<GLTexture*, int> s_lockHash;
+};
+
+QHash<GLTexture*, int> TextureExtRendererLocker::s_lockHash = QHash<GLTexture*, int>();
+
static QHash<unsigned int, SubmissionContext*> static_contexts;
namespace {
@@ -475,6 +509,9 @@ void SubmissionContext::endDrawing(bool swapBuffers)
if (m_ownCurrent)
m_gl->doneCurrent();
decayTextureScores();
+ for (int i = 0; i < m_activeTextures.size(); ++i)
+ if (m_activeTextures[i].texture)
+ TextureExtRendererLocker::unlock(m_activeTextures[i].texture);
}
void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeId, const AttachmentPack &attachments, GLuint defaultFboId)
@@ -827,6 +864,8 @@ void SubmissionContext::bindFrameBufferAttachmentHelper(GLuint fboId, const Atta
if (!m_glHelper->frameBufferNeedsRenderBuffer(attachment)) {
QOpenGLTexture *glTex = rTex ? rTex->getOrCreateGLTexture() : nullptr;
if (glTex != nullptr) {
+ // The texture can not be rendered simultaniously by another renderer
+ Q_ASSERT(!rTex->isExternalRenderingEnabled());
if (fboSize.isEmpty())
fboSize = QSize(glTex->width(), glTex->height());
else
@@ -892,7 +931,10 @@ int SubmissionContext::activateTexture(TextureScope scope, GLTexture *tex, int o
if (glTex == nullptr)
return -1;
glTex->bind(onUnit);
+ if (m_activeTextures[onUnit].texture)
+ TextureExtRendererLocker::unlock(m_activeTextures[onUnit].texture);
m_activeTextures[onUnit].texture = tex;
+ TextureExtRendererLocker::lock(tex);
}
#if defined(QT3D_RENDER_ASPECT_OPENGL_DEBUG)