mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
Add api for accessing backend texture via epi (#695)
* Define NativeTexture trait for offscreen rendering add demo for NativeTexture trait * write changelog * add comment for native texture example * formatting * add license of Rust logo * NativeTexture trait method rename remove duplicate function with native texture remove rust logo * deprecated notice for register_glium_texture,register_webgl_texture * collect deprecated notice
This commit is contained in:
@@ -40,7 +40,8 @@ use {
|
||||
std::hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
pub use copypasta::ClipboardContext; // TODO: remove
|
||||
pub use copypasta::ClipboardContext;
|
||||
use std::borrow::BorrowMut; // TODO: remove
|
||||
|
||||
pub struct GliumInputState {
|
||||
pub pointer_pos_in_points: Option<Pos2>,
|
||||
@@ -644,4 +645,8 @@ impl EguiGlium {
|
||||
&self.egui_ctx.texture(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn painter_mut(&mut self) -> &mut Painter {
|
||||
self.painter.borrow_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,8 +241,7 @@ impl Painter {
|
||||
id
|
||||
}
|
||||
|
||||
/// register glium texture as egui texture
|
||||
/// Usable for render to image rectangle
|
||||
#[deprecated = "Use: `NativeTexture::register_native_texture` instead"]
|
||||
pub fn register_glium_texture(
|
||||
&mut self,
|
||||
texture: glium::texture::SrgbTexture2d,
|
||||
@@ -319,3 +318,31 @@ impl Painter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl epi::NativeTexture for Painter {
|
||||
type Texture = glium::texture::srgb_texture2d::SrgbTexture2d;
|
||||
|
||||
fn register_native_texture(&mut self, native: Self::Texture) -> 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(native),
|
||||
}
|
||||
}
|
||||
}
|
||||
id
|
||||
}
|
||||
|
||||
fn replace_native_texture(&mut self, id: egui::TextureId, replacing: Self::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(replacing),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user