sync pyglet

This commit is contained in:
shenjack 2023-08-09 12:29:18 +08:00
parent a2f12c2e77
commit 7278368b4c
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -98,7 +98,7 @@ class Win32Config(Config):
class Win32CanvasConfig(CanvasConfig):
def __init__(self, canvas, pf, config):
super(Win32CanvasConfig, self).__init__(canvas, config)
super().__init__(canvas, config)
self._pf = pf
self._pfd = PIXELFORMATDESCRIPTOR()
@ -153,7 +153,7 @@ class Win32CanvasConfigARB(CanvasConfig):
}
def __init__(self, canvas, pf, config):
super(Win32CanvasConfigARB, self).__init__(canvas, config)
super().__init__(canvas, config)
self._pf = pf
names = list(self.attribute_ids.keys())
@ -182,35 +182,21 @@ class Win32CanvasConfigARB(CanvasConfig):
_gdi32.SetPixelFormat(canvas.hdc, self._pf, None)
class Win32Context(Context):
class _BaseWin32Context(Context):
def __init__(self, config, share):
super(Win32Context, self).__init__(config, share)
super().__init__(config, share)
self._context = None
def attach(self, canvas):
super(Win32Context, self).attach(canvas)
if not self._context:
self.config._set_pixel_format(canvas)
self._context = wgl.wglCreateContext(canvas.hdc)
share = self.context_share
if share:
if not share.canvas:
raise RuntimeError('Share context has no canvas.')
if not wgl.wglShareLists(share._context, self._context):
raise gl.ContextException('Unable to share contexts.')
def set_current(self):
if self._context is not None and self != gl.current_context:
wgl.wglMakeCurrent(self.canvas.hdc, self._context)
super(Win32Context, self).set_current()
super().set_current()
def detach(self):
if self.canvas:
wgl.wglDeleteContext(self._context)
self._context = None
super(Win32Context, self).detach()
super().detach()
def flip(self):
_gdi32.SwapBuffers(self.canvas.hdc)
@ -224,9 +210,23 @@ class Win32Context(Context):
wglext_arb.wglSwapIntervalEXT(int(vsync))
class Win32ARBContext(Win32Context):
def __init__(self, config, share):
super(Win32ARBContext, self).__init__(config, share)
class Win32Context(_BaseWin32Context):
def attach(self, canvas):
super().attach(canvas)
if not self._context:
self.config._set_pixel_format(canvas)
self._context = wgl.wglCreateContext(canvas.hdc)
share = self.context_share
if share:
if not share.canvas:
raise RuntimeError('Share context has no canvas.')
if not wgl.wglShareLists(share._context, self._context):
raise gl.ContextException('Unable to share contexts.')
class Win32ARBContext(_BaseWin32Context):
def attach(self, canvas):
share = self.context_share
@ -252,4 +252,4 @@ class Win32ARBContext(Win32Context):
self.config._set_pixel_format(canvas)
self._context = wglext_arb.wglCreateContextAttribsARB(canvas.hdc, share, attribs)
super(Win32ARBContext, self).attach(canvas)
super().attach(canvas)