From 156e9c15c4160b14221f8320a6d1de7bba556377 Mon Sep 17 00:00:00 2001 From: fand Date: Tue, 26 Sep 2023 15:17:09 -0700 Subject: [PATCH] feat: add lose_context() / restore_context() --- src/web_sys.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/web_sys.rs b/src/web_sys.rs index 165c014..bfcd400 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -1328,6 +1328,23 @@ impl Context { }) .unwrap_or(false) } + + /// Simulate losing WebGL rendering context. + /// Only works when "WEBGL_lose_context" extension is available. + pub fn lose_context(&self) { + if let Some(ext) = &self.extensions.webgl_lose_context { + ext.lose_context() + } + } + + /// Simulate restoring WebGL rendering context. + /// Only works when "WEBGL_lose_context" extension is available. + /// This will panic when the context is not lost. + pub fn restore_context(&self) { + if let Some(ext) = &self.extensions.webgl_lose_context { + ext.restore_context() + } + } } new_key_type! { pub struct WebShaderKey; }