Example usage for com.google.gwt.typedarrays.client Uint8Array get

List of usage examples for com.google.gwt.typedarrays.client Uint8Array get

Introduction

In this page you can find the example usage for com.google.gwt.typedarrays.client Uint8Array get.

Prototype

public native final int get(int index) ;

Source Link

Document

Returns the element at the given numeric index.

Usage

From source file:forplay.html.HtmlGraphicsGL.java

License:Apache License

/**
 * Try basic GL operations to detect failure cases early.
 * //from w  w w .ja v a  2s  . 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: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 ava 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");
    }
}