Last active
November 17, 2017 12:39
-
-
Save tguillem/d4964b43f14c78a8db0c32606d48cfda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if 0 | |
# Test program that crashes with nVidia drivers | |
# Reproduce with | |
# $ make -f egl_test.c && ./egl_test 2 | |
# The int argument (2 here) is the number of time egl display will be | |
# opened/closed (./egl_test 1 will not crash) | |
egl_test: egl_test.c | |
gcc -o egl_test egl_test.c -g -O1 -I/usr/include/X11 -lX11 -lEGL -lGL -lxcb | |
ifdef undef | |
#endif | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <xcb/xcb.h> | |
#include <EGL/egl.h> | |
#include <EGL/eglext.h> | |
#include <GL/gl.h> | |
#include <X11/Xlib.h> | |
#include <X11/Xlibint.h> | |
#define TEST_SURFACE_CTX 1 | |
xcb_connection_t *conn; | |
xcb_window_t window; | |
static int screenp; | |
static Display *x11; | |
static EGLDisplay *display; | |
static EGLSurface *surface; | |
static EGLContext *context; | |
static void | |
xcb_open(void) | |
{ | |
conn = xcb_connect(NULL, &screenp); | |
assert(conn && !xcb_connection_has_error(conn)); | |
const xcb_setup_t *setup = xcb_get_setup(conn); | |
const xcb_screen_t *scr = NULL; | |
for (xcb_screen_iterator_t i = xcb_setup_roots_iterator(setup); | |
i.rem > 0; xcb_screen_next (&i)) | |
{ | |
if (screenp == 0) | |
{ | |
scr = i.data; | |
break; | |
} | |
screenp--; | |
} | |
assert(scr); | |
window = xcb_generate_id(conn); | |
assert(window); | |
xcb_void_cookie_t ck | |
= xcb_create_window_checked(conn, scr->root_depth, window, scr->root, | |
0, 0, 640, 480, 0, | |
XCB_WINDOW_CLASS_INPUT_OUTPUT, | |
scr->root_visual, 0, 0); | |
assert(!xcb_request_check(conn, ck)); | |
} | |
static void | |
xcb_close(void) | |
{ | |
xcb_disconnect(conn); | |
} | |
static void | |
egl_open(void) | |
{ | |
x11 = XOpenDisplay(NULL); | |
assert(x11); | |
XWindowAttributes wa; | |
Status status = XGetWindowAttributes(x11, window, &wa); | |
assert(status); | |
display = eglGetDisplay(x11); | |
assert(display); | |
EGLint major, minor; | |
EGLBoolean ret; | |
ret = eglInitialize(display, &major, &minor); | |
assert(ret == EGL_TRUE); | |
printf("EGL version %s by %s\n", eglQueryString(display, EGL_VERSION), | |
eglQueryString(display, EGL_VENDOR)); | |
#if TEST_SURFACE_CTX | |
ret = eglBindAPI(EGL_OPENGL_API); | |
assert(ret == EGL_TRUE); | |
const EGLint conf_attrs[] = { | |
EGL_RED_SIZE, 5, | |
EGL_GREEN_SIZE, 5, | |
EGL_BLUE_SIZE, 5, | |
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, | |
EGL_NONE | |
}; | |
EGLConfig cfgv[1]; | |
EGLint cfgc; | |
ret = eglChooseConfig(display, conf_attrs, cfgv, 1, &cfgc); | |
assert(ret == EGL_TRUE && cfgc > 0); | |
EGLNativeWindowType native = window; | |
surface = eglCreateWindowSurface(display, cfgv[0], native, NULL); | |
assert(surface != EGL_NO_SURFACE); | |
EGLint context_attrs[] = { EGL_NONE }; | |
context = eglCreateContext(display, cfgv[0], EGL_NO_CONTEXT, context_attrs); | |
ret = eglMakeCurrent(display, surface, surface, context); | |
assert(ret == EGL_TRUE); | |
const char *version = (const char *)glGetString(GL_VERSION); | |
assert(version); | |
printf("GL version: %s\n", version); | |
const char *extensions = (const char *)glGetString(GL_EXTENSIONS); | |
assert(extensions); | |
printf("GL extensions: %s\n", extensions); | |
ret = eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, | |
EGL_NO_CONTEXT); | |
assert(ret == EGL_TRUE); | |
#endif | |
} | |
static void | |
egl_close(void) | |
{ | |
#if TEST_SURFACE_CTX | |
eglDestroySurface(display, surface); | |
#endif | |
eglTerminate(display); | |
XCloseDisplay(x11); | |
} | |
int | |
main(int argc, const char *argv[]) | |
{ | |
int count = argc > 1 ? atoi(argv[1]) : 1; | |
if (count <= 0) | |
count = 1; | |
XInitThreads(); | |
xcb_open(); | |
for (int i = 0; i < count; ++i) | |
{ | |
egl_open(); | |
egl_close(); | |
} | |
xcb_close(); | |
return 0; | |
} | |
#if 0 | |
# end of Makefile | |
endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment