mosra / magnum-bootstrap

Bootstrap projects for the Magnum C++11 graphics engine

Home Page:https://magnum.graphics/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help understanding bootstrap emscripten js error

UNDEFINED-BEHAVIOR opened this issue · comments

Hello I've managed to build out emscripten bootstrap using cmake->ninja on windows but however, it fails to load in the browser. Any idea what's causing this?

What I did aside form modifying "src" module

  • specified language level c++17 in top level cmakelist
  • uncomment #undef MAGNUM_TARGET_GLES2 in magnum configure.h
  • specified GL version 300 for shaders
  • add USE_SDL=2 -s USE_WEBGL2=1 -s FULL_ES3=1 to em++ 's LINK_FLAGS in build.ninja because it complains about missing SDL symbol

image

image

Basically Same result on both js and wasm

Wait wait wait, the build doesn't work like that.

uncomment #undef MAGNUM_TARGET_GLES2 in magnum configure.h

This will cause several problems down the line. You're supposed to toggle the TARGET_GLES2 option in CMake instead, which will then generate a different configure.h, among other things.

specified GL version 300 for shaders

Can you elaborate? Shaders for WebGL 2 should use GL::Version::ES300, yes, but for the builtin ones it's done automatically based on what configuration is set in CMake. I suspect it's a problem resulting from the above manual patching of configure.h.

add USE_SDL=2 -s USE_WEBGL2=1 -s FULL_ES3=1

No. The build doesn't use the "full SDL2" since it only inflates the resulting binary by quite a lot but doesn't add anything useful. Neither the "full ES3", Magnum has WebGL support natively and the ES3 stuff in Emscripten is just a pile of unneded workarounds. Finally, -s USE_WEBGL2=1 should be set for you by CMake if everything is going as expected.

My question is, how did you compile Magnum for Emscripten? Did you use the toolchain file as described in the docs? To me it seems that you didn't and the rest of the issues in the list seem to be a result of that.

For the in-browser error, what version of magnum do you have? There was a breaking change in the HTML markup recently in order to make it work with recent Emscripten versions and current bootstrap project thus doesn't work with the stable 2019.01 -- because Emscripten moves fast and breaks some things every now and then I'm strongly suggesting using latest master of Magnum.

You're supposed to toggle the TARGET_GLES2 option in CMake instead
oh
I do have some familiarity with c++ but still struggling with cmake system, sorry.
but for the builtin ones
I'm not using the build-in ones, I'm passing string shader source to GL::Shader directly.
It's a simple DIY vertex color shader.
full SDL2
Build size was quite large indeed.
That was the setting that works before I moved to Magnum so it was the first instinct..
how did you compile Magnum for Emscripten
I'v added magnum/corrade as submodule and adding "add_subdirectory" to toplevel cmake
I did tried to follow the instruction here to build corrade/magnum seperately and installed it to emscripten's /system folder.
https://doc.magnum.graphics/magnum/building.html#building-cross-emscripten
and here
https://blog.squareys.de/magnum-emscripten-on-windows/
But I did observe that corrade/magnum are being recompiled again anyway upon compiling the top level bootstrap cmakelist using this instruction
https://github.com/mosra/magnum-bootstrap#base-application-with-port-to-emscripten

This is the exact cmake command used(the last, top level one), adjusted to my environment. With emcmdprompt.bat activated

cmake .. ^
    -G "Ninja" ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DEMSCRIPTEN_PREFIX=%EMSCRIPTEN:\=/% ^
    -DCMAKE_PREFIX_PATH=c:/Magnum/bin ^
    -DCMAKE_INSTALL_PREFIX=../emout ^
    -DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/Emscripten-wasm.cmake" ^
    -DWITH_SDL2APPLICATION=ON

what version of magnum
magnum submodule: tag 2019.01
corrade submodule: also tag 2019.01

Ok, thanks for the extra info, now I understand your case better 👍

But I did observe that corrade/magnum are being recompiled again anyway

If you have them already installed, you don't need to add_subdirectory() (that will cause them to be built again, yes). Or, conversely, if you add_subdirectory() them, they don't need to be in the system location. You'll likely get problems and conflicts due to slightly different configuration being used for each, so remove of the instances. Pass -DTARGET_GLES2=OFF to CMake either when you are building/installing Magnum or to the top-level CMake invocation when you have Magnum add_subdirectory()'d.

tag 2019.01

is it possible for you to use master? if not, then the other option is to change the MyApplication.html to say <canvas id="module"> instead of <canvas id="canvas"> and that could fix the browser error. But I can't guarantee it due to how Emscripten changed lately, better would be to use latest master of magnum.

I'm trying to make it work on both desktop and web (capped at GL 3.0)
wasn't add_subdirectory() necessary for desktop build? (at least I could add emscripten target check in cmake, I think)

I'll set the project up again using your tip and see how it goes.

It's not, in all cases (desktop or the cross-compilation builds) it's just an alternative way of setting up the project:

  • either you install to some filesystem location (C:/magnum for the native build and C:/emscripten/system/somewhere for the emscripten build, for example)
  • or you add_subdirectory() them

Each of these has some pros/cons, depends only on you what you prefer.

Closing as resolved.