<p>Ah, cool, yeah this looks good to me.</p>
<p>Reviewed-by: Robert Bragg &lt;<a href="mailto:robert@linux.intel.com">robert@linux.intel.com</a>&gt;</p>
<p>Regards,<br>
Robert</p>
<div class="gmail_quote">On May 8, 2012 6:34 PM, &quot;Neil Roberts&quot; &lt;<a href="mailto:neil@linux.intel.com">neil@linux.intel.com</a>&gt; 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-&gt;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-&gt;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>
                    &quot;The SDL winsys only supports the GL driver&quot;);<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 (&amp;display-&gt;onscreen_template-&gt;config);<br>
<br>
+  switch (display-&gt;renderer-&gt;driver)<br>
+    {<br>
+    case COGL_DRIVER_GL:<br>
+      sdl_display-&gt;video_mode_flags = SDL_OPENGL;<br>
+      break;<br>
+<br>
+#ifdef COGL_HAS_SDL_GLES_SUPPORT<br>
+    case COGL_DRIVER_GLES2:<br>
+      sdl_display-&gt;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-&gt;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&#39;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&#39;ll have to just guess at<br>
      a size an resize it later */<br>
-  sdl_display-&gt;surface = SDL_SetVideoMode (640, 480, 0, SDL_OPENGL);<br>
+  sdl_display-&gt;surface = SDL_SetVideoMode (640, 480, /* width/height */<br>
+                                           0, /* bitsperpixel */<br>
+                                           sdl_display-&gt;video_mode_flags);<br>
<br>
   if (sdl_display-&gt;surface == NULL)<br>
     {<br>
@@ -213,7 +247,9 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,<br>
   if (width != sdl_display-&gt;surface-&gt;w ||<br>
       height != sdl_display-&gt;surface-&gt;h)<br>
     {<br>
-      sdl_display-&gt;surface = SDL_SetVideoMode (width, height, 0, SDL_OPENGL);<br>
+      sdl_display-&gt;surface = SDL_SetVideoMode (width, height,<br>
+                                               0, /* bitsperpixel */<br>
+                                               sdl_display-&gt;video_mode_flags);<br>
<br>
       if (sdl_display-&gt;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 &quot;x$enable_gles1&quot; = &quot;xyes&quot;],<br>
         PKG_CHECK_EXISTS([glesv1_cm],<br>
           [COGL_PKG_REQUIRES_GL=&quot;$COGL_PKG_REQUIRES_GL glesv1_cm&quot;<br>
            COGL_GLES1_LIBNAME=&quot;libGLESv1_CM.so&quot;<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 &quot;x$enable_gles2&quot; = &quot;xyes&quot;],<br>
<br>
             COGL_GLES2_LIBNAME=&quot;libGLESv2.so&quot;<br>
           ])<br>
-<br>
-        NEED_EGL=yes<br>
       ])<br>
<br>
 HAVE_GL=0<br>
@@ -681,6 +678,46 @@ AS_IF([test &quot;x$enable_wgl&quot; = &quot;xyes&quot;],<br>
       ])<br>
 AM_CONDITIONAL(SUPPORT_WGL, [test &quot;x$SUPPORT_WGL&quot; = &quot;xyes&quot;])<br>
<br>
+AC_ARG_ENABLE(<br>
+  [sdl],<br>
+  [AC_HELP_STRING([--enable-sdl=@&lt;:@no/yes@:&gt;@], [Enable support SDL @&lt;:@default=no@:&gt;@])],<br>
+  [],<br>
+  [enable_sdl=no])<br>
+AS_IF([test &quot;x$enable_sdl&quot; = &quot;xyes&quot;],<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=&quot;$GL_WINSYS_APIS sdl&quot;<br>
+        COGL_PKG_REQUIRES=&quot;$COGL_PKG_REQUIRES sdl&quot;<br>
+<br>
+        COGL_DEFINES_SYMBOLS=&quot;$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT&quot;<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=&quot;$CPPFLAGS&quot;<br>
+        CPPFLAGS=&quot;$CPPFLAGS $SDL_CFLAGS&quot;<br>
+        AC_CHECK_DECL([SDL_OPENGLES],<br>
+                      [SUPPORT_SDL_GLES=yes],<br>
+                      [SUPPORT_SDL_GLES=no],<br>
+                      [#include &lt;SDL.h&gt;])<br>
+        AC_CHECK_DECL([SDL_GL_CONTEXT_MAJOR_VERSION], [], [SUPPORT_SDL_GLES=no],<br>
+                      [#include &lt;SDL.h&gt;])<br>
+        AC_CHECK_DECL([SDL_GL_CONTEXT_MINOR_VERSION], [], [SUPPORT_SDL_GLES=no],<br>
+                      [#include &lt;SDL.h&gt;])<br>
+        CPPFLAGS=&quot;$cogl_save_CPPFLAGS&quot;<br>
+<br>
+        AS_IF([test &quot;x$SUPPORT_SDL_GLES&quot; = &quot;xyes&quot;],<br>
+              COGL_DEFINES_SYMBOLS=&quot;$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_GLES_SUPPORT&quot;)<br>
+      ],<br>
+      [SUPPORT_SDL=no])<br>
+AM_CONDITIONAL(SUPPORT_SDL, [test &quot;x$SUPPORT_SDL&quot; = &quot;xyes&quot;])<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=@&lt;:@no/yes@:&gt;@], [Enable support for the Xlib egl platform @&lt;:@default=auto@:&gt;@])],<br>
   [],<br>
-  AS_IF([test &quot;x$enable_gles1&quot; = &quot;xyes&quot; -o &quot;x$enable_gles2&quot; = &quot;xyes&quot; &amp;&amp; test $EGL_PLATFORM_COUNT -eq 0],<br>
+  AS_IF([test &quot;x$enable_gles1&quot; = &quot;xyes&quot; -o &quot;x$enable_gles2&quot; = &quot;xyes&quot; &amp;&amp; test &quot;x$SUPPORT_SDL_GLES&quot; != &quot;xyes&quot; &amp;&amp; test $EGL_PLATFORM_COUNT -eq 0],<br>

         [enable_xlib_egl_platform=yes], [enable_xlib_egl_platform=no])<br>
 )<br>
 AS_IF([test &quot;x$enable_xlib_egl_platform&quot; = &quot;xyes&quot;],<br>
@@ -875,26 +912,6 @@ AS_IF([test &quot;x$NEED_EGL&quot; = &quot;xyes&quot;],<br>
<br>
 AM_CONDITIONAL(SUPPORT_EGL, [test &quot;x$SUPPORT_EGL&quot; = &quot;xyes&quot;])<br>
<br>
-AC_ARG_ENABLE(<br>
-  [sdl],<br>
-  [AC_HELP_STRING([--enable-sdl=@&lt;:@no/yes@:&gt;@], [Enable support SDL @&lt;:@default=no@:&gt;@])],<br>
-  [],<br>
-  [enable_sdl=no])<br>
-AS_IF([test &quot;x$enable_sdl&quot; = &quot;xyes&quot;],<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=&quot;$GL_WINSYS_APIS sdl&quot;<br>
-        COGL_PKG_REQUIRES=&quot;$COGL_PKG_REQUIRES sdl&quot;<br>
-<br>
-        COGL_DEFINES_SYMBOLS=&quot;$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT&quot;<br>
-      ],<br>
-      [SUPPORT_SDL=no])<br>
-AM_CONDITIONAL(SUPPORT_SDL, [test &quot;x$SUPPORT_SDL&quot; = &quot;xyes&quot;])<br>
-<br>
 dnl         ========================================================<br>
 dnl         Check X11 dependencies if required<br>
 dnl         ========================================================<br>
@@ -1165,6 +1182,9 @@ if test &quot;x$SUPPORT_EGL&quot; = &quot;xyes&quot;; then<br>
 echo &quot;        EGL Platforms:${EGL_PLATFORMS}&quot;<br>
 echo &quot;        Wayland compositor support: ${enable_wayland_egl_server}&quot;<br>
 fi<br>
+if test &quot;x$SUPPORT_SDL&quot; = &quot;xyes&quot;; then<br>
+echo &quot;        Support GLES under SDL: ${SUPPORT_SDL_GLES}&quot;<br>
+fi<br>
 echo &quot;        Image backend: ${COGL_IMAGE_BACKEND}&quot;<br>
 echo &quot;        Cogl Pango: ${enable_cogl_pango}&quot;<br>
 echo &quot;        Profiling: ${enable_profile}&quot;<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>