Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ By @andyleiserson in [#9321](https://github.com/gfx-rs/wgpu/pull/9321).
#### GLES

- Added support for GLSL passthrough. By @inner-daemons in [#9064](https://github.com/gfx-rs/wgpu/pull/9064).
- Implement `Adapter::new_external()` for WebGL2 (just like EGL/WGL) to import an external WebGL2 rendering context, and expose the imported context back through `Adapter::adapter_context()` / `Device::context()`. By @pepperoni505 in [#9438](https://github.com/gfx-rs/wgpu/pull/9438).

#### DX12

Expand Down
38 changes: 38 additions & 0 deletions wgpu-hal/src/gles/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,44 @@ impl crate::Instance for Instance {
}
}

impl super::Adapter {
/// Creates a new external adapter from an existing WebGL2 rendering context.
///
/// # Safety
///
/// - The underlying WebGL2 context must be valid (not lost).
/// - The underlying WebGL2 context must be valid when interfacing with any objects returned by
/// wgpu-hal from this adapter.
/// - The underlying WebGL2 context must be valid when dropping this adapter and when
/// dropping any objects returned from this adapter.
pub unsafe fn new_external(
webgl2_context: web_sys::WebGl2RenderingContext,
options: wgt::GlBackendOptions,
) -> Option<crate::ExposedAdapter<super::Api>> {
let glow_context = glow::Context::from_webgl2_context(webgl2_context.clone());
unsafe {
Self::expose(
AdapterContext {
glow_context,
webgl2_context,
},
options,
)
}
}

pub fn adapter_context(&self) -> &AdapterContext {
&self.shared.context
}
}

impl super::Device {
/// Returns the underlying WebGL2 `AdapterContext`.
pub fn context(&self) -> &AdapterContext {
&self.shared.context
}
}

#[derive(Debug)]
pub struct Surface {
canvas: Canvas,
Expand Down