mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
[wgpu-hal] return None
in Adapter.surface_capabilities()
if the Surface
and the Adapter
don't share the same WebGL2 context
This commit is contained in:
parent
7910fd8059
commit
9f34acd567
@ -134,6 +134,9 @@ By @atlv24 in [#5383](https://github.com/gfx-rs/wgpu/pull/5383)
|
||||
When targeting WebGL2, it has always been the case that a surface had to be created before calling `request_adapter()`.
|
||||
We now make this requirement explicit.
|
||||
|
||||
Validation was also added to prevent configuring the surface with a device that doesn't share the same underlying
|
||||
WebGL2 context since this has never worked.
|
||||
|
||||
Calling `enumerate_adapters()` when targeting WebGPU used to return an empty `Vec` and since we now require users
|
||||
to pass a compatible surface when targeting WebGL2, having `enumerate_adapters()` doesn't make sense.
|
||||
|
||||
|
@ -1151,6 +1151,11 @@ impl crate::Adapter for super::Adapter {
|
||||
&self,
|
||||
surface: &super::Surface,
|
||||
) -> Option<crate::SurfaceCapabilities> {
|
||||
#[cfg(webgl)]
|
||||
if self.shared.context.webgl2_context != surface.webgl2_context {
|
||||
return None;
|
||||
}
|
||||
|
||||
if surface.presentable {
|
||||
let mut formats = vec![
|
||||
wgt::TextureFormat::Rgba8Unorm,
|
||||
|
@ -8,6 +8,7 @@ use super::TextureFormatDesc;
|
||||
/// with the `AdapterContext` API from the EGL implementation.
|
||||
pub struct AdapterContext {
|
||||
pub glow_context: glow::Context,
|
||||
pub webgl2_context: web_sys::WebGl2RenderingContext,
|
||||
}
|
||||
|
||||
impl AdapterContext {
|
||||
@ -124,9 +125,14 @@ impl crate::Instance for Instance {
|
||||
if let Some(surface_hint) = surface_hint {
|
||||
let gl = glow::Context::from_webgl2_context(surface_hint.webgl2_context.clone());
|
||||
|
||||
unsafe { super::Adapter::expose(AdapterContext { glow_context: gl }) }
|
||||
.into_iter()
|
||||
.collect()
|
||||
unsafe {
|
||||
super::Adapter::expose(AdapterContext {
|
||||
glow_context: gl,
|
||||
webgl2_context: surface_hint.webgl2_context.clone(),
|
||||
})
|
||||
}
|
||||
.into_iter()
|
||||
.collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
@ -172,7 +178,7 @@ impl crate::Instance for Instance {
|
||||
#[derive(Debug)]
|
||||
pub struct Surface {
|
||||
canvas: Canvas,
|
||||
webgl2_context: web_sys::WebGl2RenderingContext,
|
||||
pub(super) webgl2_context: web_sys::WebGl2RenderingContext,
|
||||
pub(super) swapchain: RwLock<Option<Swapchain>>,
|
||||
texture: Mutex<Option<glow::Texture>>,
|
||||
pub(super) presentable: bool,
|
||||
|
Loading…
Reference in New Issue
Block a user