<commit_before>var gl;
var canvas;

var vertices;
var colors;

var colorBuffer;
var positionBuffer;

var modelMatrixLoc;
var modelMatrix;

window.onload = function init()
{
    // Get canvas and setup webGL
    
    canvas = document.getElementById("gl-canvas");
    gl = WebGLUtils.setupWebGL(canvas);
    if (!gl) { alert("WebGL isn't available"); }
    
    gl.enable(gl.DEPTH_TEST);
    gl.depthFunc(gl.LESS);

    // Specify position and color of the vertices
    
                                 // Front
    vertices = new Float32Array([-0.5, -0.5, 0.5,
                                 0.5, -0.5, 0.5,
                                 0.5, 0.5, 0.5,
                                 
                                 0.5, 0.5, 0.5,
                                 -0.5, 0.5 ,0.5,
                                 -0.5, -0.5, 0.5,
                                 
                                 // Right
                                 0.5, 0.5, 0.5,
                                 0.5, -0.5, 0.5,
                                 0.5, -0.5, -0.5,
                                 
                                 0.5, -0.5, -0.5,
                                 0.5, 0.5, -0.5,
                                 0.5, 0.5, 0.5,
                                 
                                 // Back
                                 -0.5, -0.5, -0.5,
                                 0.5, -0.5, -0.5,
                                 0.5, 0.5, -0.5,
                                 
                                 0.5, 0.5, -0.5,
                                 -0.5, 0.5 ,-0.5,
                                 -0.5, -0.5, -0.5,
                                 
                                 // Left
                                 -0.5, 0.5, 0.5,
                                 -0.5, -0.5, 0.5,
                                 -0.5, -0.5, -0.5,
                                 
                                 -0.5, -0.5, -0.5,
                                 -0.5, 0.5, -0.5,
                                 -0.5, 0.5, 0.5,
                                 
                                 // Bottom
                                 -0.5, -0.5, 0.5,
                                 0.5, -0.5, 0.5,
                                 0.5, -0.5, -0.5,
                                 
                                 0.5, -0.5, -0.5,
                                 -0.5, -0.5 , -0.5,
                                 -0.5, -0.5, 0.5,
                                 
                                 // Top
                                 -0.5, 0.5, 0.5,
                                 0.5, 0.5, 0.5,
                                 0.5, 0.5, -0.5,
                                 
                                 0.5, 0.5, -0.5,
                                 -0.5, 0.5 , -0.5,
                                 -0.5, 0.5, 0.5
                                 ]);
                                        
                                // Front
    colors = new Float32Array([1, 0, 0, 1, 
                               1, 0, 0, 1,
                               1, 0, 0, 1,
                               1, 0, 0, 1,
                               1, 0, 0, 1,
                               1, 0, 0, 1,
                               
                               // Right
                               0, 1, 0, 1, 
                               0, 1, 0, 1,
                               0, 1, 0, 1,
                               0, 1, 0, 1,
                               0, 1, 0, 1,
                               0, 1, 0, 1,
                               
                               // Back
                               0, 0, 1, 1, 
                               0, 0, 1, 1,
                               0, 0, 1, 1,
                               0, 0, 1, 1,
                               0, 0, 1, 1,
                               0, 0, 1, 1,
                               
                               // Left
                               1, 1, 0, 1, 
                               1, 1, 0, 1,
                               1, 1, 0, 1,
                               1, 1, 0, 1,
                               1, 1, 0, 1,
                               1, 1, 0, 1,
                               
                               // Bottom
                               1, 0, 1, 1, 
                               1, 0, 1, 1,
                               1, 0, 1, 1,
                               1, 0, 1, 1,
                               1, 0, 1, 1,
                               1, 0, 1, 1,
                               
                               // Top
                               0, 1, 1, 1, 
                               0, 1, 1, 1,
                               0, 1, 1, 1,
                               0, 1, 1, 1,
                               0, 1, 1, 1,
                               0, 1, 1, 1
                               ]);

    // Configure viewport

    gl.viewport(0,0,canvas.width,canvas.height);
    gl.clearColor(1.0,1.0,1.0,1.0);

    // Init shader program and bind it

    var program = initShaders(gl, "vertex-shader", "fragment-shader");

    gl.useProgram(program);
    
    // Load colors into the GPU and associate shader variables
    
    colorBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
    
    var vColor = gl.getAttribLocation(program, "vColor");
    gl.vertexAttribPointer(vColor, 4, gl.FLOAT, false, 0, 0);
    gl.enableVertexAttribArray(vColor);

    // Load positions into the GPU and associate shader variables

    positionBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);

    var vPosition = gl.getAttribLocation(program, "vPosition");
    gl.vertexAttribPointer(vPosition, 3, gl.FLOAT, false, 0, 0);
    gl.enableVertexAttribArray(vPosition);
    
    // Set and load modelMatrix
    modelMatrix = mat4.create();
    modelMatrix = new Float32Array(modelMatrix);
    var rotvec = vec3.create();
    vec3.set(rotvec, 0, 1, 1);
    modelMatrixLoc = gl.getUniformLocation(program, "modelMatrix");

    function rotate()
    {
        mat4.rotate(modelMatrix, modelMatrix, 0.01, rotvec);
        gl.uniformMatrix4fv(modelMatrixLoc, false, modelMatrix);
        render();
    }
    setInterval(rotate, 150);
};


function render()
{
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    gl.drawArrays(gl.TRIANGLES, 0, vertices.length/3);
    requestAnimFrame(render);
}

<commit_msg>06: fix massive performance issues<commit_after>var gl;
var canvas;

var vertices;
var colors;

var colorBuffer;
var positionBuffer;

var modelMatrixLoc;
var modelMatrix;

window.onload = function init()
{
    // Get canvas and setup webGL
    
    canvas = document.getElementById("gl-canvas");
    gl = WebGLUtils.setupWebGL(canvas);
    if (!gl) { alert("WebGL isn't available"); }
    
    gl.enable(gl.DEPTH_TEST);
    gl.depthFunc(gl.LESS);

    // Specify position and color of the vertices
    
                                 // Front
    vertices = new Float32Array([-0.5, -0.5, 0.5,
                                 0.5, -0.5, 0.5,
                                 0.5, 0.5, 0.5,
                                 
                                 0.5, 0.5, 0.5,
                                 -0.5, 0.5 ,0.5,
                                 -0.5, -0.5, 0.5,
                                 
                                 // Right
                                 0.5, 0.5, 0.5,
                                 0.5, -0.5, 0.5,
                                 0.5, -0.5, -0.5,
                                 
                                 0.5, -0.5, -0.5,
                                 0.5, 0.5, -0.5,
                                 0.5, 0.5, 0.5,
                                 
                                 // Back
                                 -0.5, -0.5, -0.5,
                                 0.5, -0.5, -0.5,
                                 0.5, 0.5, -0.5,
                                 
                                 0.5, 0.5, -0.5,
                                 -0.5, 0.5 ,-0.5,
                                 -0.5, -0.5, -0.5,
                                 
                                 // Left
                                 -0.5, 0.5, 0.5,
                                 -0.5, -0.5, 0.5,
                                 -0.5, -0.5, -0.5,
                                 
                                 -0.5, -0.5, -0.5,
                                 -0.5, 0.5, -0.5,
                                 -0.5, 0.5, 0.5,
                                 
                                 // Bottom
                                 -0.5, -0.5, 0.5,
                                 0.5, -0.5, 0.5,
                                 0.5, -0.5, -0.5,
                                 
                                 0.5, -0.5, -0.5,
                                 -0.5, -0.5 , -0.5,
                                 -0.5, -0.5, 0.5,
                                 
                                 // Top
                                 -0.5, 0.5, 0.5,
                                 0.5, 0.5, 0.5,
                                 0.5, 0.5, -0.5,
                                 
                                 0.5, 0.5, -0.5,
                                 -0.5, 0.5 , -0.5,
                                 -0.5, 0.5, 0.5
                                 ]);
                                        
                                // Front
    colors = new Float32Array([1, 0, 0, 1, 
                               1, 0, 0, 1,
                               1, 0, 0, 1,
                               1, 0, 0, 1,
                               1, 0, 0, 1,
                               1, 0, 0, 1,
                               
                               // Right
                               0, 1, 0, 1, 
                               0, 1, 0, 1,
                               0, 1, 0, 1,
                               0, 1, 0, 1,
                               0, 1, 0, 1,
                               0, 1, 0, 1,
                               
                               // Back
                               0, 0, 1, 1, 
                               0, 0, 1, 1,
                               0, 0, 1, 1,
                               0, 0, 1, 1,
                               0, 0, 1, 1,
                               0, 0, 1, 1,
                               
                               // Left
                               1, 1, 0, 1, 
                               1, 1, 0, 1,
                               1, 1, 0, 1,
                               1, 1, 0, 1,
                               1, 1, 0, 1,
                               1, 1, 0, 1,
                               
                               // Bottom
                               1, 0, 1, 1, 
                               1, 0, 1, 1,
                               1, 0, 1, 1,
                               1, 0, 1, 1,
                               1, 0, 1, 1,
                               1, 0, 1, 1,
                               
                               // Top
                               0, 1, 1, 1, 
                               0, 1, 1, 1,
                               0, 1, 1, 1,
                               0, 1, 1, 1,
                               0, 1, 1, 1,
                               0, 1, 1, 1
                               ]);

    // Configure viewport

    gl.viewport(0,0,canvas.width,canvas.height);
    gl.clearColor(1.0,1.0,1.0,1.0);

    // Init shader program and bind it

    var program = initShaders(gl, "vertex-shader", "fragment-shader");

    gl.useProgram(program);
    
    // Load colors into the GPU and associate shader variables
    
    colorBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
    
    var vColor = gl.getAttribLocation(program, "vColor");
    gl.vertexAttribPointer(vColor, 4, gl.FLOAT, false, 0, 0);
    gl.enableVertexAttribArray(vColor);

    // Load positions into the GPU and associate shader variables

    positionBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
    gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);

    var vPosition = gl.getAttribLocation(program, "vPosition");
    gl.vertexAttribPointer(vPosition, 3, gl.FLOAT, false, 0, 0);
    gl.enableVertexAttribArray(vPosition);
    
    // Set and load modelMatrix
    modelMatrix = mat4.create();
    modelMatrix = new Float32Array(modelMatrix);
    var rotvec = vec3.create();
    vec3.set(rotvec, 0, 1, 1);
    modelMatrixLoc = gl.getUniformLocation(program, "modelMatrix");

    function rotate()
    {
        mat4.rotate(modelMatrix, modelMatrix, 0.01, rotvec);
        gl.uniformMatrix4fv(modelMatrixLoc, false, modelMatrix);
    }
    setInterval(rotate, 50);
    render();
};


function render()
{
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    gl.drawArrays(gl.TRIANGLES, 0, vertices.length/3);
    requestAnimFrame(render);
}


{'fraction_non_alphanumeric': 0.10714285714285714, 'fraction_numerical': 0.060178193899124134, 'mean_word_length': 0.5646780862374483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 188, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2704807', 'n_tokens_mistral': 4122, 'n_tokens_neox': 3612, 'n_words': 842}