npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lazy-renderer

v0.3.1

Published

Lazy loading cached WebGL2 wrapper

Downloads

36

Readme

lazy-renderer

Lazy loading cached WebGL wrapper.

Demo

A demo application is available at:

https://rafaelromeiro.github.io/lazy-renderer/

This corresponds to the index.html file in the root folder of this repository.

Installation

Install this library with:

npm install lazy-renderer

To import this library as an ECMAScript module (preferred):

import {
    LazyRenderer,
    ResourceType,
    ShaderType,
    PrimitiveType,
    BufferTarget,
    BufferDataType,
    ShaderDataType,
    TextureFilter,
    TextureWrapping,
    TextureType,
    TextureFormat,
} from "lazy-renderer";

Alternatively, to import this library as a Node module (when ESM not available):

const {
    LazyRenderer,
    ResourceType,
    ShaderType,
    PrimitiveType,
    BufferTarget,
    BufferDataType,
    ShaderDataType,
    TextureFilter,
    TextureWrapping,
    TextureType,
    TextureFormat,
} = require("lazy-renderer");

Browser

To use this library in a browser through IIFE:

<script src="https://cdn.jsdelivr.net/npm/lazy-renderer/dist/lazy-renderer.iife.min.js"></script>
<script>
    const {
        LazyRenderer,
        ResourceType,
        ShaderType,
        PrimitiveType,
        BufferTarget,
        BufferDataType,
        ShaderDataType,
        TextureFilter,
        TextureWrapping,
        TextureType,
        TextureFormat,
    } = window.LazyRenderer;
    // ...
</script>

Usage

To use this library, an instance of the LazyRenderer class must be created:

const lazyRenderer = new LazyRenderer(canvas, requestResource);

Where canvas must be an HTMLCanvasElement object and requestResource must be a callback of type RequestResourceCallback.

The callback type RequestResourceCallback receives a resource type (ResourceType) and a resource name (string). It is called by the lazy-renderer every time a resource is needed but is not available.

In summary, the lazy-renderer manages named resources. There are 8 types of resources:

  • Framebuffer
  • Program
  • Shader
  • Primitive
  • Accessor
  • Buffer
  • Sampler
  • Texture

To make a resource available to the lazy-renderer, it must first be registered through the appropriate register method. There is a register method for each resource type. A register method receives the name (string) of the resource followed by parameters specific for the resource type. The resource information is stored in CPU memory and is not loaded into the GPU right away, hence the lazyness.

Information is loaded into the GPU only when needed (and available) inside a call to the render method. The render method receives the names of the program (string), primitive (string) and framebuffer (string or null). The program is how to render, the primitive is what to render and the framebuffer is where to render. When passing null as the framebuffer name, the rendering is output to the canvas.

The user is encourage to call the render method without worrying about resource availability. The register methods can be called reactively to the requestResource callback.

The render method can also receive mappings regarding uniforms and textures. The uniforms (Map<string, ArrayBufferView>) maps a uniform name to an ArrayBufferView containing the values to be loaded into the GPU. The textures (Map<string, { textureName: string, samplerName: string}>) maps a uniform sampler name to a pair of texture resource name and a sampler resource name.

Finally, buffers and textures can be written or read through the methods:

  • writeBufferData, that writes into the buffer from an ArrayBufferView.
  • readBufferData, that reads the buffer contents to an ArrayBufferView.
  • writeTextureURI, that writes into the texture from an image URI.
  • readTextureURI, that reads the texture contents to an image URI.
  • writeTextureImage, that writes into the texture from an HTMLImageElement.
  • readTextureImage, that reads the texture contents to an HTMLImageElement.
  • writeTextureData, that writes into the texture from an ArrayBufferView.
  • readTextureData, that reads the texture contents to an ArrayBufferView.

Documentation

A more in-depth documentation is still being written.