mirror of https://github.com/bkaradzic/bgfx
Setup emscripten canvas.
This commit is contained in:
parent
b0075aa06c
commit
4bc42d9f97
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright 2011-2012 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <bx/bx.h>
|
||||
|
||||
#if BX_PLATFORM_EMSCRIPTEN
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <pthread.h>
|
||||
|
||||
extern int _main_(int _argc, char** _argv);
|
||||
|
||||
#include <setjmp.h>
|
||||
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
|
|
@ -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" }
|
||||
|
|
|
@ -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) );
|
||||
|
|
|
@ -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_
|
||||
}
|
||||
|
|
|
@ -95,6 +95,10 @@
|
|||
# define BGFX_USE_EGL 1
|
||||
# endif // BX_PLATFORM_
|
||||
|
||||
# if BX_PLATFORM_EMSCRIPTEN
|
||||
# include <emscripten/emscripten.h>
|
||||
# endif // BX_PLATFORM_EMSCRIPTEN
|
||||
|
||||
# ifndef GL_BGRA_EXT
|
||||
# define GL_BGRA_EXT 0x80E1
|
||||
# endif // GL_BGRA_EXT
|
||||
|
|
Loading…
Reference in New Issue