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

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

Introduction

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

Prototype

int NO_ERROR

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

Click 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);//ww  w  .  ja va 2s  .  c o 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;
    }
}