Add functions to register textures in egui_web and egui_glium (#226)

* add texture registering function

* fmt

* Revert "add texture registering function"

This reverts commit f9b4db12

* make get_texture public to get render target owned by Painter .

* revert egui_web painter.rs change
This commit is contained in:
triangle drawer 2021-03-13 20:41:51 +09:00 committed by GitHub
parent 958aea922f
commit b1883d5d48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 7 deletions

View File

@ -250,7 +250,23 @@ 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,
@ -283,7 +299,7 @@ impl Painter {
}
}
fn get_texture(&self, texture_id: egui::TextureId) -> Option<&SrgbTexture2d> {
pub fn get_texture(&self, texture_id: egui::TextureId) -> Option<&SrgbTexture2d> {
match texture_id {
egui::TextureId::Egui => self.egui_texture.as_ref(),
egui::TextureId::User(id) => self

View File

@ -136,8 +136,7 @@ impl WebGlPainter {
}
}
}
fn get_texture(&self, texture_id: egui::TextureId) -> Option<&WebGlTexture> {
pub fn get_texture(&self, texture_id: egui::TextureId) -> Option<&WebGlTexture> {
match texture_id {
egui::TextureId::Egui => Some(&self.egui_texture),
egui::TextureId::User(id) => self
@ -190,7 +189,17 @@ 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());

View File

@ -139,7 +139,7 @@ impl WebGl2Painter {
}
}
fn get_texture(&self, texture_id: egui::TextureId) -> Option<&WebGlTexture> {
pub fn get_texture(&self, texture_id: egui::TextureId) -> Option<&WebGlTexture> {
match texture_id {
egui::TextureId::Egui => Some(&self.egui_texture),
egui::TextureId::User(id) => self
@ -192,7 +192,17 @@ 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());