curiosity-ai / h5

🚀 The next generation C# to JavaScript compiler

Home Page:https://h5.rocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow typed arrays as parameter for texImage2D

thomz12 opened this issue · comments

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?

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.