From b0075aa06c7e07f635487447758703da952417eb Mon Sep 17 00:00:00 2001 From: Branimir Karadzic Date: Sun, 21 Oct 2012 22:09:14 -0700 Subject: [PATCH] Added emscripten platform. --- makefile | 37 ++++++++++++++++--------------- premake/example-00-helloworld.lua | 3 +++ premake/example-01-cubes.lua | 3 +++ premake/example-02-metaballs.lua | 3 +++ premake/example-03-raymarch.lua | 3 +++ premake/example-04-mesh.lua | 3 +++ premake/example-05-instancing.lua | 3 +++ premake/premake4.lua | 13 +++++++++++ src/config.h | 5 ++++- src/renderer_gl.cpp | 4 +++- src/renderer_gl.h | 2 +- 11 files changed, 58 insertions(+), 21 deletions(-) diff --git a/makefile b/makefile index 2f4250f4..791dcb8b 100644 --- a/makefile +++ b/makefile @@ -8,17 +8,18 @@ all: premake --file=premake/premake4.lua --gcc=nacl gmake premake --file=premake/premake4.lua --gcc=mingw gmake premake --file=premake/premake4.lua --gcc=linux gmake + premake --file=premake/premake4.lua --gcc=emscripten gmake make -s --no-print-directory -C src -nacl-debug32: - make -C .build/projects/gmake-nacl config=debug32 -nacl-release32: - make -C .build/projects/gmake-nacl config=release32 -nacl-debug64: - make -C .build/projects/gmake-nacl config=debug64 -nacl-release64: - make -C .build/projects/gmake-nacl config=release64 -nacl: nacl-debug32 nacl-release32 nacl-debug64 nacl-release64 +linux-debug32: + make -C .build/projects/gmake-linux config=debug32 +linux-release32: + make -C .build/projects/gmake-linux config=release32 +linux-debug64: + make -C .build/projects/gmake-linux config=debug64 +linux-release64: + make -C .build/projects/gmake-linux config=release64 +linux: linux-debug32 linux-release32 linux-debug64 linux-release64 mingw-debug32: make -C .build/projects/gmake-mingw config=debug32 @@ -30,12 +31,12 @@ mingw-release64: make -C .build/projects/gmake-mingw config=release64 mingw: mingw-debug32 mingw-release32 mingw-debug64 mingw-release64 -linux-debug32: - make -C .build/projects/gmake-linux config=debug32 -linux-release32: - make -C .build/projects/gmake-linux config=release32 -linux-debug64: - make -C .build/projects/gmake-linux config=debug64 -linux-release64: - make -C .build/projects/gmake-linux config=release64 -linux: linux-debug32 linux-release32 linux-debug64 linux-release64 +nacl-debug32: + make -C .build/projects/gmake-nacl config=debug32 +nacl-release32: + make -C .build/projects/gmake-nacl config=release32 +nacl-debug64: + make -C .build/projects/gmake-nacl config=debug64 +nacl-release64: + make -C .build/projects/gmake-nacl config=release64 +nacl: nacl-debug32 nacl-release32 nacl-debug64 nacl-release64 diff --git a/premake/example-00-helloworld.lua b/premake/example-00-helloworld.lua index e99afd74..e856e374 100644 --- a/premake/example-00-helloworld.lua +++ b/premake/example-00-helloworld.lua @@ -18,6 +18,9 @@ project "example-00-helloworld" "bgfx", } + configuration { "emscripten" } + targetextension ".bc" + configuration { "nacl" } targetextension ".nexe" diff --git a/premake/example-01-cubes.lua b/premake/example-01-cubes.lua index 40f153d5..fda9ba84 100644 --- a/premake/example-01-cubes.lua +++ b/premake/example-01-cubes.lua @@ -20,6 +20,9 @@ project "example-01-cubes" "bgfx", } + configuration { "emscripten" } + targetextension ".bc" + configuration { "nacl" } targetextension ".nexe" diff --git a/premake/example-02-metaballs.lua b/premake/example-02-metaballs.lua index 07ee4bc5..0fb0963b 100644 --- a/premake/example-02-metaballs.lua +++ b/premake/example-02-metaballs.lua @@ -20,6 +20,9 @@ project "example-02-metaballs" "bgfx", } + configuration { "emscripten" } + targetextension ".bc" + configuration { "nacl" } targetextension ".nexe" diff --git a/premake/example-03-raymarch.lua b/premake/example-03-raymarch.lua index 4d484f05..7107ca90 100644 --- a/premake/example-03-raymarch.lua +++ b/premake/example-03-raymarch.lua @@ -20,6 +20,9 @@ project "example-03-raymarch" "bgfx", } + configuration { "emscripten" } + targetextension ".bc" + configuration { "nacl" } targetextension ".nexe" diff --git a/premake/example-04-mesh.lua b/premake/example-04-mesh.lua index ba69c701..abf856ca 100644 --- a/premake/example-04-mesh.lua +++ b/premake/example-04-mesh.lua @@ -27,6 +27,9 @@ project "example-04-mesh" "openctm", } + configuration { "emscripten" } + targetextension ".bc" + configuration { "nacl" } targetextension ".nexe" diff --git a/premake/example-05-instancing.lua b/premake/example-05-instancing.lua index 0b472476..3a354473 100644 --- a/premake/example-05-instancing.lua +++ b/premake/example-05-instancing.lua @@ -27,6 +27,9 @@ project "example-05-instancing" "openctm", } + configuration { "emscripten" } + targetextension ".bc" + configuration { "nacl" } targetextension ".nexe" diff --git a/premake/premake4.lua b/premake/premake4.lua index 4a4486ec..93148ac1 100644 --- a/premake/premake4.lua +++ b/premake/premake4.lua @@ -22,6 +22,7 @@ newoption { value = "GCC", description = "Choose GCC flavor", allowed = { + { "emscripten", "Emscripten" }, { "linux", "Linux" }, { "mingw", "MinGW" }, { "nacl", "Google Native Client" }, @@ -57,6 +58,13 @@ if _ACTION == "gmake" then "ExtraWarnings", } + if "emscripten" == _OPTIONS["gcc"] then + premake.gcc.cc = "emcc" + premake.gcc.cxx = "em++" + premake.gcc.ar = "emar" + location (BGFX_BUILD_DIR .. "projects/" .. _ACTION .. "-emscripten") + end + if "linux" == _OPTIONS["gcc"] then location (BGFX_BUILD_DIR .. "projects/" .. _ACTION .. "-linux") end @@ -191,6 +199,11 @@ configuration { "linux", "x64" } "-m64", } +configuration { "emscripten" } + targetdir (BGFX_BUILD_DIR .. "emscripten" .. "/bin") + objdir (BGFX_BUILD_DIR .. "emscripten" .. "/obj") + libdirs { BGFX_THIRD_PARTY_DIR .. "lib/emscripten" } + configuration { "nacl" } defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600" } includedirs { BX_DIR .. "include/compat/nacl" } diff --git a/src/config.h b/src/config.h index d6f52cd6..8701aac2 100644 --- a/src/config.h +++ b/src/config.h @@ -26,7 +26,10 @@ # endif // BGFX_CONFIG_RENDERER_OPENGL # ifndef BGFX_CONFIG_RENDERER_OPENGLES2 -# define BGFX_CONFIG_RENDERER_OPENGLES2 (BX_PLATFORM_NACL|BX_PLATFORM_ANDROID|BX_PLATFORM_IOS) +# define BGFX_CONFIG_RENDERER_OPENGLES2 (BX_PLATFORM_EMSCRIPTEN \ + |BX_PLATFORM_NACL \ + |BX_PLATFORM_ANDROID \ + |BX_PLATFORM_IOS) # endif // BGFX_CONFIG_RENDERER_OPENGLES2 # ifndef BGFX_CONFIG_RENDERER_OPENGLES3 diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 67786655..b200eb25 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -340,8 +340,10 @@ namespace bgfx if (NULL == m_context) { EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY; + EGLNativeWindowType nwt = (EGLNativeWindowType)NULL; # if BX_PLATFORM_WINDOWS ndt = GetDC(g_bgfxHwnd); + nwt = g_bgfxHwnd; # endif // BX_PLATFORM_ m_display = eglGetDisplay(ndt); BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::OPENGL_UnableToCreateContext, "Failed to create display 0x%08x", m_display); @@ -380,7 +382,7 @@ namespace bgfx success = eglChooseConfig(m_display, attrs, &config, 1, &numConfig); BGFX_FATAL(success, Fatal::OPENGL_UnableToCreateContext, "eglChooseConfig"); - m_surface = eglCreateWindowSurface(m_display, config, (EGLNativeWindowType)g_bgfxHwnd, NULL); + m_surface = eglCreateWindowSurface(m_display, config, nwt, NULL); BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::OPENGL_UnableToCreateContext, "Failed to create surface."); m_context = eglCreateContext(m_display, config, EGL_NO_CONTEXT, contextAttrs); diff --git a/src/renderer_gl.h b/src/renderer_gl.h index 5c39f4be..a166f34f 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -89,7 +89,7 @@ # include # endif // BGFX_CONFIG_RENDERER_ -# if BX_PLATFORM_WINDOWS +# if BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINDOWS # include # undef BGFX_USE_EGL # define BGFX_USE_EGL 1