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

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

Introduction

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

Prototype

public final native int getError() ;

Source Link

Usage

From source file:playn.html.HtmlGraphicsGL.java

License:Apache License

HtmlGraphicsGL(HtmlPlatform platform, HtmlPlatform.Configuration config) throws RuntimeException {
    canvas = Document.get().createCanvasElement();
    rootElement.appendChild(canvas);/*  w  w w .j  a  va 2  s  .co m*/
    try {
        WebGLContextAttributes attrs = WebGLContextAttributes.create();
        attrs.setAlpha(config.transparentCanvas);
        attrs.setAntialias(config.antiAliasing);

        // if this returns null, the browser doesn't support WebGL on this machine
        WebGLRenderingContext gl = WebGLRenderingContext.getContext(canvas, attrs);
        // Some systems seem to have a problem where they return a valid context, but it's in an
        // error state initially. We give up and fall back to Canvas in this case, because nothing
        // seems to work properly.
        if (gl == null || gl.getError() != WebGLRenderingContext.NO_ERROR) {
            throw new RuntimeException(
                    "GL context not created [err=" + (gl == null ? "null" : gl.getError()) + "]");
        }

        ctx = new HtmlGLContext(platform, gl, canvas);
        rootLayer = new GroupLayerGL(ctx);
    } catch (RuntimeException re) {
        // Give up. HtmlPlatform will catch the exception and fall back to dom/canvas.
        rootElement.removeChild(canvas);
        throw re;
    }
}