Make threaded WorldView buffer swaps optional

This commit is contained in:
David Vierra 2016-02-06 23:45:35 -10:00
parent 2ec18c1e9b
commit 35cf39d9c3

View File

@ -70,6 +70,7 @@ def anglesToVector(yaw, pitch):
dz = math.cos(math.radians(yaw)) * math.cos(math.radians(pitch)) dz = math.cos(math.radians(yaw)) * math.cos(math.radians(pitch))
return Vector(*map(nanzero, [dx, dy, dz])) return Vector(*map(nanzero, [dx, dy, dz]))
THREADED_BUFFER_SWAP = True
class BufferSwapper(QtCore.QObject): class BufferSwapper(QtCore.QObject):
def __init__(self, view): def __init__(self, view):
@ -136,14 +137,16 @@ class WorldView(QGLWidget):
validateWidgetQGLContext(self) validateWidgetQGLContext(self)
self.setAutoBufferSwap(False)
self.bufferSwapDone = True self.bufferSwapDone = True
self.bufferSwapThread = QtCore.QThread()
self.bufferSwapper = BufferSwapper(self) if THREADED_BUFFER_SWAP:
self.bufferSwapper.moveToThread(self.bufferSwapThread) self.setAutoBufferSwap(False)
self.doSwapBuffers.connect(self.bufferSwapper.swap) self.bufferSwapThread = QtCore.QThread()
self.bufferSwapThread.start() self.bufferSwapper = BufferSwapper(self)
self.bufferSwapper.moveToThread(self.bufferSwapThread)
self.doSwapBuffers.connect(self.bufferSwapper.swap)
self.bufferSwapThread.start()
self.setAcceptDrops(True) self.setAcceptDrops(True)
self.setSizePolicy(QtGui.QSizePolicy.Policy.Expanding, QtGui.QSizePolicy.Policy.Expanding) self.setSizePolicy(QtGui.QSizePolicy.Policy.Expanding, QtGui.QSizePolicy.Policy.Expanding)
@ -195,8 +198,9 @@ class WorldView(QGLWidget):
def dealloc(self): def dealloc(self):
log.info("Deallocating GL resources for worldview %s", self) log.info("Deallocating GL resources for worldview %s", self)
self.waitForSwapThread() if THREADED_BUFFER_SWAP:
self.bufferSwapThread.quit() self.waitForSwapThread()
self.bufferSwapThread.quit()
self.makeCurrent() self.makeCurrent()
self.renderGraph.dealloc() self.renderGraph.dealloc()
@ -573,6 +577,7 @@ class WorldView(QGLWidget):
super(WorldView, self).glDraw(*args, **kwargs) super(WorldView, self).glDraw(*args, **kwargs)
shouldRender = True shouldRender = True
def paintGL(self): def paintGL(self):
if not self.shouldRender: if not self.shouldRender:
return return
@ -585,9 +590,10 @@ class WorldView(QGLWidget):
with profiler.context("renderScene"): with profiler.context("renderScene"):
rendernode.renderScene(self.renderGraph) rendernode.renderScene(self.renderGraph)
self.doneCurrent() if THREADED_BUFFER_SWAP:
self.bufferSwapDone = False self.doneCurrent()
self.doSwapBuffers.emit() self.bufferSwapDone = False
self.doSwapBuffers.emit()
except: except:
self.shouldRender = False self.shouldRender = False
raise raise