From 96feb074d085977345fe11363a1844136303ab68 Mon Sep 17 00:00:00 2001 From: Toad King Date: Wed, 2 Jul 2014 21:56:22 -0400 Subject: [PATCH] (EMSCRIPTEN) add shared context support --- Makefile.emscripten | 3 ++- gfx/context/emscriptenegl_ctx.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Makefile.emscripten b/Makefile.emscripten index a6d976ce5f..82a4cab37a 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -57,7 +57,8 @@ HAVE_SDL = 0 HAVE_ZLIB = 1 HAVE_FBO = 1 WANT_MINIZ = 1 -MEMORY = 67108864 +#MEMORY = 67108864 +MEMORY = 134217728 LTO = 0 # XXX: setting this to 1/2 currently crashes Firefox nightly PRECISE_F32 = 0 diff --git a/gfx/context/emscriptenegl_ctx.c b/gfx/context/emscriptenegl_ctx.c index 236c7986e8..4b8d98e562 100644 --- a/gfx/context/emscriptenegl_ctx.c +++ b/gfx/context/emscriptenegl_ctx.c @@ -32,12 +32,14 @@ #include #include +static EGLContext g_egl_hw_ctx; static EGLContext g_egl_ctx; static EGLSurface g_egl_surf; static EGLDisplay g_egl_dpy; static EGLConfig g_config; static bool g_inited; +static bool g_use_hw_ctx; static unsigned g_fb_width; static unsigned g_fb_height; @@ -153,6 +155,16 @@ static bool gfx_ctx_init(void *data) if (!g_egl_ctx) goto error; + if (g_use_hw_ctx) + { + g_egl_hw_ctx = eglCreateContext(g_egl_dpy, g_config, g_egl_ctx, + context_attributes); + RARCH_LOG("[VC/EGL]: Created shared context: %p.\n", (void*)g_egl_hw_ctx); + + if (g_egl_hw_ctx == EGL_NO_CONTEXT) + goto error; + } + // create an EGL window surface g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_config, 0, NULL); if (!g_egl_surf) @@ -271,6 +283,14 @@ static bool gfx_ctx_write_egl_image(void *data, const void *frame, unsigned widt return false; } +static void gfx_ctx_bind_hw_render(void *data, bool enable) +{ + (void)data; + g_use_hw_ctx = enable; + if (g_egl_dpy && g_egl_surf) + eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, enable ? g_egl_hw_ctx : g_egl_ctx); +} + const gfx_ctx_driver_t gfx_ctx_emscripten = { gfx_ctx_init, gfx_ctx_destroy, @@ -290,4 +310,5 @@ const gfx_ctx_driver_t gfx_ctx_emscripten = { gfx_ctx_write_egl_image, NULL, "emscripten", + gfx_ctx_bind_hw_render, };