Developer Referencegpu_probe
_EGL
The few EGL and GL entry points the helpers call, through glvnd.
Attributes
attributeegl= ctypes.CDLL('libEGL.so.1')attributegl= ctypes.CDLL(name)Functions
constructor__init__() -> NoneSource Code
def __init__(self) -> None:
self.egl = ctypes.CDLL("libEGL.so.1")
c = ctypes
self.egl.eglGetProcAddress.restype = c.c_void_p
self.egl.eglGetProcAddress.argtypes = [c.c_char_p]
self.egl.eglGetDisplay.restype = c.c_void_p
self.egl.eglGetDisplay.argtypes = [c.c_void_p]
self.egl.eglInitialize.restype = c.c_uint
self.egl.eglInitialize.argtypes = [c.c_void_p, c.POINTER(c.c_int), c.POINTER(c.c_int)]
self.egl.eglBindAPI.restype = c.c_uint
self.egl.eglBindAPI.argtypes = [c.c_uint]
self.egl.eglChooseConfig.restype = c.c_uint
self.egl.eglChooseConfig.argtypes = [c.c_void_p, c.POINTER(c.c_int), c.POINTER(c.c_void_p), c.c_int, c.POINTER(c.c_int)]
self.egl.eglCreateContext.restype = c.c_void_p
self.egl.eglCreateContext.argtypes = [c.c_void_p, c.c_void_p, c.c_void_p, c.POINTER(c.c_int)]
self.egl.eglCreatePbufferSurface.restype = c.c_void_p
self.egl.eglCreatePbufferSurface.argtypes = [c.c_void_p, c.c_void_p, c.POINTER(c.c_int)]
self.egl.eglCreateWindowSurface.restype = c.c_void_p
self.egl.eglCreateWindowSurface.argtypes = [c.c_void_p, c.c_void_p, c.c_ulong, c.POINTER(c.c_int)]
self.egl.eglMakeCurrent.restype = c.c_uint
self.egl.eglMakeCurrent.argtypes = [c.c_void_p, c.c_void_p, c.c_void_p, c.c_void_p]
self.egl.eglSwapBuffers.restype = c.c_uint
self.egl.eglSwapBuffers.argtypes = [c.c_void_p, c.c_void_p]
self.egl.eglTerminate.argtypes = [c.c_void_p]
for name in ("libOpenGL.so.0", "libGL.so.1"):
try:
self.gl = ctypes.CDLL(name)
break
except OSError:
continue
else:
raise OSError("no GL dispatch library")
self.gl.glGetString.restype = c.c_char_p
self.gl.glGetString.argtypes = [c.c_uint]Returns
Nonefuncproc(name, restype, argtypes)Source Code
def proc(self, name: str, restype, argtypes):
address = self.egl.eglGetProcAddress(name.encode())
if not address:
raise OSError(f"{name} is not available")
return ctypes.CFUNCTYPE(restype, *argtypes)(address)paramnamestrparamrestypeparamargtypesReturns
Nonefuncattribs(*values)Source Code
def attribs(self, *values: int):
return (ctypes.c_int * (len(values) + 1))(*values, EGL_NONE)paramvaluesint= ()Returns
Nonefunccontext(display, surface_type) -> Tuple[Optional[ctypes.c_void_p], Optional[ctypes.c_void_p]]An OpenGL context on display and a config that can back surface_type.
Source Code
def context(self, display, surface_type: int) -> Tuple[Optional[ctypes.c_void_p], Optional[ctypes.c_void_p]]:
"""An OpenGL context on `display` and a config that can back `surface_type`."""
if not self.egl.eglInitialize(display, None, None) or not self.egl.eglBindAPI(EGL_OPENGL_API):
return None, None
config = ctypes.c_void_p()
count = ctypes.c_int(0)
chosen = self.attribs(EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_SURFACE_TYPE, surface_type)
if not self.egl.eglChooseConfig(display, chosen, ctypes.byref(config), 1, ctypes.byref(count)) or not count.value:
return None, None
context = self.egl.eglCreateContext(display, config, None, self.attribs())
return (ctypes.c_void_p(context) if context else None), configparamdisplayparamsurface_typeintReturns
typing.Tuple[typing.Optional[ctypes.ctypes.c_void_p], typing.Optional[ctypes.ctypes.c_void_p]]funcrenderer(display, context, surface) -> strSource Code
def renderer(self, display, context, surface) -> str:
if not self.egl.eglMakeCurrent(display, surface, surface, context):
# Vendors without surfaceless contexts get a pbuffer to answer on.
return ""
seen = self.gl.glGetString(GL_RENDERER)
return seen.decode(errors="replace") if seen else ""paramdisplayparamcontextparamsurfaceReturns
str