WebGL Troubleshooting

Alessandro Pignotti edited this page Dec 14, 2015 · 2 revisions

Passing data to WebGL uniform* APIs

uniform* APIs and, more in general, WebGL APIs which expects buffer requires typed arrays of a suitable type.

If you have data stored in a C/C++ array or std::vector or any other continguos memory storage, you can use the cheerp::MakeTypedArray to convert the data into a JS typed array object. Please note that the conversion happens without copying, so it's very efficient.

Please note that arrays of arrays (multidimensional arrays) are not necessarily contiguos in memory when using Cheerp, so you can't do this

float matrix[4][4];
webgl->uniform4fv(location, cheerp::MakeTypedArray(&matrix[0][0]));

On the other hand, the following code will work

float matrix[16];
webgl->uniform4fv(location, cheerp::MakeTypedArray(matrix));
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.