|
106 | 106 |
|
107 | 107 | DEBUG = False |
108 | 108 | IOHUB_ACTIVE = False |
109 | | - |
| 109 | +retinaContext = None # only needed for retina-ready displays |
110 | 110 |
|
111 | 111 | # keep track of windows that have been opened |
112 | 112 | # Use a list of weak references so that we don't stop the window being deleted |
@@ -165,7 +165,7 @@ def __init__(self, |
165 | 165 | name='window1', |
166 | 166 | checkTiming=True, |
167 | 167 | useFBO=False, |
168 | | - useRetina=False, |
| 168 | + useRetina=True, |
169 | 169 | autoLog=True): |
170 | 170 | """ |
171 | 171 | These attributes can only be set at initialization. See further down |
@@ -238,10 +238,10 @@ def __init__(self, |
238 | 238 | this will be enabled. |
239 | 239 | You can switch between left and right-eye scenes for drawing |
240 | 240 | operations using :func:`~psychopy.visual.Window.setBuffer` |
241 | | - useRetina : True or *False* |
242 | | - Try to use the full resolution of the Retina display (only on |
243 | | - certain Macs). By default the display's reduced resolution will |
244 | | - be used. NB when you use Retina display the initial win size |
| 241 | + useRetina : *True* or False |
| 242 | + In PsychoPy >1.85.3 this should always be True as pyglet |
| 243 | + (or Apple) no longer allows us to create a non-retina display. |
| 244 | + NB when you use Retina display the initial win size |
245 | 245 | request will be in the larger pixels but subsequent use of |
246 | 246 | units='pix' should refer to the tiny Retina pixels. Window.size |
247 | 247 | will give the actual size of the screen in Retina pixels |
@@ -273,6 +273,14 @@ def __init__(self, |
273 | 273 | self.useFBO = useFBO |
274 | 274 | self.useRetina = useRetina |
275 | 275 |
|
| 276 | + if sys.platform=='darwin' and not useRetina and pyglet.version >= "1.3": |
| 277 | + raise ValueError("As of PsychoPy 1.85.3 OSX windows should all be " |
| 278 | + "set to useRetina=True (or remove the argument). " |
| 279 | + "Pyglet 1.3 appears to be forcing " |
| 280 | + "us to use retina on any retina-capable screen " |
| 281 | + "so setting to False has no effect.") |
| 282 | + |
| 283 | + |
276 | 284 | self._toLog = [] |
277 | 285 | self._toCall = [] |
278 | 286 | # settings for the monitor: local settings (if available) override |
@@ -1447,36 +1455,6 @@ def _setupPyglet(self): |
1447 | 1455 | samples=aa_samples, stencil_size=stencil_size, stereo=self.stereo, |
1448 | 1456 | vsync=vsync) |
1449 | 1457 |
|
1450 | | - # monkey patches for retina display if needed |
1451 | | - def retinaAttach(self, canvas): |
1452 | | - """Replaces pyglet.gl.cocoa.CocoaContext.attach method |
1453 | | - """ |
1454 | | - super(CocoaContext, self).attach(canvas) |
1455 | | - self._nscontext.setView_(canvas.nsview) |
1456 | | - try: |
1457 | | - self._nscontext.view().setWantsBestResolutionOpenGLSurface_(1) |
1458 | | - except AttributeError: |
1459 | | - pass |
1460 | | - self.set_current() |
1461 | | - |
1462 | | - def retina_on_resize(self, width, height): |
1463 | | - """Insert as method """ |
1464 | | - view = self.context._nscontext.view() |
1465 | | - bounds = view.convertRectToBacking_(view.bounds()).size |
1466 | | - back_width, back_height = (int(bounds.width), int(bounds.height)) |
1467 | | - |
1468 | | - GL.glViewport(0, 0, back_width, back_height) |
1469 | | - GL.glMatrixMode(GL.GL_PROJECTION) |
1470 | | - GL.glLoadIdentity() |
1471 | | - GL.glOrtho(0, width, 0, height, -1, 1) |
1472 | | - GL.glMatrixMode(GL.GL_MODELVIEW) |
1473 | | - |
1474 | | - if self.useRetina and sys.platform == 'darwin': |
1475 | | - from pyglet.gl.cocoa import CocoaContext |
1476 | | - CocoaContext.attach = retinaAttach |
1477 | | - from pyglet.window.cocoa import CocoaWindow |
1478 | | - CocoaWindow.on_resize = retina_on_resize |
1479 | | - |
1480 | 1458 | defDisp = pyglet.window.get_platform().get_default_display() |
1481 | 1459 | allScrs = defDisp.get_screens() |
1482 | 1460 | # Screen (from Exp Settings) is 1-indexed, |
@@ -1515,16 +1493,18 @@ def retina_on_resize(self, width, height): |
1515 | 1493 | else: |
1516 | 1494 | self._hw_handle = self.winHandle._hwnd |
1517 | 1495 | elif sys.platform == 'darwin': |
| 1496 | + if self.useRetina: |
| 1497 | + global retinaContext |
| 1498 | + retinaContext = self.winHandle.context._nscontext |
| 1499 | + view = retinaContext.view() |
| 1500 | + bounds = view.convertRectToBacking_(view.bounds()).size |
| 1501 | + self.size = (int(bounds.width), int(bounds.height)) |
1518 | 1502 | try: |
1519 | 1503 | # python 32bit (1.4. or 1.2 pyglet) |
1520 | 1504 | self._hw_handle = self.winHandle._window.value |
1521 | 1505 | except Exception: |
1522 | 1506 | # pyglet 1.2 with 64bit python? |
1523 | 1507 | self._hw_handle = self.winHandle._nswindow.windowNumber() |
1524 | | - if self.useRetina: |
1525 | | - view = self.context._nscontext.view() |
1526 | | - bounds = view.convertRectToBacking_(view.bounds()).size |
1527 | | - self.size = (int(bounds.width), int(bounds.height)) |
1528 | 1508 | elif sys.platform == 'linux2': |
1529 | 1509 | self._hw_handle = self.winHandle._window |
1530 | 1510 |
|
@@ -2053,9 +2033,19 @@ def _onResize(width, height): |
2053 | 2033 | Override this event handler with your own to create another |
2054 | 2034 | projection, for example in perspective. |
2055 | 2035 | """ |
| 2036 | + global retinaContext |
| 2037 | + |
2056 | 2038 | if height == 0: |
2057 | 2039 | height = 1 |
2058 | | - GL.glViewport(0, 0, width, height) |
| 2040 | + |
| 2041 | + if retinaContext is not None: |
| 2042 | + view = retinaContext.view() |
| 2043 | + bounds = view.convertRectToBacking_(view.bounds()).size |
| 2044 | + back_width, back_height = (int(bounds.width), int(bounds.height)) |
| 2045 | + else: |
| 2046 | + back_width, back_height = width, height |
| 2047 | + |
| 2048 | + GL.glViewport(0, 0, back_width, back_height) |
2059 | 2049 | GL.glMatrixMode(GL.GL_PROJECTION) |
2060 | 2050 | GL.glLoadIdentity() |
2061 | 2051 | GL.glOrtho(-1, 1, -1, 1, -1, 1) |
|
0 commit comments