• Stars
    star
    231
  • Rank 173,434 (Top 4 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WebGLWorker

WebGLWorker lets you write WebGL code in a web worker, as if WebGL were implemented there. It transparently proxies the commands to the main thread, where they are executed.

WebGLWorker is asynchronous. It does not support synchronous things like getError (assumed to always succeed) or readPixels (will error). However, the asynchronous subset of WebGL is still pretty comprehensive. In this repos are 2 examples: BananaBread (a first person shooter, a port of Cube 2/Sauerbraten using Emscripten) and a demo of PlayCanvas (an open source JavaScript game engine using WebGL). Both examples are unmodified - their usage of WebGL works fine asynchronously.

Work is underway in web browsers to implement WebGL in workers. When that happens, this project could be used as a polyfill, with the caveat of being asynchronous.

Usage

See the PlayCanvas demo for a simple example. Basically you include a few JS files in your HTML, and make sure your JS (which should be in a file called worker.js) loads the worker-corresponding files (proxyClient/proxyWorker, etc.). That's basically it.

For Emscripten-compiled projects, like BananaBread, you just need to build with --proxy-to-worker.

Limitations

Enough of WebGL has been implemented here for those 2 demos, but much of the spec still isn't. Aside from synchronous features, nothing prevents the rest from being added.

WebGL objects can be destroyed in 2 ways: explicitly, using deleteX (deleteBuffer, deleteShader, etc.), or implicitly, when the corresponding JavaScript object is garbage collected. In WebGLWorker, the corresponding JavaScript object is created on the main thread, and we have a map of them by a numeric ID, so we can identify them when a message arrives from the worker. That means that we will hold on to them unti we are explicitly told otherwise. In other words, you must use the deleteX methods to explicitly free WebGL objects, or else they will leak. (Note that this is not a problem for Emscripten-compiled projects, as in the C or C++ source code there would have to be calls to glDeleteX, which Emscripten maps to deleteX).

More Repositories

1

ammo.js

Direct port of the Bullet physics engine to JavaScript using Emscripten
C++
4,147
star
2

BananaBread

BananaBread is a C++ 3D game engine that runs on the web using JavaScript+WebGL+HTML
C++
1,375
star
3

box2d.js

Port of Box2D to JavaScript using Emscripten
C
1,316
star
4

speak.js

Text-to-Speech in JavaScript using eSpeak
C++
1,279
star
5

llvm.js

LLVM compiled to JavaScript using Emscripten
JavaScript
455
star
6

xml.js

Port of libxml to JavaScript using Emscripten
JavaScript
174
star
7

zee.js

zlib compiled to JavaScript using Emscripten
C
97
star
8

j2k.js

Port of OpenJPEG, an open-source JPEG2000 codec, to JavaScript using Emscripten
C
82
star
9

intensityengine

[Not active!] An open source platform for 3D games and virtual worlds
C++
58
star
10

lzma.js

An LZMA implementation in JavaScript, compiled from lzip
C++
56
star
11

meandmyshadow.web

C
51
star
12

Massive

The asm.js benchmark
JavaScript
47
star
13

gmp.js

A port of the GNU Multiple-Precision Library (GMP), a library for arbitrary precision arithmetic, to JavaScript using Emscripten
C
44
star
14

mloc_emscripten_talk

JavaScript
41
star
15

clangor

clang ported to js
C++
41
star
16

worker-ui

Discussions and experiments with splitting UI rendering off the main thread on the web, using workers
34
star
17

boon

Freedoom + PrBoom: Open source Doom in HTML5
C++
33
star
18

Relooper

this repo is deprecated, see the binaryen repo
C++
21
star
19

build-suite

Pre-built WASM builds
JavaScript
19
star
20

bullet

C++
18
star
21

cashew

asm.js parser in C++
C++
18
star
22

syntensity

Experimental port of Sauerbraten/Syntensity to the web, using Emscripten
C++
17
star
23

talks

JavaScript
16
star
24

llvm-js

C++
16
star
25

clang-js

C++
14
star
26

cxx_demangle

C++ name demangling
JavaScript
14
star
27

misc-js-benchmarks

Miscellaneous JavaScript Benchmarks, of Dubious Value
JavaScript
13
star
28

emscripten-site

Emscripten website
HTML
11
star
29

demo-bananabread

BananaBread demo
JavaScript
10
star
30

musl-emscripten

C
10
star
31

binaryen-webpack-plugin

Binaryen plugin for webpack: shrinks wasm files
Python
8
star
32

webgl-2d-screen

JavaScript
7
star
33

embenchen

Emscripten benchmark suite
JavaScript
6
star
34

xz-lzma.js

C
3
star
35

simulations

Python
2
star
36

almond

C
2
star
37

tps_report_cloud_archiver

JavaScript
2
star
38

blog

SCSS
2
star
39

minir

C++
1
star
40

embooken

1
star
41

llvm-js-2

Trying to coax the Cpu0 backend to output JS
C++
1
star