[cogl/wip/emscripten: 2/2] stash: start adding emscripten support



commit e7236d685c953086836d12e35a9f8c5e379dec3f
Author: Robert Bragg <robert linux intel com>
Date:   Mon Sep 24 15:37:11 2012 +0100

    stash: start adding emscripten support

 cogl/Makefile.am              |    5 ++
 cogl/cogl-debug.c             |    6 ++-
 cogl/cogl-poll.h              |    2 +-
 cogl/cogl-util.c              |    2 +-
 cogl/cogl-util.h              |    2 +-
 cogl/cogl.c                   |    4 +-
 cogl/winsys/cogl-winsys-sdl.c |   34 +++++++--
 configure.ac                  |  161 +++++++++++++++++++++++++++--------------
 deps/glib/Makefile.am         |    2 +-
 examples/cogl-info.c          |    2 +-
 tests/conform/Makefile.am     |   32 --------
 11 files changed, 152 insertions(+), 100 deletions(-)
---
diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index de5f4cc..3ed06b0 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -43,6 +43,11 @@ AM_CPPFLAGS += \
        -DCOGL_DEFAULT_DRIVER=\"$(COGL_DEFAULT_DRIVER)\"
 endif
 
+if USE_NLS
+AM_CPPFLAGS += -DUSE_NLS
+endif
+
+
 
 AM_CFLAGS = $(COGL_DEP_CFLAGS) $(COGL_EXTRA_CFLAGS) $(MAINTAINER_CFLAGS)
 
diff --git a/cogl/cogl-debug.c b/cogl/cogl-debug.c
index 01af450..5436079 100644
--- a/cogl/cogl-debug.c
+++ b/cogl/cogl-debug.c
@@ -26,7 +26,9 @@
 #endif
 
 #include <stdlib.h>
-#include <glib/gi18n-lib.h>
+//#include <glib/gi18n-lib.h>
+#define _(X) X
+#define N_(X) X
 
 #include "cogl-private.h"
 #include "cogl-debug.h"
@@ -211,6 +213,8 @@ _cogl_debug_check_environment (void)
 {
   const char *env_string;
 
+  setenv ("COGL_DEBUG", "all", 1);
+
   env_string = g_getenv ("COGL_DEBUG");
   if (env_string != NULL)
     {
diff --git a/cogl/cogl-poll.h b/cogl/cogl-poll.h
index 7a7e311..75405b4 100644
--- a/cogl/cogl-poll.h
+++ b/cogl/cogl-poll.h
@@ -71,7 +71,7 @@ COGL_BEGIN_DECLS
 typedef enum
 {
   COGL_POLL_FD_EVENT_IN = COGL_SYSDEF_POLLIN,
-  COGL_POLL_FD_EVENT_PRI = COGL_SYSDEF_POLLPRI,
+  //COGL_POLL_FD_EVENT_PRI = COGL_SYSDEF_POLLPRI,
   COGL_POLL_FD_EVENT_OUT = COGL_SYSDEF_POLLOUT,
   COGL_POLL_FD_EVENT_ERR = COGL_SYSDEF_POLLERR,
   COGL_POLL_FD_EVENT_HUP = COGL_SYSDEF_POLLHUP,
diff --git a/cogl/cogl-util.c b/cogl/cogl-util.c
index 9ecc34c..a4992c4 100644
--- a/cogl/cogl-util.c
+++ b/cogl/cogl-util.c
@@ -61,7 +61,7 @@ _cogl_util_one_at_a_time_mix (unsigned int hash)
 }
 
 /* The 'ffs' function is part of C99 so it isn't always available */
-#ifndef HAVE_FFS
+#if !defined (HAVE_FFS) || defined (USING_EMSCRIPTEN)
 
 int
 _cogl_util_ffs (int num)
diff --git a/cogl/cogl-util.h b/cogl/cogl-util.h
index 9f6bfff..fac86d8 100644
--- a/cogl/cogl-util.h
+++ b/cogl/cogl-util.h
@@ -128,7 +128,7 @@ _cogl_util_one_at_a_time_mix (unsigned int hash);
 #endif
 
 /* The 'ffs' function is part of C99 so it isn't always available */
-#ifdef HAVE_FFS
+#if defined (HAVE_FFS) && !defined (USING_EMSCRIPTEN)
 #define _cogl_util_ffs ffs
 #else
 int
diff --git a/cogl/cogl.c b/cogl/cogl.c
index 578f0b4..3820e27 100644
--- a/cogl/cogl.c
+++ b/cogl/cogl.c
@@ -28,7 +28,7 @@
 #include <string.h>
 #include <math.h>
 #include <stdlib.h>
-#include <glib/gi18n-lib.h>
+//#include <glib/gi18n-lib.h>
 
 #include "cogl-debug.h"
 #include "cogl-util.h"
@@ -161,8 +161,10 @@ _cogl_init (void)
 
   if (initialized == FALSE)
     {
+#ifdef USE_NLS
       bindtextdomain (GETTEXT_PACKAGE, COGL_LOCALEDIR);
       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+#endif
 
 #ifdef COGL_HAS_GTYPE_SUPPORT
       g_type_init ();
diff --git a/cogl/winsys/cogl-winsys-sdl.c b/cogl/winsys/cogl-winsys-sdl.c
index 8c4e2ac..4b2e1a7 100644
--- a/cogl/winsys/cogl-winsys-sdl.c
+++ b/cogl/winsys/cogl-winsys-sdl.c
@@ -57,6 +57,8 @@ _cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer,
                                         const char *name,
                                         CoglBool in_core)
 {
+  CoglFuncPtr ptr;
+
   /* XXX: It's not totally clear whether it's safe to call this for
    * core functions. From the code it looks like the implementations
    * will fall back to using some form of dlsym if the winsys
@@ -67,12 +69,17 @@ _cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer,
    * calling SDL_GL_GetProcAddress is probably the best we can do
    * here. */
 
-#ifdef COGL_HAS_SDL_GLES_SUPPORT
+#if !defined (USING_EMSCRIPTEN) && defined (COGL_HAS_SDL_GLES_SUPPORT)
   if (renderer->driver != COGL_DRIVER_GL)
     return SDL_GLES_GetProcAddress (name);
 #endif
 
-  return SDL_GL_GetProcAddress (name);
+  ptr = SDL_GL_GetProcAddress (name);
+
+  if (!ptr)
+    g_printerr ("Failed to find proc address: %s\n", name);
+
+  return ptr;
 }
 
 static void
@@ -87,7 +94,16 @@ static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                                CoglError **error)
 {
-#ifndef COGL_HAS_SDL_GLES_SUPPORT
+#ifdef USING_EMSCRIPTEN
+  if (renderer->driver != COGL_DRIVER_GLES2)
+    {
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
+                       COGL_WINSYS_ERROR_INIT,
+                       "The SDL winsys with emscripten only supports "
+                       "the GLES2 driver");
+      return FALSE;
+    }
+#elif !defined (COGL_HAS_SDL_GLES_SUPPORT)
   if (renderer->driver != COGL_DRIVER_GL)
     {
       _cogl_set_error (error, COGL_WINSYS_ERROR,
@@ -95,7 +111,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                    "The SDL winsys only supports the GL driver");
       return FALSE;
     }
-#endif /* COGL_HAS_SDL_GLES_SUPPORT */
+#endif
 
   if (SDL_Init (SDL_INIT_VIDEO) == -1)
     {
@@ -168,7 +184,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
                        "The SDL winsys does not support GL 3");
       goto error;
 
-#ifdef COGL_HAS_SDL_GLES_SUPPORT
+#if !defined (USING_EMSCRIPTEN) && defined (COGL_HAS_SDL_GLES_SUPPORT)
     case COGL_DRIVER_GLES2:
       sdl_display->video_mode_flags = SDL_OPENGLES;
       SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
@@ -180,7 +196,13 @@ _cogl_winsys_display_setup (CoglDisplay *display,
       SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 1);
       SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 1);
       break;
-#endif /* COGL_HAS_SDL_GLES_SUPPORT */
+
+#elif defined (USING_EMSCRIPTEN)
+    case COGL_DRIVER_GLES2:
+      sdl_display->video_mode_flags = SDL_OPENGL;
+      break;
+
+#endif
 
     default:
       g_assert_not_reached ();
diff --git a/configure.ac b/configure.ac
index bdf843f..325d05b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -189,6 +189,29 @@ dnl ================================================================
 dnl Handle extra configure options
 dnl ================================================================
 
+
+dnl     ============================================================
+dnl     Emscripten support
+dnl     ============================================================
+
+AC_ARG_ENABLE(
+  [emscripten],
+  [AC_HELP_STRING([--enable-emscripten=@<:@no/yes@:>@], [Support building for emscripten])],
+  [],
+  enable_emscripten=no
+)
+AS_IF([test "x$enable_emscripten" = "xyes"],
+      [
+        enable_standalone=yes
+        enable_sdl=yes
+        enable_gles2=yes
+        enable_gl=no
+        AC_DEFINE([USING_EMSCRIPTEN], 1, [Cogl is being compiled with emscripten])
+      ]
+)
+AM_CONDITIONAL(USING_EMSCRIPTEN, [test "$enable_emscripten" = "yes"])
+
+
 dnl     ============================================================
 dnl     Standalone cogl
 dnl     ============================================================
@@ -635,24 +658,32 @@ AS_IF([test "x$enable_gles2" = "xyes"],
         COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_GLES2"
         HAVE_GLES2=1
 
-        PKG_CHECK_EXISTS([glesv2],
-          [COGL_PKG_REQUIRES_GL="$COGL_PKG_REQUIRES_GL glesv2"
-           COGL_GLES2_LIBNAME="libGLESv2.so"
-          ],
-          [
-            # We have to check the two headers independently as GLES2/gl2ext.h
-            # needs to include GLES2/gl2.h to have the GL types defined (eg.
-            # GLenum).
-            AC_CHECK_HEADER([GLES2/gl2.h],
-                            [],
-                            [AC_MSG_ERROR([Unable to locate GLES2/gl2.h])])
-            AC_CHECK_HEADER([GLES2/gl2ext.h],
-                            [],
-                            [AC_MSG_ERROR([Unable to locate GLES2/gl2ext.h])],
-                            [#include <GLES2/gl2.h>])
+        AS_IF([test "x$enable_emscripten" = "xyes"],
+              [
+                GL_LIBRARY_DIRECTLY_LINKED=yes
+                COGL_GLES2_LIBNAME=""
+              ],
 
-            COGL_GLES2_LIBNAME="libGLESv2.so"
-          ])
+              [
+                PKG_CHECK_EXISTS([glesv2],
+                  [COGL_PKG_REQUIRES_GL="$COGL_PKG_REQUIRES_GL glesv2"
+                   COGL_GLES2_LIBNAME="libGLESv2.so"
+                  ],
+                  [
+                    # We have to check the two headers independently as GLES2/gl2ext.h
+                    # needs to include GLES2/gl2.h to have the GL types defined (eg.
+                    # GLenum).
+                    AC_CHECK_HEADER([GLES2/gl2.h],
+                                    [],
+                                    [AC_MSG_ERROR([Unable to locate GLES2/gl2.h])])
+                    AC_CHECK_HEADER([GLES2/gl2ext.h],
+                                    [],
+                                    [AC_MSG_ERROR([Unable to locate GLES2/gl2ext.h])],
+                                    [#include <GLES2/gl2.h>])
+
+                    COGL_GLES2_LIBNAME="libGLESv2.so"
+                  ])
+              ])
       ])
 
 HAVE_GL=0
@@ -820,32 +851,48 @@ AC_ARG_ENABLE(
   [enable_sdl=no])
 AS_IF([test "x$enable_sdl" = "xyes"],
       [
-        PKG_CHECK_MODULES([SDL],
-                          [sdl],
-                          [],
-                          [AC_MSG_ERROR([SDL support requested but SDL not found])])
+        AS_IF([test "x$enable_emscripten" = "xno"],
+              [
+                PKG_CHECK_MODULES([SDL],
+                                  [sdl],
+                                  [
+                                   COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES sdl"
+                                  ],
+                                  [
+                                   AC_CHECK_HEADER([SDL/SDL.h],
+                                                   [],
+                                                   [AC_MSG_ERROR([SDL support requested but SDL not found])])
+                                  ])
+              ])
 
         SUPPORT_SDL=yes
         GL_WINSYS_APIS="$GL_WINSYS_APIS sdl"
-        COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES sdl"
 
         COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT"
 
-        dnl WebOS has a specially patched version of SDL to add
-        dnl support for creating a GLES1/2 context. This tries to
-        dnl detect that patch so we can use it if the GLES2 driver is
-        dnl selected.
-        cogl_save_CPPFLAGS="$CPPFLAGS"
-        CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
-        AC_CHECK_DECL([SDL_OPENGLES],
-                      [SUPPORT_SDL_GLES=yes],
-                      [SUPPORT_SDL_GLES=no],
-                      [#include <SDL.h>])
-        AC_CHECK_DECL([SDL_GL_CONTEXT_MAJOR_VERSION], [], [SUPPORT_SDL_GLES=no],
-                      [#include <SDL.h>])
-        AC_CHECK_DECL([SDL_GL_CONTEXT_MINOR_VERSION], [], [SUPPORT_SDL_GLES=no],
-                      [#include <SDL.h>])
-        CPPFLAGS="$cogl_save_CPPFLAGS"
+        dnl If we are building with emscripten then that simply implies we are
+        dnl using SDL in conjunction with WebGL (GLES2)
+        AS_IF([test "x$enable_emscripten" = "xyes"],
+              [
+                SUPPORT_SDL_GLES=yes
+              ],
+              [
+                dnl WebOS has a specially patched version of SDL to add
+                dnl support for creating a GLES1/2 context. This tries to
+                dnl detect that patch so we can use it if the GLES2 driver is
+                dnl selected.
+                cogl_save_CPPFLAGS="$CPPFLAGS"
+                CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
+                AC_CHECK_DECL([SDL_OPENGLES],
+                              [SUPPORT_SDL_GLES=yes],
+                              [SUPPORT_SDL_GLES=no],
+                              [#include <SDL.h>])
+                AC_CHECK_DECL([SDL_GL_CONTEXT_MAJOR_VERSION], [], [SUPPORT_SDL_GLES=no],
+                              [#include <SDL.h>])
+                AC_CHECK_DECL([SDL_GL_CONTEXT_MINOR_VERSION], [], [SUPPORT_SDL_GLES=no],
+                              [#include <SDL.h>])
+                CPPFLAGS="$cogl_save_CPPFLAGS"
+              ])
 
         AS_IF([test "x$SUPPORT_SDL_GLES" = "xyes"],
               COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_GLES_SUPPORT")
@@ -1144,22 +1191,25 @@ AS_ALL_LINGUAS
 
 
 AC_SUBST(COGL_PKG_REQUIRES)
-PKG_CHECK_MODULES(COGL_DEP, [$COGL_PKG_REQUIRES])
-if test -n "$COGL_PKG_REQUIRES_GL"; then
-  PKG_CHECK_MODULES(COGL_DEP_GL, [$COGL_PKG_REQUIRES_GL])
-
-  dnl Strip out the GL libraries from the GL pkg-config files so we can
-  dnl dynamically load them instead
-  gl_libs=""
-  for x in $COGL_DEP_GL_LIBS; do
-    AS_CASE([$x],
-            [-lGL], [],
-            [-lGLESv2], [],
-            [-lGLESv1_CM], [],
-            [*], [gl_libs="$gl_libs $x"])
-  done
-  COGL_DEP_CFLAGS="$COGL_DEP_CFLAGS $COGL_DEP_CFLAGS_GL"
-  COGL_DEP_LIBS="$COGL_DEP_LIBS $gl_libs"
+if test -n "$COGL_PKG_REQUIRES"; then
+  PKG_CHECK_MODULES(COGL_DEP, [$COGL_PKG_REQUIRES])
+
+  if test -n "$COGL_PKG_REQUIRES_GL"; then
+    PKG_CHECK_MODULES(COGL_DEP_GL, [$COGL_PKG_REQUIRES_GL])
+
+    dnl Strip out the GL libraries from the GL pkg-config files so we can
+    dnl dynamically load them instead
+    gl_libs=""
+    for x in $COGL_DEP_GL_LIBS; do
+      AS_CASE([$x],
+              [-lGL], [],
+              [-lGLESv2], [],
+              [-lGLESv1_CM], [],
+              [*], [gl_libs="$gl_libs $x"])
+    done
+    COGL_DEP_CFLAGS="$COGL_DEP_CFLAGS $COGL_DEP_CFLAGS_GL"
+    COGL_DEP_LIBS="$COGL_DEP_LIBS $gl_libs"
+  fi
 fi
 AC_SUBST(COGL_PANGO_PKG_REQUIRES)
 
@@ -1230,8 +1280,6 @@ AC_CHECK_HEADER(poll.h,
         [
          AC_COMPUTE_INT(COGL_SYSDEF_POLLIN, POLLIN, [#include <poll.h>],
                         AC_MSG_ERROR([Unable to get value of POLLIN]))
-         AC_COMPUTE_INT(COGL_SYSDEF_POLLPRI, POLLPRI, [#include <poll.h>],
-                        AC_MSG_ERROR([Unable to get value of POLLPRI]))
          AC_COMPUTE_INT(COGL_SYSDEF_POLLOUT, POLLOUT, [#include <poll.h>],
                         AC_MSG_ERROR([Unable to get value of POLLOUT]))
          AC_COMPUTE_INT(COGL_SYSDEF_POLLERR, POLLERR, [#include <poll.h>],
@@ -1300,6 +1348,8 @@ AC_SUBST(COGL_EXTRA_LDFLAGS)
 MAINTAINER_CFLAGS=
 AC_SUBST(MAINTAINER_CFLAGS)
 
+AM_CONDITIONAL(USE_NLS, [test "$USE_NLS" = "yes"])
+
 AC_OUTPUT(
 Makefile
 README
@@ -1373,6 +1423,7 @@ fi
 if test "x$SUPPORT_SDL" = "xyes"; then
 echo "        Support GLES under SDL: ${SUPPORT_SDL_GLES}"
 fi
+echo "        Building for emscripten environment: $enable_emscripten"
 echo "        Build libcogl-gles2 GLES 2.0 frontend api: ${enable_cogl_gles2}"
 echo "        Image backend: ${COGL_IMAGE_BACKEND}"
 echo "        Cogl Pango: ${enable_cogl_pango}"
diff --git a/deps/glib/Makefile.am b/deps/glib/Makefile.am
index 9a4544f..ea35cb1 100644
--- a/deps/glib/Makefile.am
+++ b/deps/glib/Makefile.am
@@ -71,5 +71,5 @@ libglib_la_SOURCES =          \
        gutils.c                \
        gutils.h                \
        $(NULL)
-       
+
 EXTRA_DIST = README
diff --git a/examples/cogl-info.c b/examples/cogl-info.c
index 1680f7d..d5231a2 100644
--- a/examples/cogl-info.c
+++ b/examples/cogl-info.c
@@ -222,7 +222,7 @@ main (int argc, char **argv)
   const char *winsys_name;
   OutputState output_state;
 
-  ctx = cogl_context_new (NULL, &error);
+  ctx = cogl_sdl_context_new (SDL_USEREVENT, &error);
   if (!ctx) {
       fprintf (stderr, "Failed to create context: %s\n", error->message);
       return 1;
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index 6650766..214912e 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -27,43 +27,11 @@ unported_test_sources = \
 
 test_sources = \
        test-atlas-migration.c \
-       test-bitmask.c \
        test-blend-strings.c \
        test-depth-test.c \
        test-color-mask.c \
        test-backface-culling.c \
        test-just-vertex-shader.c \
-       test-path.c \
-       test-pipeline-uniforms.c \
-       test-pixel-buffer.c \
-       test-premult.c \
-       test-snippets.c \
-       test-wrap-modes.c \
-       test-sub-texture.c \
-       test-custom-attributes.c \
-       test-offscreen.c \
-       test-primitive.c \
-       test-texture-3d.c \
-       test-sparse-pipeline.c \
-       test-read-texture-formats.c \
-       test-write-texture-formats.c \
-       test-point-size.c \
-       test-point-sprite.c \
-       test-no-gl-header.c \
-       test-version.c \
-       test-gles2-context.c \
-       test-euler-quaternion.c \
-       test-layer-remove.c \
-       test-alpha-test.c \
-       test-map-buffer-range.c \
-       test-npot-texture.c \
-       test-alpha-textures.c \
-       test-wrap-rectangle-textures.c \
-       test-texture-get-set-data.c \
-       test-texture-mipmap-get-set.c \
-       test-framebuffer-get-bits.c \
-       test-primitive-and-journal.c \
-       test-copy-replace-texture.c \
        $(NULL)
 
 test_conformance_SOURCES = $(common_sources) $(test_sources)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]