Demos (master): xeglgears: Make EGL_KHR_image usage portable

Kristian Høgsberg krh at kemper.freedesktop.org
Fri Jun 29 16:25:03 UTC 2012


Module: Demos
Branch: master
Commit: 43c2122af1caa750531f29bf734c03d1f50801d1
URL:    http://cgit.freedesktop.org/mesa/demos/commit/?id=43c2122af1caa750531f29bf734c03d1f50801d1

Author: Frank Binns <frank.binns at imgtec.com>
Date:   Fri Jun 29 14:06:27 2012 +0100

xeglgears: Make EGL_KHR_image usage portable

EGL extension functions don't have to be exported which means
xeglgears was failing to link against implementations that
support EGL_KHR_image but were not exporting its related functions.

This has been fixed by using eglGetProcAddress to get a function
pointer instead of using the functions prototype. This is portable.

Signed-off-by: Frank Binns <frank.binns at imgtec.com>

---

 src/egl/opengl/xeglgears.c |   37 +++++++++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/src/egl/opengl/xeglgears.c b/src/egl/opengl/xeglgears.c
index 513c587..866b89a 100644
--- a/src/egl/opengl/xeglgears.c
+++ b/src/egl/opengl/xeglgears.c
@@ -51,6 +51,10 @@
 static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES_func;
 #endif
 
+#ifdef EGL_KHR_image
+static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR_func;
+#endif
+
 
 #define BENCHMARK
 
@@ -405,6 +409,17 @@ egl_manager_new(EGLNativeDisplayType xdpy, const EGLint *attrib_list,
       eglGetProcAddress("glEGLImageTargetTexture2DOES");
 #endif
 
+#ifdef EGL_KHR_image
+   eglCreateImageKHR_func = (PFNEGLCREATEIMAGEKHRPROC)
+      eglGetProcAddress("eglCreateImageKHR");
+   if (eglCreateImageKHR_func == NULL) {
+      printf("failed to get eglCreateImageKHR\n");
+      eglTerminate(eman->dpy);
+      free(eman);
+      return NULL;
+   }
+#endif
+
    return eman;
 }
 
@@ -850,10 +865,16 @@ main(int argc, char *argv[])
    case GEARS_PIXMAP:
    case GEARS_PIXMAP_TEXTURE:
       ret = egl_manager_create_pixmap(eman, eman->xwin, EGL_TRUE, NULL);
+
+#ifdef EGL_KHR_image
       if (surface_type == GEARS_PIXMAP_TEXTURE)
-	 eman->image = eglCreateImageKHR (eman->dpy, eman->ctx,
-					  EGL_NATIVE_PIXMAP_KHR,
-					  (EGLClientBuffer) eman->xpix, NULL);
+	 eman->image = eglCreateImageKHR_func(eman->dpy, eman->ctx,
+					      EGL_NATIVE_PIXMAP_KHR,
+					      (EGLClientBuffer) eman->xpix, NULL);
+#else
+      fprintf(stderr, "EGL_KHR_image not found at compile time.\n");
+#endif
+
       if (ret)
          ret = eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx);
       break;
@@ -892,9 +913,13 @@ main(int argc, char *argv[])
 				   GL_RENDERBUFFER_EXT,
 				   color_rb);
 
-      eman->image = eglCreateImageKHR(eman->dpy, eman->ctx,
-				      EGL_GL_RENDERBUFFER_KHR,
-				      (EGLClientBuffer) color_rb, NULL);
+#ifdef EGL_KHR_image
+      eman->image = eglCreateImageKHR_func(eman->dpy, eman->ctx,
+					   EGL_GL_RENDERBUFFER_KHR,
+					   (EGLClientBuffer) color_rb, NULL);
+#else
+      fprintf(stderr, "EGL_KHR_image not found at compile time.\n");
+#endif
 
       glGenRenderbuffers(1, &depth_rb);
       glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_rb);




More information about the mesa-commit mailing list