Skip to content

Commit c1bddc6

Browse files
authored
emscripten: fixes to get bgfx working (#13255)
* Emscripten: Fixes to get BGFX working * Move emscripten specific setup into an #elif statement * Fix indentation * emscripten: remove no longer link option DEMANGLE_SUPPORT
1 parent 11cd461 commit c1bddc6

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

docs/source/initialsetup/compilingmame.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ above in All Platforms.
353353
Emscripten Javascript and HTML
354354
------------------------------
355355

356-
First, download and install Emscripten 2.0.25 or later by following the
356+
First, download and install Emscripten 3.1.35 or later by following the
357357
instructions at the `official site <https://emscripten.org/docs/getting_started/downloads.html>`_.
358358

359359
Once Emscripten has been installed, it should be possible to compile MAME

scripts/genie.lua

+5-6
Original file line numberDiff line numberDiff line change
@@ -1170,26 +1170,24 @@ configuration { "asmjs" }
11701170
"-O" .. _OPTIONS["OPTIMIZE"],
11711171
"-s USE_SDL=2",
11721172
"-s USE_SDL_TTF=2",
1173-
"--memory-init-file 0",
11741173
"-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=\"['\\$$ERRNO_CODES']\"",
11751174
"-s EXPORTED_FUNCTIONS=\"['_main', '_malloc', '__ZN15running_machine30emscripten_get_running_machineEv', '__ZN15running_machine17emscripten_get_uiEv', '__ZN15running_machine20emscripten_get_soundEv', '__ZN15mame_ui_manager12set_show_fpsEb', '__ZNK15mame_ui_manager8show_fpsEv', '__ZN13sound_manager4muteEbh', '_SDL_PauseAudio', '_SDL_SendKeyboardKey', '__ZN15running_machine15emscripten_saveEPKc', '__ZN15running_machine15emscripten_loadEPKc', '__ZN15running_machine21emscripten_hard_resetEv', '__ZN15running_machine21emscripten_soft_resetEv', '__ZN15running_machine15emscripten_exitEv']\"",
11761175
"-s EXPORTED_RUNTIME_METHODS=\"['cwrap']\"",
11771176
"-s ERROR_ON_UNDEFINED_SYMBOLS=0",
1178-
"-s USE_WEBGL2=1",
1179-
"-s LEGACY_GL_EMULATION=1",
1180-
"-s GL_UNSAFE_OPTS=0",
1177+
"-s STACK_SIZE=5MB",
1178+
"-s MAX_WEBGL_VERSION=2",
11811179
"--pre-js " .. _MAKE.esc(MAME_DIR) .. "src/osd/modules/sound/js_sound.js",
11821180
"--post-js " .. _MAKE.esc(MAME_DIR) .. "scripts/resources/emscripten/emscripten_post.js",
11831181
"--embed-file " .. _MAKE.esc(MAME_DIR) .. "bgfx/chains@bgfx/chains",
11841182
"--embed-file " .. _MAKE.esc(MAME_DIR) .. "bgfx/effects@bgfx/effects",
11851183
"--embed-file " .. _MAKE.esc(MAME_DIR) .. "bgfx/shaders/essl@bgfx/shaders/essl",
11861184
"--embed-file " .. _MAKE.esc(MAME_DIR) .. "artwork/bgfx@artwork/bgfx",
1185+
"--embed-file " .. _MAKE.esc(MAME_DIR) .. "artwork/lut-default.png@artwork/lut-default.png",
11871186
"--embed-file " .. _MAKE.esc(MAME_DIR) .. "artwork/slot-mask.png@artwork/slot-mask.png",
11881187
}
11891188
if _OPTIONS["SYMBOLS"]~=nil and _OPTIONS["SYMBOLS"]~="0" then
11901189
linkoptions {
11911190
"-g" .. _OPTIONS["SYMLEVEL"],
1192-
"-s DEMANGLE_SUPPORT=1",
11931191
}
11941192
end
11951193
if _OPTIONS["WEBASSEMBLY"] then
@@ -1205,11 +1203,12 @@ configuration { "asmjs" }
12051203
-- define a fixed memory size because allowing memory growth disables asm.js optimizations
12061204
linkoptions {
12071205
"-s ALLOW_MEMORY_GROWTH=0",
1208-
"-s TOTAL_MEMORY=268435456",
1206+
"-s INITIAL_MEMORY=256MB",
12091207
}
12101208
else
12111209
linkoptions {
12121210
"-s ALLOW_MEMORY_GROWTH=1",
1211+
"-s INITIAL_MEMORY=24MB"
12131212
}
12141213
end
12151214
archivesplit_size "20"

src/osd/modules/font/font_sdl.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
#include "unicode.h"
1616
#include "osdcore.h"
1717

18-
#ifdef SDLMAME_EMSCRIPTEN
19-
#include <SDL_ttf.h>
20-
#else
2118
#include <SDL2/SDL_ttf.h>
22-
#endif
19+
2320
#if !defined(SDLMAME_HAIKU) && !defined(SDLMAME_EMSCRIPTEN)
2421
#include <fontconfig/fontconfig.h>
2522
#endif

src/osd/modules/render/bgfx/shadermanager.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ std::string shader_manager::make_path_string(const osd_options &options, const s
8383
{
8484
std::string shader_path(options.bgfx_path());
8585
shader_path += PATH_SEPARATOR "shaders" PATH_SEPARATOR;
86+
87+
#if defined(SDLMAME_EMSCRIPTEN)
88+
// Hard-code renderer type to OpenGL ES for emscripten builds since the
89+
// bgfx::getRendererType() is called here before BGFX has been
90+
// initialized and therefore gives the wrong renderer type (Noop).
91+
shader_path += "essl" PATH_SEPARATOR;
92+
return shader_path;
93+
#endif
94+
8695
switch (bgfx::getRendererType())
8796
{
8897
case bgfx::RendererType::Noop:

src/osd/modules/render/drawbgfx.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ bool video_bgfx::set_platform_data(bgfx::PlatformData &platform_data, osd_window
394394
#elif defined(OSD_MAC)
395395
platform_data.ndt = nullptr;
396396
platform_data.nwh = GetOSWindow(dynamic_cast<mac_window_info const &>(window).platform_window());
397+
#elif defined(SDLMAME_EMSCRIPTEN)
398+
platform_data.ndt = nullptr;
399+
platform_data.nwh = (void *)"#canvas"; // HTML5 target selector
397400
#else // defined(OSD_*)
398401
SDL_SysWMinfo wmi;
399402
SDL_VERSION(&wmi.version);

0 commit comments

Comments
 (0)