Skip to content

Commit

Permalink
Update the grid display list inside paintGL only
Browse files Browse the repository at this point in the history
Otherwise this may break if the OpenGL context is not current.
  • Loading branch information
tlecomte committed Nov 8, 2015
1 parent bd9113f commit fcac883
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions friture/plotting/glCanvasWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, parent, verticalScaleTransform, horizontalScaleTransform):
self.attachedItems = []

self.gridList = None
self.gridNeedsUpdating = True

self.horizontalScaleTransform = horizontalScaleTransform
self.verticalScaleTransform = verticalScaleTransform
Expand Down Expand Up @@ -104,7 +105,8 @@ def setGrid(self, xMajorTick, xMinorTick, yMajorTick, yMinorTick):
self.yMajorTick = self.verticalScaleTransform.toScreen(yMajorTick)
self.yMinorTick = self.verticalScaleTransform.toScreen(yMinorTick)

self.updateGrid()
# trigger a grid update on next paintGL call
self.gridNeedsUpdating = True

def updateGrid(self):
if self.gridList is None or self.gridList == 0:
Expand Down Expand Up @@ -149,6 +151,8 @@ def updateGrid(self):

GL.glEndList()

self.gridNeedsUpdating = False

def paintGL(self):
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glPushMatrix()
Expand Down Expand Up @@ -281,7 +285,8 @@ def drawTrackerText(self, painter):

def resizeGL(self, width, height):
self.setupViewport(self.width(), self.height())
self.updateGrid()

self.gridNeedsUpdating = True

# give the opportunity to the scales to adapt
self.resized.emit(self.width(), self.height())
Expand Down Expand Up @@ -320,6 +325,7 @@ def drawGrid(self):
if self.gridList == 0 or self.gridList is None:
raise RuntimeError("""Unable to generate a new display-list, context may not support display lists""")

if self.gridNeedsUpdating:
self.updateGrid()

GL.glCallList(self.gridList)
Expand Down

0 comments on commit fcac883

Please sign in to comment.