build/browser/index.js
/**
     * Returns a WebGL rendering context given a canvas element.
     * @param canvas The canvas element.
     * @param options The arguments to the HTMLCanvasElement.getContext() method.
     * @param contextId An optional override for the context identifier.
     * If the canvas is undefined then an undefined value is returned for the context.
     * @hidden
     */
Returns a WebGL rendering context given a canvas element.
@param canvas The canvas element.
@param options The arguments to the HTMLCanvasElement.getContext() method.
@param contextId An optional override for the context identifier.
If the canvas is undefined then an undefined value is returned for the context.
@hidden
Returns a WebGL rendering context given a canvas element . @param canvas The canvas element . @param options The arguments to the HTMLCanvasElement . getContext () method . @param contextId An optional override for the context identifier . If the canvas is undefined then an undefined value is returned for the context . @hidden
function initWebGL(canvas, options, contextId) {
        if (isDefined(canvas)) {
            if (contextId) {
                switch (contextId) {
                    case 'webgl2': {
                        var context = canvas.getContext(contextId, options);
                        if (context) {
                            return { context: context, contextId: contextId };
                        }
                        else {
                            throw new Error(getContextFailed(contextId));
                        }
                    }
                    case 'webgl': {
                        var context = canvas.getContext(contextId, options);
                        if (context) {
                            return { context: context, contextId: contextId };
                        }
                        else {
                            throw new Error(getContextFailed(contextId));
                        }
                    }
                    default: {
                        throw new Error(invalidContextId(contextId));
                    }
                }
            }
            else {
                try {
                    var candidateContextId = 'webgl2';
                    var context = canvas.getContext(candidateContextId, options);
                    if (context) {
                        return { context: context, contextId: candidateContextId };
                    }
                    else {
                        throw new Error(getContextFailed(candidateContextId));
                    }
                }
                catch (e) {
                    var candidateContextId = 'webgl';
                    var context = canvas.getContext(candidateContextId, options);
                    if (context) {
                        return { context: context, contextId: candidateContextId };
                    }
                    else {
                        throw new Error(getContextFailed(candidateContextId));
                    }
                }
            }
        }
        else {
            return void 0;
        }
    }
function initWebGL ( canvas , options , contextId ) { if ( isDefined ( canvas ) ) { if ( contextId ) { switch ( contextId ) { case 'webgl2' : { var context = canvas . getContext ( contextId , options ) ; if ( context ) { return { context : context , contextId : contextId } ; } else { throw new Error ( getContextFailed ( contextId ) ) ; } } case 'webgl' : { var context = canvas . getContext ( contextId , options ) ; if ( context ) { return { context : context , contextId : contextId } ; } else { throw new Error ( getContextFailed ( contextId ) ) ; } } default : { throw new Error ( invalidContextId ( contextId ) ) ; } } } else { try { var candidateContextId = 'webgl2' ; var context = canvas . getContext ( candidateContextId , options ) ; if ( context ) { return { context : context , contextId : candidateContextId } ; } else { throw new Error ( getContextFailed ( candidateContextId ) ) ; } } catch ( e ) { var candidateContextId = 'webgl' ; var context = canvas . getContext ( candidateContextId , options ) ; if ( context ) { return { context : context , contextId : candidateContextId } ; } else { throw new Error ( getContextFailed ( candidateContextId ) ) ; } } } } else { return void 0 ; } }
Returns a WebGL rendering context given a canvas element.
Returns a WebGL rendering context given a canvas element .
// We'll be hyper-functional. An undefined canvas begets an undefined context. // Clients must check their context output or canvas input. // From a type-safety perspective, this should never happen. // An undefined canvas results in an undefined context.