@Override
public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) {
if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) {
throw new GdxRuntimeException(
"Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...).");
}
if (!(pixels instanceof ByteBuffer)) {
throw new GdxRuntimeException("Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...).");
}
int size = 4 * width * height;
Uint8Array buffer = Uint8Array.create(size);
gl.readPixels(x, y, width, height, format, type, buffer);
ByteBuffer pixelsByte = (ByteBuffer)pixels;
for (int i = 0; i < size; i++) {
pixelsByte.put((byte)buffer.get(i));
}
}