1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-28 07:23:13 -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:
triangle drawer
2021-09-05 18:00:45 +09:00
committed by GitHub
parent acf9d0114d
commit 203d571c8b
10 changed files with 227 additions and 5 deletions

View File

@@ -223,6 +223,7 @@ impl WebGlPainter {
}
}
#[deprecated = "Use: `NativeTexture::register_native_texture` instead"]
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) {
@@ -370,6 +371,34 @@ impl epi::TextureAllocator for WebGlPainter {
}
}
impl epi::NativeTexture for WebGlPainter {
type Texture = WebGlTexture;
fn register_native_texture(&mut self, native: Self::Texture) -> 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(native),
}
}
egui::TextureId::User(id as u64)
}
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 {
size: (0, 0),
pixels: vec![],
gl_texture: Some(replacing),
}
}
}
}
}
impl crate::Painter for WebGlPainter {
fn as_tex_allocator(&mut self) -> &mut dyn epi::TextureAllocator {
self

View File

@@ -202,6 +202,7 @@ impl WebGl2Painter {
}
}
#[deprecated = "Use: `NativeTexture::register_native_texture` instead"]
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) {
@@ -349,6 +350,34 @@ impl epi::TextureAllocator for WebGl2Painter {
}
}
impl epi::NativeTexture for WebGl2Painter {
type Texture = WebGlTexture;
fn register_native_texture(&mut self, native: Self::Texture) -> 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(native),
}
}
egui::TextureId::User(id as u64)
}
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 {
size: (0, 0),
pixels: vec![],
gl_texture: Some(replacing),
}
}
}
}
}
impl crate::Painter for WebGl2Painter {
fn as_tex_allocator(&mut self) -> &mut dyn epi::TextureAllocator {
self