List of usage examples for com.google.gwt.typedarrays.client Uint8Array create
public static final native Uint8Array create(JsArrayInteger data) ;
From source file:com.googlecode.gwtgl.wrapper.UnsignedByteArray.java
License:Apache License
/** * Create a new Uint8Array object of the given length with a new underlying ArrayBuffer large enough to hold length elements of the specific type. Data in the buffer is initialized to 0. * //w w w . j ava2s.co m * @param length */ public UnsignedByteArray(int length) { super(Uint8Array.create(length)); }
From source file:com.googlecode.gwtgl.wrapper.UnsignedByteArray.java
License:Apache License
/** * Create a new Uint8Array object with a new underlying ArrayBuffer large enough to hold the given data, then copy the passed data into the buffer. * /* w ww .j av a2s . c o m*/ * @param array */ public UnsignedByteArray(Uint8Array array) { super(Uint8Array.create(array)); }
From source file:com.googlecode.gwtgl.wrapper.UnsignedByteArray.java
License:Apache License
/** * Create a new Uint8Array object with a new underlying ArrayBuffer large enough to hold the given data, then copy the passed data into the buffer. * /*w w w . j a v a2s . c o m*/ * @param array */ public UnsignedByteArray(int[] array) { super(Uint8Array.create(array)); }
From source file:com.googlecode.gwtgl.wrapper.UnsignedByteArray.java
License:Apache License
/** * Create a new Uint8Array object using the passed ArrayBuffer for its storage. * /*www . ja v a2 s . c om*/ * @param buffer */ public UnsignedByteArray(ArrayBuffer buffer) { super(Uint8Array.create(buffer)); }
From source file:forplay.html.HtmlGraphicsGL.java
License:Apache License
/** * Try basic GL operations to detect failure cases early. * // w w w . j a v a 2 s. co m * @return true if calls succeed, false otherwise. */ private boolean tryBasicGlCalls() { int err; try { // test that our Float32 arrays work (a technique found in other WebGL checks) Float32Array testFloat32Array = Float32Array.create(new float[] { 0.0f, 1.0f, 2.0f }); if (testFloat32Array.get(0) != 0.0f || testFloat32Array.get(1) != 1.0f || testFloat32Array.get(2) != 2.0f) { throw new RuntimeException("Typed Float32Array check failed"); } // test that our Int32 arrays work Int32Array testInt32Array = Int32Array.create(new int[] { 0, 1, 2 }); if (testInt32Array.get(0) != 0 || testInt32Array.get(1) != 1 || testInt32Array.get(2) != 2) { throw new RuntimeException("Typed Int32Array check failed"); } // test that our Uint16 arrays work Uint16Array testUint16Array = Uint16Array.create(new int[] { 0, 1, 2 }); if (testUint16Array.get(0) != 0 || testUint16Array.get(1) != 1 || testUint16Array.get(2) != 2) { throw new RuntimeException("Typed Uint16Array check failed"); } // test that our Uint8 arrays work Uint8Array testUint8Array = Uint8Array.create(new int[] { 0, 1, 2 }); if (testUint8Array.get(0) != 0 || testUint8Array.get(1) != 1 || testUint8Array.get(2) != 2) { throw new RuntimeException("Typed Uint8Array check failed"); } // Perform GL read back test where we paint rgba(1, 1, 1, 1) and then read back that data. // (should be 100% opaque white). bindFramebuffer(); gl.clearColor(1, 1, 1, 1); err = gl.getError(); if (err != NO_ERROR) { throw new RuntimeException("Read back GL test failed to clear color (error " + err + ")"); } updateLayers(); Uint8Array pixelData = Uint8Array.create(4); gl.readPixels(0, 0, 1, 1, RGBA, UNSIGNED_BYTE, pixelData); if (pixelData.get(0) != 255 || pixelData.get(1) != 255 || pixelData.get(2) != 255) { throw new RuntimeException("Read back GL test failed to read back correct color"); } } catch (RuntimeException e) { ForPlay.log().info("Basic GL check failed: " + e.getMessage()); return false; } catch (Throwable t) { ForPlay.log().info("Basic GL check failed with an unknown error: " + t.getMessage()); return false; } return true; }
From source file:playn.html.HtmlGLContext.java
License:Apache License
private void tryBasicGLCalls() throws RuntimeException { // test that our Float32 arrays work (a technique found in other WebGL checks) Float32Array testFloat32Array = Float32Array.create(new float[] { 0.0f, 1.0f, 2.0f }); if (testFloat32Array.get(0) != 0.0f || testFloat32Array.get(1) != 1.0f || testFloat32Array.get(2) != 2.0f) { throw new RuntimeException("Typed Float32Array check failed"); }// w ww . jav a 2s. c om // test that our Int32 arrays work Int32Array testInt32Array = Int32Array.create(new int[] { 0, 1, 2 }); if (testInt32Array.get(0) != 0 || testInt32Array.get(1) != 1 || testInt32Array.get(2) != 2) { throw new RuntimeException("Typed Int32Array check failed"); } // test that our Uint16 arrays work Uint16Array testUint16Array = Uint16Array.create(new int[] { 0, 1, 2 }); if (testUint16Array.get(0) != 0 || testUint16Array.get(1) != 1 || testUint16Array.get(2) != 2) { throw new RuntimeException("Typed Uint16Array check failed"); } // test that our Uint8 arrays work Uint8Array testUint8Array = Uint8Array.create(new int[] { 0, 1, 2 }); if (testUint8Array.get(0) != 0 || testUint8Array.get(1) != 1 || testUint8Array.get(2) != 2) { throw new RuntimeException("Typed Uint8Array check failed"); } // Perform GL read back test where we paint rgba(1, 1, 1, 1) and then read back that data. // (should be 100% opaque white). bindFramebuffer(); clear(1, 1, 1, 1); int err = glc.getError(); if (err != NO_ERROR) { throw new RuntimeException("Read back GL test failed to clear color (error " + err + ")"); } Uint8Array pixelData = Uint8Array.create(4); glc.readPixels(0, 0, 1, 1, RGBA, UNSIGNED_BYTE, pixelData); if (pixelData.get(0) != 255 || pixelData.get(1) != 255 || pixelData.get(2) != 255) { throw new RuntimeException("Read back GL test failed to read back correct color"); } }
From source file:playn.html.HtmlWebSocket.java
License:Apache License
@Override public void send(ByteBuffer data) { int len = data.limit(); // TODO(haustein) Sending the view directly does not work for some reason. // May be a chrome issue...? // Object trick = data; // ArrayBufferView ta = ((HasArrayBufferView) trick).getTypedArray(); // Int8Array view = Int8Array.create(ta.getBuffer(), ta.getByteOffset(), len) // ws.send(view); ArrayBuffer buf = ArrayBuffer.create(len); Uint8Array view = Uint8Array.create(buf); for (int i = 0; i < len; i++) { view.set(i, data.get(i));//from w w w . j a va 2s. c o m } ws.send(buf); }