From 255e9e6435ca8b1d90c4479b98069d44eb191a0d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 20 Sep 2016 19:46:26 -0700 Subject: [PATCH] Add support for executing arbitrary commands on the texture transfer thread --- libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp | 15 +++++++++++++-- libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.h | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp b/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp index 4cb8e4fad1..7a709dfce3 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp @@ -97,12 +97,23 @@ void GLTextureTransferHelper::shutdown() { #endif } +void GLTextureTransferHelper::queueExecution(VoidLambda lambda) { + Lock lock(_mutex); + _pendingCommands.push_back(lambda); +} + bool GLTextureTransferHelper::process() { - // Take any new textures off the queue + // Take any new textures or commands off the queue + VoidLambdaList pendingCommands; TextureList newTransferTextures; { Lock lock(_mutex); newTransferTextures.swap(_pendingTextures); + pendingCommands.swap(_pendingCommands); + } + + for (auto command : pendingCommands) { + command(); } if (!newTransferTextures.empty()) { @@ -144,7 +155,7 @@ bool GLTextureTransferHelper::process() { gltexture->finishTransfer(); //glNamedFramebufferTexture(_readFramebuffer, GL_COLOR_ATTACHMENT0, gltexture->_id, 0); //glBlitNamedFramebuffer(_readFramebuffer, _drawFramebuffer, 0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST); - //clientWait(); + clientWait(); gltexture->_contentStamp = gltexture->_gpuObject.getDataStamp(); gltexture->updateSize(); gltexture->setSyncState(gpu::gl::GLSyncState::Transferred); diff --git a/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.h b/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.h index fe7414e370..289aec40bb 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.h +++ b/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.h @@ -28,10 +28,13 @@ using TextureListIterator = TextureList::iterator; class GLTextureTransferHelper : public GenericThread { public: + using VoidLambda = std::function; + using VoidLambdaList = std::list; using Pointer = std::shared_ptr; GLTextureTransferHelper(); ~GLTextureTransferHelper(); void transferTexture(const gpu::TexturePointer& texturePointer); + void queueExecution(VoidLambda lambda); void setup() override; void shutdown() override; @@ -47,6 +50,8 @@ private: #endif // A mutex for protecting items access on the render and transfer threads Mutex _mutex; + // Commands that have been submitted for execution on the texture transfer thread + VoidLambdaList _pendingCommands; // Textures that have been submitted for transfer TextureList _pendingTextures; // Textures currently in the transfer process