Skip to content

Add WebGL2 Adapter::new_external() + context accessor#9438

Merged
cwfitzgerald merged 4 commits into
gfx-rs:trunkfrom
pepperoni505:feat/webgl2-external-context
Apr 29, 2026
Merged

Add WebGL2 Adapter::new_external() + context accessor#9438
cwfitzgerald merged 4 commits into
gfx-rs:trunkfrom
pepperoni505:feat/webgl2-external-context

Conversation

@pepperoni505
Copy link
Copy Markdown
Contributor

@pepperoni505 pepperoni505 commented Apr 17, 2026

Connections
#6152, which added Adapter::new_external for WGL.

Description
This PR adds Adapter::new_external to the WebGL2 backend, mirroring the existing functions of the same name in gles/egl.rs and gles/wgl.rs. It accepts an externally-created web_sys::WebGl2RenderingContext and produces an ExposedAdapter, so wgpu-hal` can render into a context that another party owns.

It also adds Adapter::adapter_context() and Device::context() accessors that return the underlying AdapterContext, so an embedder who brought their own context can reach the shared WebGl2RenderingContext back for raw-GL interop

Testing
Validated end-to-end in a browser against Mapbox GL JS's internal WebGl2RenderingContext: the adapter is created successfully and its AdapterInfo, Features, and Capabilities populate correctly. No unit tests are added; this matches the existing pattern for Adapter::new_external on EGL and WGL, neither of which is covered by tests.

Squash or Rebase?
Squash

Checklist

  • I self-reviewed and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

Mirrors the existing Adapter::new_external in gles/egl.rs and
gles/wgl.rs for importing an externally-created WebGL2 rendering
context. The caller retains ownership of the canvas and the context;
no Surface is created.
@pepperoni505 pepperoni505 changed the title Add Adapter::new_external() for WebGL2 Add Adapter::new_external() for WebGL2 in wgpu-hal Apr 17, 2026
Pair with Adapter::new_external: embedders that bring their own
WebGL2 context need a way to reach it back for interop. Add
Adapter::adapter_context() and Device::context(), both returning
the AdapterContext so callers can drive raw-GL work on the shared
glow::Context or web_sys::WebGl2RenderingContext.
@pepperoni505 pepperoni505 changed the title Add Adapter::new_external() for WebGL2 in wgpu-hal Add WebGL2 Adapter::new_external() + context accessor Apr 17, 2026
Copy link
Copy Markdown
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) April 29, 2026 20:34
@cwfitzgerald cwfitzgerald merged commit 632ab0f into gfx-rs:trunk Apr 29, 2026
61 of 62 checks passed
@pepperoni505 pepperoni505 deleted the feat/webgl2-external-context branch April 30, 2026 13:13
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