<commit_before>/*
 * MelonJS Game Engine
 * Copyright (C) 2011 - 2015 <NAME>, <NAME>, <NAME>
 * http://www.melonjs.org
 *
 */
(function () {

    /**
     * The WebGL Shader singleton <br>
     * There is no constructor function for me.video.shader
     * @namespace me.video.shader
     * @memberOf me.video
     */
    me.video.shader = (function () {
        /**
         * Public API
         * @ignore
         */
        var api = {};

        /**
         * Compile GLSL into a shader object
         * @private
         */
        function getShader(gl, type, source) {
            var shader = gl.createShader(type);
            gl.shaderSource(shader, source);
            gl.compileShader(shader);

            if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
                throw new me.video.Error(gl.getShaderInfoLog(shader));
            }

            return shader;
        }

        /**
         * Hash map of GLSL data types to WebGL Uniform methods
         * @private
         */
        var fnHash = {
            "bool"      : "1i",
            "int"       : "1i",
            "float"     : "1f",
            "vec2"      : "2fv",
            "vec3"      : "3fv",
            "vec4"      : "4fv",
            "bvec2"     : "2iv",
            "bvec3"     : "3iv",
            "bvec4"     : "4iv",
            "ivec2"     : "2iv",
            "ivec3"     : "3iv",
            "ivec4"     : "4iv",
            "mat2"      : "Matrix2fv",
            "mat3"      : "Matrix3fv",
            "mat4"      : "Matrix4fv",
            "sampler2D" : "1i",
        };

        /**
         * Create a shader program (with bindings) using the given GLSL sources
         * @name createShader
         * @memberOf me.video.shader
         * @function
         * @param {WebGLContext} gl WebGL Context
         * @param {String} vertex Vertex shader source
         * @param {String} fragment Fragment shader source
         * @return {Object} A reference to the WebGL Shader Program
         */
        api.createShader = function (gl, vertex, fragment) {
            var program = {
                    "attributes"    : {},
                    "uniforms"      : {},
                    "handle"        : null,
                },
                handle = program.handle = gl.createProgram(),
                attrRx = /attribute\s+\w+\s+(\w+)/g,
                uniRx = /uniform\s+(\w+)\s+(\w+)/g,
                attributes = [],
                uniforms = {},
                match,
                descriptor = {},
                locations = {};

            gl.attachShader(handle, getShader(gl, gl.VERTEX_SHADER, vertex));
            gl.attachShader(handle, getShader(gl, gl.FRAGMENT_SHADER, fragment));
            gl.linkProgram(handle);

            if (!gl.getProgramParameter(handle, gl.LINK_STATUS)) {
                throw new me.video.Error("Could not initialize shaders");
            }

            gl.useProgram(handle);

            // Detect all attribute names
            while ((match = attrRx.exec(vertex))) {
                attributes.push(match[1]);
            }

            // Detect all uniform names and types<commit_msg>WebGL: Better compiler error output<commit_after>/*
 * MelonJS Game Engine
 * Copyright (C) 2011 - 2015 <NAME>, <NAME>, <NAME>
 * http://www.melonjs.org
 *
 */
(function () {

    /**
     * The WebGL Shader singleton <br>
     * There is no constructor function for me.video.shader
     * @namespace me.video.shader
     * @memberOf me.video
     */
    me.video.shader = (function () {
        /**
         * Public API
         * @ignore
         */
        var api = {};

        /**
         * Compile GLSL into a shader object
         * @private
         */
        function getShader(gl, type, source) {
            var shader = gl.createShader(type);
            gl.shaderSource(shader, source);
            gl.compileShader(shader);

            if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
                throw new me.video.Error(gl.getShaderInfoLog(shader));
            }

            return shader;
        }

        /**
         * Hash map of GLSL data types to WebGL Uniform methods
         * @private
         */
        var fnHash = {
            "bool"      : "1i",
            "int"       : "1i",
            "float"     : "1f",
            "vec2"      : "2fv",
            "vec3"      : "3fv",
            "vec4"      : "4fv",
            "bvec2"     : "2iv",
            "bvec3"     : "3iv",
            "bvec4"     : "4iv",
            "ivec2"     : "2iv",
            "ivec3"     : "3iv",
            "ivec4"     : "4iv",
            "mat2"      : "Matrix2fv",
            "mat3"      : "Matrix3fv",
            "mat4"      : "Matrix4fv",
            "sampler2D" : "1i",
        };

        /**
         * Create a shader program (with bindings) using the given GLSL sources
         * @name createShader
         * @memberOf me.video.shader
         * @function
         * @param {WebGLContext} gl WebGL Context
         * @param {String} vertex Vertex shader source
         * @param {String} fragment Fragment shader source
         * @return {Object} A reference to the WebGL Shader Program
         */
        api.createShader = function (gl, vertex, fragment) {
            var program = {
                    "attributes"    : {},
                    "uniforms"      : {},
                    "handle"        : null,
                },
                handle = program.handle = gl.createProgram(),
                attrRx = /attribute\s+\w+\s+(\w+)/g,
                uniRx = /uniform\s+(\w+)\s+(\w+)/g,
                attributes = [],
                uniforms = {},
                match,
                descriptor = {},
                locations = {};

            gl.attachShader(handle, getShader(gl, gl.VERTEX_SHADER, vertex));
            gl.attachShader(handle, getShader(gl, gl.FRAGMENT_SHADER, fragment));
            gl.linkProgram(handle);

            if (!gl.getProgramParameter(handle, gl.LINK_STATUS)) {
                throw new me.video.Error(gl.getProgramInfoLog(handle));
            }

            gl.useProgram(handle);

            // Detect all attribute names
            while ((match = attrRx.exec(vertex))) {
                attributes.push(match[1]);
            }

            // Detect all uniform names and types
{'fraction_non_alphanumeric': 0.12641509433962264, 'fraction_numerical': 0.011949685534591196, 'mean_word_length': 1.2939055174900829, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7118133', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1777, 'n_words': 408}