From 075583e06e065e5b19eea0d96dd396b4ceeb1a77 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Tue, 22 Mar 2016 17:11:37 +0000 Subject: [PATCH] Well. I am now using a separate GL context for every canvas. This fixes rendering on OSX VMs. There is a refresh issue running in a real OS (colour texture change), and I need to update docs in gl/__init__.py. --- fsl/fsleyes/gl/__init__.py | 33 +++++++------------------------ fsl/fsleyes/gl/wxglslicecanvas.py | 20 +++++++++++-------- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/fsl/fsleyes/gl/__init__.py b/fsl/fsleyes/gl/__init__.py index dffe3c51c..3eb4ab3f1 100644 --- a/fsl/fsleyes/gl/__init__.py +++ b/fsl/fsleyes/gl/__init__.py @@ -189,10 +189,8 @@ package also contains the following: import logging -import platform import os -import fsl.utils.async as async import fsl.utils.platform as fslplatform @@ -625,28 +623,12 @@ class WXGLCanvasTarget(object): """ import wx + import wx.glcanvas as wxgl self._glReady = False - self.Bind(wx.EVT_PAINT, self._mainDraw) - - # Using the Apple software renderer under OSX, - # we need to call refresh on the idle loop, - # otherwise refresh of multiple canvases (i.e. - # the OrthoPanel). gets all screwed up. Don't - # know why. - if platform.system() == 'Darwin' and \ - 'software' in fslplatform.glRenderer.lower(): - - def refresh(*a): - async.idle(self.Refresh) - - # On other platforms/renderers, - # we can call Refresh directly - else: - def refresh(*a): - self.Refresh() - self._refresh = refresh + self.__context = wxgl.GLContext(self, other=getWXGLContext()[0]) + self.Bind(wx.EVT_PAINT, self._mainDraw) def _initGL(self): @@ -704,15 +686,14 @@ class WXGLCanvasTarget(object): log.debug('Setting context target to {} ({})'.format( type(self).__name__, id(self))) - getWXGLContext()[0].SetCurrent(self) + self.__context.SetCurrent(self) return True def _refresh(self, *a): - """Triggers a redraw via the :meth:`_draw` method. - - .. note:: This method is dynamically assigned in :meth:`__init__`. - """ + """Triggers a redraw via the :meth:`_draw` method. """ + self.Refresh() + def _postDraw(self): """Called after the scene has been rendered. Swaps the front/back diff --git a/fsl/fsleyes/gl/wxglslicecanvas.py b/fsl/fsleyes/gl/wxglslicecanvas.py index d56f5dd0e..91a0c15b9 100644 --- a/fsl/fsleyes/gl/wxglslicecanvas.py +++ b/fsl/fsleyes/gl/wxglslicecanvas.py @@ -37,14 +37,18 @@ class WXGLSliceCanvas(slicecanvas.SliceCanvas, slicecanvas.SliceCanvas.__init__(self, overlayList, displayCtx, zax) fslgl.WXGLCanvasTarget .__init__(self) - # When the canvas is resized, we have to update - # the display bounds to preserve the aspect ratio - def onResize(ev): - self._updateDisplayBounds() - ev.Skip() - self.Bind(wx.EVT_SIZE, onResize) - - + self.Bind(wx.EVT_SIZE, self.__onResize) + + + def __onResize(self, ev): + """Called on ``wx.EVT_SIZE`` events, when the canvas is resized. When + the canvas is resized, we have to update the display bounds to preserve + the aspect ratio. + """ + self._updateDisplayBounds() + ev.Skip() + + def Show(self, show): """Overrides ``GLCanvas.Show``. When running over SSH/X11, it doesn't seem to be possible to hide a ``GLCanvas`` - the most recent scene -- GitLab