pyglet 2.1.13__py3-none-any.whl → 3.0.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyglet/__init__.py +67 -61
- pyglet/__init__.pyi +15 -8
- pyglet/app/__init__.py +22 -13
- pyglet/app/async_app.py +212 -0
- pyglet/app/base.py +2 -1
- pyglet/app/{xlib.py → linux.py} +3 -3
- pyglet/config/__init__.py +101 -0
- pyglet/config/gl/__init__.py +30 -0
- pyglet/config/gl/egl.py +120 -0
- pyglet/config/gl/macos.py +262 -0
- pyglet/config/gl/windows.py +267 -0
- pyglet/config/gl/x11.py +142 -0
- pyglet/customtypes.py +43 -2
- pyglet/display/__init__.py +8 -6
- pyglet/display/base.py +3 -63
- pyglet/display/cocoa.py +12 -17
- pyglet/display/emscripten.py +39 -0
- pyglet/display/headless.py +23 -30
- pyglet/display/wayland.py +157 -0
- pyglet/display/win32.py +5 -21
- pyglet/display/xlib.py +19 -27
- pyglet/display/xlib_vidmoderestore.py +2 -2
- pyglet/enums.py +183 -0
- pyglet/event.py +0 -1
- pyglet/experimental/geoshader_sprite.py +15 -13
- pyglet/experimental/hidraw.py +6 -15
- pyglet/experimental/multitexture_sprite.py +31 -19
- pyglet/experimental/particles.py +13 -35
- pyglet/font/__init__.py +251 -85
- pyglet/font/base.py +116 -61
- pyglet/font/dwrite/__init__.py +349 -204
- pyglet/font/dwrite/dwrite_lib.py +27 -5
- pyglet/font/fontconfig.py +14 -6
- pyglet/font/freetype.py +138 -87
- pyglet/font/freetype_lib.py +19 -0
- pyglet/font/group.py +179 -0
- pyglet/font/harfbuzz/__init__.py +3 -3
- pyglet/font/pyodide_js.py +310 -0
- pyglet/font/quartz.py +319 -126
- pyglet/font/ttf.py +45 -3
- pyglet/font/user.py +14 -19
- pyglet/font/win32.py +45 -21
- pyglet/graphics/__init__.py +8 -787
- pyglet/graphics/allocation.py +115 -1
- pyglet/graphics/api/__init__.py +77 -0
- pyglet/graphics/api/base.py +299 -0
- pyglet/graphics/api/gl/__init__.py +58 -0
- pyglet/graphics/api/gl/base.py +24 -0
- pyglet/graphics/{vertexbuffer.py → api/gl/buffer.py} +104 -159
- pyglet/graphics/api/gl/cocoa/context.py +76 -0
- pyglet/graphics/api/gl/context.py +391 -0
- pyglet/graphics/api/gl/default_shaders.py +0 -0
- pyglet/graphics/api/gl/draw.py +627 -0
- pyglet/graphics/api/gl/egl/__init__.py +0 -0
- pyglet/graphics/api/gl/egl/context.py +92 -0
- pyglet/graphics/api/gl/enums.py +76 -0
- pyglet/graphics/api/gl/framebuffer.py +315 -0
- pyglet/graphics/api/gl/gl.py +5463 -0
- pyglet/graphics/api/gl/gl_info.py +188 -0
- pyglet/graphics/api/gl/global_opengl.py +226 -0
- pyglet/{gl → graphics/api/gl}/lib.py +34 -18
- pyglet/graphics/api/gl/shader.py +1476 -0
- pyglet/graphics/api/gl/shapes.py +55 -0
- pyglet/graphics/api/gl/sprite.py +102 -0
- pyglet/graphics/api/gl/state.py +219 -0
- pyglet/graphics/api/gl/text.py +190 -0
- pyglet/graphics/api/gl/texture.py +1526 -0
- pyglet/graphics/{vertexarray.py → api/gl/vertexarray.py} +11 -13
- pyglet/graphics/api/gl/vertexdomain.py +751 -0
- pyglet/graphics/api/gl/win32/__init__.py +0 -0
- pyglet/graphics/api/gl/win32/context.py +108 -0
- pyglet/graphics/api/gl/win32/wgl_info.py +24 -0
- pyglet/graphics/api/gl/xlib/__init__.py +0 -0
- pyglet/graphics/api/gl/xlib/context.py +174 -0
- pyglet/{gl → graphics/api/gl/xlib}/glx_info.py +26 -31
- pyglet/graphics/api/gl1/__init__.py +0 -0
- pyglet/{gl → graphics/api/gl1}/gl_compat.py +3 -2
- pyglet/graphics/api/gl2/__init__.py +0 -0
- pyglet/graphics/api/gl2/buffer.py +320 -0
- pyglet/graphics/api/gl2/draw.py +600 -0
- pyglet/graphics/api/gl2/global_opengl.py +122 -0
- pyglet/graphics/api/gl2/shader.py +200 -0
- pyglet/graphics/api/gl2/shapes.py +51 -0
- pyglet/graphics/api/gl2/sprite.py +79 -0
- pyglet/graphics/api/gl2/text.py +175 -0
- pyglet/graphics/api/gl2/vertexdomain.py +364 -0
- pyglet/graphics/api/webgl/__init__.py +233 -0
- pyglet/graphics/api/webgl/buffer.py +302 -0
- pyglet/graphics/api/webgl/context.py +234 -0
- pyglet/graphics/api/webgl/draw.py +590 -0
- pyglet/graphics/api/webgl/enums.py +76 -0
- pyglet/graphics/api/webgl/framebuffer.py +360 -0
- pyglet/graphics/api/webgl/gl.py +1537 -0
- pyglet/graphics/api/webgl/gl_info.py +130 -0
- pyglet/graphics/api/webgl/shader.py +1346 -0
- pyglet/graphics/api/webgl/shapes.py +92 -0
- pyglet/graphics/api/webgl/sprite.py +102 -0
- pyglet/graphics/api/webgl/state.py +227 -0
- pyglet/graphics/api/webgl/text.py +187 -0
- pyglet/graphics/api/webgl/texture.py +1227 -0
- pyglet/graphics/api/webgl/vertexarray.py +54 -0
- pyglet/graphics/api/webgl/vertexdomain.py +616 -0
- pyglet/graphics/api/webgl/webgl_js.pyi +307 -0
- pyglet/{image → graphics}/atlas.py +33 -32
- pyglet/graphics/base.py +10 -0
- pyglet/graphics/buffer.py +245 -0
- pyglet/graphics/draw.py +578 -0
- pyglet/graphics/framebuffer.py +26 -0
- pyglet/graphics/instance.py +178 -69
- pyglet/graphics/shader.py +267 -1553
- pyglet/graphics/state.py +83 -0
- pyglet/graphics/texture.py +703 -0
- pyglet/graphics/vertexdomain.py +695 -538
- pyglet/gui/ninepatch.py +10 -10
- pyglet/gui/widgets.py +120 -10
- pyglet/image/__init__.py +20 -1973
- pyglet/image/animation.py +12 -12
- pyglet/image/base.py +730 -0
- pyglet/image/codecs/__init__.py +9 -0
- pyglet/image/codecs/bmp.py +53 -30
- pyglet/image/codecs/dds.py +53 -31
- pyglet/image/codecs/gdiplus.py +38 -14
- pyglet/image/codecs/gdkpixbuf2.py +0 -2
- pyglet/image/codecs/js_image.py +99 -0
- pyglet/image/codecs/ktx2.py +161 -0
- pyglet/image/codecs/pil.py +1 -1
- pyglet/image/codecs/png.py +1 -1
- pyglet/image/codecs/wic.py +11 -2
- pyglet/info.py +26 -24
- pyglet/input/__init__.py +8 -0
- pyglet/input/base.py +163 -105
- pyglet/input/controller.py +13 -19
- pyglet/input/controller_db.py +39 -24
- pyglet/input/emscripten/__init__.py +18 -0
- pyglet/input/emscripten/gamepad_js.py +397 -0
- pyglet/input/linux/__init__.py +11 -5
- pyglet/input/linux/evdev.py +10 -11
- pyglet/input/linux/x11_xinput.py +2 -2
- pyglet/input/linux/x11_xinput_tablet.py +1 -1
- pyglet/input/macos/__init__.py +7 -2
- pyglet/input/macos/darwin_gc.py +559 -0
- pyglet/input/win32/__init__.py +1 -1
- pyglet/input/win32/directinput.py +34 -29
- pyglet/input/win32/xinput.py +11 -61
- pyglet/lib.py +3 -3
- pyglet/libs/__init__.py +1 -1
- pyglet/{gl → libs/darwin}/agl.py +1 -1
- pyglet/libs/darwin/cocoapy/__init__.py +2 -2
- pyglet/libs/darwin/cocoapy/cocoahelpers.py +181 -0
- pyglet/libs/darwin/cocoapy/cocoalibs.py +31 -0
- pyglet/libs/darwin/cocoapy/cocoatypes.py +27 -0
- pyglet/libs/darwin/cocoapy/runtime.py +81 -45
- pyglet/libs/darwin/coreaudio.py +4 -4
- pyglet/{gl → libs/darwin}/lib_agl.py +9 -8
- pyglet/libs/darwin/quartzkey.py +1 -3
- pyglet/libs/egl/__init__.py +2 -0
- pyglet/libs/egl/egl_lib.py +576 -0
- pyglet/libs/egl/eglext.py +51 -5
- pyglet/libs/linux/__init__.py +0 -0
- pyglet/libs/linux/egl/__init__.py +0 -0
- pyglet/libs/linux/egl/eglext.py +22 -0
- pyglet/libs/linux/glx/__init__.py +0 -0
- pyglet/{gl → libs/linux/glx}/glx.py +13 -14
- pyglet/{gl → libs/linux/glx}/glxext_arb.py +408 -192
- pyglet/{gl → libs/linux/glx}/glxext_mesa.py +1 -1
- pyglet/{gl → libs/linux/glx}/glxext_nv.py +345 -164
- pyglet/{gl → libs/linux/glx}/lib_glx.py +3 -2
- pyglet/libs/linux/wayland/__init__.py +0 -0
- pyglet/libs/linux/wayland/client.py +1068 -0
- pyglet/libs/linux/wayland/lib_wayland.py +207 -0
- pyglet/libs/linux/wayland/wayland_egl.py +38 -0
- pyglet/libs/{wayland → linux/wayland}/xkbcommon.py +26 -0
- pyglet/libs/{x11 → linux/x11}/xf86vmode.py +4 -4
- pyglet/libs/{x11 → linux/x11}/xinerama.py +2 -2
- pyglet/libs/{x11 → linux/x11}/xinput.py +10 -10
- pyglet/libs/linux/x11/xrandr.py +0 -0
- pyglet/libs/{x11 → linux/x11}/xrender.py +1 -1
- pyglet/libs/shared/__init__.py +0 -0
- pyglet/libs/shared/spirv/__init__.py +0 -0
- pyglet/libs/shared/spirv/lib_shaderc.py +85 -0
- pyglet/libs/shared/spirv/lib_spirv_cross.py +126 -0
- pyglet/libs/win32/__init__.py +28 -8
- pyglet/libs/win32/constants.py +59 -48
- pyglet/libs/win32/context_managers.py +20 -3
- pyglet/libs/win32/dinput.py +105 -88
- pyglet/{gl → libs/win32}/lib_wgl.py +52 -26
- pyglet/libs/win32/types.py +58 -23
- pyglet/{gl → libs/win32}/wgl.py +32 -25
- pyglet/{gl → libs/win32}/wglext_arb.py +364 -2
- pyglet/media/__init__.py +9 -10
- pyglet/media/codecs/__init__.py +12 -1
- pyglet/media/codecs/base.py +99 -96
- pyglet/media/codecs/ffmpeg.py +2 -2
- pyglet/media/codecs/ffmpeg_lib/libavformat.py +3 -8
- pyglet/media/codecs/webaudio_pyodide.py +111 -0
- pyglet/media/drivers/__init__.py +9 -4
- pyglet/media/drivers/base.py +4 -4
- pyglet/media/drivers/openal/__init__.py +1 -1
- pyglet/media/drivers/openal/adaptation.py +3 -3
- pyglet/media/drivers/pulse/__init__.py +1 -1
- pyglet/media/drivers/pulse/adaptation.py +3 -3
- pyglet/media/drivers/pyodide_js/__init__.py +8 -0
- pyglet/media/drivers/pyodide_js/adaptation.py +288 -0
- pyglet/media/drivers/xaudio2/adaptation.py +3 -3
- pyglet/media/player.py +276 -193
- pyglet/media/player_worker_thread.py +1 -1
- pyglet/model/__init__.py +39 -29
- pyglet/model/codecs/base.py +4 -4
- pyglet/model/codecs/gltf.py +3 -3
- pyglet/model/codecs/obj.py +71 -43
- pyglet/resource.py +129 -78
- pyglet/shapes.py +154 -194
- pyglet/sprite.py +47 -164
- pyglet/text/__init__.py +44 -54
- pyglet/text/caret.py +12 -7
- pyglet/text/document.py +19 -17
- pyglet/text/formats/html.py +2 -2
- pyglet/text/formats/structured.py +10 -40
- pyglet/text/layout/__init__.py +20 -13
- pyglet/text/layout/base.py +176 -287
- pyglet/text/layout/incremental.py +9 -10
- pyglet/text/layout/scrolling.py +7 -95
- pyglet/window/__init__.py +183 -172
- pyglet/window/cocoa/__init__.py +62 -51
- pyglet/window/cocoa/pyglet_delegate.py +2 -25
- pyglet/window/cocoa/pyglet_view.py +9 -8
- pyglet/window/dialog/__init__.py +184 -0
- pyglet/window/dialog/base.py +99 -0
- pyglet/window/dialog/darwin.py +121 -0
- pyglet/window/dialog/linux.py +72 -0
- pyglet/window/dialog/windows.py +194 -0
- pyglet/window/emscripten/__init__.py +779 -0
- pyglet/window/headless/__init__.py +44 -28
- pyglet/window/key.py +2 -0
- pyglet/window/mouse.py +2 -2
- pyglet/window/wayland/__init__.py +377 -0
- pyglet/window/win32/__init__.py +101 -46
- pyglet/window/xlib/__init__.py +104 -66
- {pyglet-2.1.13.dist-info → pyglet-3.0.dev1.dist-info}/METADATA +2 -3
- pyglet-3.0.dev1.dist-info/RECORD +322 -0
- {pyglet-2.1.13.dist-info → pyglet-3.0.dev1.dist-info}/WHEEL +1 -1
- pyglet/gl/__init__.py +0 -208
- pyglet/gl/base.py +0 -499
- pyglet/gl/cocoa.py +0 -309
- pyglet/gl/gl.py +0 -4625
- pyglet/gl/gl.pyi +0 -2320
- pyglet/gl/gl_compat.pyi +0 -3097
- pyglet/gl/gl_info.py +0 -190
- pyglet/gl/headless.py +0 -166
- pyglet/gl/wgl_info.py +0 -36
- pyglet/gl/wglext_nv.py +0 -1096
- pyglet/gl/win32.py +0 -268
- pyglet/gl/xlib.py +0 -295
- pyglet/image/buffer.py +0 -274
- pyglet/image/codecs/s3tc.py +0 -354
- pyglet/libs/x11/xrandr.py +0 -166
- pyglet-2.1.13.dist-info/RECORD +0 -234
- /pyglet/{libs/wayland → graphics/api/gl/cocoa}/__init__.py +0 -0
- /pyglet/libs/{egl → linux/egl}/egl.py +0 -0
- /pyglet/libs/{egl → linux/egl}/lib.py +0 -0
- /pyglet/libs/{ioctl.py → linux/ioctl.py} +0 -0
- /pyglet/libs/{wayland → linux/wayland}/gbm.py +0 -0
- /pyglet/libs/{x11 → linux/x11}/__init__.py +0 -0
- /pyglet/libs/{x11 → linux/x11}/cursorfont.py +0 -0
- /pyglet/libs/{x11 → linux/x11}/xlib.py +0 -0
- /pyglet/libs/{x11 → linux/x11}/xsync.py +0 -0
- {pyglet-2.1.13.dist-info/licenses → pyglet-3.0.dev1.dist-info}/LICENSE +0 -0
|
File without changes
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ctypes import c_int
|
|
4
|
+
|
|
5
|
+
from pyglet.graphics.api.gl.base import ContextException
|
|
6
|
+
from pyglet.graphics.api.gl.context import OpenGLSurfaceContext
|
|
7
|
+
from pyglet.libs.win32 import wglext_arb, wgl
|
|
8
|
+
from pyglet.libs.win32.wgl import WGLFunctions
|
|
9
|
+
from pyglet.graphics.api.gl.win32.wgl_info import WGLInfo
|
|
10
|
+
from pyglet.libs.win32 import _gdi32
|
|
11
|
+
from typing import TYPE_CHECKING
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from pyglet.config.gl.windows import GLSurfaceConfig, GLLegacyConfig
|
|
15
|
+
from pyglet.graphics.api.gl.global_opengl import OpenGLBackend
|
|
16
|
+
from pyglet.window.win32 import Win32Window
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _BaseWin32Context(OpenGLSurfaceContext):
|
|
21
|
+
def __init__(self,
|
|
22
|
+
opengl_backend: OpenGLBackend,
|
|
23
|
+
window: Win32Window,
|
|
24
|
+
config: GLSurfaceConfig,
|
|
25
|
+
share: Win32Context | Win32ARBContext) -> None:
|
|
26
|
+
super().__init__(opengl_backend, window, config,
|
|
27
|
+
platform_info=WGLInfo(), context_share=share, platform_func_class=WGLFunctions)
|
|
28
|
+
|
|
29
|
+
def set_current(self) -> None:
|
|
30
|
+
if self._context is not None and self != self.core.current_context:
|
|
31
|
+
wgl.wglMakeCurrent(self.window._dc, self._context) # noqa: SLF001
|
|
32
|
+
super().set_current()
|
|
33
|
+
|
|
34
|
+
def detach(self) -> None:
|
|
35
|
+
if self._context:
|
|
36
|
+
wgl.wglDeleteContext(self._context)
|
|
37
|
+
self._context = None
|
|
38
|
+
super().detach()
|
|
39
|
+
|
|
40
|
+
def flip(self) -> None:
|
|
41
|
+
_gdi32.SwapBuffers(self.window._dc) # noqa: SLF001
|
|
42
|
+
|
|
43
|
+
def get_vsync(self) -> bool:
|
|
44
|
+
if self._info.have_extension('WGL_EXT_swap_control'):
|
|
45
|
+
return bool(self.platform_func.wglGetSwapIntervalEXT())
|
|
46
|
+
return False
|
|
47
|
+
|
|
48
|
+
def set_vsync(self, vsync: bool) -> None:
|
|
49
|
+
if self._info.have_extension('WGL_EXT_swap_control'):
|
|
50
|
+
self.platform_func.wglSwapIntervalEXT(int(vsync))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Win32Context(_BaseWin32Context):
|
|
54
|
+
config: GLLegacyConfig
|
|
55
|
+
context_share: Win32Context | None
|
|
56
|
+
|
|
57
|
+
def attach(self, window: Win32Window) -> None:
|
|
58
|
+
if not self._context:
|
|
59
|
+
self.config.apply_format()
|
|
60
|
+
self._context = wgl.wglCreateContext(window.dc)
|
|
61
|
+
|
|
62
|
+
share = self.context_share
|
|
63
|
+
if share:
|
|
64
|
+
if not share.window:
|
|
65
|
+
msg = 'Share context has no window.'
|
|
66
|
+
raise RuntimeError(msg)
|
|
67
|
+
if not wgl.wglShareLists(share._context, self._context): # noqa: SLF001
|
|
68
|
+
msg = 'Unable to share contexts.'
|
|
69
|
+
raise ContextException(msg)
|
|
70
|
+
|
|
71
|
+
super().attach(window)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class Win32ARBContext(_BaseWin32Context):
|
|
75
|
+
config: GLSurfaceConfig
|
|
76
|
+
context_share: Win32ARBContext | None
|
|
77
|
+
|
|
78
|
+
def attach(self, window: Win32Window) -> None:
|
|
79
|
+
share = self.context_share
|
|
80
|
+
if share:
|
|
81
|
+
if not share.window:
|
|
82
|
+
msg = 'Share context has no window.'
|
|
83
|
+
raise RuntimeError(msg)
|
|
84
|
+
share = share._context # noqa: SLF001
|
|
85
|
+
|
|
86
|
+
attribs = []
|
|
87
|
+
user_config = self.config.config
|
|
88
|
+
if user_config.major_version is not None:
|
|
89
|
+
attribs.extend([wglext_arb.WGL_CONTEXT_MAJOR_VERSION_ARB, user_config.major_version])
|
|
90
|
+
if user_config.minor_version is not None:
|
|
91
|
+
attribs.extend([wglext_arb.WGL_CONTEXT_MINOR_VERSION_ARB, user_config.minor_version])
|
|
92
|
+
flags = 0
|
|
93
|
+
if user_config.forward_compatible and not user_config.opengl_api:
|
|
94
|
+
flags |= wglext_arb.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
|
|
95
|
+
if user_config.debug:
|
|
96
|
+
flags |= wglext_arb.WGL_CONTEXT_DEBUG_BIT_ARB
|
|
97
|
+
if user_config.opengl_api == "gles":
|
|
98
|
+
attribs.extend([wglext_arb.WGL_CONTEXT_PROFILE_MASK_ARB, wglext_arb.WGL_CONTEXT_ES_PROFILE_BIT_EXT])
|
|
99
|
+
if flags:
|
|
100
|
+
attribs.extend([wglext_arb.WGL_CONTEXT_FLAGS_ARB, flags])
|
|
101
|
+
attribs.append(0)
|
|
102
|
+
attribs = (c_int * len(attribs))(*attribs)
|
|
103
|
+
|
|
104
|
+
self.config.apply_format()
|
|
105
|
+
|
|
106
|
+
from pyglet.config.gl.windows import _global_wgl
|
|
107
|
+
self._context = _global_wgl.funcs.wglCreateContextAttribsARB(window.dc, share, attribs)
|
|
108
|
+
super().attach(window)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Cached information about version and extensions of current WGL implementation."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import warnings
|
|
5
|
+
from ctypes import c_char_p, cast
|
|
6
|
+
|
|
7
|
+
from pyglet.graphics.api.gl import GL_EXTENSIONS, OpenGLSurfaceContext
|
|
8
|
+
from pyglet.graphics.api.gl.lib import MissingFunctionException
|
|
9
|
+
from pyglet.util import asstr
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WGLInfoException(Exception): # noqa: N818
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class WGLInfo:
|
|
17
|
+
@staticmethod
|
|
18
|
+
def get_extensions(ctx: OpenGLSurfaceContext) -> list[str]:
|
|
19
|
+
"""Can only be called when a context is in scope."""
|
|
20
|
+
try:
|
|
21
|
+
return asstr(ctx.platform_func.wglGetExtensionsStringEXT()).split()
|
|
22
|
+
except MissingFunctionException:
|
|
23
|
+
warnings.warn("Missing WGL function: wglGetExtensionsStringEXT}.")
|
|
24
|
+
return asstr(cast(ctx.glGetString(GL_EXTENSIONS), c_char_p).value).split()
|
|
File without changes
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
from ctypes import byref, c_int, c_uint
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from pyglet.graphics.api import gl
|
|
8
|
+
from pyglet.graphics.api.gl import lib, OpenGLSurfaceContext
|
|
9
|
+
from pyglet.graphics.api.gl.base import ContextException
|
|
10
|
+
from pyglet.graphics.api.gl.xlib import glx_info
|
|
11
|
+
from pyglet.libs.linux.glx import glxext_arb, glx, glxext_mesa
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from pyglet.config.gl.x11 import XlibGLSurfaceConfig
|
|
15
|
+
from pyglet.graphics.api.gl import OpenGLBackend
|
|
16
|
+
from pyglet.window.xlib import XlibWindow
|
|
17
|
+
from pyglet.libs.linux.x11.xlib import Display
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class XlibContext(OpenGLSurfaceContext):
|
|
21
|
+
x_display: Display
|
|
22
|
+
glx_context: glx.GLXContext
|
|
23
|
+
glx_window: glx.GLXWindow | None
|
|
24
|
+
_use_video_sync: bool
|
|
25
|
+
_vsync: bool
|
|
26
|
+
config: XlibGLSurfaceConfig
|
|
27
|
+
attached: bool = False
|
|
28
|
+
|
|
29
|
+
_have_SGI_swap_control: bool # noqa: N815
|
|
30
|
+
_have_EXT_swap_control: bool # noqa: N815
|
|
31
|
+
_have_MESA_swap_control: bool # noqa: N815
|
|
32
|
+
_have_SGI_video_sync: bool # noqa: N815
|
|
33
|
+
|
|
34
|
+
def __init__(self,
|
|
35
|
+
opengl_backend: OpenGLBackend,
|
|
36
|
+
window: XlibWindow,
|
|
37
|
+
config: XlibGLSurfaceConfig,
|
|
38
|
+
share: XlibContext | None) -> None:
|
|
39
|
+
self.x_display = window._x_display # noqa: SLF001
|
|
40
|
+
info = glx_info.GLXInfo(self.x_display)
|
|
41
|
+
super().__init__(opengl_backend, window, config,
|
|
42
|
+
platform_info=info,
|
|
43
|
+
context_share=share)
|
|
44
|
+
|
|
45
|
+
self.glx_context = self._create_glx_context(share)
|
|
46
|
+
if not self.glx_context:
|
|
47
|
+
# TODO: Check Xlib error generated
|
|
48
|
+
msg = 'Could not create GL context'
|
|
49
|
+
raise ContextException(msg)
|
|
50
|
+
|
|
51
|
+
self._have_SGI_video_sync = info.have_extension('GLX_SGI_video_sync')
|
|
52
|
+
self._have_SGI_swap_control = info.have_extension('GLX_SGI_swap_control')
|
|
53
|
+
self._have_EXT_swap_control = info.have_extension('GLX_EXT_swap_control')
|
|
54
|
+
self._have_MESA_swap_control = info.have_extension('GLX_MESA_swap_control')
|
|
55
|
+
|
|
56
|
+
# In order of preference:
|
|
57
|
+
# 1. GLX_EXT_swap_control (more likely to work where video_sync will not)
|
|
58
|
+
# 2. GLX_MESA_swap_control (same as above, but supported by MESA drivers)
|
|
59
|
+
# 3. GLX_SGI_video_sync (does not work on Intel 945GM, but that has EXT)
|
|
60
|
+
# 4. GLX_SGI_swap_control (cannot be disabled once enabled)
|
|
61
|
+
self._use_video_sync = (self._have_SGI_video_sync and
|
|
62
|
+
not (self._have_EXT_swap_control or self._have_MESA_swap_control))
|
|
63
|
+
|
|
64
|
+
# XXX Mandate that vsync defaults on across all platforms.
|
|
65
|
+
self._vsync = True
|
|
66
|
+
self.glx_window = None
|
|
67
|
+
|
|
68
|
+
def is_direct(self) -> bool:
|
|
69
|
+
return bool(glx.glXIsDirect(self.x_display, self.glx_context))
|
|
70
|
+
|
|
71
|
+
def _create_glx_context(self, share: XlibContext | None) -> glx.GLXContext:
|
|
72
|
+
if share:
|
|
73
|
+
share_context = share.glx_context
|
|
74
|
+
else:
|
|
75
|
+
share_context = None
|
|
76
|
+
|
|
77
|
+
user_config = self.config.config
|
|
78
|
+
|
|
79
|
+
attribs = []
|
|
80
|
+
if user_config.major_version is not None:
|
|
81
|
+
attribs.extend([glxext_arb.GLX_CONTEXT_MAJOR_VERSION_ARB, user_config.major_version])
|
|
82
|
+
if user_config.minor_version is not None:
|
|
83
|
+
attribs.extend([glxext_arb.GLX_CONTEXT_MINOR_VERSION_ARB, user_config.minor_version])
|
|
84
|
+
|
|
85
|
+
if user_config.opengl_api == "gl":
|
|
86
|
+
attribs.extend([glxext_arb.GLX_CONTEXT_PROFILE_MASK_ARB, glxext_arb.GLX_CONTEXT_CORE_PROFILE_BIT_ARB])
|
|
87
|
+
elif user_config.opengl_api == "gles":
|
|
88
|
+
attribs.extend([glxext_arb.GLX_CONTEXT_PROFILE_MASK_ARB, glxext_arb.GLX_CONTEXT_ES2_PROFILE_BIT_EXT])
|
|
89
|
+
|
|
90
|
+
flags = 0
|
|
91
|
+
if user_config.forward_compatible:
|
|
92
|
+
flags |= glxext_arb.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
|
|
93
|
+
if user_config.debug:
|
|
94
|
+
flags |= glxext_arb.GLX_CONTEXT_DEBUG_BIT_ARB
|
|
95
|
+
|
|
96
|
+
if flags:
|
|
97
|
+
attribs.extend([glxext_arb.GLX_CONTEXT_FLAGS_ARB, flags])
|
|
98
|
+
attribs.append(0)
|
|
99
|
+
attribs = (c_int * len(attribs))(*attribs)
|
|
100
|
+
|
|
101
|
+
return glxext_arb.glXCreateContextAttribsARB(self.window._x_display, self.config.fbconfig, # noqa: SLF001
|
|
102
|
+
share_context, True, attribs)
|
|
103
|
+
|
|
104
|
+
def attach(self, window: XlibWindow) -> None:
|
|
105
|
+
if self.attached:
|
|
106
|
+
return
|
|
107
|
+
|
|
108
|
+
super().attach(window)
|
|
109
|
+
|
|
110
|
+
self.glx_window = glx.glXCreateWindow(self.x_display,
|
|
111
|
+
self.config.fbconfig, self.window._x_window, # noqa: SLF001
|
|
112
|
+
None)
|
|
113
|
+
self.set_current()
|
|
114
|
+
self.attached = True
|
|
115
|
+
|
|
116
|
+
def set_current(self) -> None:
|
|
117
|
+
glx.glXMakeContextCurrent(self.x_display, self.glx_window, self.glx_window, self.glx_context)
|
|
118
|
+
super().set_current()
|
|
119
|
+
|
|
120
|
+
def detach(self) -> None:
|
|
121
|
+
if not self.attached:
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
self.set_current()
|
|
125
|
+
gl.glFlush()
|
|
126
|
+
|
|
127
|
+
super().detach()
|
|
128
|
+
|
|
129
|
+
self.attached = False
|
|
130
|
+
|
|
131
|
+
glx.glXMakeContextCurrent(self.x_display, 0, 0, None)
|
|
132
|
+
if self.glx_window:
|
|
133
|
+
glx.glXDestroyWindow(self.x_display, self.glx_window)
|
|
134
|
+
self.glx_window = None
|
|
135
|
+
|
|
136
|
+
def destroy(self) -> None:
|
|
137
|
+
super().destroy()
|
|
138
|
+
if self.glx_window:
|
|
139
|
+
glx.glXDestroyWindow(self.x_display, self.glx_window)
|
|
140
|
+
self.glx_window = None
|
|
141
|
+
if self.glx_context:
|
|
142
|
+
glx.glXDestroyContext(self.x_display, self.glx_context)
|
|
143
|
+
self.glx_context = None
|
|
144
|
+
|
|
145
|
+
def set_vsync(self, vsync: bool = True) -> None:
|
|
146
|
+
self._vsync = vsync
|
|
147
|
+
interval = (vsync and 1) or 0
|
|
148
|
+
try:
|
|
149
|
+
if not self._use_video_sync and self._have_EXT_swap_control:
|
|
150
|
+
glxext_arb.glXSwapIntervalEXT(self.x_display, glx.glXGetCurrentDrawable(), interval)
|
|
151
|
+
elif not self._use_video_sync and self._have_MESA_swap_control:
|
|
152
|
+
glxext_mesa.glXSwapIntervalMESA(interval)
|
|
153
|
+
elif self._have_SGI_swap_control:
|
|
154
|
+
glxext_arb.glXSwapIntervalSGI(interval)
|
|
155
|
+
except lib.MissingFunctionException as e:
|
|
156
|
+
warnings.warn(str(e))
|
|
157
|
+
|
|
158
|
+
def get_vsync(self) -> bool:
|
|
159
|
+
return self._vsync
|
|
160
|
+
|
|
161
|
+
def _wait_vsync(self) -> None:
|
|
162
|
+
if self._vsync and self._have_SGI_video_sync and self._use_video_sync:
|
|
163
|
+
count = c_uint()
|
|
164
|
+
glxext_arb.glXGetVideoSyncSGI(byref(count))
|
|
165
|
+
glxext_arb.glXWaitVideoSyncSGI(2, (count.value + 1) % 2, byref(count))
|
|
166
|
+
|
|
167
|
+
def flip(self) -> None:
|
|
168
|
+
if not self.glx_window:
|
|
169
|
+
return
|
|
170
|
+
|
|
171
|
+
if self._vsync:
|
|
172
|
+
self._wait_vsync()
|
|
173
|
+
|
|
174
|
+
glx.glXSwapBuffers(self.x_display, self.glx_window)
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Usage::
|
|
4
4
|
|
|
5
|
-
from pyglet.
|
|
5
|
+
from pyglet.graphics.api.core.current_context.info import platform_info
|
|
6
6
|
|
|
7
|
-
if
|
|
7
|
+
if platform_info.have_extension('GLX_NV_float_buffer'):
|
|
8
8
|
# ...
|
|
9
9
|
|
|
10
|
-
Or, if using more than one
|
|
10
|
+
Or, if using more than one Window::
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
info = GLXInfo(window._display)
|
|
12
|
+
info = window.context.info.platform_info
|
|
15
13
|
if info.get_server_vendor() == 'ATI':
|
|
16
14
|
# ...
|
|
17
15
|
|
|
@@ -22,7 +20,7 @@ from __future__ import annotations
|
|
|
22
20
|
from ctypes import byref, c_int
|
|
23
21
|
from typing import TYPE_CHECKING
|
|
24
22
|
|
|
25
|
-
from pyglet.
|
|
23
|
+
from pyglet.libs.linux.glx.glx import (
|
|
26
24
|
GLX_EXTENSIONS,
|
|
27
25
|
GLX_VENDOR,
|
|
28
26
|
GLX_VERSION,
|
|
@@ -36,22 +34,19 @@ from pyglet.gl.glx import (
|
|
|
36
34
|
from pyglet.util import asstr
|
|
37
35
|
|
|
38
36
|
if TYPE_CHECKING:
|
|
39
|
-
from pyglet.libs.x11
|
|
37
|
+
from pyglet.libs.linux.x11 import xlib
|
|
40
38
|
|
|
41
39
|
|
|
42
|
-
class GLXInfoException(Exception): # noqa:
|
|
40
|
+
class GLXInfoException(Exception): # noqa: N818
|
|
43
41
|
pass
|
|
44
42
|
|
|
45
43
|
|
|
46
|
-
class GLXInfo:
|
|
47
|
-
def __init__(self, display: Display | None = None) -> None:
|
|
44
|
+
class GLXInfo:
|
|
45
|
+
def __init__(self, display: xlib.Display | None = None) -> None:
|
|
48
46
|
# Set default display if not set
|
|
49
|
-
if display and not _glx_info.display:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
self.display = display
|
|
47
|
+
# if display and not _glx_info.display:
|
|
48
|
+
# _glx_info.set_display(display)
|
|
53
49
|
|
|
54
|
-
def set_display(self, display: Display) -> None:
|
|
55
50
|
self.display = display
|
|
56
51
|
|
|
57
52
|
def check_display(self) -> None:
|
|
@@ -105,7 +100,7 @@ class GLXInfo: # noqa: D101
|
|
|
105
100
|
self.check_display()
|
|
106
101
|
return asstr(glXGetClientString(self.display, GLX_EXTENSIONS)).split()
|
|
107
102
|
|
|
108
|
-
def get_extensions(self) -> list[str]:
|
|
103
|
+
def get_extensions(self, _context) -> list[str]:
|
|
109
104
|
self.check_display()
|
|
110
105
|
return asstr(glXQueryExtensionsString(self.display, 0)).split()
|
|
111
106
|
|
|
@@ -113,20 +108,20 @@ class GLXInfo: # noqa: D101
|
|
|
113
108
|
self.check_display()
|
|
114
109
|
if not self.have_version(1, 1):
|
|
115
110
|
return False
|
|
116
|
-
return extension in self.get_extensions()
|
|
111
|
+
return extension in self.get_extensions(None)
|
|
117
112
|
|
|
118
113
|
|
|
119
114
|
# Single instance suitable for apps that use only a single display.
|
|
120
|
-
_glx_info = GLXInfo()
|
|
121
|
-
|
|
122
|
-
set_display = _glx_info.set_display
|
|
123
|
-
check_display = _glx_info.check_display
|
|
124
|
-
have_version = _glx_info.have_version
|
|
125
|
-
get_server_vendor = _glx_info.get_server_vendor
|
|
126
|
-
get_server_version = _glx_info.get_server_version
|
|
127
|
-
get_server_extensions = _glx_info.get_server_extensions
|
|
128
|
-
get_client_vendor = _glx_info.get_client_vendor
|
|
129
|
-
get_client_version = _glx_info.get_client_version
|
|
130
|
-
get_client_extensions = _glx_info.get_client_extensions
|
|
131
|
-
get_extensions = _glx_info.get_extensions
|
|
132
|
-
have_extension = _glx_info.have_extension
|
|
115
|
+
# _glx_info = GLXInfo()
|
|
116
|
+
#
|
|
117
|
+
# set_display = _glx_info.set_display
|
|
118
|
+
# check_display = _glx_info.check_display
|
|
119
|
+
# have_version = _glx_info.have_version
|
|
120
|
+
# get_server_vendor = _glx_info.get_server_vendor
|
|
121
|
+
# get_server_version = _glx_info.get_server_version
|
|
122
|
+
# get_server_extensions = _glx_info.get_server_extensions
|
|
123
|
+
# get_client_vendor = _glx_info.get_client_vendor
|
|
124
|
+
# get_client_version = _glx_info.get_client_version
|
|
125
|
+
# get_client_extensions = _glx_info.get_client_extensions
|
|
126
|
+
# get_extensions = _glx_info.get_extensions
|
|
127
|
+
# have_extension = _glx_info.have_extension
|
|
File without changes
|
|
@@ -8,8 +8,9 @@ from ctypes import (
|
|
|
8
8
|
CFUNCTYPE, POINTER, Structure, c_byte, c_char, c_double, c_float,
|
|
9
9
|
c_int, c_int64, c_short, c_ubyte, c_uint, c_uint64, c_ushort
|
|
10
10
|
)
|
|
11
|
-
|
|
12
|
-
from pyglet.gl.lib import
|
|
11
|
+
|
|
12
|
+
from pyglet.graphics.api.gl.lib import link_GL as _link_function
|
|
13
|
+
from pyglet.graphics.api.gl.lib import c_ptrdiff_t
|
|
13
14
|
|
|
14
15
|
class struct___GLsync(Structure):
|
|
15
16
|
__slots__ = [
|
|
File without changes
|