glcontext 3.2.0__cp313-cp313t-win_arm64.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.
glcontext/__init__.py ADDED
@@ -0,0 +1,143 @@
1
+ import os
2
+
3
+ __version__ = '3.2.0'
4
+
5
+
6
+ def default_backend():
7
+ """Get default backend based on the detected platform.
8
+ Supports detecting an existing context and standalone contexts.
9
+ If no context if found for the platform we return the linux backend.
10
+
11
+ Example::
12
+
13
+ # Get the available backend
14
+ backend = get_default_backend(standalone=False/True)
15
+ # Create an opengl 3.3 context or detect the currently active
16
+ # context requiring at least opengl 3.3 support.
17
+ ctx = backend(330)
18
+
19
+ Returns:
20
+ A backend object for creating and/or detecting context
21
+ """
22
+ PLATFORMS = {'windows', 'linux', 'darwin'}
23
+
24
+ import platform
25
+ target = platform.system().lower()
26
+
27
+ for known in PLATFORMS:
28
+ if target.startswith(known):
29
+ target = known
30
+
31
+ if target not in PLATFORMS:
32
+ target = 'linux'
33
+
34
+ if target == 'windows':
35
+ return _wgl()
36
+
37
+ if target == 'linux':
38
+ return _x11()
39
+
40
+ if target == 'darwin':
41
+ return _darwin()
42
+
43
+ raise ValueError("Cannot find suitable default backend")
44
+
45
+
46
+ def get_backend_by_name(name: str):
47
+ """Request a specific backend by name"""
48
+ if name == 'egl':
49
+ return _egl()
50
+
51
+ raise ValueError("Cannot find supported backend: '{}'".format(name))
52
+
53
+
54
+ def _wgl():
55
+ """Create wgl backend"""
56
+ from glcontext import wgl
57
+
58
+ def create(*args, **kwargs):
59
+ _apply_env_var(kwargs, 'glversion', 'GLCONTEXT_GLVERSION', arg_type=int)
60
+ _apply_env_var(kwargs, 'libgl', 'GLCONTEXT_WIN_LIBGL')
61
+
62
+ # make sure libgl is an absolute path
63
+ if 'libgl' in kwargs:
64
+ _libgl = kwargs['libgl']
65
+ if '/' in _libgl or '\\' in _libgl:
66
+ kwargs['libgl'] = os.path.abspath(_libgl)
67
+
68
+ kwargs = _strip_kwargs(kwargs, ['glversion', 'mode', 'libgl'])
69
+ return wgl.create_context(**kwargs)
70
+
71
+ return create
72
+
73
+
74
+ def _x11():
75
+ """Create x11 backend"""
76
+ from glcontext import x11
77
+ from ctypes.util import find_library
78
+
79
+ def create(*args, **kwargs):
80
+ if not kwargs.get('libgl'):
81
+ kwargs['libgl'] = find_library('GL')
82
+
83
+ if not kwargs.get('libx11'):
84
+ kwargs['libx11'] = find_library("X11")
85
+
86
+ _apply_env_var(kwargs, 'glversion', 'GLCONTEXT_GLVERSION', arg_type=int)
87
+ _apply_env_var(kwargs, 'libgl', 'GLCONTEXT_LINUX_LIBGL')
88
+ _apply_env_var(kwargs, 'libx11', 'GLCONTEXT_LINUX_LIBX11')
89
+ kwargs = _strip_kwargs(kwargs, ['glversion', 'mode', 'libgl', 'libx11'])
90
+ return x11.create_context(**kwargs)
91
+
92
+ return create
93
+
94
+
95
+ def _darwin():
96
+ """Create darwin/cgl context"""
97
+ from glcontext import darwin
98
+
99
+ def create(*args, **kwargs):
100
+ return darwin.create_context(**_strip_kwargs(kwargs, ['mode']))
101
+
102
+ return create
103
+
104
+
105
+ def _egl():
106
+ from glcontext import egl
107
+ from ctypes.util import find_library
108
+
109
+ def create(*args, **kwargs):
110
+ if not kwargs.get('libgl'):
111
+ kwargs['libgl'] = find_library('GL')
112
+ if not kwargs.get('libegl'):
113
+ kwargs['libegl'] = find_library('EGL')
114
+
115
+ _apply_env_var(kwargs, 'device_index', 'GLCONTEXT_DEVICE_INDEX', arg_type=int)
116
+ _apply_env_var(kwargs, 'glversion', 'GLCONTEXT_GLVERSION', arg_type=int)
117
+ _apply_env_var(kwargs, 'libgl', 'GLCONTEXT_LINUX_LIBGL')
118
+ _apply_env_var(kwargs, 'libegl', 'GLCONTEXT_LINUX_LIBEGL')
119
+ kwargs = _strip_kwargs(kwargs, ['glversion', 'mode', 'libgl', 'libegl', 'device_index'])
120
+ return egl.create_context(**kwargs)
121
+
122
+ return create
123
+
124
+
125
+ def _strip_kwargs(kwargs: dict, supported_args: list):
126
+ """Strips away unwanted keyword arguments.
127
+
128
+ The backends are using ``PyArg_ParseTupleAndKeywords`` to
129
+ parse the incoming ``kwargs`` data. It's not well suited
130
+ to handle additional arguments.
131
+
132
+ - Removes None key arguments
133
+ - Removes unsupported arguments
134
+ """
135
+ return {k: v for k, v in kwargs.items() if v is not None and k in supported_args}
136
+
137
+
138
+ def _apply_env_var(kwargs, arg_name, env_name, arg_type=str):
139
+ """Injects an environment variable into the arg dict if present"""
140
+ value = os.environ.get(env_name, kwargs.get(arg_name))
141
+ if value:
142
+ kwargs[arg_name] = arg_type(value)
143
+
glcontext/empty.py ADDED
@@ -0,0 +1,19 @@
1
+ class GLContext:
2
+ def __init__(self):
3
+ pass
4
+
5
+ def load_opengl_function(self, name):
6
+ return 0
7
+
8
+ def __enter__(self):
9
+ pass
10
+
11
+ def __exit__(self, *args):
12
+ pass
13
+
14
+ def release(self):
15
+ pass
16
+
17
+
18
+ def create_context():
19
+ return GLContext()
Binary file
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.4
2
+ Name: glcontext
3
+ Version: 3.2.0
4
+ Summary: Portable Headless OpenGL Context
5
+ Home-page: https://github.com/moderngl/glcontext
6
+ Author: Szabolcs Dombi
7
+ Author-email: szabolcs@szabolcsdombi.com
8
+ License: MIT
9
+ Platform: any
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Games/Entertainment
14
+ Classifier: Topic :: Multimedia :: Graphics
15
+ Classifier: Topic :: Multimedia :: Graphics :: 3D Rendering
16
+ Classifier: Topic :: Scientific/Engineering :: Visualization
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: home-page
26
+ Dynamic: license
27
+ Dynamic: license-file
28
+ Dynamic: platform
29
+ Dynamic: summary
30
+
31
+ # glcontext
32
+
33
+ <img align="right" width="300" height="200" src="https://github.com/moderngl/glcontext/raw/main/.github/icon.svg">
34
+
35
+ **glcontext** is a library providing OpenGL implementation for ModernGL on multiple platforms.
36
+
37
+ * [glcontext on github](https://github.com/moderngl/glcontext)
38
+ * [glcontext on pypi](https://pypi.org/project/glcontext)
39
+ * [ModernGL](https://github.com/moderngl/moderngl)
40
+
41
+ ## Backends
42
+
43
+ A glcontext backend is either an extension or a submodule of the glcontext package.
44
+ The package itself does not import any of the backends.
45
+ Importing the base package `glcontext` must be safe and lightweight.
46
+
47
+ ## Structure
48
+
49
+ Every backend of glcontext must provide a factory function:
50
+
51
+ ```py
52
+ def create_context(*args, **kwargs) -> GLContext:
53
+ pass
54
+ ```
55
+
56
+ The create\_context method can take any number of positional and keyword arguments.
57
+ The factory function must return an object supporting the following methods:
58
+
59
+ ```py
60
+ def load(self, name:str) -> int:
61
+ pass
62
+ ```
63
+
64
+ The load method takes an OpenGL function name as an input and returns a C/C++ function pointer as a python integer.
65
+ The return value must be 0 for not implemented functions.
66
+
67
+ ```py
68
+ def __enter__(self, name:str):
69
+ pass
70
+ ```
71
+
72
+ The enter method calls `___MakeCurrent` to make the GLContext the calling thread's current rendering context.
73
+ `___MakeCurrent` stands for `wglMakeCurrent`, `glxMakeCurrent`, ...
74
+
75
+ ```py
76
+ def __exit__(self, exc_type, exc_val, exc_tb):
77
+ pass
78
+ ```
79
+
80
+ The exit method calls `___MakeCurrent` to make the GLContext no longer current.
81
+
82
+ ```py
83
+ def release(self):
84
+ pass
85
+ ```
86
+
87
+ The release method destroys the OpenGL context.
88
+
89
+ ## Development Guide
90
+
91
+ There are "empty" example backends provided for developers to help adding new backends to the library.
92
+ There is a pure python example in [empty.py](#) and an extension example in [empty.cpp](#).
93
+ Besides their name match, they do not depend on each other, they are independent submodules of glcontext.
94
+
95
+ A "portable" backend implementation must load its dependency at runtime.
96
+ This rule is for simplifying the build of the entire package.
97
+ If an implementation cannot provide a "portable" backend, it will not be added to this library.
98
+ Non "portable" backends are welcome as third-party libraries.
99
+
100
+ A backend must be lightweight; its size must fit within reasonable limits.
101
+
102
+ To add support for new platforms, one must edit the `setup.py` too.
103
+ Platform-specific dependencies are exceptions to the "portability" rule.
104
+
105
+ Example for platform-specific dependencies:
106
+
107
+ - `gdi32.lib` on Windows
108
+ - `libdl.a` on Linux
109
+
110
+ Please note that `libGL.so` is loaded dynamically by the backends.
111
+
112
+ ## Current backends
113
+
114
+ Each backend supports `glversion` and `mode` parameters as a minimum.
115
+ The `glversion` is the minimum OpenGL version required, while `mode`
116
+ decides how the context is created.
117
+
118
+ Modes
119
+
120
+ * `detect`: Will detect an existing active OpenGL context.
121
+ * `standalone`: Creates a headless OpenGL context
122
+ * `share`: Creates a new context sharing objects with the currently active context (headless)
123
+
124
+ ### wgl
125
+
126
+ Parameters
127
+
128
+ * `glversion` (`int`): The minimum OpenGL version for the context
129
+ * `mode` (`str`): Creation mode. `detect` | `standalone` | `share`
130
+ * `libgl` (`str`): Name of gl library to load (default: `opengl32.dll`)
131
+
132
+ ### x11
133
+
134
+ If `libgl` is not passed in the backend will try to locate
135
+ the GL library using `ctypes.utils.find_library`.
136
+
137
+ Parameters
138
+
139
+ * `glversion` (`int`): The minimum OpenGL version for the context
140
+ * `mode` (`str`): Creation mode. `detect` | `standalone` | `share`
141
+ * `libgl` (`str`): Name of gl library to load (default: `libGL.so`)
142
+ * `libx11` (`str`): Name of x11 library to load (default: `libX11.so`)
143
+
144
+ ### darwin
145
+
146
+ Will create the highest core context available.
147
+
148
+ Parameters
149
+
150
+ * `mode` (`str`): Creation mode. `detect` | `standalone`
151
+
152
+ ### egl
153
+
154
+ Only supports standalone mode.
155
+
156
+ If `libgl` and/or `libegl` are not passed in, the backend will try to locate
157
+ GL and/or EGL library using `ctypes.utils.find_library`.
158
+
159
+ Parameters
160
+
161
+ * `glversion` (`int`): The minimum OpenGL version for the context
162
+ * `mode` (`str`): Creation mode. `standalone`
163
+ * `libgl` (`str`): Name of gl library to load (default: `libGL.so`)
164
+ * `libegl` (`str`): Name of gl library to load (default: `libEGL.so`)
165
+ * `device_index` (`int`) The device index to use (default: `0`)
166
+
167
+ ## Environment Variables
168
+
169
+ Environment variables can be set to configure backends.
170
+ These will get first priority if defined.
171
+
172
+ ```bash
173
+ # Override OpenGL version code. For example: 410 (for opengl 4.1)
174
+ GLCONTEXT_GLVERSION
175
+ # Override libgl on linux. For example: libGL.1.so
176
+ GLCONTEXT_LINUX_LIBGL
177
+ # Override libx11 on linux. For exampleØ libX11.x.so
178
+ GLCONTEXT_LINUX_LIBX11
179
+ # Override libegl on linux. For exampleØ libEGL.x.so
180
+ GLCONTEXT_LINUX_LIBEGL
181
+ # Override gl dll on windows. For example: opengl32_custom.dll
182
+ GLCONTEXT_WIN_LIBGL
183
+ # Override the device index (egl)
184
+ GLCONTEXT_DEVICE_INDEX
185
+ ```
186
+
187
+ ## Running tests
188
+
189
+ ```
190
+ pip install -r tests/requirements.txt
191
+ pytest tests
192
+ ```
193
+
194
+ ## Contributing
195
+
196
+ Contributions are welcome.
197
+
198
+ Pull Requests will be merged if they match the [Development Guide](#).
199
+
200
+ For prototypes, pure Python implementations using ctypes are also welcome.
201
+ We will probably port it to a proper extension in the future.
202
+
203
+ Please ask questions [here](https://github.com/moderngl/glcontext/issues).
@@ -0,0 +1,8 @@
1
+ glcontext/__init__.py,sha256=yS4jemx7PiMUlo_M82XEmH7Gz9KYteI130RuhJPRDXI,4368
2
+ glcontext/empty.py,sha256=QoORP5osLGtwU7PABUMQ5WfB4k0pvOHS8I76ujGm4ac,301
3
+ glcontext/wgl.cp313t-win_arm64.pyd,sha256=5YtmZFCOeWLIBUHzRZmw20qQkGrXES32zUuF6vR2s2Y,16384
4
+ glcontext-3.2.0.dist-info/licenses/LICENSE,sha256=4Wv1PYcf1YDkPIAKrNjhCqeklQVwGs7sH3CK6qyX36c,1099
5
+ glcontext-3.2.0.dist-info/METADATA,sha256=4ZI4ZqhyU10aqHiRQ7UBUXfhMp-uxp8pAWgKtrDaYYM,6413
6
+ glcontext-3.2.0.dist-info/WHEEL,sha256=JNIBvAD745HDWm5cXzrdCvntYBYmZnAppJx9toTOlnc,102
7
+ glcontext-3.2.0.dist-info/top_level.txt,sha256=IosXQkJ9R4RvrG2uHZJtIQAHYoKmvTeBTb-zdwzFLDE,10
8
+ glcontext-3.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313t-win_arm64
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 ModernGL Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ glcontext