diff --git a/app/render/backend/opengl/openglbackend.cpp b/app/render/backend/opengl/openglbackend.cpp index ec4a61d45..99d393919 100644 --- a/app/render/backend/opengl/openglbackend.cpp +++ b/app/render/backend/opengl/openglbackend.cpp @@ -159,6 +159,8 @@ void OpenGLBackend::EmitCachedFrameReady(const QList ×, const QVa OpenGLTexturePtr OpenGLBackend::CopyTexture(OpenGLTexturePtr input) { + input->Lock(); + QOpenGLContext* ctx = QOpenGLContext::currentContext(); OpenGLTexturePtr copy = std::make_shared(); @@ -176,5 +178,7 @@ OpenGLTexturePtr OpenGLBackend::CopyTexture(OpenGLTexturePtr input) copy_buffer_.Release(); copy_buffer_.Detach(); + input->Unlock(); + return copy; } diff --git a/app/render/backend/opengl/opengltexture.cpp b/app/render/backend/opengl/opengltexture.cpp index 036ef6096..57ea91edf 100644 --- a/app/render/backend/opengl/opengltexture.cpp +++ b/app/render/backend/opengl/opengltexture.cpp @@ -156,6 +156,16 @@ void OpenGLTexture::Upload(const void *data) Release(); } +void OpenGLTexture::Lock() +{ + mutex_.lock(); +} + +void OpenGLTexture::Unlock() +{ + mutex_.unlock(); +} + void OpenGLTexture::CreateInternal(QOpenGLContext* create_ctx, GLuint* tex, const void *data) { QOpenGLFunctions* f = create_ctx->functions(); diff --git a/app/render/backend/opengl/opengltexture.h b/app/render/backend/opengl/opengltexture.h index ef1c7c23e..1247a5a50 100644 --- a/app/render/backend/opengl/opengltexture.h +++ b/app/render/backend/opengl/opengltexture.h @@ -22,6 +22,7 @@ #define OPENGLTEXTURE_H #include +#include #include #include "codec/frame.h" @@ -59,6 +60,10 @@ public: void Upload(const void *data); + void Lock(); + + void Unlock(); + public slots: void Destroy(); @@ -75,6 +80,8 @@ private: PixelFormat::Format format_; + QMutex mutex_; + }; using OpenGLTexturePtr = std::shared_ptr; diff --git a/app/render/backend/opengl/openglworker.cpp b/app/render/backend/opengl/openglworker.cpp index 8c065a348..e1545c243 100644 --- a/app/render/backend/opengl/openglworker.cpp +++ b/app/render/backend/opengl/openglworker.cpp @@ -355,6 +355,8 @@ void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer) PixelFormat::Info format_info = PixelService::GetPixelFormatInfo(video_params().format()); + texture->texture()->Lock(); + QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions(); buffer_.Attach(texture->texture()); buffer_.Bind(); @@ -369,6 +371,8 @@ void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer) buffer_.Release(); buffer_.Detach(); + + texture->texture()->Unlock(); } void OpenGLWorker::FinishInit()