diff --git a/docs/egui_demo_app_bg.wasm b/docs/egui_demo_app_bg.wasm deleted file mode 100644 index 013c83f55..000000000 Binary files a/docs/egui_demo_app_bg.wasm and /dev/null differ diff --git a/egui_glium/src/painter.rs b/egui_glium/src/painter.rs index cb2541834..3351df985 100644 --- a/egui_glium/src/painter.rs +++ b/egui_glium/src/painter.rs @@ -250,7 +250,17 @@ impl Painter { self.user_textures.push(Some(Default::default())); id } - + /// register glium texture as egui texture + /// Usable for render to image rectangle + pub fn register_glium_texture(&mut self,texture:glium::texture::SrgbTexture2d)->egui::TextureId{ + let id= self.alloc_user_texture(); + if let egui::TextureId::User(id)=id{ + if let Some(Some(user_texture))=self.user_textures.get_mut(id as usize){ + *user_texture=UserTexture{ pixels: vec![], gl_texture: Some(texture) } + } + } + id + } pub fn set_user_texture( &mut self, id: egui::TextureId, diff --git a/egui_web/src/painter.rs b/egui_web/src/painter.rs index fa1d84b2d..853b98e5f 100644 --- a/egui_web/src/painter.rs +++ b/egui_web/src/painter.rs @@ -1,4 +1,5 @@ use wasm_bindgen::prelude::JsValue; +use web_sys::WebGlTexture; pub trait Painter { fn as_tex_allocator(&mut self) -> &mut dyn epi::TextureAllocator; diff --git a/egui_web/src/webgl1.rs b/egui_web/src/webgl1.rs index 855d5becf..54686bbdd 100644 --- a/egui_web/src/webgl1.rs +++ b/egui_web/src/webgl1.rs @@ -4,10 +4,7 @@ use { web_sys::{WebGlBuffer, WebGlProgram, WebGlRenderingContext, WebGlShader, WebGlTexture}, }; -use egui::{ - emath::{clamp, vec2}, - epaint::{Color32, Texture}, -}; +use egui::{emath::{clamp, vec2}, epaint::{Color32, Texture}}; type Gl = WebGlRenderingContext; @@ -190,7 +187,13 @@ impl WebGlPainter { } } } - + pub fn register_webgl_texture(&mut self, texture:WebGlTexture) -> egui::TextureId { + let id= self.alloc_user_texture_index(); + if let Some(Some(user_texture))=self.user_textures.get_mut(id){ + *user_texture=UserTexture{ size: (0, 0), pixels: vec![], gl_texture: Some(texture) } + } + egui::TextureId::User(id as u64) + } fn paint_mesh(&self, mesh: &egui::epaint::Mesh16) -> Result<(), JsValue> { debug_assert!(mesh.is_valid()); diff --git a/egui_web/src/webgl2.rs b/egui_web/src/webgl2.rs index 7e741be4d..27cc97d68 100644 --- a/egui_web/src/webgl2.rs +++ b/egui_web/src/webgl2.rs @@ -192,7 +192,13 @@ impl WebGl2Painter { } } } - + pub fn register_webgl_texture(&mut self, texture:WebGlTexture) ->egui::TextureId { + let id= self.alloc_user_texture_index(); + if let Some(Some(user_texture))=self.user_textures.get_mut(id){ + *user_texture=UserTexture{ size: (0, 0), pixels: vec![], gl_texture: Some(texture) } + } + egui::TextureId::User(id as u64) + } fn paint_mesh(&self, mesh: &egui::epaint::Mesh16) -> Result<(), JsValue> { debug_assert!(mesh.is_valid());