Closed hansagames closed 3 years ago
I've just created a PR for a new method copyIntoArray(array-like, index)
, so in your case you might do
gl.uniformMatrix4fv(cameraLoc, false, cameraMatrix.copyIntoArray(new Float32Array(), 0));
// or have a single Float32Array for all uploads
var matrixUploadArray = new Float32Array(16);
// per-frame
cameraMatrix.copyIntoArray(matrixUploadArray, 0);
gl.uniformMatrix4fv(cameraLoc, false, matrixUploadArray);
// or if you're setting some vertex data
var vertexBuffer = new Float32Array(vertexCount * 3);
for (i in 0...vertexCount) {
var position = vec3(0.0);
// some clever vector math to generate position
// ...
position.copyIntoArray(vertexBuffer, i * 3);
}
The generated code is a bit chunky because it sets the fields one by one – I benchmarked it and this seems to be the fastest method still
@haxiomic thanks looks good
Awesome, merged :)
Hi, any plans to add converter to Float32Array in order to pass Mat4 data to gpu or better add extra utils for that ?
Thank you