How to use the gl/utils.VBO function in gl

To help you get started, we’ve selected a few gl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jwagner / voxelworlds / src / gl / voxel.js View on Github external
for(var i = 0; i < this.world.chunks.length; i++) {
            var chunk = this.world.chunks[i];
            if(chunk.nonempty_voxels === 0) continue;
            var mesh = this.buffers[chunk.key];
            if(!mesh){
                var buffer = this.generate_mesh(chunk);
                //console.log(mesh);
                mesh = this.buffers[chunk.key] = {vbo: new glutils.VBO(buffer), version: chunk.version};
            }
            else if(mesh.version < chunk.version && update){
                console.time('free');
                mesh.vbo.free();
                console.timeEnd('free');
                var data = this.generate_mesh(chunk);
                mesh.vbo = new glutils.VBO(data);
                console.log('regenerating buffer');
                mesh.version = chunk.version;
                // update at most one mesh per frame
                update = false;
            }
            var vbo = mesh.vbo;

            graph.uniforms.offset = chunk.position;
            shader.uniforms(graph.uniforms);

            vbo.bind();
            var stride = 10;
            gl.enableVertexAttribArray(position);
            gl.vertexAttribPointer(position, 3, gl.UNSIGNED_BYTE, false, stride, 0);
            gl.enableVertexAttribArray(normal);
            gl.vertexAttribPointer(normal, 3, gl.BYTE, false, stride, 3);
github jwagner / voxelworlds / src / gl / voxel.js View on Github external
normal = shader.getAttribLocation('normal'),
            color = shader.getAttribLocation('color'),
            //ambient = shader.getAttribLocation('ambient'),
            update = true;

        graph.pushUniforms();
        graph.uniforms.scale = this.world.scale;

        for(var i = 0; i < this.world.chunks.length; i++) {
            var chunk = this.world.chunks[i];
            if(chunk.nonempty_voxels === 0) continue;
            var mesh = this.buffers[chunk.key];
            if(!mesh){
                var buffer = this.generate_mesh(chunk);
                //console.log(mesh);
                mesh = this.buffers[chunk.key] = {vbo: new glutils.VBO(buffer), version: chunk.version};
            }
            else if(mesh.version < chunk.version && update){
                console.time('free');
                mesh.vbo.free();
                console.timeEnd('free');
                var data = this.generate_mesh(chunk);
                mesh.vbo = new glutils.VBO(data);
                console.log('regenerating buffer');
                mesh.version = chunk.version;
                // update at most one mesh per frame
                update = false;
            }
            var vbo = mesh.vbo;

            graph.uniforms.offset = chunk.position;
            shader.uniforms(graph.uniforms);
github jwagner / voxelworlds / src / main.js View on Github external
blurFBO1 = new FBO(canvas.width>>1, canvas.height>>1, gl.FLOAT),
        blurFBO2 = new FBO(canvas.width>>2, canvas.height>>2, gl.FLOAT),
        blurFBO3 = new FBO(canvas.width>>2, canvas.height>>2, gl.FLOAT);

    resizeVBO = function() {
        // hoping the GC will clean up...
        FBO.call(albedoFBO, canvas.width, canvas.height, gl.FLOAT);
        FBO.call(blurFBO0, canvas.width>>1, canvas.height>>1, gl.FLOAT);
        FBO.call(blurFBO1, canvas.width>>1, canvas.height>>1, gl.FLOAT);
        FBO.call(blurFBO2, canvas.width>>2, canvas.height>>2, gl.FLOAT);
        FBO.call(blurFBO3, canvas.width>>2, canvas.height>>2, gl.FLOAT);
    }; 

    cube = new scene.Transform([
        new scene.Material(shaders.get('solid'), {color: vec4.create([0.5, 0.0, 0.0, 0.5])}, [
            new scene.SimpleMesh(new glUtils.VBO(mesh.cube(-0.5)))])
        ]);
    cube2 = new scene.Transform([
        new scene.Material(shaders.get('solid'), {color: vec4.create([0.0, 0.0, 1.0, 0.5])}, [
            new scene.SimpleMesh(new glUtils.VBO(mesh.cube(-0.5)))])
    ]);


    var shader = new scene.Material(shaders.get('voxel'), {}, [
            //new scene.SimpleMesh(new glutils.VBO(mesh.cube())),
            window.renderer
        ]);

    camera = new scene.Camera([
        new scene.RenderTarget(albedoFBO, [
            shader,
            cube
github jwagner / voxelworlds / src / gl / scene.js View on Github external
scene.Postprocess = function PostprocessNode(shader, uniforms) {
    var mesh_ = new scene.SimpleMesh(new glUtils.VBO(mesh.screen_quad())),
        material = new scene.Material(shader, uniforms, [mesh_]);
    this.children = [material];
};
scene.Postprocess.prototype = scene.Node.prototype;
github jwagner / voxelworlds / src / gl / scene.js View on Github external
scene.Skybox = function SkyboxNode(scale, shader, uniforms) {
    var mesh_ = new scene.SimpleMesh(new glUtils.VBO(mesh.cube(scale))),
        material = new scene.Material(shader, uniforms, [mesh_]);
    this.children = [material];
};
scene.Skybox.prototype = extend({}, scene.Node.prototype, {