curiosity-ai / h5

🚀 The next generation C# to JavaScript compiler
https://github.com/curiosity-ai/h5
Apache License 2.0
211 stars 30 forks source link

Allow typed arrays as parameter for texImage2D #39

Closed thomz12 closed 1 year ago

thomz12 commented 3 years ago

For some reason I can't use a typed array for the texImage2D and texSubImage2D functions.

Uint8Array platformData = new Uint8Array(data);

_gl.texImage2D(_gl.TEXTURE_2D, 0, _gl.RGBA, width, height, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, platformData);

Casting it to an ArrayBufferView works with H5:

Uint8Array platformData = new Uint8Array(data);
ArrayBufferView view = (object)platformData as ArrayBufferView;

_gl.texImage2D(_gl.TEXTURE_2D, 0, _gl.RGBA, width, height, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, view);

It used to work in Bridge.NET, is this a bug?

theolivenbaum commented 3 years ago

Strange, I didn't remove anything with the fork, but should be an easy fix. Meanwhile you can also use the .As<ArrayBufferView>() method to cast it to the other type - this is a nop when converted to javascript and in C# it will not check if the type can be casted - it exists for these cases to make it more legible.