Lidar_Muxa/docker/gl_probe.py

51 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Чем рисует OpenGL в контейнере: видеокарта или программный llvmpipe.
docker run --rm -e DISPLAY=:0 -v /tmp/.X11-unix:/tmp/.X11-unix \
-v "$PWD/docker:/smoke:ro" flyguard python3 /smoke/gl_probe.py
Окно не открывается: контекст создаётся на pbuffer 1×1 через EGL.
"""
import ctypes
import sys
EGL_OPENGL_API = 0x30A2
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT = 0x3033, 0x0001
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT = 0x3040, 0x0008
EGL_WIDTH, EGL_HEIGHT, EGL_NONE = 0x3057, 0x3056, 0x3038
GL_VENDOR, GL_RENDERER, GL_VERSION = 0x1F00, 0x1F01, 0x1F02
egl = ctypes.CDLL("libEGL.so.1")
gl = ctypes.CDLL("libGL.so.1")
egl.eglGetDisplay.restype = ctypes.c_void_p
egl.eglGetDisplay.argtypes = [ctypes.c_void_p]
egl.eglInitialize.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
egl.eglChooseConfig.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p,
ctypes.c_int, ctypes.c_void_p]
egl.eglCreatePbufferSurface.restype = ctypes.c_void_p
egl.eglCreatePbufferSurface.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
egl.eglCreateContext.restype = ctypes.c_void_p
egl.eglCreateContext.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p,
ctypes.c_void_p]
egl.eglMakeCurrent.argtypes = [ctypes.c_void_p] * 4
gl.glGetString.restype = ctypes.c_char_p
dpy = egl.eglGetDisplay(None)
if not dpy or not egl.eglInitialize(dpy, None, None):
sys.exit("EGL не инициализировался (нет DISPLAY?)")
egl.eglBindAPI(EGL_OPENGL_API)
attrs = (ctypes.c_int * 5)(EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_NONE)
cfg, n = ctypes.c_void_p(), ctypes.c_int()
if not egl.eglChooseConfig(dpy, attrs, ctypes.byref(cfg), 1, ctypes.byref(n)) or n.value < 1:
sys.exit("нет подходящей конфигурации EGL")
surf = egl.eglCreatePbufferSurface(dpy, cfg, (ctypes.c_int * 5)(EGL_WIDTH, 1, EGL_HEIGHT, 1,
EGL_NONE))
ctx = egl.eglCreateContext(dpy, cfg, None, None)
if not ctx or not egl.eglMakeCurrent(dpy, surf, surf, ctx):
sys.exit("контекст OpenGL не создан")
renderer = gl.glGetString(GL_RENDERER).decode()
print("vendor: ", gl.glGetString(GL_VENDOR).decode())
print("renderer:", renderer)
print("version: ", gl.glGetString(GL_VERSION).decode())
print("ПРОГРАММНО (процессор)" if "llvmpipe" in renderer or "softpipe" in renderer
else "ВИДЕОКАРТА")