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.
Files changed (267) hide show
  1. pyglet/__init__.py +67 -61
  2. pyglet/__init__.pyi +15 -8
  3. pyglet/app/__init__.py +22 -13
  4. pyglet/app/async_app.py +212 -0
  5. pyglet/app/base.py +2 -1
  6. pyglet/app/{xlib.py → linux.py} +3 -3
  7. pyglet/config/__init__.py +101 -0
  8. pyglet/config/gl/__init__.py +30 -0
  9. pyglet/config/gl/egl.py +120 -0
  10. pyglet/config/gl/macos.py +262 -0
  11. pyglet/config/gl/windows.py +267 -0
  12. pyglet/config/gl/x11.py +142 -0
  13. pyglet/customtypes.py +43 -2
  14. pyglet/display/__init__.py +8 -6
  15. pyglet/display/base.py +3 -63
  16. pyglet/display/cocoa.py +12 -17
  17. pyglet/display/emscripten.py +39 -0
  18. pyglet/display/headless.py +23 -30
  19. pyglet/display/wayland.py +157 -0
  20. pyglet/display/win32.py +5 -21
  21. pyglet/display/xlib.py +19 -27
  22. pyglet/display/xlib_vidmoderestore.py +2 -2
  23. pyglet/enums.py +183 -0
  24. pyglet/event.py +0 -1
  25. pyglet/experimental/geoshader_sprite.py +15 -13
  26. pyglet/experimental/hidraw.py +6 -15
  27. pyglet/experimental/multitexture_sprite.py +31 -19
  28. pyglet/experimental/particles.py +13 -35
  29. pyglet/font/__init__.py +251 -85
  30. pyglet/font/base.py +116 -61
  31. pyglet/font/dwrite/__init__.py +349 -204
  32. pyglet/font/dwrite/dwrite_lib.py +27 -5
  33. pyglet/font/fontconfig.py +14 -6
  34. pyglet/font/freetype.py +138 -87
  35. pyglet/font/freetype_lib.py +19 -0
  36. pyglet/font/group.py +179 -0
  37. pyglet/font/harfbuzz/__init__.py +3 -3
  38. pyglet/font/pyodide_js.py +310 -0
  39. pyglet/font/quartz.py +319 -126
  40. pyglet/font/ttf.py +45 -3
  41. pyglet/font/user.py +14 -19
  42. pyglet/font/win32.py +45 -21
  43. pyglet/graphics/__init__.py +8 -787
  44. pyglet/graphics/allocation.py +115 -1
  45. pyglet/graphics/api/__init__.py +77 -0
  46. pyglet/graphics/api/base.py +299 -0
  47. pyglet/graphics/api/gl/__init__.py +58 -0
  48. pyglet/graphics/api/gl/base.py +24 -0
  49. pyglet/graphics/{vertexbuffer.py → api/gl/buffer.py} +104 -159
  50. pyglet/graphics/api/gl/cocoa/context.py +76 -0
  51. pyglet/graphics/api/gl/context.py +391 -0
  52. pyglet/graphics/api/gl/default_shaders.py +0 -0
  53. pyglet/graphics/api/gl/draw.py +627 -0
  54. pyglet/graphics/api/gl/egl/__init__.py +0 -0
  55. pyglet/graphics/api/gl/egl/context.py +92 -0
  56. pyglet/graphics/api/gl/enums.py +76 -0
  57. pyglet/graphics/api/gl/framebuffer.py +315 -0
  58. pyglet/graphics/api/gl/gl.py +5463 -0
  59. pyglet/graphics/api/gl/gl_info.py +188 -0
  60. pyglet/graphics/api/gl/global_opengl.py +226 -0
  61. pyglet/{gl → graphics/api/gl}/lib.py +34 -18
  62. pyglet/graphics/api/gl/shader.py +1476 -0
  63. pyglet/graphics/api/gl/shapes.py +55 -0
  64. pyglet/graphics/api/gl/sprite.py +102 -0
  65. pyglet/graphics/api/gl/state.py +219 -0
  66. pyglet/graphics/api/gl/text.py +190 -0
  67. pyglet/graphics/api/gl/texture.py +1526 -0
  68. pyglet/graphics/{vertexarray.py → api/gl/vertexarray.py} +11 -13
  69. pyglet/graphics/api/gl/vertexdomain.py +751 -0
  70. pyglet/graphics/api/gl/win32/__init__.py +0 -0
  71. pyglet/graphics/api/gl/win32/context.py +108 -0
  72. pyglet/graphics/api/gl/win32/wgl_info.py +24 -0
  73. pyglet/graphics/api/gl/xlib/__init__.py +0 -0
  74. pyglet/graphics/api/gl/xlib/context.py +174 -0
  75. pyglet/{gl → graphics/api/gl/xlib}/glx_info.py +26 -31
  76. pyglet/graphics/api/gl1/__init__.py +0 -0
  77. pyglet/{gl → graphics/api/gl1}/gl_compat.py +3 -2
  78. pyglet/graphics/api/gl2/__init__.py +0 -0
  79. pyglet/graphics/api/gl2/buffer.py +320 -0
  80. pyglet/graphics/api/gl2/draw.py +600 -0
  81. pyglet/graphics/api/gl2/global_opengl.py +122 -0
  82. pyglet/graphics/api/gl2/shader.py +200 -0
  83. pyglet/graphics/api/gl2/shapes.py +51 -0
  84. pyglet/graphics/api/gl2/sprite.py +79 -0
  85. pyglet/graphics/api/gl2/text.py +175 -0
  86. pyglet/graphics/api/gl2/vertexdomain.py +364 -0
  87. pyglet/graphics/api/webgl/__init__.py +233 -0
  88. pyglet/graphics/api/webgl/buffer.py +302 -0
  89. pyglet/graphics/api/webgl/context.py +234 -0
  90. pyglet/graphics/api/webgl/draw.py +590 -0
  91. pyglet/graphics/api/webgl/enums.py +76 -0
  92. pyglet/graphics/api/webgl/framebuffer.py +360 -0
  93. pyglet/graphics/api/webgl/gl.py +1537 -0
  94. pyglet/graphics/api/webgl/gl_info.py +130 -0
  95. pyglet/graphics/api/webgl/shader.py +1346 -0
  96. pyglet/graphics/api/webgl/shapes.py +92 -0
  97. pyglet/graphics/api/webgl/sprite.py +102 -0
  98. pyglet/graphics/api/webgl/state.py +227 -0
  99. pyglet/graphics/api/webgl/text.py +187 -0
  100. pyglet/graphics/api/webgl/texture.py +1227 -0
  101. pyglet/graphics/api/webgl/vertexarray.py +54 -0
  102. pyglet/graphics/api/webgl/vertexdomain.py +616 -0
  103. pyglet/graphics/api/webgl/webgl_js.pyi +307 -0
  104. pyglet/{image → graphics}/atlas.py +33 -32
  105. pyglet/graphics/base.py +10 -0
  106. pyglet/graphics/buffer.py +245 -0
  107. pyglet/graphics/draw.py +578 -0
  108. pyglet/graphics/framebuffer.py +26 -0
  109. pyglet/graphics/instance.py +178 -69
  110. pyglet/graphics/shader.py +267 -1553
  111. pyglet/graphics/state.py +83 -0
  112. pyglet/graphics/texture.py +703 -0
  113. pyglet/graphics/vertexdomain.py +695 -538
  114. pyglet/gui/ninepatch.py +10 -10
  115. pyglet/gui/widgets.py +120 -10
  116. pyglet/image/__init__.py +20 -1973
  117. pyglet/image/animation.py +12 -12
  118. pyglet/image/base.py +730 -0
  119. pyglet/image/codecs/__init__.py +9 -0
  120. pyglet/image/codecs/bmp.py +53 -30
  121. pyglet/image/codecs/dds.py +53 -31
  122. pyglet/image/codecs/gdiplus.py +38 -14
  123. pyglet/image/codecs/gdkpixbuf2.py +0 -2
  124. pyglet/image/codecs/js_image.py +99 -0
  125. pyglet/image/codecs/ktx2.py +161 -0
  126. pyglet/image/codecs/pil.py +1 -1
  127. pyglet/image/codecs/png.py +1 -1
  128. pyglet/image/codecs/wic.py +11 -2
  129. pyglet/info.py +26 -24
  130. pyglet/input/__init__.py +8 -0
  131. pyglet/input/base.py +163 -105
  132. pyglet/input/controller.py +13 -19
  133. pyglet/input/controller_db.py +39 -24
  134. pyglet/input/emscripten/__init__.py +18 -0
  135. pyglet/input/emscripten/gamepad_js.py +397 -0
  136. pyglet/input/linux/__init__.py +11 -5
  137. pyglet/input/linux/evdev.py +10 -11
  138. pyglet/input/linux/x11_xinput.py +2 -2
  139. pyglet/input/linux/x11_xinput_tablet.py +1 -1
  140. pyglet/input/macos/__init__.py +7 -2
  141. pyglet/input/macos/darwin_gc.py +559 -0
  142. pyglet/input/win32/__init__.py +1 -1
  143. pyglet/input/win32/directinput.py +34 -29
  144. pyglet/input/win32/xinput.py +11 -61
  145. pyglet/lib.py +3 -3
  146. pyglet/libs/__init__.py +1 -1
  147. pyglet/{gl → libs/darwin}/agl.py +1 -1
  148. pyglet/libs/darwin/cocoapy/__init__.py +2 -2
  149. pyglet/libs/darwin/cocoapy/cocoahelpers.py +181 -0
  150. pyglet/libs/darwin/cocoapy/cocoalibs.py +31 -0
  151. pyglet/libs/darwin/cocoapy/cocoatypes.py +27 -0
  152. pyglet/libs/darwin/cocoapy/runtime.py +81 -45
  153. pyglet/libs/darwin/coreaudio.py +4 -4
  154. pyglet/{gl → libs/darwin}/lib_agl.py +9 -8
  155. pyglet/libs/darwin/quartzkey.py +1 -3
  156. pyglet/libs/egl/__init__.py +2 -0
  157. pyglet/libs/egl/egl_lib.py +576 -0
  158. pyglet/libs/egl/eglext.py +51 -5
  159. pyglet/libs/linux/__init__.py +0 -0
  160. pyglet/libs/linux/egl/__init__.py +0 -0
  161. pyglet/libs/linux/egl/eglext.py +22 -0
  162. pyglet/libs/linux/glx/__init__.py +0 -0
  163. pyglet/{gl → libs/linux/glx}/glx.py +13 -14
  164. pyglet/{gl → libs/linux/glx}/glxext_arb.py +408 -192
  165. pyglet/{gl → libs/linux/glx}/glxext_mesa.py +1 -1
  166. pyglet/{gl → libs/linux/glx}/glxext_nv.py +345 -164
  167. pyglet/{gl → libs/linux/glx}/lib_glx.py +3 -2
  168. pyglet/libs/linux/wayland/__init__.py +0 -0
  169. pyglet/libs/linux/wayland/client.py +1068 -0
  170. pyglet/libs/linux/wayland/lib_wayland.py +207 -0
  171. pyglet/libs/linux/wayland/wayland_egl.py +38 -0
  172. pyglet/libs/{wayland → linux/wayland}/xkbcommon.py +26 -0
  173. pyglet/libs/{x11 → linux/x11}/xf86vmode.py +4 -4
  174. pyglet/libs/{x11 → linux/x11}/xinerama.py +2 -2
  175. pyglet/libs/{x11 → linux/x11}/xinput.py +10 -10
  176. pyglet/libs/linux/x11/xrandr.py +0 -0
  177. pyglet/libs/{x11 → linux/x11}/xrender.py +1 -1
  178. pyglet/libs/shared/__init__.py +0 -0
  179. pyglet/libs/shared/spirv/__init__.py +0 -0
  180. pyglet/libs/shared/spirv/lib_shaderc.py +85 -0
  181. pyglet/libs/shared/spirv/lib_spirv_cross.py +126 -0
  182. pyglet/libs/win32/__init__.py +28 -8
  183. pyglet/libs/win32/constants.py +59 -48
  184. pyglet/libs/win32/context_managers.py +20 -3
  185. pyglet/libs/win32/dinput.py +105 -88
  186. pyglet/{gl → libs/win32}/lib_wgl.py +52 -26
  187. pyglet/libs/win32/types.py +58 -23
  188. pyglet/{gl → libs/win32}/wgl.py +32 -25
  189. pyglet/{gl → libs/win32}/wglext_arb.py +364 -2
  190. pyglet/media/__init__.py +9 -10
  191. pyglet/media/codecs/__init__.py +12 -1
  192. pyglet/media/codecs/base.py +99 -96
  193. pyglet/media/codecs/ffmpeg.py +2 -2
  194. pyglet/media/codecs/ffmpeg_lib/libavformat.py +3 -8
  195. pyglet/media/codecs/webaudio_pyodide.py +111 -0
  196. pyglet/media/drivers/__init__.py +9 -4
  197. pyglet/media/drivers/base.py +4 -4
  198. pyglet/media/drivers/openal/__init__.py +1 -1
  199. pyglet/media/drivers/openal/adaptation.py +3 -3
  200. pyglet/media/drivers/pulse/__init__.py +1 -1
  201. pyglet/media/drivers/pulse/adaptation.py +3 -3
  202. pyglet/media/drivers/pyodide_js/__init__.py +8 -0
  203. pyglet/media/drivers/pyodide_js/adaptation.py +288 -0
  204. pyglet/media/drivers/xaudio2/adaptation.py +3 -3
  205. pyglet/media/player.py +276 -193
  206. pyglet/media/player_worker_thread.py +1 -1
  207. pyglet/model/__init__.py +39 -29
  208. pyglet/model/codecs/base.py +4 -4
  209. pyglet/model/codecs/gltf.py +3 -3
  210. pyglet/model/codecs/obj.py +71 -43
  211. pyglet/resource.py +129 -78
  212. pyglet/shapes.py +154 -194
  213. pyglet/sprite.py +47 -164
  214. pyglet/text/__init__.py +44 -54
  215. pyglet/text/caret.py +12 -7
  216. pyglet/text/document.py +19 -17
  217. pyglet/text/formats/html.py +2 -2
  218. pyglet/text/formats/structured.py +10 -40
  219. pyglet/text/layout/__init__.py +20 -13
  220. pyglet/text/layout/base.py +176 -287
  221. pyglet/text/layout/incremental.py +9 -10
  222. pyglet/text/layout/scrolling.py +7 -95
  223. pyglet/window/__init__.py +183 -172
  224. pyglet/window/cocoa/__init__.py +62 -51
  225. pyglet/window/cocoa/pyglet_delegate.py +2 -25
  226. pyglet/window/cocoa/pyglet_view.py +9 -8
  227. pyglet/window/dialog/__init__.py +184 -0
  228. pyglet/window/dialog/base.py +99 -0
  229. pyglet/window/dialog/darwin.py +121 -0
  230. pyglet/window/dialog/linux.py +72 -0
  231. pyglet/window/dialog/windows.py +194 -0
  232. pyglet/window/emscripten/__init__.py +779 -0
  233. pyglet/window/headless/__init__.py +44 -28
  234. pyglet/window/key.py +2 -0
  235. pyglet/window/mouse.py +2 -2
  236. pyglet/window/wayland/__init__.py +377 -0
  237. pyglet/window/win32/__init__.py +101 -46
  238. pyglet/window/xlib/__init__.py +104 -66
  239. {pyglet-2.1.13.dist-info → pyglet-3.0.dev1.dist-info}/METADATA +2 -3
  240. pyglet-3.0.dev1.dist-info/RECORD +322 -0
  241. {pyglet-2.1.13.dist-info → pyglet-3.0.dev1.dist-info}/WHEEL +1 -1
  242. pyglet/gl/__init__.py +0 -208
  243. pyglet/gl/base.py +0 -499
  244. pyglet/gl/cocoa.py +0 -309
  245. pyglet/gl/gl.py +0 -4625
  246. pyglet/gl/gl.pyi +0 -2320
  247. pyglet/gl/gl_compat.pyi +0 -3097
  248. pyglet/gl/gl_info.py +0 -190
  249. pyglet/gl/headless.py +0 -166
  250. pyglet/gl/wgl_info.py +0 -36
  251. pyglet/gl/wglext_nv.py +0 -1096
  252. pyglet/gl/win32.py +0 -268
  253. pyglet/gl/xlib.py +0 -295
  254. pyglet/image/buffer.py +0 -274
  255. pyglet/image/codecs/s3tc.py +0 -354
  256. pyglet/libs/x11/xrandr.py +0 -166
  257. pyglet-2.1.13.dist-info/RECORD +0 -234
  258. /pyglet/{libs/wayland → graphics/api/gl/cocoa}/__init__.py +0 -0
  259. /pyglet/libs/{egl → linux/egl}/egl.py +0 -0
  260. /pyglet/libs/{egl → linux/egl}/lib.py +0 -0
  261. /pyglet/libs/{ioctl.py → linux/ioctl.py} +0 -0
  262. /pyglet/libs/{wayland → linux/wayland}/gbm.py +0 -0
  263. /pyglet/libs/{x11 → linux/x11}/__init__.py +0 -0
  264. /pyglet/libs/{x11 → linux/x11}/cursorfont.py +0 -0
  265. /pyglet/libs/{x11 → linux/x11}/xlib.py +0 -0
  266. /pyglet/libs/{x11 → linux/x11}/xsync.py +0 -0
  267. {pyglet-2.1.13.dist-info/licenses → pyglet-3.0.dev1.dist-info}/LICENSE +0 -0
pyglet/gl/win32.py DELETED
@@ -1,268 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from ctypes import byref, c_int, c_uint, sizeof
4
-
5
- from pyglet import gl
6
- from pyglet.display.win32 import Win32Canvas
7
- from pyglet.gl import gl_info, wgl, wgl_info, wglext_arb
8
- from pyglet.libs.win32 import PIXELFORMATDESCRIPTOR, _gdi32
9
- from pyglet.libs.win32.constants import (
10
- PFD_DEPTH_DONTCARE,
11
- PFD_DOUBLEBUFFER,
12
- PFD_DOUBLEBUFFER_DONTCARE,
13
- PFD_DRAW_TO_WINDOW,
14
- PFD_STEREO,
15
- PFD_STEREO_DONTCARE,
16
- PFD_SUPPORT_OPENGL,
17
- PFD_TYPE_RGBA,
18
- )
19
-
20
- from .base import DisplayConfig, Config, Context
21
-
22
-
23
- class Win32Config(Config): # noqa: D101
24
-
25
- def match(self, canvas: Win32Canvas) -> list[Win32DisplayConfig] | list[Win32DisplayConfigARB]:
26
- if not isinstance(canvas, Win32Canvas):
27
- msg = 'Canvas must be instance of Win32Canvas'
28
- raise RuntimeError(msg)
29
-
30
- # Use ARB API if available
31
- if gl_info.have_context() and wgl_info.have_extension('WGL_ARB_pixel_format'):
32
- return self._get_arb_pixel_format_matching_configs(canvas)
33
-
34
- return self._get_pixel_format_descriptor_matching_configs(canvas)
35
-
36
- def _get_pixel_format_descriptor_matching_configs(self, canvas: Win32Canvas) -> list[Win32DisplayConfig]:
37
- """Get matching configs using standard PIXELFORMATDESCRIPTOR technique."""
38
- pfd = PIXELFORMATDESCRIPTOR()
39
- pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR)
40
- pfd.nVersion = 1
41
- pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL
42
-
43
- if self.double_buffer:
44
- pfd.dwFlags |= PFD_DOUBLEBUFFER
45
- else:
46
- pfd.dwFlags |= PFD_DOUBLEBUFFER_DONTCARE
47
-
48
- if self.stereo:
49
- pfd.dwFlags |= PFD_STEREO
50
- else:
51
- pfd.dwFlags |= PFD_STEREO_DONTCARE
52
-
53
- # Not supported in pyglet API: swap_copy: PFD_SWAP_COPY and swap_exchange: PFD_SWAP_EXCHANGE
54
-
55
- if not self.depth_size:
56
- pfd.dwFlags |= PFD_DEPTH_DONTCARE
57
-
58
- pfd.iPixelType = PFD_TYPE_RGBA
59
- pfd.cColorBits = self.buffer_size or 0
60
- pfd.cRedBits = self.red_size or 0
61
- pfd.cGreenBits = self.green_size or 0
62
- pfd.cBlueBits = self.blue_size or 0
63
- pfd.cAlphaBits = self.alpha_size or 0
64
- pfd.cAccumRedBits = self.accum_red_size or 0
65
- pfd.cAccumGreenBits = self.accum_green_size or 0
66
- pfd.cAccumBlueBits = self.accum_blue_size or 0
67
- pfd.cAccumAlphaBits = self.accum_alpha_size or 0
68
- pfd.cDepthBits = self.depth_size or 0
69
- pfd.cStencilBits = self.stencil_size or 0
70
- pfd.cAuxBuffers = self.aux_buffers or 0
71
-
72
- pf = _gdi32.ChoosePixelFormat(canvas.hdc, byref(pfd))
73
- if pf:
74
- return [Win32DisplayConfig(canvas, pf, self)]
75
- else:
76
- return []
77
-
78
- def _get_arb_pixel_format_matching_configs(self, canvas: Win32Canvas) -> list[Win32DisplayConfigARB]:
79
- """Get configs using the WGL_ARB_pixel_format extension.
80
-
81
- This method assumes a (dummy) GL context is already created.
82
- """
83
- # Check for required extensions
84
- if (self.sample_buffers or self.samples) and not gl_info.have_extension('GL_ARB_multisample'):
85
- return []
86
-
87
- # Construct array of attributes
88
- attrs = []
89
- for name, value in self.get_gl_attributes():
90
- attr = Win32DisplayConfigARB.attribute_ids.get(name, None)
91
- if attr and value is not None:
92
- attrs.extend([attr, int(value)])
93
- attrs.append(0)
94
- attrs = (c_int * len(attrs))(*attrs)
95
-
96
- pformats = (c_int * 16)()
97
- nformats = c_uint(16)
98
- wglext_arb.wglChoosePixelFormatARB(canvas.hdc, attrs, None, nformats, pformats, nformats)
99
-
100
- formats = [Win32DisplayConfigARB(canvas, pf, self) for pf in pformats[:nformats.value]]
101
- return formats
102
-
103
-
104
- class Win32DisplayConfig(DisplayConfig): # noqa: D101
105
- def __init__(self, canvas: Win32Canvas, pf: int, config: Win32Config) -> None: # noqa: D107
106
- super().__init__(canvas, config)
107
- self._pf = pf
108
- self._pfd = PIXELFORMATDESCRIPTOR()
109
-
110
- _gdi32.DescribePixelFormat(canvas.hdc, pf, sizeof(PIXELFORMATDESCRIPTOR), byref(self._pfd))
111
-
112
- self.double_buffer = bool(self._pfd.dwFlags & PFD_DOUBLEBUFFER)
113
- self.sample_buffers = 0
114
- self.samples = 0
115
- self.stereo = bool(self._pfd.dwFlags & PFD_STEREO)
116
- self.buffer_size = self._pfd.cColorBits
117
- self.red_size = self._pfd.cRedBits
118
- self.green_size = self._pfd.cGreenBits
119
- self.blue_size = self._pfd.cBlueBits
120
- self.alpha_size = self._pfd.cAlphaBits
121
- self.accum_red_size = self._pfd.cAccumRedBits
122
- self.accum_green_size = self._pfd.cAccumGreenBits
123
- self.accum_blue_size = self._pfd.cAccumBlueBits
124
- self.accum_alpha_size = self._pfd.cAccumAlphaBits
125
- self.depth_size = self._pfd.cDepthBits
126
- self.stencil_size = self._pfd.cStencilBits
127
- self.aux_buffers = self._pfd.cAuxBuffers
128
-
129
- def compatible(self, canvas: Win32Canvas) -> bool:
130
- return isinstance(canvas, Win32Canvas)
131
-
132
- def create_context(self, share: Win32Context | None) -> Win32Context:
133
- return Win32Context(self, share)
134
-
135
- def _set_pixel_format(self, canvas: Win32Canvas) -> None:
136
- _gdi32.SetPixelFormat(canvas.hdc, self._pf, byref(self._pfd))
137
-
138
-
139
- class Win32DisplayConfigARB(DisplayConfig): # noqa: D101
140
- attribute_ids = { # noqa: RUF012
141
- 'double_buffer': wglext_arb.WGL_DOUBLE_BUFFER_ARB,
142
- 'stereo': wglext_arb.WGL_STEREO_ARB,
143
- 'buffer_size': wglext_arb.WGL_COLOR_BITS_ARB,
144
- 'aux_buffers': wglext_arb.WGL_AUX_BUFFERS_ARB,
145
- 'sample_buffers': wglext_arb.WGL_SAMPLE_BUFFERS_ARB,
146
- 'samples': wglext_arb.WGL_SAMPLES_ARB,
147
- 'red_size': wglext_arb.WGL_RED_BITS_ARB,
148
- 'green_size': wglext_arb.WGL_GREEN_BITS_ARB,
149
- 'blue_size': wglext_arb.WGL_BLUE_BITS_ARB,
150
- 'alpha_size': wglext_arb.WGL_ALPHA_BITS_ARB,
151
- 'depth_size': wglext_arb.WGL_DEPTH_BITS_ARB,
152
- 'stencil_size': wglext_arb.WGL_STENCIL_BITS_ARB,
153
- 'accum_red_size': wglext_arb.WGL_ACCUM_RED_BITS_ARB,
154
- 'accum_green_size': wglext_arb.WGL_ACCUM_GREEN_BITS_ARB,
155
- 'accum_blue_size': wglext_arb.WGL_ACCUM_BLUE_BITS_ARB,
156
- 'accum_alpha_size': wglext_arb.WGL_ACCUM_ALPHA_BITS_ARB,
157
- }
158
-
159
- def __init__(self, canvas: Win32Canvas, pf: int, config: Win32Config) -> None: # noqa: D107
160
- super().__init__(canvas, config)
161
- self._pf = pf
162
-
163
- names = list(self.attribute_ids.keys())
164
- attrs = list(self.attribute_ids.values())
165
- attrs = (c_int * len(attrs))(*attrs)
166
- values = (c_int * len(attrs))()
167
-
168
- wglext_arb.wglGetPixelFormatAttribivARB(canvas.hdc, pf, 0, len(attrs), attrs, values)
169
-
170
- for name, value in zip(names, values):
171
- setattr(self, name, value)
172
-
173
- def compatible(self, canvas: Win32Canvas) -> bool:
174
- # TODO more careful checking
175
- return isinstance(canvas, Win32Canvas)
176
-
177
- def create_context(self, share: Win32ARBContext | None) -> Win32ARBContext | Win32Context:
178
- if wgl_info.have_extension('WGL_ARB_create_context'):
179
- # Graphics adapters that ONLY support up to OpenGL 3.1/3.2
180
- # should be using the Win32ARBContext class.
181
- return Win32ARBContext(self, share)
182
-
183
- return Win32Context(self, share)
184
-
185
- def _set_pixel_format(self, canvas: Win32Canvas) -> None:
186
- _gdi32.SetPixelFormat(canvas.hdc, self._pf, None)
187
-
188
-
189
- class _BaseWin32Context(Context):
190
- def __init__(self, config: Win32DisplayConfig | Win32DisplayConfigARB, share: Win32Context | Win32ARBContext) -> None:
191
- super().__init__(config, share)
192
- self._context = None
193
-
194
- def set_current(self) -> None:
195
- if self._context is not None and self != gl.current_context:
196
- wgl.wglMakeCurrent(self.canvas.hdc, self._context)
197
- super().set_current()
198
-
199
- def detach(self) -> None:
200
- if self.canvas:
201
- wgl.wglDeleteContext(self._context)
202
- self._context = None
203
- super().detach()
204
-
205
- def flip(self) -> None:
206
- _gdi32.SwapBuffers(self.canvas.hdc)
207
-
208
- def get_vsync(self) -> bool:
209
- if wgl_info.have_extension('WGL_EXT_swap_control'):
210
- return bool(wglext_arb.wglGetSwapIntervalEXT())
211
- return False
212
-
213
- def set_vsync(self, vsync: bool) -> None:
214
- if wgl_info.have_extension('WGL_EXT_swap_control'):
215
- wglext_arb.wglSwapIntervalEXT(int(vsync))
216
-
217
-
218
- class Win32Context(_BaseWin32Context): # noqa: D101
219
- config: Win32DisplayConfig
220
- context_share: Win32Context | None
221
-
222
- def attach(self, canvas: Win32Canvas) -> None:
223
- super().attach(canvas)
224
-
225
- if not self._context:
226
- self.config._set_pixel_format(canvas) # noqa: SLF001
227
- self._context = wgl.wglCreateContext(canvas.hdc)
228
-
229
- share = self.context_share
230
- if share:
231
- if not share.canvas:
232
- msg = 'Share context has no canvas.'
233
- raise RuntimeError(msg)
234
- if not wgl.wglShareLists(share._context, self._context): # noqa: SLF001
235
- msg = 'Unable to share contexts.'
236
- raise gl.ContextException(msg)
237
-
238
-
239
- class Win32ARBContext(_BaseWin32Context): # noqa: D101
240
- config: Win32DisplayConfigARB
241
- context_share: Win32ARBContext | None
242
-
243
- def attach(self, canvas: Win32Canvas) -> None:
244
- share = self.context_share
245
- if share:
246
- if not share.canvas:
247
- msg = 'Share context has no canvas.'
248
- raise RuntimeError(msg)
249
- share = share._context # noqa: SLF001
250
-
251
- attribs = []
252
- if self.config.major_version is not None:
253
- attribs.extend([wglext_arb.WGL_CONTEXT_MAJOR_VERSION_ARB, self.config.major_version])
254
- if self.config.minor_version is not None:
255
- attribs.extend([wglext_arb.WGL_CONTEXT_MINOR_VERSION_ARB, self.config.minor_version])
256
- flags = 0
257
- if self.config.forward_compatible:
258
- flags |= wglext_arb.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
259
- if self.config.debug:
260
- flags |= wglext_arb.WGL_CONTEXT_DEBUG_BIT_ARB
261
- if flags:
262
- attribs.extend([wglext_arb.WGL_CONTEXT_FLAGS_ARB, flags])
263
- attribs.append(0)
264
- attribs = (c_int * len(attribs))(*attribs)
265
-
266
- self.config._set_pixel_format(canvas) # noqa: SLF001
267
- self._context = wglext_arb.wglCreateContextAttribsARB(canvas.hdc, share, attribs)
268
- super().attach(canvas)
pyglet/gl/xlib.py DELETED
@@ -1,295 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import warnings
4
- from _ctypes import _Pointer
5
- from ctypes import POINTER, byref, c_int, c_uint, cast
6
- from typing import TYPE_CHECKING, NoReturn
7
-
8
- from pyglet import gl
9
- from pyglet.gl import glx
10
- from pyglet.gl import glxext_arb
11
- from pyglet.gl import glx_info
12
- from pyglet.gl import glxext_mesa
13
- from pyglet.gl import lib
14
- from pyglet.gl.base import Config, DisplayConfig, Context
15
-
16
- from pyglet.display.xlib import XlibCanvas
17
- from pyglet.libs.x11 import xlib
18
- from pyglet.libs.x11.xrender import XRenderFindVisualFormat
19
-
20
- if TYPE_CHECKING:
21
- from pyglet.libs.x11.xlib import Display
22
- from .glx_info import GLXInfo
23
-
24
-
25
- class XlibConfig(Config): # noqa: D101
26
-
27
- def match(self, canvas: XlibCanvas) -> list[XlibDisplayConfig]:
28
- if not isinstance(canvas, XlibCanvas):
29
- msg = f'Canvas must be an instance of XlibCanvas {type(canvas)}'
30
- raise RuntimeError(msg)
31
-
32
- x_display = canvas.display._display # noqa: SLF001
33
- x_screen = canvas.display.x_screen
34
-
35
- info = glx_info.GLXInfo(x_display)
36
-
37
- # Construct array of attributes
38
- attrs = []
39
- for name, value in self.get_gl_attributes():
40
- attr = XlibDisplayConfig.attribute_ids.get(name, None)
41
- if attr and value is not None:
42
- attrs.extend([attr, int(value)])
43
-
44
- attrs.extend([glx.GLX_X_RENDERABLE, True])
45
- attrs.extend([0, 0]) # attrib_list must be null terminated
46
-
47
- attrib_list = (c_int * len(attrs))(*attrs)
48
-
49
- elements = c_int()
50
- configs = glx.glXChooseFBConfig(x_display, x_screen, attrib_list, byref(elements))
51
- if not configs:
52
- return []
53
-
54
- configs = cast(configs, POINTER(glx.GLXFBConfig * elements.value)).contents
55
-
56
- result = [XlibDisplayConfig(canvas, info, c, self) for c in configs]
57
-
58
- # If we intend to have a transparent framebuffer.
59
- if self.transparent_framebuffer:
60
- result = [fb_cf for fb_cf in result if fb_cf.transparent]
61
-
62
- # Can't free array until all XlibGLConfig's are GC'd. Too much
63
- # hassle, live with leak. XXX
64
- # xlib.XFree(configs)
65
-
66
- return result
67
-
68
-
69
- class XlibDisplayConfig(DisplayConfig): # noqa: D101
70
- glx_info: GLXInfo
71
-
72
- attribute_ids = { # noqa: RUF012
73
- 'buffer_size': glx.GLX_BUFFER_SIZE,
74
- 'level': glx.GLX_LEVEL, # Not supported
75
- 'double_buffer': glx.GLX_DOUBLEBUFFER,
76
- 'stereo': glx.GLX_STEREO,
77
- 'aux_buffers': glx.GLX_AUX_BUFFERS,
78
- 'red_size': glx.GLX_RED_SIZE,
79
- 'green_size': glx.GLX_GREEN_SIZE,
80
- 'blue_size': glx.GLX_BLUE_SIZE,
81
- 'alpha_size': glx.GLX_ALPHA_SIZE,
82
- 'depth_size': glx.GLX_DEPTH_SIZE,
83
- 'stencil_size': glx.GLX_STENCIL_SIZE,
84
- 'accum_red_size': glx.GLX_ACCUM_RED_SIZE,
85
- 'accum_green_size': glx.GLX_ACCUM_GREEN_SIZE,
86
- 'accum_blue_size': glx.GLX_ACCUM_BLUE_SIZE,
87
- 'accum_alpha_size': glx.GLX_ACCUM_ALPHA_SIZE,
88
-
89
- 'sample_buffers': glx.GLX_SAMPLE_BUFFERS,
90
- 'samples': glx.GLX_SAMPLES,
91
-
92
- # Not supported in current pyglet API:
93
- 'render_type': glx.GLX_RENDER_TYPE,
94
- 'config_caveat': glx.GLX_CONFIG_CAVEAT,
95
- 'transparent_type': glx.GLX_TRANSPARENT_TYPE,
96
- 'transparent_index_value': glx.GLX_TRANSPARENT_INDEX_VALUE,
97
- 'transparent_red_value': glx.GLX_TRANSPARENT_RED_VALUE,
98
- 'transparent_green_value': glx.GLX_TRANSPARENT_GREEN_VALUE,
99
- 'transparent_blue_value': glx.GLX_TRANSPARENT_BLUE_VALUE,
100
- 'transparent_alpha_value': glx.GLX_TRANSPARENT_ALPHA_VALUE,
101
-
102
- # Used internally
103
- 'x_renderable': glx.GLX_X_RENDERABLE,
104
- }
105
-
106
- def __init__(self, canvas: XlibCanvas, info: GLXInfo, fbconfig: glx.GLXFBConfig, # noqa: D107
107
- config: XlibConfig) -> None:
108
- super().__init__(canvas, config)
109
-
110
- self.glx_info = info
111
- self.fbconfig = fbconfig
112
- self.transparent = False
113
-
114
- for name, attr in self.attribute_ids.items():
115
- value = c_int()
116
- result = glx.glXGetFBConfigAttrib(canvas.display._display, self.fbconfig, attr, # noqa: SLF001
117
- byref(value))
118
- if result >= 0:
119
- setattr(self, name, value.value)
120
-
121
- # If user intends for a transparent framebuffer, the visual info needs to be
122
- # queried for it. Even if a config supports alpha_size 8 and depth_size 32, there is no
123
- # guarantee the visual info supports that same configuration.
124
- if config.transparent_framebuffer:
125
- xvi_ptr = glx.glXGetVisualFromFBConfig(canvas.display._display, self.fbconfig) # noqa: SLF001
126
- if xvi_ptr:
127
- self.transparent = self._is_visual_transparent(xvi_ptr.contents.visual) # noqa: SLF001
128
- xlib.XFree(xvi_ptr)
129
-
130
- def _is_visual_transparent(self, visual: _Pointer[xlib.Visual]) -> bool:
131
- if not XRenderFindVisualFormat:
132
- return False
133
-
134
- xrender_format = XRenderFindVisualFormat(self.canvas.display._display, visual)
135
- return xrender_format and xrender_format.contents.direct.alphaMask != 0
136
-
137
- def get_visual_info(self) -> glx.XVisualInfo:
138
- return glx.glXGetVisualFromFBConfig(self.canvas.display._display, self.fbconfig).contents # noqa: SLF001
139
-
140
- def create_context(self, share: XlibContext | None) -> XlibContext:
141
- return XlibContext(self, share)
142
-
143
- def compatible(self, canvas: XlibCanvas) -> bool:
144
- # TODO check more
145
- return isinstance(canvas, XlibCanvas)
146
-
147
- def _create_glx_context(self, _share: None) -> NoReturn:
148
- raise NotImplementedError
149
-
150
- def is_complete(self) -> bool:
151
- return True
152
-
153
-
154
- class XlibContext(Context): # noqa: D101
155
- x_display: Display
156
- glx_context: glx.GLXContext
157
- glx_window: glx.GLXWindow | None
158
- _use_video_sync: bool
159
- _vsync: bool
160
- config: XlibDisplayConfig
161
-
162
- _have_SGI_swap_control: bool # noqa: N815
163
- _have_EXT_swap_control: bool # noqa: N815
164
- _have_MESA_swap_control: bool # noqa: N815
165
- _have_SGI_video_sync: bool # noqa: N815
166
-
167
- def __init__(self, config: XlibDisplayConfig, share: XlibContext | None) -> None: # noqa: D107
168
- super().__init__(config, share)
169
-
170
- self.x_display = config.canvas.display._display # noqa: SLF001
171
-
172
- self.glx_context = self._create_glx_context(share)
173
- if not self.glx_context:
174
- # TODO: Check Xlib error generated
175
- msg = 'Could not create GL context'
176
- raise gl.ContextException(msg)
177
-
178
- self._have_SGI_video_sync = config.glx_info.have_extension('GLX_SGI_video_sync')
179
- self._have_SGI_swap_control = config.glx_info.have_extension('GLX_SGI_swap_control')
180
- self._have_EXT_swap_control = config.glx_info.have_extension('GLX_EXT_swap_control')
181
- self._have_MESA_swap_control = config.glx_info.have_extension('GLX_MESA_swap_control')
182
-
183
- # In order of preference:
184
- # 1. GLX_EXT_swap_control (more likely to work where video_sync will not)
185
- # 2. GLX_MESA_swap_control (same as above, but supported by MESA drivers)
186
- # 3. GLX_SGI_video_sync (does not work on Intel 945GM, but that has EXT)
187
- # 4. GLX_SGI_swap_control (cannot be disabled once enabled)
188
- self._use_video_sync = (self._have_SGI_video_sync and
189
- not (self._have_EXT_swap_control or self._have_MESA_swap_control))
190
-
191
- # XXX Mandate that vsync defaults on across all platforms.
192
- self._vsync = True
193
-
194
- self.glx_window = None
195
-
196
- def is_direct(self) -> bool:
197
- return bool(glx.glXIsDirect(self.x_display, self.glx_context))
198
-
199
- def _create_glx_context(self, share: XlibContext | None) -> glx.GLXContext:
200
- if share:
201
- share_context = share.glx_context
202
- else:
203
- share_context = None
204
-
205
- attribs = []
206
- if self.config.major_version is not None:
207
- attribs.extend([glxext_arb.GLX_CONTEXT_MAJOR_VERSION_ARB, self.config.major_version])
208
- if self.config.minor_version is not None:
209
- attribs.extend([glxext_arb.GLX_CONTEXT_MINOR_VERSION_ARB, self.config.minor_version])
210
-
211
- if self.config.opengl_api == "gl":
212
- attribs.extend([glxext_arb.GLX_CONTEXT_PROFILE_MASK_ARB, glxext_arb.GLX_CONTEXT_CORE_PROFILE_BIT_ARB])
213
- elif self.config.opengl_api == "gles":
214
- attribs.extend([glxext_arb.GLX_CONTEXT_PROFILE_MASK_ARB, glxext_arb.GLX_CONTEXT_ES2_PROFILE_BIT_EXT])
215
-
216
- flags = 0
217
- if self.config.forward_compatible:
218
- flags |= glxext_arb.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
219
- if self.config.debug:
220
- flags |= glxext_arb.GLX_CONTEXT_DEBUG_BIT_ARB
221
-
222
- if flags:
223
- attribs.extend([glxext_arb.GLX_CONTEXT_FLAGS_ARB, flags])
224
- attribs.append(0)
225
- attribs = (c_int * len(attribs))(*attribs)
226
-
227
- return glxext_arb.glXCreateContextAttribsARB(self.config.canvas.display._display, # noqa: SLF001
228
- self.config.fbconfig, share_context, True, attribs)
229
-
230
- def attach(self, canvas: XlibCanvas) -> None:
231
- if canvas is self.canvas:
232
- return
233
-
234
- super().attach(canvas)
235
-
236
- self.glx_window = glx.glXCreateWindow(self.x_display, self.config.fbconfig, canvas.x_window, None)
237
- self.set_current()
238
-
239
- def set_current(self) -> None:
240
- glx.glXMakeContextCurrent(self.x_display, self.glx_window, self.glx_window, self.glx_context)
241
- super().set_current()
242
-
243
- def detach(self) -> None:
244
- if not self.canvas:
245
- return
246
-
247
- self.set_current()
248
- gl.glFlush()
249
-
250
- super().detach()
251
-
252
- glx.glXMakeContextCurrent(self.x_display, 0, 0, None)
253
- if self.glx_window:
254
- glx.glXDestroyWindow(self.x_display, self.glx_window)
255
- self.glx_window = None
256
-
257
- def destroy(self) -> None:
258
- super().destroy()
259
- if self.glx_window:
260
- glx.glXDestroyWindow(self.x_display, self.glx_window)
261
- self.glx_window = None
262
- if self.glx_context:
263
- glx.glXDestroyContext(self.x_display, self.glx_context)
264
- self.glx_context = None
265
-
266
- def set_vsync(self, vsync: bool = True) -> None:
267
- self._vsync = vsync
268
- interval = vsync and 1 or 0
269
- try:
270
- if not self._use_video_sync and self._have_EXT_swap_control:
271
- glxext_arb.glXSwapIntervalEXT(self.x_display, glx.glXGetCurrentDrawable(), interval)
272
- elif not self._use_video_sync and self._have_MESA_swap_control:
273
- glxext_mesa.glXSwapIntervalMESA(interval)
274
- elif self._have_SGI_swap_control:
275
- glxext_arb.glXSwapIntervalSGI(interval)
276
- except lib.MissingFunctionException as e:
277
- warnings.warn(str(e))
278
-
279
- def get_vsync(self) -> bool:
280
- return self._vsync
281
-
282
- def _wait_vsync(self) -> None:
283
- if self._vsync and self._have_SGI_video_sync and self._use_video_sync:
284
- count = c_uint()
285
- glxext_arb.glXGetVideoSyncSGI(byref(count))
286
- glxext_arb.glXWaitVideoSyncSGI(2, (count.value + 1) % 2, byref(count))
287
-
288
- def flip(self) -> None:
289
- if not self.glx_window:
290
- return
291
-
292
- if self._vsync:
293
- self._wait_vsync()
294
-
295
- glx.glXSwapBuffers(self.x_display, self.glx_window)