Skip to content

feat(shaders): Add outline shader - #988

Open
wouterlucas wants to merge 2 commits into
lightning-js:mainfrom
wouterlucas:feat/phase3-outline-shader
Open

wouterlucas wants to merge 2 commits into
lightning-js:mainfrom
wouterlucas:feat/phase3-outline-shader

Conversation

@wouterlucas

Copy link
Copy Markdown
Contributor

Similar to L2 - simple rect step outline shader

…am VAOs

Phase 1 of the L2-style fast paths: behavior-preserving reduction of
redundant WebGL attribute setup.

- WebGlContextWrapper now keeps per-VAO shadow state (enable flags,
  full vertexAttribPointer parameter sets, element-buffer binding) and
  skips native calls when the effective state is unchanged. The
  ARRAY_BUFFER bind still happens before a skipped pointer call.
  deleteBuffer/deleteVertexArray invalidate the shadow tables; the
  constructor seeds them from the live context; context restoration
  recreates the wrapper, so no stale GL assumptions survive.
- WebGlShaderProgram owns a lazily created VAO on WebGL2 and configures
  it once per BufferCollection layout (identity + layout version), so
  rebinding the same layout issues zero enable/pointer calls in steady
  state. WebGL1 keeps the per-attribute path, backed by the wrapper
  shadow state. detach() unbinds the VAO instead of disabling
  attributes; destroy() deletes it.
- BufferCollection gains a layout version (invalidateLayout) so caches
  keyed on (collection, version) reconfigure on real layout changes.
- createIndexBuffer returns the shared index buffer, stored on the
  renderer so each program VAO can bind it (ELEMENT_ARRAY_BUFFER is
  captured per VAO in WebGL2).

Tests: WebGlContextWrapper.attribState.test.ts (8) and
WebGlShaderProgram.vao.test.ts (4). Full suite 561 passed, build clean.
Phase 3 of the L2-style fast paths: an explicit, opt-in outline
primitive for simple rectangles — not a transparent replacement for the
anti-aliased general Border shader, which is unchanged.

- New Outline shader (src/core/shaders/webgl/Outline.ts +
  OutlineTemplate.ts, exported from exports/webgl-shaders.ts) with props
  { w = 0, color = 0xffffffff }: rectangular fill plus a uniform-width,
  hard-edged, inside-aligned stroke via step()/mix() on interpolated
  edge coordinates. No radius, gap or shadow; no u_dimensions, so
  mixed-size nodes batch together.
- Dedicated OutlineBuffer (7 floats/vertex incl. a_dimensions, 112 B per
  quad, capped at 16384 quads by the shared Uint16 index buffer) and
  OutlineRenderOp; WebGlRenderer.addQuad routes nodes whose shader type
  sets usesOutlineBuffer to this buffer. Full bufferData upload per pass
  in render()/renderRTTNodes(). Canvas renderer falls back to the
  default shader for this shader type.
- WebGlShaderType gains the usesOutlineBuffer flag; WebGlShaderNode and
  WebGlShaderProgram carry the outline buffer/routing. Existing Border
  and Default rendering paths are untouched.

Selection is explicit (shader: { type: Outline } via createShader);
plain rectangles keep the Default shader and border users keep Border.

Tests: WebGlRenderer.outline.test.ts (8). Full suite 569 passed on top
of phase 1, build clean, eslint 0 errors.

This branch has not been deployed

No deployments
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.

1 participant