<commit_before>pc.extend(pc, function () {
    'use strict';

    var EVENT_RESIZE = 'resizecanvas';

    // Exceptions
    function UnsupportedBrowserError(message) {
        this.name = "UnsupportedBrowserError";
        this.message = (message || "");
    }
    UnsupportedBrowserError.prototype = Error.prototype;

    function ContextCreationError(message) {
        this.name = "ContextCreationError";
        this.message = (message || "");
    }
    ContextCreationError.prototype = Error.prototype;

    var _contextLostHandler = function () {
        logWARNING("Context lost.");
    };

    var _contextRestoredHandler = function () {
        logINFO("Context restored.");
    };

    var _createContext = function (canvas, options) {
        var names = ["webgl", "experimental-webgl"];
        var context = null;
        for (var i = 0; i < names.length; i++) {
            try {
                context = canvas.getContext(names[i], options);
            } catch(e) {}
            if (context) {
                break;
            }
        }
        return context;
    };

    var _downsampleImage = function (image, size) {
        var srcW = image.width;
        var srcH = image.height;

        if ((srcW > size) || (srcH > size)) {
            var scale = size / Math.max(srcW, srcH);
            var dstW = Math.floor(srcW * scale);
            var dstH = Math.floor(srcH * scale);

            console.warn('Image dimensions larger than max supported texture size of ' + size + '. ' +
                         'Resizing from ' + srcW + ', ' + srcH + ' to ' + dstW + ', ' + dstH + '.');

            var canvas = document.createElement('canvas');
            canvas.width = dstW;
            canvas.height = dstH;

            var context = canvas.getContext('2d');
            context.drawImage(image, 0, 0, srcW, srcH, 0, 0, dstW, dstH);

            return canvas;
        }

        return image;
    };

    function _isIE() {
        var ua = window.navigator.userAgent;
        var msie = ua.indexOf("MSIE ");
        var trident = navigator.userAgent.match(/Trident.*rv\:11\./);

        return (msie > 0 || !!trident);
    };

    /**
     * @name pc.GraphicsDevice
     * @class The graphics device manages the underlying graphics context. It is responsible
     * for submitting render state changes and graphics primitives to the hardware. A graphics
     * device is tied to a specific canvas HTML element. It is valid to have more than one
     * canvas element per page and create a new graphics device against each.
     * @constructor Creates a new graphics device.
     * @param {Object} canvas The canvas to which the graphics device is tied.
     * @property {Number} width Width of the back buffer in pixels (read-only).
     * @property {Number} height Height of the back buffer in pixels (read-only).
     * @property {Number} maxAnisotropy The maximum supported texture anisotropy setting (read-only).
     * @property {Number} maxCubeMapSize The maximum supported dimension of a cube map (read-only).
     * @property {Number} maxTextureSize The maximum supported dimension of a texture (read-only).
     * is attached is fullscreen or not.
     */

     /**
     * @event
     * @name pc.GraphicsDevice#resizecanvas
     * @description The 'resizecanvas' event is fired when the canvas is resized
     * @param {Number} width The new width of the canvas in pixels
     * @param {Number} height The new height of the canvas in pixels
    */
    var GraphicsDevice = function (canvas) {
        this.gl = undefined;
        this.canvas = canvas;
        this.shader = null;
        this.indexBuffer = null;
        this.vertexBuffers = [];
        this.precision = "highp";
        this.enableAutoInstancing = false;
        this.autoInstancingMaxObjects = 16384;
        this.attributesInvalidated = true;
        this.boundBuffer = null;
        this.instancedAttribs = {};
        this.enabledAttributes = {};
        this.textureUnits = [];
        this.commitFunction = {};
        this._maxPixelRatio = 1;
        // local width/height without pixelRatio applied
        this._width = 0;
        this._height = 0;

        if (!window.WebGLRenderingContext) {
            throw new pc.UnsupportedBrowserError();
        }

        // Retrieve the WebGL context
        if (canvas) {
            this.gl = _createContext(canvas);
        }

        if (!this.gl) {
            throw new pc.ContextCreationError();
        }

        var gl = this.gl;

        // put the rest of the contructor in a function
        // so that the constructor remains small. Small constructors
        // are optimized by Firefox due to type inference
        (function() {

            canvas.addEventListener("webglcontextlost", _contextLostHandler, false);
            canvas.addEventListener("webglcontextrestored", _contextRestoredHandler, false);

            this.canvas        = canvas;
            this.shader        = null;
            this.indexBuffer   = null;
            this.vertexBuffers = [];
            this.precision     = 'highp';

            this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
            this.maxCubeMapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
            this.maxRenderBufferSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);<commit_msg>Pass optional options when creating WebGL context<commit_after>pc.extend(pc, function () {
    'use strict';

    var EVENT_RESIZE = 'resizecanvas';

    // Exceptions
    function UnsupportedBrowserError(message) {
        this.name = "UnsupportedBrowserError";
        this.message = (message || "");
    }
    UnsupportedBrowserError.prototype = Error.prototype;

    function ContextCreationError(message) {
        this.name = "ContextCreationError";
        this.message = (message || "");
    }
    ContextCreationError.prototype = Error.prototype;

    var _contextLostHandler = function () {
        logWARNING("Context lost.");
    };

    var _contextRestoredHandler = function () {
        logINFO("Context restored.");
    };

    var _createContext = function (canvas, options) {
        var names = ["webgl", "experimental-webgl"];
        var context = null;
        for (var i = 0; i < names.length; i++) {
            try {
                context = canvas.getContext(names[i], options);
            } catch(e) {}
            if (context) {
                break;
            }
        }
        return context;
    };

    var _downsampleImage = function (image, size) {
        var srcW = image.width;
        var srcH = image.height;

        if ((srcW > size) || (srcH > size)) {
            var scale = size / Math.max(srcW, srcH);
            var dstW = Math.floor(srcW * scale);
            var dstH = Math.floor(srcH * scale);

            console.warn('Image dimensions larger than max supported texture size of ' + size + '. ' +
                         'Resizing from ' + srcW + ', ' + srcH + ' to ' + dstW + ', ' + dstH + '.');

            var canvas = document.createElement('canvas');
            canvas.width = dstW;
            canvas.height = dstH;

            var context = canvas.getContext('2d');
            context.drawImage(image, 0, 0, srcW, srcH, 0, 0, dstW, dstH);

            return canvas;
        }

        return image;
    };

    function _isIE() {
        var ua = window.navigator.userAgent;
        var msie = ua.indexOf("MSIE ");
        var trident = navigator.userAgent.match(/Trident.*rv\:11\./);

        return (msie > 0 || !!trident);
    };

    /**
     * @name pc.GraphicsDevice
     * @class The graphics device manages the underlying graphics context. It is responsible
     * for submitting render state changes and graphics primitives to the hardware. A graphics
     * device is tied to a specific canvas HTML element. It is valid to have more than one
     * canvas element per page and create a new graphics device against each.
     * @constructor Creates a new graphics device.
     * @param {Object} canvas The canvas to which the graphics device is tied.
     * @param {Object} [options] Options passed when creating the WebGL context. More info here https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
     * @property {Number} width Width of the back buffer in pixels (read-only).
     * @property {Number} height Height of the back buffer in pixels (read-only).
     * @property {Number} maxAnisotropy The maximum supported texture anisotropy setting (read-only).
     * @property {Number} maxCubeMapSize The maximum supported dimension of a cube map (read-only).
     * @property {Number} maxTextureSize The maximum supported dimension of a texture (read-only).
     * is attached is fullscreen or not.
     */

     /**
     * @event
     * @name pc.GraphicsDevice#resizecanvas
     * @description The 'resizecanvas' event is fired when the canvas is resized
     * @param {Number} width The new width of the canvas in pixels
     * @param {Number} height The new height of the canvas in pixels
    */
    var GraphicsDevice = function (canvas, options) {
        this.gl = undefined;
        this.canvas = canvas;
        this.shader = null;
        this.indexBuffer = null;
        this.vertexBuffers = [];
        this.precision = "highp";
        this.enableAutoInstancing = false;
        this.autoInstancingMaxObjects = 16384;
        this.attributesInvalidated = true;
        this.boundBuffer = null;
        this.instancedAttribs = {};
        this.enabledAttributes = {};
        this.textureUnits = [];
        this.commitFunction = {};
        this._maxPixelRatio = 1;
        // local width/height without pixelRatio applied
        this._width = 0;
        this._height = 0;

        if (!window.WebGLRenderingContext) {
            throw new pc.UnsupportedBrowserError();
        }

        // Retrieve the WebGL context
        if (canvas) {
            this.gl = _createContext(canvas, options);
        }

        if (!this.gl) {
            throw new pc.ContextCreationError();
        }

        var gl = this.gl;

        // put the rest of the contructor in a function
        // so that the constructor remains small. Small constructors
        // are optimized by Firefox due to type inference
        (function() {

            canvas.addEventListener("webglcontextlost", _contextLostHandler, false);
            canvas.addEventListener("webglcontextrestored", _contextRestoredHandler, false);

            this.canvas        = canvas;
            this.shader        = null;
            this.indexBuffer   = null;
            this.vertexBuffers = [];
            this.precision     = 'highp';

            this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
            this.maxCubeMapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
            this.maxRenderBufferSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);
{'fraction_non_alphanumeric': 0.10214757709251102, 'fraction_numerical': 0.003120411160058737, 'mean_word_length': 2.144877344877345, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3928874', 'n_tokens_mistral': 2966, 'n_tokens_neox': 2876, 'n_words': 869}