summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2012-09-24 15:37:11 +0100
committerRobert Bragg <robert@linux.intel.com>2013-03-22 15:30:32 +0000
commit77a1c842c6d6a14042b75ad71c0569b2a75f776d (patch)
tree6270d38c34653ca1f58ed3ef1ffb804b53a4dada
parentb9068e75b0b226039cf7834d26d7736e86796faf (diff)
downloadcogl-77a1c842c6d6a14042b75ad71c0569b2a75f776d.tar.gz
stash: start adding emscripten supportwip/emscripten
-rw-r--r--cogl/Makefile.am5
-rw-r--r--cogl/cogl-debug.c4
-rw-r--r--cogl/cogl-poll.h2
-rw-r--r--cogl/cogl-util.c2
-rw-r--r--cogl/cogl-util.h2
-rw-r--r--cogl/cogl.c4
-rw-r--r--cogl/winsys/cogl-winsys-sdl.c34
-rw-r--r--configure.ac161
-rw-r--r--deps/glib/Makefile.am2
-rw-r--r--examples/cogl-info.c2
-rw-r--r--examples/cogl-sdl-hello.c51
-rw-r--r--tests/conform/Makefile.am32
12 files changed, 175 insertions, 126 deletions
diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index de5f4cc2..3ed06b05 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 01af450f..cf9d81d7 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"
diff --git a/cogl/cogl-poll.h b/cogl/cogl-poll.h
index 7a7e311b..75405b4b 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 9ecc34c2..a4992c4b 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 9f6bfffb..fac86d8a 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 578f0b43..3820e274 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 8c4e2ac1..4b2e1a7b 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 e7bf1f24..bc439831 100644
--- a/configure.ac
+++ b/configure.ac
@@ -191,6 +191,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 ============================================================
@@ -637,24 +660,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
@@ -822,32 +853,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")
@@ -1135,22 +1182,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)
@@ -1215,8 +1265,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>],
@@ -1285,6 +1333,8 @@ AC_SUBST(COGL_EXTRA_LDFLAGS)
MAINTAINER_CFLAGS=
AC_SUBST(MAINTAINER_CFLAGS)
+AM_CONDITIONAL(USE_NLS, [test "$USE_NLS" = "yes"])
+
AC_OUTPUT(
Makefile
README
@@ -1358,6 +1408,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 9a4544ff..ea35cb19 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 1680f7d5..d5231a20 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/examples/cogl-sdl-hello.c b/examples/cogl-sdl-hello.c
index 961137ae..a6965992 100644
--- a/examples/cogl-sdl-hello.c
+++ b/examples/cogl-sdl-hello.c
@@ -1,6 +1,7 @@
#include <cogl/cogl.h>
#include <stdio.h>
#include <SDL.h>
+#include <emscripten.h>
/* This short example is just to demonstrate mixing SDL with Cogl as a
simple way to get portable support for events */
@@ -16,6 +17,9 @@ typedef struct Data
CoglBool ready_to_draw;
} Data;
+static Data data;
+static CoglContext *ctx;
+
static void
redraw (Data *data)
{
@@ -73,10 +77,29 @@ frame_cb (CoglOnscreen *onscreen,
data->ready_to_draw = TRUE;
}
+static void
+mainloop (void)
+{
+ SDL_Event event;
+ while (SDL_PollEvent (&event) && !data.quit)
+ {
+ handle_event (&data, &event);
+ cogl_sdl_handle_event (ctx, &event);
+ }
+
+ if (data.quit)
+ emscripten_cancel_main_loop ();
+
+ redraw (&data);
+ data.redraw_queued = FALSE;
+ data.ready_to_draw = FALSE;
+
+ cogl_sdl_idle (ctx);
+}
+
int
main (int argc, char **argv)
{
- CoglContext *ctx;
CoglOnscreen *onscreen;
CoglError *error = NULL;
CoglVertexP2C4 triangle_vertices[] = {
@@ -84,8 +107,6 @@ main (int argc, char **argv)
{-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
{0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
};
- Data data;
- SDL_Event event;
ctx = cogl_sdl_context_new (SDL_USEREVENT, &error);
if (!ctx)
@@ -115,29 +136,7 @@ main (int argc, char **argv)
data.redraw_queued = TRUE;
data.ready_to_draw = TRUE;
- while (!data.quit)
- {
- if (!SDL_PollEvent (&event))
- {
- if (data.redraw_queued && data.ready_to_draw)
- {
- redraw (&data);
- data.redraw_queued = FALSE;
- data.ready_to_draw = FALSE;
- continue;
- }
-
- cogl_sdl_idle (ctx);
- if (!SDL_WaitEvent (&event))
- {
- fprintf (stderr, "Error waiting for SDL events");
- return 1;
- }
- }
-
- handle_event (&data, &event);
- cogl_sdl_handle_event (ctx, &event);
- }
+ emscripten_set_main_loop (mainloop, -1, TRUE);
cogl_object_unref (ctx);
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index 66507669..214912e6 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)