Fork me on GitHub

PicoGL.js

Coverage Status
API Docs | Tutorial | Chat
PicoGL.js is a minimal WebGL 2 rendering library. It's meant for developers who understand the WebGL 2 rendering pipeline and want to use it, but with a more convenient API. Typical usage of PicoGL.js will involve creating programs, vertex buffers, vertex arrays, uniform buffers, framebuffers, textures, transform feedbacks, and combining them into draw calls.

    // Create a PicoGL.js app to manage GL state.
    let app = PicoGL.createApp(canvas)
    .clearColor(0.0, 0.0, 0.0, 1.0);

    // Create program from shader source.
    // Shaders are compiled in parallel if supported by the platform.
    app.createPrograms([vertexShaderSource, fragmentShaderSource]).then(([program]) => {
        // Scene geometry stored vertex buffer object.
        let positions = app.createVertexBuffer(PicoGL.FLOAT, 2, new Float32Array([
            -0.5, -0.5,
             0.5, -0.5,
             0.0,  0.5
        ]));

        // Vertex buffer and attribute pointer state stored
        // in vertex array object.
        let vertexArray = app.createVertexArray()
        .vertexAttributeBuffer(0, positions);

        // Scene data stored in uniform buffer object.
        let uniformBuffer = app.createUniformBuffer([
            PicoGL.FLOAT_VEC4,
            PicoGL.FLOAT_VEC4
        ])
        .set(0, new Float32Array([1.0, 0.0, 0.0, 0.3]))
        .set(1, new Float32Array([0.0, 0.0, 1.0, 0.7]))
        .update();

        // Create a draw call from program, vertex array, uniform buffer.
        let drawCall = app.createDrawCall(program, vertexArray)
        .uniformBlock("ColorUniforms", uniformBuffer);

        // Draw!
        app.clear()
        drawCall.draw();
    });
    
PicoGL.js can be used directly by downloading the built source and loading it via a script tag:

    <script src="js/picogl.min.js"></script>
    
or it can be installed via npm:

    npm install picogl
    
and loaded via ES6-style import:

    import PicoGL from "picogl";
    
Note that PicoGL.js is not a scene graph library. There are no objects, hierarchies, transforms, materials, etc. It has been designed only to make management of GPU state more convenient. Its conceptual model maps fairly directly to the constructs one deals with when writing directly with the WebGL 2 API. The only higher-level construct is the draw call, which manages sets of related lower-level constructs.

Basic Examples

Triangle Interleaved Triangle Uniform Buffers Instanced Drawing Multi-draw Transform Feedback Interleaved Transform Feedback Phong-shaded Cube Cubemap Texture Array 3D Texture Render to Texture Render to MSAA Renderbuffer Render to Cubemap Render to 3D texture Compressed Textures Compressed Cubemap Context Loss

Advanced Examples

Picking Shadow Mapping Depth of Field Screen Space Ambient Occlusion Deferred Rendering Order-independent Transparency Particles Bloom Wandering Triangles Cloth Outline Occlusion Culling Motion Blur Mesh Compression Omni-directional Shadows

Benchmarks

64,000 Cubes 125,000 Cubes