def match(self, canvas): if not isinstance(canvas, HeadlessCanvas): raise RuntimeError('Canvas must be an instance of HeadlessCanvas') display_connection = canvas.display._display_connection # Construct array of attributes attrs = [] for name, value in self.get_gl_attributes(): if name == 'double_buffer': continue attr = HeadlessCanvasConfig.attribute_ids.get(name, None) if attr and value is not None: attrs.extend([attr, int(value)]) attrs.extend([EGL_SURFACE_TYPE, EGL_PBUFFER_BIT]) attrs.extend([EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT]) attrs.extend([EGL_NONE]) attrs_list = (egl.EGLint * len(attrs))(*attrs) num_config = egl.EGLint() egl.eglChooseConfig(display_connection, attrs_list, None, 0, byref(num_config)) configs = (egl.EGLConfig * num_config.value)() egl.eglChooseConfig(display_connection, attrs_list, configs, num_config.value, byref(num_config)) result = [HeadlessCanvasConfig(canvas, c, self) for c in configs] return result
def __init__(self): super().__init__() # TODO: fix this placeholder: self._screens = [HeadlessScreen(self, 0, 0, 1920, 1080)] num_devices = egl.EGLint() eglext.eglQueryDevicesEXT(0, None, byref(num_devices)) if num_devices.value > 0: headless_device = pyglet.options['headless_device'] if headless_device < 0 or headless_device >= num_devices.value: raise ValueError('Invalid EGL devide id: %d' % headless_device) devices = (eglext.EGLDeviceEXT * num_devices.value)() eglext.eglQueryDevicesEXT(num_devices.value, devices, byref(num_devices)) self._display_connection = eglext.eglGetPlatformDisplayEXT(eglext.EGL_PLATFORM_DEVICE_EXT, devices[headless_device], None) else: warning.warn('No device available for EGL device platform. Using native display type.') display = egl.EGLNativeDisplayType() self._display_connection = egl.eglGetDisplay(display) egl.eglInitialize(self._display_connection, None, None)
def __init__(self, canvas, egl_config, config): super(HeadlessCanvasConfig, self).__init__(canvas, config) self._egl_config = egl_config context_attribs = (EGL_CONTEXT_MAJOR_VERSION, config.major_version or 2, EGL_CONTEXT_MINOR_VERSION, config.minor_version or 0, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE, config.forward_compatible or 0, EGL_CONTEXT_OPENGL_DEBUG, config.debug or 0, EGL_NONE) self._context_attrib_array = (egl.EGLint * len(context_attribs))(*context_attribs) for name, attr in self.attribute_ids.items(): value = egl.EGLint() egl.eglGetConfigAttrib(canvas.display._display_connection, egl_config, attr, byref(value)) setattr(self, name, value.value) for name, value in _fake_gl_attributes.items(): setattr(self, name, value)
EGL_SINGLE_BUFFER: "EGL_RENDER_BUFFER", EGL_BACK_BUFFER: "EGL_BACK_BUFFER", EGL_NONE: "EGL_NONE" } _api_types = { EGL_OPENGL_API: "EGL_OPENGL_API", EGL_OPENGL_ES_API: "EGL_OPENGL_ES_API", EGL_NONE: "EGL_NONE" } # Initialize a display: display = libegl.EGLNativeDisplayType() display_connection = libegl.eglGetDisplay(display) majorver = libegl.EGLint() minorver = libegl.EGLint() result = libegl.eglInitialize(display_connection, majorver, minorver) assert result == 1, "EGL Initialization Failed" egl_version = majorver.value, minorver.value print(f"EGL version: {egl_version}") # Get the number of configs: num_configs = libegl.EGLint() config_size = libegl.EGLint() result = libegl.eglGetConfigs(display_connection, None, config_size, num_configs) assert result == 1, "Failed to query Configs" print("Number of configs available: ", num_configs.value)