Example usage for com.google.gwt.typedarrays.client Uint16Array create

List of usage examples for com.google.gwt.typedarrays.client Uint16Array create

Introduction

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

Prototype

public static final native Uint16Array create(JsArrayInteger data) ;

Source Link

Document

Create a new ArrayBuffer with enough bytes to hold array.length elements of this typed array, then create a typed array view referring to the full buffer.

Usage

From source file:com.googlecode.gwtgl.example.client.examples.coloredtriangle.binding.ColoredTriangleBindingExample.java

License:Apache License

/**
 * Initializes the buffer containing the vertex and color coordinates.
 *///from w w  w .  j a v a2 s.  c o  m
private void initBuffers() {
    // create the vertexBuffer
    // One Triangle with 3 Points  3 coordinates
    vertexBuffer = glContext.createBuffer();
    glContext.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, vertexBuffer);
    float[] vertices = new float[] { 0.0f, 1.0f, -5.0f, // x y z des ersten Dreieckpunktes
            -1.0f, -1.0f, -5.0f, // x y z des zweiten Dreieckpunktes
            1.0f, -1.0f, -5.0f // x y z des dritten Dreieckpunktes
    };
    glContext.bufferData(WebGLRenderingContext.ARRAY_BUFFER, Float32Array.create(vertices),
            WebGLRenderingContext.STATIC_DRAW);

    // create the colorBuffer
    colorBuffer = glContext.createBuffer();
    glContext.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, colorBuffer);
    float[] colors = new float[] { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f };
    glContext.bufferData(WebGLRenderingContext.ARRAY_BUFFER, Float32Array.create(colors),
            WebGLRenderingContext.STATIC_DRAW);

    // create the indexBuffer
    indexBuffer = glContext.createBuffer();
    glContext.bindBuffer(WebGLRenderingContext.ELEMENT_ARRAY_BUFFER, indexBuffer);
    int[] indices = new int[] { 0, 1, 2 };
    glContext.bufferData(WebGLRenderingContext.ELEMENT_ARRAY_BUFFER, Uint16Array.create(indices),
            WebGLRenderingContext.STATIC_DRAW);
    checkErrors();
}

From source file:forplay.html.HtmlGraphicsGL.java

License:Apache License

/**
 * Try basic GL operations to detect failure cases early.
 * /*w ww.  j ava2 s.c o 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 .  j  a va2  s.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");
    }
}