pyglet 2.1.12__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 +4 -17
- 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 +27 -5
- 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 +147 -177
- 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.12.dist-info → pyglet-3.0.dev1.dist-info}/METADATA +2 -3
- pyglet-3.0.dev1.dist-info/RECORD +322 -0
- {pyglet-2.1.12.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.12.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.12.dist-info/licenses → pyglet-3.0.dev1.dist-info}/LICENSE +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Information about version and extensions of current GL implementation.
|
|
2
|
+
|
|
3
|
+
Usage::
|
|
4
|
+
|
|
5
|
+
if pyglet.graphics.api.have_extension('GL_NV_register_combiners'):
|
|
6
|
+
# ...
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from ctypes import c_char_p, cast, c_int, c_float
|
|
12
|
+
from pyglet.graphics.api.gl import gl
|
|
13
|
+
from pyglet.graphics.api.gl.lib import GLException
|
|
14
|
+
|
|
15
|
+
from typing import TYPE_CHECKING
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from pyglet.graphics.api.gl.win32.wgl_info import WGLInfo
|
|
19
|
+
from pyglet.graphics.api.gl.xlib.glx_info import GLXInfo
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class GLInfo:
|
|
23
|
+
"""Information interface for a single GL context.
|
|
24
|
+
|
|
25
|
+
A default instance is created automatically when the first OpenGL context
|
|
26
|
+
is created. You can use the module functions as a convenience for
|
|
27
|
+
this default instance's methods.
|
|
28
|
+
|
|
29
|
+
If you are using more than one context, you must call `set_active_context`
|
|
30
|
+
when the context is active for this `GLInfo` instance.
|
|
31
|
+
"""
|
|
32
|
+
extensions: set[str]
|
|
33
|
+
vendor: str = ''
|
|
34
|
+
renderer: str = ''
|
|
35
|
+
version: str = '0.0'
|
|
36
|
+
major_version: int = 0
|
|
37
|
+
minor_version: int = 0
|
|
38
|
+
opengl_api: str = 'gl'
|
|
39
|
+
|
|
40
|
+
was_queried = False
|
|
41
|
+
|
|
42
|
+
platform_info: GLXInfo | WGLInfo | None
|
|
43
|
+
|
|
44
|
+
def __init__(self, platform_info: GLXInfo | WGLInfo | None) -> None:
|
|
45
|
+
"""Store information for the currently active context.
|
|
46
|
+
|
|
47
|
+
Combines any information from the platform information.
|
|
48
|
+
"""
|
|
49
|
+
super().__init__()
|
|
50
|
+
self.extensions = set()
|
|
51
|
+
|
|
52
|
+
# A subset of OpenGL that is platform specific. (WGL, GLX)
|
|
53
|
+
self.platform_info = platform_info
|
|
54
|
+
|
|
55
|
+
def query(self, context) -> None:
|
|
56
|
+
self.context = context
|
|
57
|
+
self.vendor = self.get_str(gl.GL_VENDOR)
|
|
58
|
+
"""The vendor string. For example 'NVIDIA Corporation'"""
|
|
59
|
+
|
|
60
|
+
self.renderer = self.get_str(gl.GL_RENDERER)
|
|
61
|
+
"""The graphics renderer. For example "NVIDIA GeForce RTX 2080 SUPER/PCIe/SSE2"""
|
|
62
|
+
|
|
63
|
+
self.version = self.get_str(gl.GL_VERSION)
|
|
64
|
+
|
|
65
|
+
self.MAX_ARRAY_TEXTURE_LAYERS = self.get_int(gl.GL_MAX_ARRAY_TEXTURE_LAYERS)
|
|
66
|
+
"""Value indicates the maximum number of layers allowed in a texture array"""
|
|
67
|
+
|
|
68
|
+
self.MAX_TEXTURE_SIZE = self.get_int(gl.GL_MAX_TEXTURE_SIZE)
|
|
69
|
+
"""The largest texture size available."""
|
|
70
|
+
|
|
71
|
+
self.MAX_COLOR_ATTACHMENTS = self.get_int(gl.GL_MAX_COLOR_ATTACHMENTS)
|
|
72
|
+
"""Get the maximum allowable framebuffer color attachments."""
|
|
73
|
+
|
|
74
|
+
self.MAX_COLOR_TEXTURE_SAMPLES = self.get_int(gl.GL_MAX_COLOR_TEXTURE_SAMPLES)
|
|
75
|
+
"""Maximum number of samples in a color multisample texture"""
|
|
76
|
+
|
|
77
|
+
self.MAX_TEXTURE_IMAGE_UNITS = self.get_int(gl.GL_MAX_TEXTURE_IMAGE_UNITS)
|
|
78
|
+
"""Maximum number of texture units that can be used."""
|
|
79
|
+
|
|
80
|
+
self.MAX_UNIFORM_BUFFER_BINDINGS = self.get_int(gl.GL_MAX_UNIFORM_BUFFER_BINDINGS)
|
|
81
|
+
|
|
82
|
+
# NOTE: The version string requirements for gles is a lot stricter
|
|
83
|
+
# so using this to rely on detecting the API is not too unreasonable
|
|
84
|
+
self.opengl_api = "gles" if "opengl es" in self.version.lower() else "gl"
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
self.major_version = self.get_int(gl.GL_MAJOR_VERSION)
|
|
88
|
+
"""Major version number of the OpenGL API supported by the current context."""
|
|
89
|
+
|
|
90
|
+
self.minor_version = self.get_int(gl.GL_MINOR_VERSION)
|
|
91
|
+
"""Minor version number of the OpenGL API supported by the current context"""
|
|
92
|
+
|
|
93
|
+
num_ext = self.get_int(gl.GL_NUM_EXTENSIONS)
|
|
94
|
+
extensions = (self.get_str_index(gl.GL_EXTENSIONS, i) for i in range(num_ext))
|
|
95
|
+
self.extensions = set(extensions)
|
|
96
|
+
except GLException:
|
|
97
|
+
pass # GL3 is likely not available
|
|
98
|
+
|
|
99
|
+
if self.platform_info:
|
|
100
|
+
self.extensions.update(set(self.platform_info.get_extensions(context)))
|
|
101
|
+
|
|
102
|
+
self.was_queried = True
|
|
103
|
+
|
|
104
|
+
def have_extension(self, extension: str) -> bool:
|
|
105
|
+
"""Determine if an OpenGL extension is available.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
extension:
|
|
109
|
+
The name of the extension to test for, including its ``GL_`` prefix.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
True if the extension is provided by the driver.
|
|
113
|
+
"""
|
|
114
|
+
return extension in self.extensions
|
|
115
|
+
|
|
116
|
+
def get_extensions(self) -> set[str]:
|
|
117
|
+
"""Get a set of available OpenGL extensions."""
|
|
118
|
+
return self.extensions
|
|
119
|
+
|
|
120
|
+
def get_version(self) -> tuple[int, int]:
|
|
121
|
+
"""Get the current major and minor version of OpenGL."""
|
|
122
|
+
return self.major_version, self.minor_version
|
|
123
|
+
|
|
124
|
+
def get_version_string(self) -> str:
|
|
125
|
+
"""Get the current OpenGL version string."""
|
|
126
|
+
return self.version
|
|
127
|
+
|
|
128
|
+
def have_version(self, major: int, minor: int = 0) -> bool:
|
|
129
|
+
"""Determine if a version of OpenGL is supported.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
major:
|
|
133
|
+
The major revision number (typically 1 or 2).
|
|
134
|
+
minor:
|
|
135
|
+
The minor revision number.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
``True`` if the requested or a later version is supported.
|
|
139
|
+
"""
|
|
140
|
+
if not self.major_version and not self.minor_version:
|
|
141
|
+
return False
|
|
142
|
+
|
|
143
|
+
return (self.major_version > major or
|
|
144
|
+
(self.major_version == major and self.minor_version >= minor) or
|
|
145
|
+
(self.major_version == major and self.minor_version == minor))
|
|
146
|
+
|
|
147
|
+
def get_renderer(self) -> str:
|
|
148
|
+
"""Determine the renderer string of the OpenGL context."""
|
|
149
|
+
return self.renderer
|
|
150
|
+
|
|
151
|
+
def get_vendor(self) -> str:
|
|
152
|
+
"""Determine the vendor string of the OpenGL context."""
|
|
153
|
+
return self.vendor
|
|
154
|
+
|
|
155
|
+
def get_opengl_api(self) -> str:
|
|
156
|
+
"""Determine the OpenGL API version.
|
|
157
|
+
|
|
158
|
+
Usually ``gl`` or ``gles``.
|
|
159
|
+
"""
|
|
160
|
+
return self.opengl_api
|
|
161
|
+
|
|
162
|
+
def get_int(self, enum: int, default: int=0) -> int | tuple[int]:
|
|
163
|
+
try:
|
|
164
|
+
value = c_int()
|
|
165
|
+
self.context.glGetIntegerv(enum, value)
|
|
166
|
+
return value.value
|
|
167
|
+
except GLException:
|
|
168
|
+
return default
|
|
169
|
+
|
|
170
|
+
def get_float(self, enum: int, default=0.0) -> float:
|
|
171
|
+
try:
|
|
172
|
+
value = c_float()
|
|
173
|
+
self.context.glGetFloatv(enum, value)
|
|
174
|
+
return value.value
|
|
175
|
+
except GLException:
|
|
176
|
+
return default
|
|
177
|
+
|
|
178
|
+
def get_str(self, enum: int) -> str:
|
|
179
|
+
try:
|
|
180
|
+
return cast(self.context.glGetString(enum), c_char_p).value.decode()
|
|
181
|
+
except GLException:
|
|
182
|
+
return "Unknown"
|
|
183
|
+
|
|
184
|
+
def get_str_index(self, enum: int, index: int) -> str:
|
|
185
|
+
try:
|
|
186
|
+
return cast(self.context.glGetStringi(enum, index), c_char_p).value.decode()
|
|
187
|
+
except GLException:
|
|
188
|
+
return "Unknown"
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import warnings
|
|
5
|
+
from typing import Sequence, TYPE_CHECKING, Literal
|
|
6
|
+
|
|
7
|
+
import pyglet
|
|
8
|
+
from pyglet.graphics.api.base import BackendGlobalObject, SurfaceContext, UBOMatrixTransformations
|
|
9
|
+
from pyglet.math import Mat4
|
|
10
|
+
from pyglet.graphics.api.gl.shader import Shader, ShaderProgram
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from pyglet.graphics.api.gl.win32.wgl import WGLFunctions
|
|
14
|
+
from pyglet.graphics.shader import ShaderType
|
|
15
|
+
from pyglet.graphics.api.gl import OpenGLWindowConfig, ObjectSpace, OpenGLSurfaceContext
|
|
16
|
+
from pyglet.window import Window
|
|
17
|
+
|
|
18
|
+
_is_pyglet_doc_run = hasattr(sys, "is_pyglet_doc_run") and sys.is_pyglet_doc_run
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class OpenGL3_Matrices(UBOMatrixTransformations):
|
|
22
|
+
# Create a default ShaderProgram, so the Window instance can
|
|
23
|
+
# update the `WindowBlock` UBO shared by all default shaders.
|
|
24
|
+
_default_vertex_source = """#version 150 core
|
|
25
|
+
in vec4 position;
|
|
26
|
+
|
|
27
|
+
uniform WindowBlock
|
|
28
|
+
{
|
|
29
|
+
mat4 projection;
|
|
30
|
+
mat4 view;
|
|
31
|
+
} window;
|
|
32
|
+
|
|
33
|
+
void main()
|
|
34
|
+
{
|
|
35
|
+
gl_Position = window.projection * window.view * position;
|
|
36
|
+
}
|
|
37
|
+
"""
|
|
38
|
+
_default_fragment_source = """#version 150 core
|
|
39
|
+
out vec4 color;
|
|
40
|
+
|
|
41
|
+
void main()
|
|
42
|
+
{
|
|
43
|
+
color = vec4(1.0, 0.0, 0.0, 1.0);
|
|
44
|
+
}
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __init__(self, window: Window, backend: OpenGLBackend):
|
|
48
|
+
|
|
49
|
+
self._default_program = backend.create_shader_program(
|
|
50
|
+
backend.create_shader(self._default_vertex_source, 'vertex'),
|
|
51
|
+
backend.create_shader(self._default_fragment_source, 'fragment'))
|
|
52
|
+
|
|
53
|
+
window_block = self._default_program.uniform_blocks['WindowBlock']
|
|
54
|
+
self.ubo = window_block.create_ubo()
|
|
55
|
+
window_block.bind(self.ubo)
|
|
56
|
+
|
|
57
|
+
self._viewport = (0, 0, *window.get_framebuffer_size())
|
|
58
|
+
|
|
59
|
+
width, height = window.get_size()
|
|
60
|
+
|
|
61
|
+
super().__init__(window, Mat4.orthogonal_projection(0, width, 0, height, -255, 255), Mat4(), Mat4())
|
|
62
|
+
|
|
63
|
+
with self.ubo as window_block:
|
|
64
|
+
window_block.view[:] = self._view
|
|
65
|
+
window_block.projection[:] = self._projection
|
|
66
|
+
#window_block.model[:] = self._model
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def projection(self) -> Mat4:
|
|
70
|
+
return self._projection
|
|
71
|
+
|
|
72
|
+
@projection.setter
|
|
73
|
+
def projection(self, projection: Mat4):
|
|
74
|
+
with self.ubo as window_block:
|
|
75
|
+
window_block.projection[:] = projection
|
|
76
|
+
|
|
77
|
+
self._projection = projection
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def view(self) -> Mat4:
|
|
81
|
+
return self._view
|
|
82
|
+
|
|
83
|
+
@view.setter
|
|
84
|
+
def view(self, view: Mat4):
|
|
85
|
+
with self.ubo as window_block:
|
|
86
|
+
window_block.view[:] = view
|
|
87
|
+
|
|
88
|
+
self._view = view
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def model(self) -> Mat4:
|
|
92
|
+
return self._model
|
|
93
|
+
|
|
94
|
+
@model.setter
|
|
95
|
+
def model(self, model: Mat4):
|
|
96
|
+
with self.ubo as window_block:
|
|
97
|
+
window_block.model[:] = model
|
|
98
|
+
|
|
99
|
+
self._model = model
|
|
100
|
+
|
|
101
|
+
class OpenGLBackend(BackendGlobalObject):
|
|
102
|
+
platform_func: WGLFunctions | None
|
|
103
|
+
gl_api: Literal["gl", "gles"]
|
|
104
|
+
current_context: OpenGLSurfaceContext | None
|
|
105
|
+
_have_context: bool = False
|
|
106
|
+
|
|
107
|
+
def __init__(self, gl_api: Literal["gl", "gles"] = "gl") -> None:
|
|
108
|
+
self.gl_api = gl_api
|
|
109
|
+
self.initialized = False
|
|
110
|
+
self.current_context = None
|
|
111
|
+
|
|
112
|
+
# When the shadow window is created, a context is made. This is used to help the "real" context to utilize
|
|
113
|
+
# its full capabilities; however, the two contexts have no relationship normally. This is used for the purpose
|
|
114
|
+
# of sharing basic information between contexts. However, in usage, the user or internals should use the
|
|
115
|
+
# "real" context's information to prevent any discrepencies.
|
|
116
|
+
self.platform_func = None
|
|
117
|
+
self.platform_exts = []
|
|
118
|
+
super().__init__()
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def object_space(self) -> ObjectSpace:
|
|
122
|
+
assert self.current_context is not None, "Context has not been created."
|
|
123
|
+
return self.current_context.object_space
|
|
124
|
+
|
|
125
|
+
def create_context(self, config: OpenGLWindowConfig, shared: OpenGLSurfaceContext | None) -> OpenGLSurfaceContext:
|
|
126
|
+
return config.create_context(self, shared)
|
|
127
|
+
|
|
128
|
+
def get_surface_context(self, window: Window, config: OpenGLWindowConfig) -> SurfaceContext:
|
|
129
|
+
context = self.windows[window] = self.create_context(config, shared=self.current_context)
|
|
130
|
+
self._have_context = True
|
|
131
|
+
return context
|
|
132
|
+
|
|
133
|
+
def get_default_configs(self) -> Sequence[pyglet.config.OpenGLConfig]:
|
|
134
|
+
"""A sequence of configs to use if the user does not specify any.
|
|
135
|
+
|
|
136
|
+
These will be used during Window creation.
|
|
137
|
+
"""
|
|
138
|
+
# On Windows if you specify GLES but set 3.3 as major/minor version, it will upgrade to a full context.
|
|
139
|
+
# Version 3.2 needs to be specified explicitly.
|
|
140
|
+
if self.gl_api == "gles":
|
|
141
|
+
configs = [
|
|
142
|
+
pyglet.config.OpenGLConfig(double_buffer=True, depth_size=24, major_version=3, minor_version=2,
|
|
143
|
+
opengl_api=self.gl_api),
|
|
144
|
+
pyglet.config.OpenGLConfig(double_buffer=True, depth_size=16, major_version=3, minor_version=2,
|
|
145
|
+
opengl_api=self.gl_api),
|
|
146
|
+
]
|
|
147
|
+
else:
|
|
148
|
+
configs = [
|
|
149
|
+
pyglet.config.OpenGLConfig(double_buffer=True, depth_size=24, major_version=3, minor_version=3),
|
|
150
|
+
pyglet.config.OpenGLConfig(double_buffer=True, depth_size=16, major_version=3, minor_version=3),
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
return configs
|
|
154
|
+
|
|
155
|
+
def get_config(self, **kwargs: float | str | None) -> pyglet.config.OpenGLConfig:
|
|
156
|
+
return pyglet.config.OpenGLConfig(**kwargs)
|
|
157
|
+
|
|
158
|
+
def get_info(self):
|
|
159
|
+
return self.current_context.get_info()
|
|
160
|
+
|
|
161
|
+
def have_extension(self, extension_name: str) -> bool:
|
|
162
|
+
if not self.current_context:
|
|
163
|
+
warnings.warn('No GL context created yet or current context not set.')
|
|
164
|
+
return False
|
|
165
|
+
|
|
166
|
+
return self.current_context.get_info().have_extension(extension_name)
|
|
167
|
+
|
|
168
|
+
def have_version(self, major: int, minor: int = 0) -> bool:
|
|
169
|
+
if not self.current_context:
|
|
170
|
+
warnings.warn('No GL context created yet or current context not set.')
|
|
171
|
+
return False
|
|
172
|
+
|
|
173
|
+
return self.current_context.get_info().have_version(major, minor)
|
|
174
|
+
|
|
175
|
+
def get_cached_shader(self, name: str, *sources: tuple[str, ShaderType]) -> ShaderProgram:
|
|
176
|
+
"""Create a ShaderProgram from OpenGL GLSL source.
|
|
177
|
+
|
|
178
|
+
This is a convenience method that takes one or more tuples of
|
|
179
|
+
(source_string, shader_type), and returns a
|
|
180
|
+
:py:class:`~pyglet.graphics.ShaderProgram` instance.
|
|
181
|
+
|
|
182
|
+
``source_string`` is OpenGL GLSL source code as a str, and ``shader_type``
|
|
183
|
+
is the OpenGL shader type, such as "vertex" or "fragment". See
|
|
184
|
+
:py:class:`~pyglet.graphics.Shader` for more information.
|
|
185
|
+
|
|
186
|
+
.. note:: This method is cached. Given the same shader sources, the
|
|
187
|
+
same ShaderProgram instance will be returned. For more
|
|
188
|
+
control over the ShaderProgram lifecycle, it is recommended
|
|
189
|
+
to manually create Shaders and link ShaderPrograms.
|
|
190
|
+
|
|
191
|
+
.. versionadded:: 2.0.10
|
|
192
|
+
"""
|
|
193
|
+
assert self.current_context
|
|
194
|
+
assert isinstance(name, str), "First argument must be a string name for the shader."
|
|
195
|
+
if program := self.current_context.cached_programs.get(name):
|
|
196
|
+
return program
|
|
197
|
+
|
|
198
|
+
shaders = (Shader(src, srctype) for (src, srctype) in sources)
|
|
199
|
+
program = ShaderProgram(*shaders)
|
|
200
|
+
self.current_context.cached_programs[name] = program
|
|
201
|
+
return program
|
|
202
|
+
|
|
203
|
+
def create_shader_program(self, *shaders: Shader) -> ShaderProgram:
|
|
204
|
+
return ShaderProgram(*shaders)
|
|
205
|
+
|
|
206
|
+
def create_shader(self, source_string: str, shader_type: ShaderType) -> Shader:
|
|
207
|
+
return Shader(source_string, shader_type)
|
|
208
|
+
|
|
209
|
+
def get_default_batch(self) -> pyglet.graphics.Batch:
|
|
210
|
+
assert self.current_context
|
|
211
|
+
if not hasattr(self.current_context, "default_batch"):
|
|
212
|
+
self.current_context.default_batch = pyglet.graphics.Batch()
|
|
213
|
+
|
|
214
|
+
return self.current_context.default_batch
|
|
215
|
+
|
|
216
|
+
@property
|
|
217
|
+
def have_context(self) -> bool:
|
|
218
|
+
return self._have_context
|
|
219
|
+
|
|
220
|
+
def initialize_matrices(self, window):
|
|
221
|
+
return OpenGL3_Matrices(window, self)
|
|
222
|
+
|
|
223
|
+
def set_viewport(self, window, x: int, y: int, width: int, height: int) -> None:
|
|
224
|
+
self.current_context.glViewport(x, y, width, height)
|
|
225
|
+
|
|
226
|
+
|
|
@@ -5,12 +5,10 @@ from typing import Any, Callable, NoReturn, Sequence
|
|
|
5
5
|
|
|
6
6
|
import pyglet
|
|
7
7
|
|
|
8
|
-
__all__ = ['link_GL', 'link_AGL', 'link_GLX', 'link_WGL',
|
|
9
|
-
'GLException', 'missing_function', 'decorate_function']
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
_debug_api = pyglet.options.debug_api
|
|
10
|
+
_debug_api_trace = pyglet.options.debug_api_trace
|
|
11
|
+
_debug_api_trace_args = pyglet.options.debug_api_trace_args
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
class MissingFunctionException(Exception): # noqa: N818
|
|
@@ -23,7 +21,7 @@ class MissingFunctionException(Exception): # noqa: N818
|
|
|
23
21
|
Exception.__init__(self, msg)
|
|
24
22
|
|
|
25
23
|
|
|
26
|
-
def missing_function(name: str, requires: str | None =None, suggestions: Sequence[str] | None=None) -> Callable:
|
|
24
|
+
def missing_function(name: str, requires: str | None =None, suggestions: Sequence[str] | None=None) -> Callable:
|
|
27
25
|
def MissingFunction(*_args, **_kwargs) -> NoReturn: # noqa: ANN002, ANN003, N802
|
|
28
26
|
raise MissingFunctionException(name, requires, suggestions)
|
|
29
27
|
|
|
@@ -53,21 +51,22 @@ class GLException(Exception):
|
|
|
53
51
|
|
|
54
52
|
|
|
55
53
|
def errcheck(result: Any, func: Callable, arguments: Sequence) -> Any:
|
|
56
|
-
if
|
|
54
|
+
if _debug_api_trace:
|
|
57
55
|
try:
|
|
58
56
|
name = func.__name__
|
|
59
57
|
except AttributeError:
|
|
60
58
|
name = repr(func)
|
|
61
|
-
if
|
|
62
|
-
trace_args = ', '.join([repr(arg)
|
|
63
|
-
print(f'{name}({trace_args})')
|
|
59
|
+
if _debug_api_trace_args:
|
|
60
|
+
trace_args = ', '.join([repr(arg) for arg in arguments])
|
|
61
|
+
print(f'{name}({trace_args[:255]})')
|
|
64
62
|
else:
|
|
65
63
|
print(name)
|
|
66
64
|
|
|
67
|
-
from pyglet import gl
|
|
68
|
-
|
|
65
|
+
from pyglet.graphics.api import core, gl
|
|
66
|
+
ctx = core.current_context
|
|
67
|
+
if not ctx:
|
|
69
68
|
raise GLException('No GL context; create a Window first')
|
|
70
|
-
error =
|
|
69
|
+
error = ctx.glGetError()
|
|
71
70
|
if error:
|
|
72
71
|
# These are the 6 possible error codes we can get in opengl core 3.3+
|
|
73
72
|
error_types = {
|
|
@@ -84,8 +83,8 @@ def errcheck(result: Any, func: Callable, arguments: Sequence) -> Any:
|
|
|
84
83
|
return result
|
|
85
84
|
|
|
86
85
|
|
|
87
|
-
def decorate_function(func: Callable, name: str) -> None:
|
|
88
|
-
if
|
|
86
|
+
def decorate_function(func: Callable, name: str) -> None:
|
|
87
|
+
if _debug_api and name not in ('glGetError',) and name[:3] not in ('glX', 'agl', 'wgl'):
|
|
89
88
|
func.errcheck = errcheck
|
|
90
89
|
func.__name__ = name
|
|
91
90
|
|
|
@@ -93,10 +92,27 @@ def decorate_function(func: Callable, name: str) -> None: # noqa: D103
|
|
|
93
92
|
link_AGL = None
|
|
94
93
|
link_GLX = None
|
|
95
94
|
link_WGL = None
|
|
95
|
+
link_WGL_proxy = None
|
|
96
|
+
link_GL_proxy = None
|
|
96
97
|
|
|
97
98
|
if pyglet.compat_platform in ('win32', 'cygwin'):
|
|
98
|
-
from pyglet.
|
|
99
|
+
from pyglet.libs.win32.lib_wgl import link_GL, link_GL_proxy, link_WGL
|
|
99
100
|
elif pyglet.compat_platform == 'darwin':
|
|
100
|
-
from pyglet.
|
|
101
|
+
from pyglet.libs.darwin.lib_agl import link_GL, link_GL_proxy, link_AGL
|
|
102
|
+
elif pyglet.compat_platform.startswith('linux'):
|
|
103
|
+
from pyglet.libs.linux.glx.lib_glx import link_GL, link_GL_proxy, link_GLX # noqa: F401
|
|
101
104
|
else:
|
|
102
|
-
|
|
105
|
+
raise Exception("Platform not available.")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
__all__ = [
|
|
109
|
+
'GLException',
|
|
110
|
+
'MissingFunctionException',
|
|
111
|
+
'decorate_function',
|
|
112
|
+
'link_AGL',
|
|
113
|
+
'link_GL',
|
|
114
|
+
'link_GLX',
|
|
115
|
+
'link_WGL',
|
|
116
|
+
'link_WGL_proxy',
|
|
117
|
+
'missing_function',
|
|
118
|
+
]
|