use of com.google.gwt.typedarrays.shared.ArrayBufferView in project libgdx by libgdx.
the class GwtGL20 method glTexImage2D.
@Override
public void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels) {
if (pixels == null) {
gl.texImage2D(target, level, internalformat, width, height, border, format, type, null);
} else {
if (pixels.limit() > 1) {
HasArrayBufferView arrayHolder = (HasArrayBufferView) pixels;
ArrayBufferView webGLArray = arrayHolder.getTypedArray();
ArrayBufferView buffer;
if (pixels instanceof FloatBuffer) {
buffer = webGLArray;
} else {
int remainingBytes = pixels.remaining() * 4;
int byteOffset = webGLArray.byteOffset() + pixels.position() * 4;
buffer = Uint8ArrayNative.create(webGLArray.buffer(), byteOffset, remainingBytes);
}
gl.texImage2D(target, level, internalformat, width, height, border, format, type, buffer);
} else {
Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer) pixels).get(0));
// Prefer to use the HTMLImageElement when possible, since reading from the CanvasElement can be lossy.
if (pixmap.canUseImageElement()) {
gl.texImage2D(target, level, internalformat, format, type, pixmap.getImageElement());
} else {
gl.texImage2D(target, level, internalformat, format, type, pixmap.getCanvasElement());
}
}
}
}
use of com.google.gwt.typedarrays.shared.ArrayBufferView in project libgdx by libgdx.
the class GwtGL20 method glTexSubImage2D.
@Override
public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels) {
if (pixels.limit() > 1) {
HasArrayBufferView arrayHolder = (HasArrayBufferView) pixels;
ArrayBufferView webGLArray = arrayHolder.getTypedArray();
ArrayBufferView buffer;
if (pixels instanceof FloatBuffer) {
buffer = webGLArray;
} else {
int remainingBytes = pixels.remaining() * 4;
int byteOffset = webGLArray.byteOffset() + pixels.position() * 4;
buffer = Uint8ArrayNative.create(webGLArray.buffer(), byteOffset, remainingBytes);
}
gl.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, buffer);
} else {
Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer) pixels).get(0));
gl.texSubImage2D(target, level, xoffset, yoffset, format, type, pixmap.getCanvasElement());
}
}
use of com.google.gwt.typedarrays.shared.ArrayBufferView in project playn by threerings.
the class HtmlGL20 method getTypedArray.
/**
* Returns the typed array of the given native buffer.
* Set byteSize to -1 to use remaining()
*/
protected ArrayBufferView getTypedArray(Buffer buffer, int type, int byteSize) {
if (!(buffer instanceof HasArrayBufferView)) {
throw new RuntimeException("Native buffer required " + buffer);
}
HasArrayBufferView arrayHolder = (HasArrayBufferView) buffer;
int bufferElementSize = arrayHolder.getElementSize();
ArrayBufferView webGLArray = arrayHolder.getTypedArray();
if (byteSize == -1) {
byteSize = buffer.remaining() * bufferElementSize;
}
if (byteSize == buffer.capacity() * bufferElementSize && type == arrayHolder.getElementType()) {
return webGLArray;
}
int byteOffset = webGLArray.byteOffset() + buffer.position() * bufferElementSize;
switch(type) {
case FLOAT:
return TypedArrays.createFloat32Array(webGLArray.buffer(), byteOffset, byteSize / 4);
case UNSIGNED_BYTE:
return TypedArrays.createUint8Array(webGLArray.buffer(), byteOffset, byteSize);
case UNSIGNED_SHORT:
return TypedArrays.createUint16Array(webGLArray.buffer(), byteOffset, byteSize / 2);
case INT:
return TypedArrays.createInt32Array(webGLArray.buffer(), byteOffset, byteSize / 4);
case SHORT:
return TypedArrays.createInt16Array(webGLArray.buffer(), byteOffset, byteSize / 2);
case BYTE:
return TypedArrays.createInt8Array(webGLArray.buffer(), byteOffset, byteSize);
default:
throw new IllegalArgumentException("Type: " + type);
}
}
use of com.google.gwt.typedarrays.shared.ArrayBufferView in project playn by threerings.
the class HtmlGL20 method glTexImage2D.
/*
public void glTexImage2d(int target, int level, int internalformat,
int format, int type, ImageElement image) {
// log("setting texImage2d; image: " + image.getSrc());
gl.texImage2D(target, level, internalformat, format, type, image);
checkError("texImage2D");
}
public void glTexImage2d(int target, int level, int internalformat,
int format, int type, CanvasElement image) {
// log("setting texImage2d; image: " + image.getSrc());
gl.texImage2D(target, level, internalformat, format, type, image);
checkError("texImage2D");
}
*/
@Override
public void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels) {
ArrayBufferView buffer = (pixels == null) ? null : getTypedArray(pixels, type, -1);
gl.texImage2D(target, level, internalformat, width, height, border, format, type, buffer);
}
Aggregations