mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 17:02:32 +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()`.
|
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.
|
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
|
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.
|
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,
|
&self,
|
||||||
surface: &super::Surface,
|
surface: &super::Surface,
|
||||||
) -> Option<crate::SurfaceCapabilities> {
|
) -> Option<crate::SurfaceCapabilities> {
|
||||||
|
#[cfg(webgl)]
|
||||||
|
if self.shared.context.webgl2_context != surface.webgl2_context {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
if surface.presentable {
|
if surface.presentable {
|
||||||
let mut formats = vec![
|
let mut formats = vec![
|
||||||
wgt::TextureFormat::Rgba8Unorm,
|
wgt::TextureFormat::Rgba8Unorm,
|
||||||
|
@ -8,6 +8,7 @@ use super::TextureFormatDesc;
|
|||||||
/// with the `AdapterContext` API from the EGL implementation.
|
/// with the `AdapterContext` API from the EGL implementation.
|
||||||
pub struct AdapterContext {
|
pub struct AdapterContext {
|
||||||
pub glow_context: glow::Context,
|
pub glow_context: glow::Context,
|
||||||
|
pub webgl2_context: web_sys::WebGl2RenderingContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AdapterContext {
|
impl AdapterContext {
|
||||||
@ -124,9 +125,14 @@ impl crate::Instance for Instance {
|
|||||||
if let Some(surface_hint) = surface_hint {
|
if let Some(surface_hint) = surface_hint {
|
||||||
let gl = glow::Context::from_webgl2_context(surface_hint.webgl2_context.clone());
|
let gl = glow::Context::from_webgl2_context(surface_hint.webgl2_context.clone());
|
||||||
|
|
||||||
unsafe { super::Adapter::expose(AdapterContext { glow_context: gl }) }
|
unsafe {
|
||||||
.into_iter()
|
super::Adapter::expose(AdapterContext {
|
||||||
.collect()
|
glow_context: gl,
|
||||||
|
webgl2_context: surface_hint.webgl2_context.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.into_iter()
|
||||||
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
@ -172,7 +178,7 @@ impl crate::Instance for Instance {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Surface {
|
pub struct Surface {
|
||||||
canvas: Canvas,
|
canvas: Canvas,
|
||||||
webgl2_context: web_sys::WebGl2RenderingContext,
|
pub(super) webgl2_context: web_sys::WebGl2RenderingContext,
|
||||||
pub(super) swapchain: RwLock<Option<Swapchain>>,
|
pub(super) swapchain: RwLock<Option<Swapchain>>,
|
||||||
texture: Mutex<Option<glow::Texture>>,
|
texture: Mutex<Option<glow::Texture>>,
|
||||||
pub(super) presentable: bool,
|
pub(super) presentable: bool,
|
||||||
|
Loading…
Reference in New Issue
Block a user