Disable per-frame context switch on present thread

This commit is contained in:
Brad Davis 2019-03-26 13:38:52 -07:00
parent 413091fed3
commit 0c78c8fd87

View file

@ -109,7 +109,6 @@ public:
Q_ASSERT(_context); Q_ASSERT(_context);
_context->makeCurrent(); _context->makeCurrent();
CHECK_GL_ERROR(); CHECK_GL_ERROR();
_context->doneCurrent();
while (!_shutdown) { while (!_shutdown) {
if (_pendingOtherThreadOperation) { if (_pendingOtherThreadOperation) {
PROFILE_RANGE(render, "MainThreadOp") PROFILE_RANGE(render, "MainThreadOp")
@ -129,6 +128,7 @@ public:
Lock lock(_mutex); Lock lock(_mutex);
_condition.wait(lock, [&] { return _finishedOtherThreadOperation; }); _condition.wait(lock, [&] { return _finishedOtherThreadOperation; });
} }
_context->makeCurrent();
} }
// Check for a new display plugin // Check for a new display plugin
@ -140,18 +140,16 @@ public:
if (newPlugin != currentPlugin) { if (newPlugin != currentPlugin) {
// Deactivate the old plugin // Deactivate the old plugin
if (currentPlugin != nullptr) { if (currentPlugin != nullptr) {
_context->makeCurrent();
currentPlugin->uncustomizeContext(); currentPlugin->uncustomizeContext();
CHECK_GL_ERROR(); CHECK_GL_ERROR();
_context->doneCurrent(); // Force completion of all pending GL commands
glFinish();
} }
if (newPlugin) { if (newPlugin) {
bool hasVsync = true; bool hasVsync = true;
QThread::setPriority(newPlugin->getPresentPriority()); QThread::setPriority(newPlugin->getPresentPriority());
bool wantVsync = newPlugin->wantVsync(); bool wantVsync = newPlugin->wantVsync();
_context->makeCurrent();
CHECK_GL_ERROR();
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
newPlugin->swapBuffers(); newPlugin->swapBuffers();
#endif #endif
@ -163,7 +161,8 @@ public:
newPlugin->setVsyncEnabled(hasVsync); newPlugin->setVsyncEnabled(hasVsync);
newPlugin->customizeContext(); newPlugin->customizeContext();
CHECK_GL_ERROR(); CHECK_GL_ERROR();
_context->doneCurrent(); // Force completion of all pending GL commands
glFinish();
} }
currentPlugin = newPlugin; currentPlugin = newPlugin;
_newPluginQueue.pop(); _newPluginQueue.pop();
@ -180,7 +179,6 @@ public:
} }
// Execute the frame and present it to the display device. // Execute the frame and present it to the display device.
_context->makeCurrent();
{ {
PROFILE_RANGE(render, "PluginPresent") PROFILE_RANGE(render, "PluginPresent")
gl::globalLock(); gl::globalLock();
@ -188,9 +186,9 @@ public:
gl::globalRelease(false); gl::globalRelease(false);
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
_context->doneCurrent();
} }
_context->doneCurrent();
Lock lock(_mutex); Lock lock(_mutex);
_context->moveToThread(qApp->thread()); _context->moveToThread(qApp->thread());
_shutdown = false; _shutdown = false;