-
Notifications
You must be signed in to change notification settings - Fork 3
OpenGL support
Emscripten supports the WebGL-friendly subset of OpenGL, basically what maps directly to WebGL. That support is stable. There is also some support for non-WebGL elements of OpenGL, but that is experimental.
- Online demos:
- Complete OpenGL game engine (shows emulation of non-WebGL elements of OpenGL)
- OpenGL ES 2.0 gears
- Run
python tests/runner.py browser.test_glgears
for an example. For other examples, run justpython tests/runner.py browser
. - Code is in
src/library_gl.js
.
The WebGL-friendly subset of OpenGL is basically what maps directly to WebGL, call to call. That includes almost all of OpenGL ES 2.0, except for client-side arrays. The reason they are missing from WebGL is because they are less efficient than properly using GPU-side data. Similarly, if we emulated client-side arrays here, we would end up with very bad performance, since we would need to upload the data on each call to glDrawArrays etc. (Even if there are two calls one after the other, we can't know the data did not change!) So in practical terms full OpenGL ES 2.0 emulation would be convenient, but lead to bad performance so in practice you would need to properly rewrite your code to a WebGL-friendly subset anyhow.
See the files in tests/glbook and their git history for some simple examples ported to that subset.
A very useful tool is the webgl.verbose
option in Firefox. If you compile code that uses clientside arrays, that option will give you a warning when there isn't a bound buffer and so forth. It will also warn you of other differences between OpenGL and WebGL.
We are working to support some desktop GL features. Currently there is a small amount of support for GL_QUADS for example. However, this is experimental and comes with a performance cost. It is highly recommended not to rely on this; instead, target the WebGL-friendly subset.
- TODO: Investigate the new Regal library that translates OpenGL to OpenGL ES 2.0, https://github.com/p3/regal
Tested and known to work well in Firefox and Chrome. Help with testing on Safari and Opera would be welcome, and for Internet Explorer, help testing with IEWebGL would be welcome too.