List of usage examples for com.google.gwt.typedarrays.client Float32Array get
public native final float get(int index) ;
From source file:forplay.html.HtmlGraphicsGL.java
License:Apache License
/** * Try basic GL operations to detect failure cases early. * //from ww w . j a v a 2 s . c om * @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:forplay.html.HtmlGraphicsGL.java
License:Apache License
@SuppressWarnings("unused") private void printArray(String prefix, Float32Array arr, int length) { StringBuffer buf = new StringBuffer(); buf.append(prefix + ": ["); for (int i = 0; i < length; ++i) { buf.append(arr.get(i) + " "); }//w w w .j av a 2 s. c o m buf.append("]"); System.out.println(buf); }
From source file:playn.html.HtmlGL20.java
License:Apache License
@Override public void glGetUniformfv(int program, int location, FloatBuffer params) { Float32Array v = gl.getUniformv(getProgram(program), getUniformLocation(location)); for (int i = 0; i < v.getLength(); i++) { params.put(params.position() + i, v.get(i)); }//from w ww . java2 s . c om }
From source file:playn.html.HtmlGL20.java
License:Apache License
@Override public void glGetVertexAttribfv(int index, int pname, FloatBuffer params) { Float32Array v = gl.getVertexAttribv(index, pname); for (int i = 0; i < v.getLength(); i++) { params.put(params.position() + i, v.get(i)); }// www . j a v a2 s. c o m }
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"); }/*from w w w.j a v a2 s .co m*/ // 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"); } }