Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant run minimal example #16

Closed
mreyarea-fy opened this issue Jul 14, 2022 · 6 comments
Closed

Cant run minimal example #16

mreyarea-fy opened this issue Jul 14, 2022 · 6 comments

Comments

@mreyarea-fy
Copy link

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
@perey
Copy link
Owner

perey commented Jul 14, 2022

Thanks for the report!

It would appear that choose_config isn't finding any configs that support OpenGL ES. (In this case, IndexError basically means, "You asked for the first item in a list with no items!") You can replace dpy.choose_config(...) with dpy.get_configs(), which gets all configs without trying to filter them.

Could you run the following code for me and report the results?

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?!')

For comparison, here's the results on the computer I'm currently at:

Python 3.10.5 on Linux-5.18.10-100.fc35.x86_64-x86_64-with-glibc2.34
EGL version: 1.5 by Mesa Project
Configs available: 64
The first config...
APIs supported: ClientAPIFlag.OPENGL_ES3|OPENGL|OPENGL_ES2|OPENGL_ES
Color buffer: 32-bit RGB

@mreyarea-fy
Copy link
Author

I get something pretty similar. Sorry I am not too familiar with this. Do not even know what configurations are! :').

Python 3.7.13 on Linux-5.13.0-52-generic-x86_64-with-glibc2.17
EGL version: 1.5 by NVIDIA
Configs available: 65
The first config (which in theory should be the most capable)...
	APIs supported: ClientAPIFlag.OPENGL_ES3|OPENGL|OPENGL_ES2|OPENGL_ES
	Color buffer: 32-bit RGB

@mreyarea-fy
Copy link
Author

mreyarea-fy commented Jul 15, 2022

Ok so I tried on my own laptop with integrated GPU that uses Mesa and it works. I am wondering if I can choose which vendor I want to use EGL from? Instead of NVIDIA I could choose Mesa, although it might come with decrease in rendering speeds?

@perey
Copy link
Owner

perey commented Jul 15, 2022

Well, colour me confused. choose_config isn't finding any configs that support OpenGL ES, but the first available config supports OpenGL ES? Weird. I think I might have to chalk this one up to Nvidia's EGL implementation doing peculiar things.

To resolve the issue in your specific case, I'd suggest replacing the offending line with one of the following:

# 1) Request configs that meet given requirements, but don't make API support
# one of the requirements. This one says a 32-bit colour buffer is required,
# but that's just for the sake of an example.
conf = dpy.choose_config({pegl.ConfigAttrib.BUFFER_SIZE: 32})[0]

# 2) Request configs that meet given requirements... and don't actually set any.
conf = dpy.choose_config({})[0]

# 3) Just grab the first available config and hope it works!
conf = dpy.get_configs(1)[0]

Do not even know what configurations are! :').

They're basically sets of graphics capabilities: "my program wants to use OpenGL ES 2 instructions to render into a 16-bit colour buffer that uses at least 1 bit for alpha", that sort of thing.

I'd say you can browse the Pegl documentation for an explanation, but at present you'd have to build it yourself (clone repo, cd docs, make html), or else read the reStructuredText source. Putting it online somewhere like Read the Docs is planned (issue #8).

Even then, it's all written by me based on my own understanding and is in no way authoritative! You can check out the EGL specification for the official details; configs are covered in section 3.4.

(Incidentally, looking that up has made me realise I mis-remembered how configs are sorted. Contrary to my off-hand comment in the test code earlier, the first config returned is not likely to be the most capable, but rather the reverse: it's likely to be the bare minimum that meets the given requirements. I'm just noting this here for my own reference, and for the sake of anyone who comes reading this issue later.)

I am wondering if I can choose which vendor I want to use EGL from? Instead of NVIDIA I could choose Mesa, although it might come with decrease in rendering speeds?

This may be possible, but I'm afraid I don't know whether, or how well, it would work. You would need to make sure Mesa's EGL implementation is installed (something like mesa-libEGL in your system's repositories), and then convince Pegl to talk to it rather than the Nvidia one. But on typical Linux systems, this appears to be managed by libglvnd, and how to force that to do your bidding is beyond me. ☹️

@mreyarea-fy
Copy link
Author

mreyarea-fy commented Jul 15, 2022

Thanks for the explanation.

Some updates. Following this tutorial from NVIDIA I was able to solve it. Basically, the default single attribute {pegl.ConfigAttrib.RENDERABLE_TYPE: pegl.ClientAPIFlag.OPENGL_ES} is not enough for nvidia requirements. The set of configuration attributes that worked for me were:

attribs = {pegl.ConfigAttrib.SURFACE_TYPE: pegl.SurfaceTypeFlag.PBUFFER,
           pegl.ConfigAttrib.BLUE_SIZE: 8,
           pegl.ConfigAttrib.GREEN_SIZE: 8,
           pegl.ConfigAttrib.RED_SIZE: 8,
           pegl.ConfigAttrib.DEPTH_SIZE: 8,
           pegl.ConfigAttrib.RENDERABLE_TYPE: pegl.ClientAPIFlag.OPENGL_ES_BIT}

Then, I bind pegl.ClientAPI.OPENGL as API and, voilà!

@perey
Copy link
Owner

perey commented Jul 15, 2022

Excellent! I'm glad you were able to find a solution.

I still find it strange that they need all of that information (the EGL spec defines default search behaviour for when it's not supplied), but oh well.

@perey perey closed this as completed Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants