perey / pegl

A Python 3 wrapper for the EGL library.
GNU General Public License v3.0
14 stars 5 forks source link

Easier way to specify attributes #12

Open perey opened 2 years ago

perey commented 2 years ago

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:

Using keyword arguments, the example might instead look like this:

cfg.create_pbuffer_surface(gl_colorspace='SRGB', width=256, height=256,
                           largest_pbuffer=True)