Skip to content

Commit

Permalink
Update v0.1.3
Browse files Browse the repository at this point in the history
 - Fixed bug in vec4.create where only 2 components got initialized
  • Loading branch information
maierfelix committed Apr 9, 2018
1 parent a16a817 commit 1ebe120
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<br/>

### Description
This is a handcrafted, experimental near 1:1 port of [gl-matrix](https://github.com/toji/gl-matrix) [v2.4.0](https://github.com/toji/gl-matrix/blob/master/package.json#L4) to WebAssembly.
This is an experimental near 1:1 port of [gl-matrix](https://github.com/toji/gl-matrix) [v2.4.0](https://github.com/toji/gl-matrix/blob/master/package.json#L4) to WebAssembly.

### Performance
In most cases *glmw* runs more than twice as fast as *gl-matrix*.
In many cases *glmw* runs more than twice as fast as *gl-matrix*.

Some methods like ``*.str`` and ``*.equals`` are bridged and bring in some call overhead.
Some methods like ``*.str`` and ``*.equals`` are bridged and bring in some extra overhead.

Creating views with ``*.view`` is cheap, because they return a typed ``subarray`` of the WebAssembly module's memory buffer.

Expand All @@ -22,6 +22,7 @@ Creating views with ``*.view`` is cheap, because they return a typed ``subarray`
- You need to manually free data, since there is no garbage collection yet (**be careful! :p**).
- Methods like ``mat4.create`` and ``mat4.multiply`` return a numeric address. To get an view on your data you need to use e.g. ``mat4.view(address)``. This returns a ``Float32Array`` which is a direct view onto the allocated data in WebAssembly's memory. You can manually read/write from this view.
- WebAssembly's memory cannot be directly shared with JavaScript's memory. This means that you cannot pass an JavaScript array into methods like ``vec3.sqrLength``. You first have to convert it into the given module type (e.g. ``vec3.fromValues``) which then gives you the memory address of the allocated data.
- There is some overhead when calling from JavaScript->WebAssembly, but it seems acceptable. Slight performance drops are noticeable when calling a function more than ~15.000 times.

### Bridged methods
- ``*.str`` so a *JavaScript String* is returned.
Expand All @@ -48,7 +49,7 @@ npm install glmw
or the browser distribution from [here](//rawgit.com/maierfelix/glmw/master/dist/glmw-browser.js).

### Instantiation
Before being able to use the library, you have to first call it's ``init`` method which then asynchronously compiles the WebAssembly module.
Before being able to use the library, you first have to call it's ``init`` method which then asynchronously compiles the WebAssembly module.

If you call a ``glmw`` function before it got instantiated somewhere, then a ``TypeError`` is thrown, because the function is simply not compiled yet.

Expand Down Expand Up @@ -138,4 +139,4 @@ You can free data by calling ``*.free``:
````js
a = mat4.create(); // allocate data for a
mat4.free(a); // a's data is now freed
````
````
4 changes: 2 additions & 2 deletions dist/glmw-browser.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/glmw-node.es.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/glmw-node.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "glmw",
"version": "0.1.2",
"version": "0.1.3",
"description": "WebAssembly powered Matrix and Vector library",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -30,8 +30,7 @@
"scripts": {
"dist": "npm run browser && npm run build",
"build": "rollup -c rollup/rollup.config.cjs.js && rollup -c rollup/rollup.config.es.js",
"browser": "node rollup/rollup.bundle.js",
"rofl": "node rollup/rollup.bundle.js"
"browser": "node rollup/rollup.bundle.js"
},
"devDependencies": {
"rollup": "^0.47.2",
Expand Down
2 changes: 2 additions & 0 deletions src/gl-matrix/vec4.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export float *vec4(create)() {
float *out = malloc(VEC_SIZE_4 * sizeof(*out));
out[0] = 0;
out[1] = 0;
out[2] = 0;
out[3] = 0;
return out;
};

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function validateEnvironment() {
}
};

function init(resolve) {
function init() {
return new Promise(resolve => {
validateEnvironment();
load(module, imports).then(instance => {
Expand Down

0 comments on commit 1ebe120

Please sign in to comment.