+#ifdef COMMON_USE_EGL
+static void
+common_create_egl_context (Display *dpy, EGLenum api, EGLDisplay *egl_dpy_ret,
+ EGLContext *ctx_ret, EGLConfig *config_ret,
+ XVisualInfo **visual_info_ret)
+{
+ EGLDisplay egl_dpy;
+ int config_attr[] = {
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+ EGL_NONE
+ };
+ EGLConfig config;
+ int num_configs;
+ EGLint major, minor;
+ EGLBoolean success;
+ int opengl_context_attr[] = {
+ EGL_NONE
+ };
+ int glesv2_context_attr[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+ int *context_attr;
+ EGLContext ctx;
+ XVisualInfo *visual_info, visual_attr;
+ int visualid, num_visuals;
+
+ egl_dpy = _E(eglGetDisplay) (dpy);
+
+ success = _E(eglInitialize) (egl_dpy, &major, &minor);
+ if (!success) {
+ fprintf (stderr, "Error: Failed to initialized EGL\n");
+ exit (1);
+ }
+
+ success = _E(eglChooseConfig) (egl_dpy, config_attr, &config, 1, &num_configs);
+ if (!success || num_configs == 0) {
+ fprintf (stderr, "Error: Failed to find EGL config\n");
+ exit (1);
+ }
+
+ success = _E(eglGetConfigAttrib) (egl_dpy, config, EGL_NATIVE_VISUAL_ID, &visualid);
+ if (!success) {
+ fprintf (stderr, "Error: Failed to find native Visual ID\n");
+ exit (1);
+ }
+
+ visual_attr.visualid = visualid;
+ visual_info = XGetVisualInfo (dpy, VisualIDMask, &visual_attr, &num_visuals);
+ if (!visual_info) {
+ fprintf (stderr, "Error: Failed to get XVisualInfo\n");
+ exit (1);
+ }
+
+ _E(eglBindAPI) (api);
+
+ if (api == EGL_OPENGL_ES_API)
+ context_attr = glesv2_context_attr;
+ else
+ context_attr = opengl_context_attr;
+ ctx = _E(eglCreateContext) (egl_dpy, config, NULL, context_attr);
+ if (!ctx) {
+ fprintf (stderr, "Error: Failed to create EGL context\n");
+ exit (1);
+ }
+
+ *egl_dpy_ret = egl_dpy;
+ *ctx_ret = ctx;
+ *config_ret = config;
+ *visual_info_ret = visual_info;
+
+}
+#else