C++ to Web = WebAssembly. Polling for feature request

C++ to Web = WebAssembly. Polling for feature request
0.0 0


I will try to explain in brief and simply.

What is WebAssembly?
WebAssembly is a new format for compilation to the web.

With WebAssembly you can simply compile c ++ code for web.
See “Compile and run a simple program” section:

What about browsers support?

WebAssembly has reached the Browser Preview milestone.
This mean that all main browsers already support it and WebAssembly already available in regular builds as separate includes options.

What WebAssembly already can - DEMO?
Don’t forget to turn on:
Chrome: “chrome://flags#enable-webassembly”
Firefox: “about:config javascript.options.wasm”

The project is developing rapidly - in one year was achieved status MVP and Browser Preview.
Supported by leading manufacturers of browsers under the auspices of the W3C

I ask cocos2d-x team - plz. add support of WebAssembly
I ask community to support this request - to show how important this for us - just add comment with your thoughts.

Just imagine - with WebAssembly game porting for web will be no harder than for current planforms.

Thx. to all.


I agree. It’s likely a v4.x feature, and if it’s not a rewrite, but just incremental changes replacing the core renderer over time then Wasm could be supported at any point in the future. BGFX is one possibility (and the new swift engine Fiber based on cocos2d is an example of this).

The core team currently seems to have a path to move developers to write games in Javascript instead where it can then use either the WebGL engine or the native runtime wrapper.

https://blogs.unity3d.com/2015/06/18/webgl-webassembly-and-feature-roadmap/ .
https://blogs.unity3d.com/2016/09/20/understanding-memory-in-unity-webgl/ .


I didn’t really have time to read about WebAssembly, so my question might seem stupid, but how does it differ from emscripten?


@Boby Emscripten is a compiler (LLVM-based). WebAssembly (Wasm) can be thought of as a standardized version of asm.js. So the process would likely be fixing issues with cocos2d-x so that it (engine + 3rd party libs) can be built with Emscripten into asm.js now and in the future Wasm.


@stevetranby Thx. for links - really interesting articles.

@Boby - In a simplified form the difference is:
Emscripten generates JavaScript that use Asm.js
WebAssembly generates bytecode that “directly” runs in browsers.


Afaik, currently MS Edge and Safari still doesn’t support it. Only the latest Chrome (canary) and Firefox (nightly build)


It seems that there is Edge support:


Im on record as hoping for WA support


Potential benefits of WA:

  • one codebase that supports mobile, desktop, and web
  • the speed that comes from compiled code
  • access to c/c++ libraries

I think that if/when cocos2d-x starts adding more 3d support (and shouldnt we change the name to just cocos-X then?) that WA will start making more and more sense.



Yep - the message on DEMO page is “little” strange:


Uh-oh! WebAssembly isn’t enabled in this browser. To get an early preview of this experimental technology, at your own risk:

  • on Chrome Canary, open chrome://flags/#enable-webassembly and enable the switch.
  • on Firefox Nightly, open about:config and set javascript.options.wasm to true.

See a preview of Microsoft Edge support and follow Safari support on WebKit’s feature status page.

But I think is just out of date.

I checked once again:
Firefox 50.0.2 (For macOS) - stable, not nightly build.
Worked - just need turn on “about:config javascript.options.wasm” flag.

Chrome 55.0.2883.75 (64-bit) (For macOS)
Worked - just need turn on “chrome://flags/#enable-webassembly” flag.

Yep - this is not all browsers - but the main is that all are working in this direction.


Any update?


Would like to upvote this feature request. Now that Chrome and Firefox have already gotten it live.


This would have to come from the community. There’s very little chance Chukong will work on this feature.
It’s probably smarter to replace the renderer with SDL or BGFX instead of trying to get the engine to compile.
If someone is already working on this with the latest 3.15 code revision that’d be great. It’s possible to get it compiling, but it may or may not take quite a bit of tedious work??

I keep looking into it, and simple OpenGL examples are easily ported to emscripten, but the cocos2d code base has a lot of extra libraries/frameworks that must support it.

Would love to hear of any progress, but I am not holding my breath. Prob smarter to move to Urho3D or other engine if it’s a feature you need. Or just port to cocos-js/creator :smiley:


Last week we tried WASM of cocos2d-x of a commit of this January. It works properly.

We are thinking of adding it back to main branch.


Yes @ShunLin that is great news :+1:

In a WASM capable browser does it perform better than the JS version?


Yep, i used PerformanceSpriteTest, WASM is about 50% quicker then cocos2d-html5, and takes less memory. But there is a problem that, all codes in a wasm file, and all resources in a data file which makes loading much slower than cocos2d-html5.


So not a complete win for WASM. There are always tradeoffs! Thanks @zhangxm


Now that WebAssembly support has been added to Safari, it appears that all the major browsers now support it.


I also want to upvote this feature request. My C++ App is available on all platforms except the web and too large already to be easily rewritten in Javascript. WebAssembly would be a major benefit for my App.


+1, this would be very helpful indeed