Skip to content

feat(core): add ctx.resetState() for raw WebGL in effects - #272

Merged
fand merged 3 commits into
mainfrom
claude/gracious-lamport-r71za5
Nov 14, 2026
Merged

fand merged 3 commits into
mainfrom
claude/gracious-lamport-r71za5

Conversation

@fand

@fand fand commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Implements parts 1 and 4 of #268.

Changes

  • Add EffectContext.resetState(). It writes back the GL state the pipeline assumes, without any getParameter per call (the texture unit count is queried once and cached):
    • Draw/read framebuffer to the canvas, drawBuffers([BACK]), viewport to the whole canvas
    • DEPTH_TEST, CULL_FACE, STENCIL_TEST, SCISSOR_TEST, BLEND, POLYGON_OFFSET_FILL, RASTERIZER_DISCARD, SAMPLE_ALPHA_TO_COVERAGE, SAMPLE_COVERAGE disabled
    • depthMask(true), depthFunc(LESS), colorMask(true × 4), stencilMask(~0), frontFace(CCW), cullFace(BACK), clearColor(0, 0, 0, 0) (the player's per-frame clears rely on it without setting it)
    • Program, VAO, transform feedback and the ARRAY / PIXEL_PACK / PIXEL_UNPACK / UNIFORM / COPY_READ / COPY_WRITE buffer bindings unbound
    • Samplers unbound on every texture unit, active texture set to TEXTURE0
    • Pixel store reset to the WebGL defaults
    • No-op while the context is lost or after dispose. Works in init() / update() too.
  • The ctx.gl doc comment now lists the state VFX-JS relies on. Only ctx.draw / ctx.blit / ctx.clear turn off scissor; the rest of the frame doesn't, so the docs say to call resetState() before the next ctx.* call and before render() returns. It also notes that transform feedback must be ended first.
  • skills/vfx-js/references/effects.md: add resetState() to the context table and a rule for raw GL use.
  • Changeset: @vfx-js/core minor.

Not included

Testing

  • pnpm --filter @vfx-js/core test (451 passed, 6 new for resetState)
  • pnpm --filter @vfx-js/core lint
  • pnpm --filter docs test

…ects

Closes #268 (parts 1, 2 and 4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HvSd5bHZgXPhSZ8RoTxUAn
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

- resetState() also resets clearColor; the player's per-frame clears rely on it.
- ctx.gl docs: only ctx.draw/blit/clear turn off scissor, so call
  resetState() before render() returns too. List clearColor, transform
  feedback and UNPACK_COLORSPACE_CONVERSION_WEBGL in the assumed state.
- Note that transform feedback must be ended before resetState().
- Tests: dispose no-op, object spread, and the remaining reset calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HvSd5bHZgXPhSZ8RoTxUAn
@fand
fand merged commit 1c4c7d7 into main Nov 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants