throw new GdxRuntimeException("Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...).");
}
// create new ArrayBufferView (4 bytes per pixel)
int size = 4 * width * height;
Uint8Array buffer = Uint8ArrayNative.create(size);
// read bytes to ArrayBufferView
gl.readPixels(x, y, width, height, format, type, buffer);
// copy ArrayBufferView to our pixels array
ByteBuffer pixelsByte = (ByteBuffer)pixels;
for (int i = 0; i < size; i++) {
pixelsByte.put((byte)(buffer.get(i) & 0x000000ff));
}
}