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
# 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) # Choose a config: config_attribs = (EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_DEPTH_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_NONE) config_attrib_array = (libegl.EGLint * len(config_attribs))(*config_attribs) egl_config = libegl.EGLConfig() result = libegl.eglChooseConfig(display_connection, config_attrib_array, egl_config, 1, num_configs) assert result == 1, "Failed to choose Config" # Create a surface: pbufferwidth = 1 pbufferheight = 1 pbuffer_attribs = (EGL_WIDTH, pbufferwidth, EGL_HEIGHT, pbufferheight, EGL_NONE) pbuffer_attrib_array = (libegl.EGLint * len(pbuffer_attribs))(*pbuffer_attribs) surface = libegl.eglCreatePbufferSurface(display_connection, egl_config, pbuffer_attrib_array) print("Surface id: ", surface) # Bind the API: result = libegl.eglBindAPI(libegl.EGL_OPENGL_API) assert result == 1, "Failed to bind EGL_OPENGL_API"