| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import os |
| 19 |
|
| 20 |
from pyglet.libs.wayland.gbm import * |
| 21 |
from pyglet.libs.egl.egl import * |
| 22 |
from pyglet.libs.egl.eglext import * |
| 23 |
|
| 24 |
assert eglBindAPI(EGL_OPENGL_API) == EGL_TRUE |
| 25 |
|
| 26 |
try: |
| 27 |
cards = [f for f in os.listdir('/dev/dri/') if f.startswith('card')] |
| 28 |
cards = [os.path.join('/dev/dri/', name) for name in cards] |
| 29 |
assert cards |
| 30 |
except (OSError, AssertionError): |
| 31 |
print("unable to find DRI device") |
| 32 |
exit() |
| 33 |
|
| 34 |
|
| 35 |
fd = os.open(cards[0], os.O_RDWR | os.MFD_CLOEXEC) |
| 36 |
gbm_device = gbm_create_device(fd) |
| 37 |
gbm_surface = gbm_surface_create(gbm_device, 256, 256, GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING) |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
dpy = eglGetPlatformDisplay(EGL_PLATFORM_GBM_MESA, gbm_device, None) |
| 42 |
print("Display: ", dpy) |
| 43 |
|
| 44 |
major, minor = EGLint(), EGLint() |
| 45 |
result = eglInitialize(dpy, major, minor) |
| 46 |
assert result == 1, "EGL Initialization Failed" |
| 47 |
print("Initialized EGL: ", major.value, minor.value) |
| 48 |
|
| 49 |
|
| 50 |
num_configs = EGLint() |
| 51 |
result = eglGetConfigs(dpy, None, 0, num_configs) |
| 52 |
assert result == EGL_TRUE, "Failed to query Configs" |
| 53 |
print("Number of configs available: ", num_configs.value) |
| 54 |
|
| 55 |
configs = (EGLConfig * num_configs.value)() |
| 56 |
result = eglGetConfigs(dpy, configs, num_configs, byref(num_configs)) |
| 57 |
assert result == EGL_TRUE, "Failed to query Configs" |
| 58 |
|
| 59 |
for config in configs: |
| 60 |
|
| 61 |
srf = eglCreatePlatformWindowSurface(dpy, config, gbm_surface, None) |
| 62 |
if srf: |
| 63 |
print("Surface: ", srf) |
| 64 |
break |
| 65 |
else: |
| 66 |
print("No Surface Found") |
| 67 |
exit() |
| 68 |
|
| 69 |
|
| 70 |
ctx = eglCreateContext(dpy, config, None, None) |
| 71 |
print("Context:", ctx) |
| 72 |
|
| 73 |
assert eglMakeCurrent(dpy, srf, srf, ctx) == EGL_TRUE, "Failed to Make Context Current" |
| 74 |
|
| 75 |
eglDestroySurface(dpy, srf) |
| 76 |
eglDestroyContext(dpy, ctx) |
| 77 |
eglTerminate(dpy) |
| 78 |
|
| 79 |
gbm_device_destroy(gbm_device) |
| 80 |
os.close(fd) |