From b860e485b4087c425674e8f91562004a4a892d25 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Fri, 20 Jan 2012 18:11:03 +0100 Subject: [PATCH] context: add GLES2 support OpenGL pulls in lot of X dependencies on linux. To avoid this we also support OpenGLES2 now. This will also allow to run kmscon on embedded/mobile platforms. We still get X dependencies through EGL which we cannot avoid as EGL is compiled with multiple backends on most systems. However, switching to GLES2 reduces memory footprint by 30MB which is pretty good. This also enables GLES2 as default in autogen.sh. However, default behaviour of configure will still be GL. Signed-off-by: David Herrmann --- autogen.sh | 2 +- configure.ac | 17 ++++++++++++++++- src/output_context.c | 28 ++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/autogen.sh b/autogen.sh index 791a1a8..b6547af 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,4 +1,4 @@ #!/bin/sh mkdir -p m4/ autoreconf -i -./configure --enable-debug --enable-pango $* +./configure --enable-debug --enable-pango --enable-gles2 $* diff --git a/configure.ac b/configure.ac index d4db1e3..176fef1 100644 --- a/configure.ac +++ b/configure.ac @@ -33,7 +33,22 @@ PKG_CHECK_MODULES([GBM], [gbm]) AC_SUBST(GBM_CFLAGS) AC_SUBST(GBM_LIBS) -PKG_CHECK_MODULES([OPENGL], [gl]) +AC_MSG_CHECKING([whether to use OpenGLES2 instead of OpenGL]) +AC_ARG_ENABLE([gles2], + [AS_HELP_STRING([--enable-gles2], [whether to use OpenGLES2 instead of OpenGL])], + [force_gles2="$enableval"; + AC_DEFINE([USE_GLES2], [1], [Define if OpenGLES2 should be used])], + [force_gles2=no]) +AC_MSG_RESULT([$force_gles2]) + +if test x$force_gles2 = xyes ; then + PKG_CHECK_MODULES([OPENGLES2], [glesv2]) + OPENGL_CFLAGS=$OPENGLES2_CFLAGS + OPENGL_LIBS=$OPENGLES2_LIBS +else + PKG_CHECK_MODULES([OPENGL], [gl]) +fi + AC_SUBST(OPENGL_CFLAGS) AC_SUBST(OPENGL_LIBS) diff --git a/src/output_context.c b/src/output_context.c index 6c7527f..66de529 100644 --- a/src/output_context.c +++ b/src/output_context.c @@ -37,8 +37,14 @@ #include #include -#include -#include + +#ifdef USE_GLES2 + #include + #include +#else + #include + #include +#endif #include "log.h" #include "output.h" @@ -362,6 +368,14 @@ int kmscon_context_new(struct kmscon_context **out, void *gbm) EGLint major, minor; int ret; const char *ext; + EGLenum api; + +#ifdef USE_GLES2 + static const EGLint ctx_attribs[] = + { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; +#else + static const EGLint *ctx_attribs = NULL; +#endif if (!out || !gbm) return -EINVAL; @@ -395,14 +409,20 @@ int kmscon_context_new(struct kmscon_context **out, void *gbm) goto err_display; } - if (!eglBindAPI(EGL_OPENGL_API)) { +#ifdef USE_GLES2 + api = EGL_OPENGL_ES_API; +#else + api = EGL_OPENGL_API; +#endif + + if (!eglBindAPI(api)) { log_warning("context: cannot bind EGL OpenGL API\n"); ret = -EFAULT; goto err_display; } ctx->context = eglCreateContext(ctx->display, NULL, EGL_NO_CONTEXT, - NULL); + ctx_attribs); if (!ctx->context) { log_warning("context: cannot create EGL context\n"); ret = -EFAULT;