perey / pegl Goto Github PK
View Code? Open in Web Editor NEWA Python 3 wrapper for the EGL library.
License: GNU General Public License v3.0
A Python 3 wrapper for the EGL library.
License: GNU General Public License v3.0
(First of all, I must tell I don't understand much about EGL)
So I want to make some OpenGL (computing with shaders) on a headless server. I already have the OpenGL code and it works fine inside PyGame and wxPython. I wanted to "port" it to EGL as I understand this is the only way to make it run without an actual window. I downloaded your code, took the ANGLE dll (libEGL.dll, libGLESv2.dll) in the egl/lib directory and ran your code. It works fine apparently until the point where I want to actually run some OpenGL commands. So here's the program (I've taken part from yours) :
from OpenGL.GL import glClear, GL_COLOR_BUFFER_BIT
import pegl
import pegl, platform
print('Python', platform.python_version(), 'on', platform.platform(terse=True))
dpy = pegl.Display()
print('EGL version:', dpy.version_string, 'by', dpy.vendor)
all_configs = dpy.get_configs()
print('Configs available:', len(all_configs))
if len(all_configs) > 0:
cfg = all_configs[0]
print('The first config...')
print('\tAPIs supported:', cfg.renderable_type)
print(f'\tColor buffer: {cfg.buffer_size}-bit', cfg.color_buffer_type.name)
else:
print('What kind of EGL implementation offers no configurations, anyway?!')
conf = dpy.choose_config({pegl.ConfigAttrib.RENDERABLE_TYPE:
pegl.ClientAPIFlag.OPENGL_ES})[0]
pegl.bind_api(pegl.ClientAPI.OPENGL_ES)
ctx = conf.create_context()
print(ctx)
surf = conf.create_pbuffer_surface({pegl.SurfaceAttrib.WIDTH: 640,
pegl.SurfaceAttrib.HEIGHT: 480})
print(surf)
print(ctx.make_current(draw=surf))
glClear(GL_COLOR_BUFFER_BIT)
And here is it the output:
Python 3.9.13 on Windows-10
EGL version: 1.5 (ANGLE 2.1.19724 git hash: ceec659ac60b) by Google Inc. (NVIDIA)
Configs available: 200
The first config...
APIs supported: ClientAPIFlag.OPENGL_ES3|OPENGL_ES2|OPENGL_ES
Color buffer: 16-bit RGB
Google Inc. (NVIDIA)
(1, 5, '(ANGLE 2.1.19724 git hash: ceec659ac60b)')
<pegl.context.Context object at 0x000001D939DD67F0>
<pegl.surface.Surface object at 0x000001D93A60F520>
None
Traceback (most recent call last):
File "d:\newgit\HECEPython\debug\test_glsim\test_pegl.py", line 31, in <module>
glClear(GL_COLOR_BUFFER_BIT)
File "C:\Users\StephaneC\AppData\Local\Programs\Python\Python39\lib\site-packages\OpenGL\platform\baseplatform.py", line 415, in __call__
return self( *args, **named )
File "C:\Users\StephaneC\AppData\Local\Programs\Python\Python39\lib\site-packages\OpenGL\error.py",
line 230, in glCheckError
raise self._errorClass(
OpenGL.error.GLError: GLError(
err = 1282,
description = b'op\xe9ration non valide',
baseOperation = glClear,
cArguments = (GL_COLOR_BUFFER_BIT,)
)
The first obvious point is that it crashes on a simple OpenGL code. Did I miss something ? The second point is that the reported supported API's don't include regular OpenGL. That's surprising. Just to be on the safe side I also included opengl32.dll in the egl/lib directory but to no avail...
So it doesn't work but I'm not sure it is on the pegl side or mine :-( So if you ever have some interest in this issue, I'd be happy to hear it :-)
The current docs are in pretty good shape, if I do say so myself. They should be published online with some FOSS-friendly provider like Read the Docs.
After installing pegl via:
pip install pegl
I get following error when trying to create the egl context:
import pegl
from pegl.attribs.config import ClientAPIs, CBufferTypes
from pegl.attribs.context import ContextAPIs
dpy = pegl.display.Display()
AttributeError: module 'pegl' has no attribute 'display'
Currently with the format w.x_y.z
pip does not recognise the version format. Running pip install pegl
gives ERROR: Could not find a version that satisfies the requirement pegl (from versions: 0.1a3~1.4, 0.1a4_1.4)
whereas downloading the sdist gives WARNING: Built wheel for pegl is invalid: Metadata 1.2 mandates PEP 440 version, but '0.1a4-1.4' is not
. It does install, however it uses the outdated python setup.py install
mechanism. Using a PEP 440 version string could fix this, however I don't see how you would be able to include both the wrapped EGL version and the python PEGL version in one version string.
Python 3.10 has been out for six months now. I should probably start testing against it sooner rather than later, especially since 3.11 is scheduled to enter beta soon!
Bumping version numbers and publishing to PyPI should be automated, or at least streamlined.
Shouldn't line 46 in native.py be set to
if sys.platform == 'linux':
or if sys.platfom == 'linux2' or sys.platform == 'linux3'
?
That should enable usage of pegl on modern kernels.
Or, maybe, there is no support for 3rd kernel?
Thank you in advance.
Pegl uses aenum for its extensible enums, which are used to support different EGL versions and extensions that add new values to existing enumerations.
Code and tests were generally written for aenum 2.2.6, but Pegl is no longer pinned to this version as of d3c6eff. That commit also fixed one resulting bug, but another issue has arisen and others may yet arise.
Current aenum versions (namely 3.1.8) will no longer accept unknown values when constructing an IntFlag
instance from an int
. Trying to do so doesn't give an error, but returns the int
itself. I don't know if this is an intended behaviour change or not.
Before:
>>> class TestFlag(aenum.IntFlag):
... NONE = 0
... BIT_0 = 1
... BIT_1 = 2
...
>>> TestFlag(3)
<TestFlag.BIT_1|BIT_0: 3>
>>> TestFlag(8)
<TestFlag.8: 8>
>>> TestFlag(10)
<TestFlag.8|BIT_1: 10>
After:
>>> class TestFlag(aenum.IntFlag):
... NONE = 0
... BIT_0 = 1
... BIT_1 = 2
...
>>> TestFlag(3)
<TestFlag.BIT_0|BIT_1: 3>
>>> TestFlag(8)
8
>>> TestFlag(10)
10
The difference currently causes problems in tests that load an EGL version lower than the native library actually supports. As a result, enums like ClientAPIFlag
aren't extended with newer options... but the library can still use them in values that it returns. This causes tests to fail when they expect a value to be an instance of the enum, but they receive a plain int
.
Options:
int
. This would affect both tests and user code, and probably means giving up some advantages of enums (like "in" testing for flags).Of these, option 3 seems like the most practical.
Hi,
Thanks for this code! Unfortunately I am not able to run the minimal example in the README. I get the following error. Any idea?
I have some pyopengl
code which is using glfw
at the moment but I would like to use pegl
to use in a headless server.
conf = dpy.choose_config({pegl.ConfigAttrib.RENDERABLE_TYPE: pegl.ClientAPIFlag.OPENGL_ES})[0]
IndexError: tuple index out of range
The refreshed Pegl has a lot more tests in a tox setup. It should be possible to take advantage of Github Actions (and/or other FOSS-friendly providers) to run these automatically.
Installed pegl from source. Seems that libEGL.dll is expected to be put under pegl/egl/common/lib
. Windows 10 supplies libEGL.dll under C:\WINDOWS\system32\libEGL.dll
as declared by ctypes.util.find_library("libEGL")
. Maybe first check find_library
first and then try the pegl/egl/common/lib
directory?
The following exception comes up during testing:
Exception ignored in: <function Display.__del__ at 0x...>
Traceback (most recent call last):
File "C:\Users\Tim\Documents\Programming\pegl\src\pegl\display.py", line 99, in __del__
if self._as_parameter_ is egl.EGL_NO_DISPLAY:
AttributeError: 'Display' object has no attribute '_as_parameter_'
As I recall, 846da10 was an attempt to fix this… or else it fixed some other destructor-triggered exception and left this one instead.
Just tried running the sample code under Pegl 0.2a1 on Raspberry Pi OS. All went well until cleanup time:
>>> import pegl
...
>>> ctx.make_current(draw=surf)
>>> exit()
Exception ignored in: <function Context.__del__ at 0xb611eb20>
Traceback (most recent call last):
File "/home/pi/pegl-test/lib/python3.9/site-packages/pegl/context.py", line 69, in __del__
File "/home/pi/pegl-test/lib/python3.9/site-packages/pegl/egl/_common.py", line 210, in error_check
pegl.errors.NotInitializedError:
Exception ignored in: <function Surface.__del__ at 0xb612d148>
Traceback (most recent call last):
File "/home/pi/pegl-test/lib/python3.9/site-packages/pegl/surface.py", line 51, in __del__
File "/home/pi/pegl-test/lib/python3.9/site-packages/pegl/egl/_common.py", line 210, in error_check
pegl.errors.NotInitializedError:
Not only did two (ignored) exceptions get raised, they’re both singularly uninformative, with an apparently empty error text. I need to (a) make sure there’s a meaningful message (or else none at all?), and (b) stop it happening.
Specifying attributes (for Config
, Context
, Display
, Image
, Surface
, and Sync
objects) is currently pretty verbose, e.g.
cfg.create_pbuffer_surface({SurfaceAttrib.GL_COLORSPACE: GLColorspace.SRGB,
SurfaceAttrib.WIDTH: 256,
SurfaceAttrib.HEIGHT: 256,
SurfaceAttrib.LARGEST_PBUFFER: True})
It should be possible for Pegl to identify the relevant enums and build the attribs dict itself, given just the names. The above example might be rewritten like so:
cfg.create_pbuffer_surface({'GL_COLORSPACE': 'SRGB', 'WIDTH': 256,
'HEIGHT': 256, 'LARGEST_PBUFFER': True})
Other things to consider are:
ALL_CAPS
? Or accept them in lower_case
, which is more consistent with instance properties?Using keyword arguments, the example might instead look like this:
cfg.create_pbuffer_surface(gl_colorspace='SRGB', width=256, height=256,
largest_pbuffer=True)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.