diff --git a/examples/common/entry_emscripten.cpp b/examples/common/entry_emscripten.cpp new file mode 100644 index 000000000..a6ff26f69 --- /dev/null +++ b/examples/common/entry_emscripten.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2011-2012 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#include + +#if BX_PLATFORM_EMSCRIPTEN + +#include +#include + +extern int _main_(int _argc, char** _argv); + +#include +jmp_buf s_main; +jmp_buf s_loop; + +void emscripten_yield() +{ + if (!setjmp(s_main) ) + { + longjmp(s_loop, 1); + } +} + +void loop() +{ + if (!setjmp(s_loop) ) + { + longjmp(s_main, 1); + } +} + +int main(int _argc, char** _argv) +{ + if (!setjmp(s_loop) ) + { + _main_(_argc, _argv); + } + + emscripten_set_main_loop(loop, 10, true); +} + +#endif // BX_PLATFORM_EMSCRIPTEN diff --git a/premake/premake4.lua b/premake/premake4.lua index 93148ac12..80cde35a1 100644 --- a/premake/premake4.lua +++ b/premake/premake4.lua @@ -59,9 +59,14 @@ if _ACTION == "gmake" then } if "emscripten" == _OPTIONS["gcc"] then - premake.gcc.cc = "emcc" - premake.gcc.cxx = "em++" - premake.gcc.ar = "emar" + + if not os.getenv("EMSCRIPTEN") then + print("Set EMSCRIPTEN enviroment variables.") + end + + premake.gcc.cc = "$(EMSCRIPTEN)/emcc" + premake.gcc.cxx = "$(EMSCRIPTEN)/em++" + premake.gcc.ar = "$(EMSCRIPTEN)/emar" location (BGFX_BUILD_DIR .. "projects/" .. _ACTION .. "-emscripten") end @@ -203,6 +208,10 @@ configuration { "emscripten" } targetdir (BGFX_BUILD_DIR .. "emscripten" .. "/bin") objdir (BGFX_BUILD_DIR .. "emscripten" .. "/obj") libdirs { BGFX_THIRD_PARTY_DIR .. "lib/emscripten" } + includedirs { "$(EMSCRIPTEN)/system/include" } + buildoptions { + "-pthread", + } configuration { "nacl" } defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600" } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 81afaee6c..4a9bf3163 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -215,7 +215,14 @@ namespace bgfx uint8_t* rgba = mem->data; charsetFillTexture(vga8x8, rgba, 8, pitch, bpp); charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp); - m_texture = createTexture2D(2048, 24, 1, TextureFormat::L8, BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT, mem); + m_texture = createTexture2D(2048, 24, 1, TextureFormat::L8 + , BGFX_TEXTURE_MIN_POINT + | BGFX_TEXTURE_MAG_POINT + | BGFX_TEXTURE_MIP_POINT + | BGFX_TEXTURE_U_CLAMP + | BGFX_TEXTURE_V_CLAMP + , mem + ); #if BGFX_CONFIG_RENDERER_DIRECT3D9 mem = makeRef(vs_debugfont_dx9, sizeof(vs_debugfont_dx9) ); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index b200eb25a..1ae35dc2d 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -391,14 +391,18 @@ namespace bgfx success = eglMakeCurrent(m_display, m_surface, m_surface, m_context); BGFX_FATAL(success, Fatal::OPENGL_UnableToCreateContext, "Failed to set context."); -# define GL_IMPORT(_optional, _proto, _func) \ - { \ - _func = (_proto)eglGetProcAddress(#_func); \ - BX_TRACE(#_func " 0x%08x", _func); \ - BGFX_FATAL(_optional || NULL != _func, Fatal::OPENGL_UnableToCreateContext, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_func); \ - } -# include "glimports.h" -# undef GL_IMPORT +# if BX_PLATFORM_EMSCRIPTEN + emscripten_set_canvas_size(_width, _height); +# else +# define GL_IMPORT(_optional, _proto, _func) \ + { \ + _func = (_proto)eglGetProcAddress(#_func); \ + BX_TRACE(#_func " 0x%08x", _func); \ + BGFX_FATAL(_optional || NULL != _func, Fatal::OPENGL_UnableToCreateContext, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_func); \ + } +# include "glimports.h" +# undef GL_IMPORT +# endif // !BX_PLATFORM_EMSCRIPTEN } #endif // BX_PLATFORM_ } diff --git a/src/renderer_gl.h b/src/renderer_gl.h index a166f34f6..944e606c3 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -95,6 +95,10 @@ # define BGFX_USE_EGL 1 # endif // BX_PLATFORM_ +# if BX_PLATFORM_EMSCRIPTEN +# include +# endif // BX_PLATFORM_EMSCRIPTEN + # ifndef GL_BGRA_EXT # define GL_BGRA_EXT 0x80E1 # endif // GL_BGRA_EXT