Skip to content

Support WEBGL_provoking_vertex - #338

Open
pboyer wants to merge 1 commit into
stackgl:masterfrom
aircadinc:webgl-provoking-vertex
Open

pboyer wants to merge 1 commit into
stackgl:masterfrom
aircadinc:webgl-provoking-vertex

Conversation

@pboyer

@pboyer pboyer commented Nov 24, 2026

Copy link
Copy Markdown

getExtension('WEBGL_provoking_vertex') returns null, so flat varyings always come from the last vertex. This offers the extension on WebGL2 contexts using ANGLE's GL_ANGLE_provoking_vertex, as Chrome does.

  • provokingVertexWEBGL(FIRST_VERTEX_CONVENTION_WEBGL) switches flat varyings to the first vertex; ANGLE sets INVALID_ENUM for any other mode, as the extension spec says.
  • getParameter(PROVOKING_VERTEX_WEBGL) returns the convention once the extension is enabled, and null with INVALID_ENUM before.
  • WebGL1 contexts don't offer it (the extension is WebGL2 only).
  • index.d.ts declares it in SupplementalExtensions, since TypeScript's DOM types don't; the README's table lists it.

Why it matters beyond correctness: under the last vertex convention, ANGLE's Metal backend rewrites the index buffer of every indexed draw whose program has flat varyings, and keeps the copies. A WebGL2 renderer that picks the first vertex convention in browsers for that reason can now do the same here.

Tests

test/webgl-provoking-vertex.js draws a flat-shaded triangle whose vertices are red, green, and blue: the pixel is blue under the default (last) convention, red once FIRST_VERTEX_CONVENTION_WEBGL is set, and blue again when set back. It also checks the constants, getParameter before and after enabling, and INVALID_ENUM for another mode.

On macOS (M4 Max), with ANGLE's default OpenGL backend and with ANGLE_DEFAULT_PLATFORM=metal:

  • test/webgl-provoking-vertex.js: 15/15
  • every other test/*.js that doesn't need @stackgl/gl-conformance (48 files): pass
  • test/types.js (node.mts, require.cts, dom.mts, custom-context-types.mts): pass
  • standard on the changed files: clean

Not run: the conformance suite (@stackgl/gl-conformance needs a GitHub Packages token), Linux, and Windows.

Context: we render a WebGL2 CAD engine (Emscripten) in Node with headless-gl master. Master runs it with no workarounds; this extension was the one thing missing. Thanks for the WebGL2 work this month.

🤖 Generated with Claude Code

getExtension('WEBGL_provoking_vertex') returned null, so flat varyings always came from the last vertex. headless-gl now offers it on WebGL2 contexts using ANGLE's GL_ANGLE_provoking_vertex, as Chrome does, and provokingVertexWEBGL(FIRST_VERTEX_CONVENTION_WEBGL) switches to the first vertex. getParameter(PROVOKING_VERTEX_WEBGL) returns the convention once the extension is enabled.

The first vertex convention matters beyond correctness: under the last vertex convention, ANGLE's Metal backend rewrites the index buffer of each indexed draw whose program has flat varyings, and keeps the copies.

index.d.ts declares the extension, since TypeScript's DOM types don't.

test/webgl-provoking-vertex.js checks that WebGL1 doesn't offer it, that getParameter is rejected before it is enabled, and that a flat-shaded triangle takes its last vertex's color, then its first's once set, then its last's again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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