Example usage for com.google.gwt.webgl.client WebGLRenderingContext UNSIGNED_BYTE

List of usage examples for com.google.gwt.webgl.client WebGLRenderingContext UNSIGNED_BYTE

Introduction

In this page you can find the example usage for com.google.gwt.webgl.client WebGLRenderingContext UNSIGNED_BYTE.

Prototype

int UNSIGNED_BYTE

To view the source code for com.google.gwt.webgl.client WebGLRenderingContext UNSIGNED_BYTE.

Click Source Link

Usage

From source file:com.badlogic.gdx.backends.gwt.GwtGL20.java

License:Apache License

@Override
public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) {
    // verify request
    if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) {
        throw new GdxRuntimeException(
                "Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...).");
    }/*from   ww  w.jav  a 2  s  .co m*/
    if (!(pixels instanceof ByteBuffer)) {
        throw new GdxRuntimeException(
                "Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...).");
    }

    // create new ArrayBufferView (4 bytes per pixel)
    int size = 4 * width * height;
    Uint8Array buffer = Uint8ArrayNative.create(size);

    // read bytes to ArrayBufferView
    gl.readPixels(x, y, width, height, format, type, buffer);

    // copy ArrayBufferView to our pixels array
    ByteBuffer pixelsByte = (ByteBuffer) pixels;
    for (int i = 0; i < size; i++) {
        pixelsByte.put((byte) (buffer.get(i) & 0x000000ff));
    }
}

From source file:org.parallax3d.parallax.platforms.gwt.GwtGL20.java

License:Open Source License

@Override
public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) {
    // verify request
    if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) {
        throw new ParallaxRuntimeException(
                "Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...).");
    }//  w  w w .j a v  a  2s.  c o m
    if (!(pixels instanceof ByteBuffer)) {
        throw new ParallaxRuntimeException(
                "Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...).");
    }

    // create new ArrayBufferView (4 bytes per pixel)
    int size = 4 * width * height;
    Uint8Array buffer = Uint8ArrayNative.create(size);

    // read bytes to ArrayBufferView
    gl.readPixels(x, y, width, height, format, type, buffer);

    // copy ArrayBufferView to our pixels array
    ByteBuffer pixelsByte = (ByteBuffer) pixels;
    for (int i = 0; i < size; i++) {
        pixelsByte.put((byte) (buffer.get(i) & 0x000000ff));
    }
}