Add WebGL2 Adapter::new_external() + context accessor#9438
Merged
cwfitzgerald merged 4 commits intoApr 29, 2026
Conversation
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.
wgpu-hal
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.
wgpu-halAdapter::new_external() + context accessor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Connections
#6152, which added
Adapter::new_externalfor WGL.Description
This PR adds
Adapter::new_externalto the WebGL2 backend, mirroring the existing functions of the same name ingles/egl.rsandgles/wgl.rs. It accepts an externally-createdweb_sys::WebGl2RenderingContextand produces an ExposedAdapter, sowgpu-hal` can render into a context that another party owns.It also adds
Adapter::adapter_context()andDevice::context()accessors that return the underlyingAdapterContext, so an embedder who brought their own context can reach the sharedWebGl2RenderingContextback for raw-GL interopTesting
Validated end-to-end in a browser against Mapbox GL JS's internal
WebGl2RenderingContext: the adapter is created successfully and itsAdapterInfo,Features, andCapabilitiespopulate correctly. No unit tests are added; this matches the existing pattern forAdapter::new_externalon EGL and WGL, neither of which is covered by tests.Squash or Rebase?
Squash
Checklist
wgpumay be affected behaviorally.CHANGELOG.mdentries for the user-facing effects of this change are present.