GlassSource supplies pixels to one or more lenses. Choose a canvas/image source for browser content or a GPU renderer when your application already renders textures.
Images and canvases
crossOrigin = 'anonymous' before src for a cross-origin image, and configure the image server to allow it. Image uploads use premultiplied RGBA; the adapter handles top-left browser coordinates. sampling: 'nearest' preserves pixel edges.
Use a stable version until the pixels change. Increment it after drawing into the same canvas; replacing the image object also invalidates the upload. Every mounted surface can share a source identity without sharing a WebGL texture between contexts.
Animated drawing
frame.pixelWidth × frame.pixelHeight and calls draw on its display clock. This path uploads pixels each frame. Use sample for static sources or createRenderer(gl) to keep animation entirely on the GPU. Do not start a second animation clock inside a source.
GPU source
createRenderer(gl) returns { bytes, render(frame), dispose() }. render returns { target, version }, where target contains texture, framebuffer, width, height, bytes and dispose().
The texture must belong to gl, use bottom-left texture coordinates, and contain premultiplied, display-encoded RGBA. Establish your renderer’s own draw state. Linear Three.js render targets require the appropriate color conversion before Glassen samples them.
Create independent resources for every createRenderer call. The surface disposes those renderers when the final consumer leaves or the context is lost. It never destroys the caller’s source object. Make disposal idempotent and clean up partial allocations if construction fails.
Updates and activity
subscribe(notify) returns an unsubscribe function. Notify after source changes to wake suspended surfaces. setActive(active, owner) identifies each consumer so a shared producer can pause only when no consumers remain active. look(point) optionally receives pointer coordinates.
DOM capture is an optional adapter.