Repository navigation
Releases
v1.1.0
Minor Changes
-
3b63087: Everything can be cleaned up, e.g. when a React component unmounts:
- New
renderer.delete()frees its program, vertex arrays, transform feedback objects and the buffers made from attributedata. A deleted renderer does nothing. - New
framebuffer.delete()frees its framebuffers, textures and depth buffers. looptakes asignalthat stops it for good.createContext'ssignalalso removes the canvas ifcreateContextcreated it. A canvas you pass in is kept, with its context.loadTexturetakes asignal; aborting it before the image loads rejects without making a texture.
- New
-
7d006b3: Add
createContextandloopto cut setup boilerplate.createContext(options)returns a WebGL2 context and keeps the canvas's pixel size matched to its CSS size and the device pixel ratio (capped at 2 by default, and updated on zoom or when moving to another display). With no options it creates a canvas that fills the window. Options:canvas,container,dpr,autoResize,onResize(width, height, gl),attributesandsignal.loop(fn)callsfn(time, delta, frame)every animation frame, in seconds, and returns{ start, stop, running }. Time spent stopped isn't counted, so animations resume where they left off.
const gl = createContext(); loop((time) => { /* draw */ });
-
73083d1: Data textures and
flipY:createTexturecan make a texture from a typed array: passwidth,heightanddatainstead ofimg, or leave outdatafor an empty texture. Rows don't need to be 4-byte aligned.updateTextureaccepts a typed array withwidthandheight, which may differ from before.- Float types get a sized internal format (e.g.
RG32F), skip mipmaps by default, and useNEARESTfiltering where 32-bit float can't be filtered linearly. - New
flipYoption on both, so an image's top row ends up at texture coordinate y = 1. - Pixel store settings changed for an upload are restored afterwards.
-
51a3b61: Framebuffer and texture features:
createFrameBuffer({ type: gl.FLOAT })andgl.HALF_FLOATmake float render targets. The sized internal format (e.g.RGBA32F) and theEXT_color_buffer_floatextension are handled, and 32-bit float targets fall back toNEARESTfiltering where linear filtering of them isn't supported.createFrameBuffer({ depth: true })adds a depth buffer so depth testing works when drawing into the target. Depth buffers are freed onresize.createFrameBufferthrows a clear error if the framebuffer is incomplete, naming the reason, instead of drawing nothing.- New
loadTexture(gl, url, options)loads an image and resolves with a texture. - New
updateTexture(gl, texture, source)uploads new contents, such as a video frame, and regenerates mipmaps if the texture uses them.
-
4011c31: The package now includes
dist/simplegl.js, the whole library as one ES module file for copying into projects that can't install packages. It's available from unpkg and jsDelivr and attached to each GitHub release. Also adds a README. -
7488ccc: Automatic texture units and
setUniforms:- Every sampler uniform gets its own texture unit when the renderer is created. Pass a texture, or a framebuffer target such as
fbo.read, tobindUniformand it's bound to that unit whenever the renderer draws, so renderers don't interfere with each other's textures. Passing a unit number still works for textures bound by hand. - New
renderer.setUniforms({ ... })sets several uniforms at once, skipping names the shader doesn't use.
- Every sampler uniform gets its own texture unit when the renderer is created. Pass a texture, or a framebuffer target such as
-
7531ac6: Draw transform feedback results with another program:
renderer.outputsgives the buffers holding a transform feedback renderer's latest output, by attribute name.- An attribute declared as
{ from: simulation }reads the simulation's output of the same name (oroutput: "a_name"), following it each frame as the buffers swap.
Patch Changes
-
bfaa8c6: Declare the package as ES modules (
"type": "module") and publish onlylib/, leaving the demo pages out of the npm tarball. Releases are now published from CI with npm trusted publishing and provenance. -
281659f: Fix framebuffers and textures:
createFrameBufferandcreateTexturenow throw a clear error when given a WebGL1 context. The library already required WebGL2 (createRendereruses vertex arrays and transform feedback); these two just failed less obviously.createFrameBufferrestores the previous draw framebuffer and texture bindings, so drawing after creating one no longer goes into the new framebuffer by mistake. The read framebuffer binding is left untouched.framebuffer.resize()deletes the old textures and framebuffers instead of leaking them, keepssingularframebuffers to one target, and no longer re-uploads the originaldata(which no longer fits the new size).createTexturethrows a clear error whenimgis missing, or whentargetisn'tgl.TEXTURE_2D(other targets never uploaded correctly).createTexturenow defaults to trilinear filtering (LINEAR_MIPMAP_LINEAR) when mipmaps are generated. The previous default,NEAREST_MIPMAP_LINEAR, made minified textures look blocky. PassminFilterto keep the old look.
-
d626be4: Fix programs and uniforms:
createRendererno longer throws whenattributesis omitted, no longer modifies the attributes object you pass in, and no longer writeswindow.attributes.createProgramno longer shares the program through a module-level variable, andlinkProgram(gl, program)is now exported so programs made withcreateProgramcan be linked. Shaders are freed after linking or a failed compile.bindUniformswitches to the renderer's program when another one is in use, instead of setting the uniform on the wrong program.float[]uniforms acceptFloat32Arrayvalues (they were silently ignored).- Array uniforms can be set by their plain name (
u_values) as well asu_values[0]. - Adds the missing WebGL2 uniform types:
uint/uvec*, non-square matrices, and 3D, array, shadow and integer samplers. - The renderer now also returns its
program.
-
3afc549: Fix vertex arrays and transform feedback:
- Transform feedback outputs are written to the right buffers when other attributes come before them. They were rebound every frame using the attribute's position instead of its varying index.
render()binds the transform feedback object only while drawing, so its buffers can be read or drawn from afterwards without a GL error.- Only transform feedback attributes get two buffers. Other attributes are shared between the two vertex arrays instead of being uploaded twice.
createRendererthrows a clear error when transform feedback is used with a mode other thangl.POINTS,gl.LINESorgl.TRIANGLES, and when a transform feedback attribute has nodata.ELEMENT_ARRAY_BUFFERattributes are bound as the vertex array's index buffer instead of as a vertex attribute.- The vertex array is no longer left bound after creation, so later buffer binds can't change it.
-
99d54a7: Every export now has JSDoc with types, which editors show as you type and the new API reference is generated from. Option objects and return values are documented as named types (
RendererOptions,Renderer,FrameBufferand so on). -
142f1d7: Clearer errors when setting up a program:
- Shader compile errors name the shader (vertex or fragment) and show the failing source lines with line numbers. If the source doesn't start with
#version 300 es, the error says so. - Link errors start with "Program failed to link".
createProgram(and socreateRenderer) throws a clear error when given a WebGL1 context or missing shader source, instead of failing later with "createVertexArray is not a function" or a GLSL syntax error aboutundefined.- A compile failure caused by a lost context says so instead of throwing an empty error.
- Shader compile errors name the shader (vertex or fragment) and show the failing source lines with line numbers. If the source doesn't start with