def create_initialized_headless_egl_display(): """Creates an initialized EGL display directly on a device.""" all_devices = EGL.eglQueryDevicesEXT() selected_device = os.environ.get('EGL_DEVICE_ID', None) if selected_device is None: candidates = all_devices else: device_idx = int(selected_device) if not 0 <= device_idx < len(all_devices): raise RuntimeError( f'EGL_DEVICE_ID must be an integer between 0 and ' f'{len(all_devices) - 1} (inclusive), got {device_idx}.') candidates = all_devices[device_idx:device_idx + 1] for device in candidates: display = EGL.eglGetPlatformDisplayEXT( EGL.EGL_PLATFORM_DEVICE_EXT, device, None) if display != EGL.EGL_NO_DISPLAY and EGL.eglGetError() == EGL.EGL_SUCCESS: # `eglInitialize` may or may not raise an exception on failure depending # on how PyOpenGL is configured. We therefore catch a `GLError` and also # manually check the output of `eglGetError()` here. try: initialized = EGL.eglInitialize(display, None, None) except error.GLError: pass else: if initialized == EGL.EGL_TRUE and EGL.eglGetError() == EGL.EGL_SUCCESS: return display return EGL.EGL_NO_DISPLAY
def create_initialized_headless_egl_display(): """Creates an initialized EGL display directly on a device.""" display = EGL.EGL_NO_DISPLAY devices = EGL.eglQueryDevicesEXT() for device in devices: display = EGL.eglGetPlatformDisplayEXT( EGL.EGL_PLATFORM_DEVICE_EXT, device, None) if display and EGL.eglGetError() == EGL.EGL_SUCCESS: initialized = EGL.eglInitialize(display, None, None) if EGL.eglGetError() == EGL.EGL_SUCCESS and initialized == EGL.EGL_TRUE: break else: display = EGL.EGL_NO_DISPLAY return display
def create_initialized_headless_egl_display(): """Creates an initialized EGL display directly on a device.""" for device in EGL.eglQueryDevicesEXT(): display = EGL.eglGetPlatformDisplayEXT(EGL.EGL_PLATFORM_DEVICE_EXT, device, None) if display != EGL.EGL_NO_DISPLAY and EGL.eglGetError( ) == EGL.EGL_SUCCESS: # `eglInitialize` may or may not raise an exception on failure depending # on how PyOpenGL is configured. We therefore catch a `GLError` and also # manually check the output of `eglGetError()` here. try: initialized = EGL.eglInitialize(display, None, None) except error.GLError: pass else: if initialized == EGL.EGL_TRUE and EGL.eglGetError( ) == EGL.EGL_SUCCESS: return display return EGL.EGL_NO_DISPLAY