<p>Ah, cool, yeah this looks good to me.</p>
<p>Reviewed-by: Robert Bragg <<a href="mailto:robert@linux.intel.com">robert@linux.intel.com</a>></p>
<p>Regards,<br>
Robert</p>
<div class="gmail_quote">On May 8, 2012 6:34 PM, "Neil Roberts" <<a href="mailto:neil@linux.intel.com">neil@linux.intel.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The stock 1.2.x version of SDL only supports regular OpenGL. The<br>
version on WebOS is specially patched to add some extra API to request<br>
a GLES1 or GLES2 context. This patch adds a configure check to detect<br>
when Cogl is being built with the patched version of SDL. In that case<br>
it will additionally allow the gles1 and gles2 drivers and set the<br>
right video mode attributes to get the corresponding context.<br>
---<br>
cogl/winsys/cogl-winsys-sdl.c | 40 +++++++++++++++++++++++-<br>
<a href="http://configure.ac" target="_blank">configure.ac</a> | 68 ++++++++++++++++++++++++++--------------<br>
2 files changed, 82 insertions(+), 26 deletions(-)<br>
<br>
diff --git a/cogl/winsys/cogl-winsys-sdl.c b/cogl/winsys/cogl-winsys-sdl.c<br>
index a8c3520..58c177a 100644<br>
--- a/cogl/winsys/cogl-winsys-sdl.c<br>
+++ b/cogl/winsys/cogl-winsys-sdl.c<br>
@@ -47,12 +47,18 @@ typedef struct _CoglDisplaySdl<br>
{<br>
SDL_Surface *surface;<br>
CoglBool has_onscreen;<br>
+ Uint32 video_mode_flags;<br>
} CoglDisplaySdl;<br>
<br>
static CoglFuncPtr<br>
_cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer,<br>
const char *name)<br>
{<br>
+#ifdef COGL_HAS_SDL_GLES_SUPPORT<br>
+ if (renderer->driver != COGL_DRIVER_GL)<br>
+ return SDL_GLES_GetProcAddress (name);<br>
+#endif<br>
+<br>
return SDL_GL_GetProcAddress (name);<br>
}<br>
<br>
@@ -68,6 +74,7 @@ static CoglBool<br>
_cogl_winsys_renderer_connect (CoglRenderer *renderer,<br>
GError **error)<br>
{<br>
+#ifndef COGL_HAS_SDL_GLES_SUPPORT<br>
if (renderer->driver != COGL_DRIVER_GL)<br>
{<br>
g_set_error (error, COGL_WINSYS_ERROR,<br>
@@ -75,6 +82,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,<br>
"The SDL winsys only supports the GL driver");<br>
return FALSE;<br>
}<br>
+#endif /* COGL_HAS_SDL_GLES_SUPPORT */<br>
<br>
if (SDL_Init (SDL_INIT_VIDEO) == -1)<br>
{<br>
@@ -134,11 +142,37 @@ _cogl_winsys_display_setup (CoglDisplay *display,<br>
<br>
set_gl_attribs_from_framebuffer_config (&display->onscreen_template->config);<br>
<br>
+ switch (display->renderer->driver)<br>
+ {<br>
+ case COGL_DRIVER_GL:<br>
+ sdl_display->video_mode_flags = SDL_OPENGL;<br>
+ break;<br>
+<br>
+#ifdef COGL_HAS_SDL_GLES_SUPPORT<br>
+ case COGL_DRIVER_GLES2:<br>
+ sdl_display->video_mode_flags = SDL_OPENGLES;<br>
+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);<br>
+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);<br>
+ break;<br>
+<br>
+ case COGL_DRIVER_GLES1:<br>
+ sdl_display->video_mode_flags = SDL_OPENGLES;<br>
+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 1);<br>
+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 1);<br>
+ break;<br>
+#endif /* COGL_HAS_SDL_GLES_SUPPORT */<br>
+<br>
+ default:<br>
+ g_assert_not_reached ();<br>
+ }<br>
+<br>
/* There's no way to know what size the application will need until<br>
it creates the first onscreen but we need to set the video mode<br>
now so that we can get a GL context. We'll have to just guess at<br>
a size an resize it later */<br>
- sdl_display->surface = SDL_SetVideoMode (640, 480, 0, SDL_OPENGL);<br>
+ sdl_display->surface = SDL_SetVideoMode (640, 480, /* width/height */<br>
+ 0, /* bitsperpixel */<br>
+ sdl_display->video_mode_flags);<br>
<br>
if (sdl_display->surface == NULL)<br>
{<br>
@@ -213,7 +247,9 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,<br>
if (width != sdl_display->surface->w ||<br>
height != sdl_display->surface->h)<br>
{<br>
- sdl_display->surface = SDL_SetVideoMode (width, height, 0, SDL_OPENGL);<br>
+ sdl_display->surface = SDL_SetVideoMode (width, height,<br>
+ 0, /* bitsperpixel */<br>
+ sdl_display->video_mode_flags);<br>
<br>
if (sdl_display->surface == NULL)<br>
{<br>
diff --git a/<a href="http://configure.ac" target="_blank">configure.ac</a> b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
index 88ab27d..2ba1a7c 100644<br>
--- a/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
@@ -447,7 +447,6 @@ AS_IF([test "x$enable_gles1" = "xyes"],<br>
PKG_CHECK_EXISTS([glesv1_cm],<br>
[COGL_PKG_REQUIRES_GL="$COGL_PKG_REQUIRES_GL glesv1_cm"<br>
COGL_GLES1_LIBNAME="libGLESv1_CM.so"<br>
- NEED_EGL=yes<br>
],<br>
[<br>
# We have to check the two headers independently as GLES/glext.h<br>
@@ -542,8 +541,6 @@ AS_IF([test "x$enable_gles2" = "xyes"],<br>
<br>
COGL_GLES2_LIBNAME="libGLESv2.so"<br>
])<br>
-<br>
- NEED_EGL=yes<br>
])<br>
<br>
HAVE_GL=0<br>
@@ -681,6 +678,46 @@ AS_IF([test "x$enable_wgl" = "xyes"],<br>
])<br>
AM_CONDITIONAL(SUPPORT_WGL, [test "x$SUPPORT_WGL" = "xyes"])<br>
<br>
+AC_ARG_ENABLE(<br>
+ [sdl],<br>
+ [AC_HELP_STRING([--enable-sdl=@<:@no/yes@:>@], [Enable support SDL @<:@default=no@:>@])],<br>
+ [],<br>
+ [enable_sdl=no])<br>
+AS_IF([test "x$enable_sdl" = "xyes"],<br>
+ [<br>
+ PKG_CHECK_MODULES([SDL],<br>
+ [sdl],<br>
+ [],<br>
+ [AC_MSG_ERROR([SDL support requested but SDL not found])])<br>
+<br>
+ SUPPORT_SDL=yes<br>
+ GL_WINSYS_APIS="$GL_WINSYS_APIS sdl"<br>
+ COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES sdl"<br>
+<br>
+ COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT"<br>
+<br>
+ dnl WebOS has a specially patched version of SDL to add<br>
+ dnl support for creating a GLES1/2 context. This tries to<br>
+ dnl detect that patch so we can use it if the GLES2 driver is<br>
+ dnl selected.<br>
+ cogl_save_CPPFLAGS="$CPPFLAGS"<br>
+ CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"<br>
+ AC_CHECK_DECL([SDL_OPENGLES],<br>
+ [SUPPORT_SDL_GLES=yes],<br>
+ [SUPPORT_SDL_GLES=no],<br>
+ [#include <SDL.h>])<br>
+ AC_CHECK_DECL([SDL_GL_CONTEXT_MAJOR_VERSION], [], [SUPPORT_SDL_GLES=no],<br>
+ [#include <SDL.h>])<br>
+ AC_CHECK_DECL([SDL_GL_CONTEXT_MINOR_VERSION], [], [SUPPORT_SDL_GLES=no],<br>
+ [#include <SDL.h>])<br>
+ CPPFLAGS="$cogl_save_CPPFLAGS"<br>
+<br>
+ AS_IF([test "x$SUPPORT_SDL_GLES" = "xyes"],<br>
+ COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_GLES_SUPPORT")<br>
+ ],<br>
+ [SUPPORT_SDL=no])<br>
+AM_CONDITIONAL(SUPPORT_SDL, [test "x$SUPPORT_SDL" = "xyes"])<br>
+<br>
EGL_PLATFORM_COUNT=0<br>
<br>
AC_ARG_ENABLE(<br>
@@ -823,7 +860,7 @@ AC_ARG_ENABLE(<br>
[xlib-egl-platform],<br>
[AC_HELP_STRING([--enable-xlib-egl-platform=@<:@no/yes@:>@], [Enable support for the Xlib egl platform @<:@default=auto@:>@])],<br>
[],<br>
- AS_IF([test "x$enable_gles1" = "xyes" -o "x$enable_gles2" = "xyes" && test $EGL_PLATFORM_COUNT -eq 0],<br>
+ AS_IF([test "x$enable_gles1" = "xyes" -o "x$enable_gles2" = "xyes" && test "x$SUPPORT_SDL_GLES" != "xyes" && test $EGL_PLATFORM_COUNT -eq 0],<br>
[enable_xlib_egl_platform=yes], [enable_xlib_egl_platform=no])<br>
)<br>
AS_IF([test "x$enable_xlib_egl_platform" = "xyes"],<br>
@@ -875,26 +912,6 @@ AS_IF([test "x$NEED_EGL" = "xyes"],<br>
<br>
AM_CONDITIONAL(SUPPORT_EGL, [test "x$SUPPORT_EGL" = "xyes"])<br>
<br>
-AC_ARG_ENABLE(<br>
- [sdl],<br>
- [AC_HELP_STRING([--enable-sdl=@<:@no/yes@:>@], [Enable support SDL @<:@default=no@:>@])],<br>
- [],<br>
- [enable_sdl=no])<br>
-AS_IF([test "x$enable_sdl" = "xyes"],<br>
- [<br>
- PKG_CHECK_EXISTS([sdl],<br>
- [],<br>
- [AC_MSG_ERROR([SDL support requested but SDL not found])])<br>
-<br>
- SUPPORT_SDL=yes<br>
- GL_WINSYS_APIS="$GL_WINSYS_APIS sdl"<br>
- COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES sdl"<br>
-<br>
- COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT"<br>
- ],<br>
- [SUPPORT_SDL=no])<br>
-AM_CONDITIONAL(SUPPORT_SDL, [test "x$SUPPORT_SDL" = "xyes"])<br>
-<br>
dnl ========================================================<br>
dnl Check X11 dependencies if required<br>
dnl ========================================================<br>
@@ -1165,6 +1182,9 @@ if test "x$SUPPORT_EGL" = "xyes"; then<br>
echo " EGL Platforms:${EGL_PLATFORMS}"<br>
echo " Wayland compositor support: ${enable_wayland_egl_server}"<br>
fi<br>
+if test "x$SUPPORT_SDL" = "xyes"; then<br>
+echo " Support GLES under SDL: ${SUPPORT_SDL_GLES}"<br>
+fi<br>
echo " Image backend: ${COGL_IMAGE_BACKEND}"<br>
echo " Cogl Pango: ${enable_cogl_pango}"<br>
echo " Profiling: ${enable_profile}"<br>
--<br>
1.7.3.16.g9464b<br>
<br>
_______________________________________________<br>
Cogl mailing list<br>
<a href="mailto:Cogl@lists.freedesktop.org">Cogl@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/cogl" target="_blank">http://lists.freedesktop.org/mailman/listinfo/cogl</a><br>
</blockquote></div>