Compare commits

...

4 commits

Author SHA1 Message Date
Emil Ernerfeldt
a26f43dfe9 Make sure to destroy the custom 3d example 2022-03-22 09:17:45 +01:00
Emil Ernerfeldt
9028ce7a98 Fix serialization issue 2022-03-22 09:14:29 +01:00
Emil Ernerfeldt
3ff55be4be WIP: move 3d rendering example into egui_demo_lib 2022-03-22 08:46:27 +01:00
Emil Ernerfeldt
4922b1912b Move epi-code from egui_glow into eframe 2022-03-22 08:46:01 +01:00
15 changed files with 328 additions and 116 deletions

3
Cargo.lock generated
View file

@ -986,6 +986,7 @@ dependencies = [
"ehttp", "ehttp",
"epi", "epi",
"glow", "glow",
"glutin",
"image", "image",
"parking_lot 0.12.0", "parking_lot 0.12.0",
"poll-promise", "poll-promise",
@ -1040,10 +1041,12 @@ dependencies = [
"criterion", "criterion",
"egui", "egui",
"egui_extras", "egui_extras",
"egui_glow",
"ehttp", "ehttp",
"enum-map", "enum-map",
"epi", "epi",
"image", "image",
"parking_lot 0.12.0",
"poll-promise", "poll-promise",
"serde", "serde",
"syntect", "syntect",

View file

@ -46,16 +46,18 @@ screen_reader = [
[dependencies] [dependencies]
egui = { version = "0.17.0", path = "../egui", default-features = false } egui = { version = "0.17.0", path = "../egui", default-features = false }
epi = { version = "0.17.0", path = "../epi" } epi = { version = "0.17.0", path = "../epi" }
glow = "0.11"
parking_lot = "0.12"
# native: # native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false, features = [ egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false, features = [
"clipboard", "clipboard",
"epi",
"links", "links",
"winit", "winit",
] } ] }
egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false } egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false }
glutin = "0.28.0"
# web: # web:
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]

View file

@ -98,43 +98,8 @@ pub fn start_web(canvas_id: &str, app_creator: AppCreator) -> Result<(), wasm_bi
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// When compiling natively // When compiling natively
/// This is how you start a native (desktop) app.
///
/// The first argument is name of your app, used for the title bar of the native window
/// and the save location of persistence (see [`epi::App::save`]).
///
/// Call from `fn main` like this:
/// ``` no_run
/// use eframe::egui;
///
/// fn main() {
/// let native_options = eframe::NativeOptions::default();
/// eframe::run_native("MyApp", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc))));
/// }
///
/// #[derive(Default)]
/// struct MyEguiApp {}
///
/// impl MyEguiApp {
/// fn new(cc: &eframe::CreationContext<'_>) -> Self {
/// // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
/// // Restore app state using cc.storage (requires the "persistence" feature).
/// // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
/// // for e.g. egui::PaintCallback.
/// Self::default()
/// }
/// }
///
/// impl eframe::App for MyEguiApp {
/// fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
/// egui::CentralPanel::default().show(ctx, |ui| {
/// ui.heading("Hello World!");
/// });
/// }
/// }
/// ```
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
#[allow(clippy::needless_pass_by_value)] mod native;
pub fn run_native(app_name: &str, native_options: NativeOptions, app_creator: AppCreator) -> ! {
egui_glow::run(app_name, &native_options, app_creator) #[cfg(not(target_arch = "wasm32"))]
} pub use native::run_native;

View file

@ -32,18 +32,56 @@ fn create_display(
pub use epi::NativeOptions; pub use epi::NativeOptions;
/// Run an egui app /// This is how you start a native (desktop) app.
///
/// The first argument is name of your app, used for the title bar of the native window
/// and the save location of persistence (see [`epi::App::save`]).
///
/// Call from `fn main` like this:
/// ``` no_run
/// use eframe::egui;
///
/// fn main() {
/// let native_options = eframe::NativeOptions::default();
/// eframe::run_native("MyApp", native_options, |cc| Box::new(MyEguiApp::new(cc)));
/// }
///
/// #[derive(Default)]
/// struct MyEguiApp {}
///
/// impl MyEguiApp {
/// fn new(cc: &eframe::CreationContext<'_>) -> Self {
/// // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
/// // Restore app state using cc.storage (requires the "persistence" feature).
/// // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
/// // for e.g. egui::PaintCallback.
/// Self::default()
/// }
/// }
///
/// impl eframe::App for MyEguiApp {
/// fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
/// egui::CentralPanel::default().show(ctx, |ui| {
/// ui.heading("Hello World!");
/// });
/// }
/// }
/// ```
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn run(app_name: &str, native_options: &epi::NativeOptions, app_creator: epi::AppCreator) -> ! { pub fn run_native(
app_name: &str,
native_options: epi::NativeOptions,
app_creator: epi::AppCreator,
) -> ! {
let persistence = egui_winit::epi::Persistence::from_app_name(app_name); let persistence = egui_winit::epi::Persistence::from_app_name(app_name);
let window_settings = persistence.load_window_settings(); let window_settings = persistence.load_window_settings();
let window_builder = let window_builder =
egui_winit::epi::window_builder(native_options, &window_settings).with_title(app_name); egui_winit::epi::window_builder(&native_options, &window_settings).with_title(app_name);
let event_loop = winit::event_loop::EventLoop::with_user_event(); let event_loop = winit::event_loop::EventLoop::with_user_event();
let (gl_window, gl) = create_display(window_builder, &event_loop); let (gl_window, gl) = create_display(window_builder, &event_loop);
let gl = std::rc::Rc::new(gl); let gl = std::rc::Rc::new(gl);
let mut painter = crate::Painter::new(gl.clone(), None, "") let mut painter = egui_glow::Painter::new(gl.clone(), None, "")
.unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error)); .unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error));
let mut integration = egui_winit::epi::EpiIntegration::new( let mut integration = egui_winit::epi::EpiIntegration::new(

View file

@ -36,10 +36,12 @@ syntax_highlighting = ["syntect"]
[dependencies] [dependencies]
egui = { version = "0.17.0", path = "../egui", default-features = false } egui = { version = "0.17.0", path = "../egui", default-features = false }
epi = { version = "0.17.0", path = "../epi" } epi = { version = "0.17.0", path = "../epi" }
egui_glow = { version = "0.17.0", path = "../egui_glow" } # for custom_3d app
chrono = { version = "0.4", optional = true, features = ["js-sys", "wasmbind"] } chrono = { version = "0.4", optional = true, features = ["js-sys", "wasmbind"] }
enum-map = { version = "2", features = ["serde"] } enum-map = { version = "2", features = ["serde"] }
tracing = "0.1" tracing = "0.1"
parking_lot = "0.12"
unicode_names2 = { version = "0.5.0", default-features = false } unicode_names2 = { version = "0.5.0", default-features = false }
# feature "http": # feature "http":

View file

@ -0,0 +1,193 @@
//! This demo shows how to embed 3D rendering using [`glow`](https://github.com/grovesNL/glow) in `epi`.
//!
//! This is very advanced usage, and you need to be careful.
//!
//! If you want an easier way to show 3D graphics with egui, take a look at:
//! * [`bevy_egui`](https://github.com/mvlabat/bevy_egui)
//! * [`three-d`](https://github.com/asny/three-d)
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
#![allow(unsafe_code)]
use epi::{glow, Renderer as _};
use parking_lot::Mutex;
use std::sync::Arc;
#[derive(Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct Custom3dApp {
angle: f32,
/// Behind an `Arc<Mutex<…>>` so we can pass it to [`egui::PaintCallback`] and paint later.
/// Behind an `Option` so we can implement `serde::Deserialize.
#[cfg_attr(feature = "serde", serde(skip))]
rotating_triangle: Arc<Mutex<Option<RotatingTriangle>>>,
}
impl epi::App for Custom3dApp {
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.vertical_centered(|ui| {
ui.add(crate::__egui_github_link_file!());
});
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.label("The triangle is being painted using ");
ui.hyperlink_to("glow", "https://github.com/grovesNL/glow");
ui.label(" (OpenGL).");
});
egui::ScrollArea::both().show(ui, |ui| {
egui::Frame::canvas(ui.style()).show(ui, |ui| {
self.custom_painting(ui);
});
ui.label("Drag to rotate!");
});
});
}
fn on_exit(&mut self, gl: &glow::Context) {
self.rotating_triangle.lock().destroy(gl);
}
}
impl Custom3dApp {
fn custom_painting(&mut self, ui: &mut egui::Ui) {
let (rect, response) =
ui.allocate_exact_size(egui::Vec2::splat(256.0), egui::Sense::drag());
self.angle += response.drag_delta().x * 0.01;
let angle = self.angle;
let rotating_triangle = self.rotating_triangle.clone();
let callback = egui::epaint::PaintCallback {
rect,
callback: std::sync::Arc::new(move |render_ctx| {
if let Some(painter) = render_ctx.downcast_ref::<egui_glow::Painter>() {
let mut rotating_triangle = rotating_triangle.lock();
let rotating_triangle = rotating_triangle
.get_or_insert_with(|| RotatingTriangle::new(painter.gl()));
rotating_triangle.paint(painter.gl(), angle);
} else {
eprintln!("Can't do custom painting because we are not using a glow context");
}
}),
};
ui.painter().add(callback);
}
}
struct RotatingTriangle {
program: glow::Program,
vertex_array: glow::VertexArray,
}
impl RotatingTriangle {
fn new(gl: &glow::Context) -> Self {
use glow::HasContext as _;
let shader_version = if cfg!(target_arch = "wasm32") {
"#version 300 es"
} else {
"#version 410"
};
unsafe {
let program = gl.create_program().expect("Cannot create program");
let (vertex_shader_source, fragment_shader_source) = (
r#"
const vec2 verts[3] = vec2[3](
vec2(0.0, 1.0),
vec2(-1.0, -1.0),
vec2(1.0, -1.0)
);
const vec4 colors[3] = vec4[3](
vec4(1.0, 0.0, 0.0, 1.0),
vec4(0.0, 1.0, 0.0, 1.0),
vec4(0.0, 0.0, 1.0, 1.0)
);
out vec4 v_color;
uniform float u_angle;
void main() {
v_color = colors[gl_VertexID];
gl_Position = vec4(verts[gl_VertexID], 0.0, 1.0);
gl_Position.x *= cos(u_angle);
}
"#,
r#"
precision mediump float;
in vec4 v_color;
out vec4 out_color;
void main() {
out_color = v_color;
}
"#,
);
let shader_sources = [
(glow::VERTEX_SHADER, vertex_shader_source),
(glow::FRAGMENT_SHADER, fragment_shader_source),
];
let shaders: Vec<_> = shader_sources
.iter()
.map(|(shader_type, shader_source)| {
let shader = gl
.create_shader(*shader_type)
.expect("Cannot create shader");
gl.shader_source(shader, &format!("{}\n{}", shader_version, shader_source));
gl.compile_shader(shader);
if !gl.get_shader_compile_status(shader) {
panic!("{}", gl.get_shader_info_log(shader));
}
gl.attach_shader(program, shader);
shader
})
.collect();
gl.link_program(program);
if !gl.get_program_link_status(program) {
panic!("{}", gl.get_program_info_log(program));
}
for shader in shaders {
gl.detach_shader(program, shader);
gl.delete_shader(shader);
}
let vertex_array = gl
.create_vertex_array()
.expect("Cannot create vertex array");
Self {
program,
vertex_array,
}
}
}
fn destroy(self, gl: &glow::Context) {
use glow::HasContext as _;
unsafe {
gl.delete_program(self.program);
gl.delete_vertex_array(self.vertex_array);
}
}
fn paint(&self, gl: &glow::Context, angle: f32) {
use glow::HasContext as _;
unsafe {
gl.use_program(Some(self.program));
gl.uniform_1_f32(
gl.get_uniform_location(self.program, "u_angle").as_ref(),
angle,
);
gl.bind_vertex_array(Some(self.vertex_array));
gl.draw_arrays(glow::TRIANGLES, 0, 3);
}
}
}

View file

@ -1,10 +1,12 @@
mod color_test; mod color_test;
mod custom_3d;
mod demo; mod demo;
mod fractal_clock; mod fractal_clock;
#[cfg(feature = "http")] #[cfg(feature = "http")]
mod http_app; mod http_app;
pub use color_test::ColorTest; pub use color_test::ColorTest;
pub use custom_3d::Custom3dApp;
pub use demo::DemoApp; pub use demo::DemoApp;
pub use fractal_clock::FractalClock; pub use fractal_clock::FractalClock;
#[cfg(feature = "http")] #[cfg(feature = "http")]

View file

@ -1,7 +1,6 @@
/// All the different demo apps. /// All the different demo apps.
#[derive(Default)] #[derive(Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct Apps { pub struct Apps {
demo: crate::apps::DemoApp, demo: crate::apps::DemoApp,
easy_mark_editor: crate::easy_mark::EasyMarkEditor, easy_mark_editor: crate::easy_mark::EasyMarkEditor,
@ -9,6 +8,7 @@ pub struct Apps {
http: crate::apps::HttpApp, http: crate::apps::HttpApp,
clock: crate::apps::FractalClock, clock: crate::apps::FractalClock,
color_test: crate::apps::ColorTest, color_test: crate::apps::ColorTest,
custom_3d: crate::apps::Custom3dApp,
} }
impl Apps { impl Apps {
@ -32,6 +32,11 @@ impl Apps {
"colors", "colors",
&mut self.color_test as &mut dyn epi::App, &mut self.color_test as &mut dyn epi::App,
), ),
(
"🔺 3D painting",
"custom_3d",
&mut self.custom_3d as &mut dyn epi::App,
),
] ]
.into_iter() .into_iter()
} }
@ -127,6 +132,15 @@ impl epi::App for WrapApp {
self.ui_file_drag_and_drop(ctx); self.ui_file_drag_and_drop(ctx);
} }
fn on_exit(&mut self, gl: &glow::Context) {
self.apps.demo.on_exit(gl);
self.apps.easy_mark_editor.on_exit(gl);
self.apps.http.on_exit(gl);
self.apps.clock.on_exit(gl);
self.apps.color_test.on_exit(gl);
self.apps.custom_3d.on_exit(gl);
}
} }
impl WrapApp { impl WrapApp {

View file

@ -1,4 +1,4 @@
//! Example how to use [`epi::NativeTexture`] with glium. //! Example how to use native textures with glium painter.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

View file

@ -38,13 +38,7 @@ default_fonts = ["egui/default_fonts"]
links = ["egui-winit/links"] links = ["egui-winit/links"]
# enable persisting native window options and egui memory # enable persisting native window options and egui memory
persistence = [ persistence = ["egui-winit/persistence", "egui/persistence"]
"egui-winit/persistence",
"egui/persistence",
"epi", # also implied by the lines below, see https://github.com/rust-lang/cargo/issues/8832
"epi/file_storage",
"epi/persistence",
]
# experimental support for a screen reader # experimental support for a screen reader
screen_reader = ["egui-winit/screen_reader"] screen_reader = ["egui-winit/screen_reader"]
@ -58,7 +52,7 @@ winit = ["egui-winit", "glutin"]
egui = { version = "0.17.0", path = "../egui", default-features = false, features = [ egui = { version = "0.17.0", path = "../egui", default-features = false, features = [
"convert_bytemuck", "convert_bytemuck",
] } ] }
epi = { version = "0.17.0", path = "../epi", optional = true } epi = { version = "0.17.0", path = "../epi" }
bytemuck = "1.7" bytemuck = "1.7"
glow = "0.11" glow = "0.11"

View file

@ -2,7 +2,6 @@
//! //!
//! The main type you want to use is [`EguiGlow`]. //! The main type you want to use is [`EguiGlow`].
//! //!
//! This library is an [`epi`] backend.
//! If you are writing an app, you may want to look at [`eframe`](https://docs.rs/eframe) instead. //! If you are writing an app, you may want to look at [`eframe`](https://docs.rs/eframe) instead.
// Forbid warnings in release builds: // Forbid warnings in release builds:
@ -99,9 +98,3 @@ mod vao_emulate;
pub mod winit; pub mod winit;
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))] #[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
pub use winit::*; pub use winit::*;
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
mod epi_backend;
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
pub use epi_backend::{run, NativeOptions};

View file

@ -6,6 +6,7 @@ use egui::{
emath::Rect, emath::Rect,
epaint::{Color32, Mesh, Primitive, Vertex}, epaint::{Color32, Mesh, Primitive, Vertex},
}; };
use epi::Renderer as _;
use glow::HasContext; use glow::HasContext;
use memoffset::offset_of; use memoffset::offset_of;
@ -19,6 +20,31 @@ pub use glow::Context;
const VERT_SRC: &str = include_str!("shader/vertex.glsl"); const VERT_SRC: &str = include_str!("shader/vertex.glsl");
const FRAG_SRC: &str = include_str!("shader/fragment.glsl"); const FRAG_SRC: &str = include_str!("shader/fragment.glsl");
// ----------------------------------------------------------------------------
#[derive(Copy, Clone)]
pub enum TextureFilter {
Linear,
Nearest,
}
impl Default for TextureFilter {
fn default() -> Self {
TextureFilter::Linear
}
}
impl TextureFilter {
pub(crate) fn glow_code(&self) -> u32 {
match self {
TextureFilter::Linear => glow::LINEAR,
TextureFilter::Nearest => glow::NEAREST,
}
}
}
// ----------------------------------------------------------------------------
/// An OpenGL painter using [`glow`]. /// An OpenGL painter using [`glow`].
/// ///
/// This is responsible for painting egui and managing egui textures. /// This is responsible for painting egui and managing egui textures.
@ -46,7 +72,6 @@ pub struct Painter {
textures: HashMap<egui::TextureId, glow::Texture>, textures: HashMap<egui::TextureId, glow::Texture>,
#[cfg(feature = "epi")]
next_native_tex_id: u64, // TODO: 128-bit texture space? next_native_tex_id: u64, // TODO: 128-bit texture space?
/// Stores outdated OpenGL textures that are yet to be deleted /// Stores outdated OpenGL textures that are yet to be deleted
@ -56,23 +81,28 @@ pub struct Painter {
destroyed: bool, destroyed: bool,
} }
#[derive(Copy, Clone)] impl epi::Renderer for Painter {
pub enum TextureFilter { /// Access the shared glow context.
Linear, fn gl(&self) -> &std::rc::Rc<glow::Context> {
Nearest, &self.gl
} }
impl Default for TextureFilter { /// Get the [`glow::Texture`] bound to a [`egui::TextureId`].
fn default() -> Self { fn texture(&self, texture_id: egui::TextureId) -> Option<glow::Texture> {
TextureFilter::Linear self.textures.get(&texture_id).copied()
}
} }
impl TextureFilter { fn register_native_texture(&mut self, native: glow::Texture) -> egui::TextureId {
pub(crate) fn glow_code(&self) -> u32 { self.assert_not_destroyed();
match self { let id = egui::TextureId::User(self.next_native_tex_id);
TextureFilter::Linear => glow::LINEAR, self.next_native_tex_id += 1;
TextureFilter::Nearest => glow::NEAREST, self.textures.insert(id, native);
id
}
fn replace_native_texture(&mut self, id: egui::TextureId, replacing: glow::Texture) {
if let Some(old_tex) = self.textures.insert(id, replacing) {
self.textures_to_destroy.push(old_tex);
} }
} }
} }
@ -226,7 +256,6 @@ impl Painter {
vertex_buffer, vertex_buffer,
element_array_buffer, element_array_buffer,
textures: Default::default(), textures: Default::default(),
#[cfg(feature = "epi")]
next_native_tex_id: 1 << 32, next_native_tex_id: 1 << 32,
textures_to_destroy: Vec::new(), textures_to_destroy: Vec::new(),
destroyed: false, destroyed: false,
@ -234,11 +263,6 @@ impl Painter {
} }
} }
/// Access the shared glow context.
pub fn gl(&self) -> &std::rc::Rc<glow::Context> {
&self.gl
}
pub fn max_texture_side(&self) -> usize { pub fn max_texture_side(&self) -> usize {
self.max_texture_side self.max_texture_side
} }
@ -403,7 +427,7 @@ impl Painter {
#[inline(never)] // Easier profiling #[inline(never)] // Easier profiling
fn paint_mesh(&mut self, mesh: &Mesh) { fn paint_mesh(&mut self, mesh: &Mesh) {
debug_assert!(mesh.is_valid()); debug_assert!(mesh.is_valid());
if let Some(texture) = self.get_texture(mesh.texture_id) { if let Some(texture) = self.texture(mesh.texture_id) {
unsafe { unsafe {
self.gl self.gl
.bind_buffer(glow::ARRAY_BUFFER, Some(self.vertex_buffer)); .bind_buffer(glow::ARRAY_BUFFER, Some(self.vertex_buffer));
@ -579,11 +603,6 @@ impl Painter {
} }
} }
/// Get the [`glow::Texture`] bound to a [`egui::TextureId`].
pub fn get_texture(&self, texture_id: egui::TextureId) -> Option<glow::Texture> {
self.textures.get(&texture_id).copied()
}
unsafe fn destroy_gl(&self) { unsafe fn destroy_gl(&self) {
self.gl.delete_program(self.program); self.gl.delete_program(self.program);
for tex in self.textures.values() { for tex in self.textures.values() {
@ -642,25 +661,6 @@ impl Drop for Painter {
} }
} }
#[cfg(feature = "epi")]
impl epi::NativeTexture for Painter {
type Texture = glow::Texture;
fn register_native_texture(&mut self, native: Self::Texture) -> egui::TextureId {
self.assert_not_destroyed();
let id = egui::TextureId::User(self.next_native_tex_id);
self.next_native_tex_id += 1;
self.textures.insert(id, native);
id
}
fn replace_native_texture(&mut self, id: egui::TextureId, replacing: Self::Texture) {
if let Some(old_tex) = self.textures.insert(id, replacing) {
self.textures_to_destroy.push(old_tex);
}
}
}
fn set_clip_rect( fn set_clip_rect(
gl: &glow::Context, gl: &glow::Context,
size_in_pixels: (u32, u32), size_in_pixels: (u32, u32),

View file

@ -1,7 +1,6 @@
use crate::{glow_wrapping::WrappedGlowPainter, *}; use crate::{glow_wrapping::WrappedGlowPainter, *};
use egui::TexturesDelta; use egui::TexturesDelta;
pub use egui::{pos2, Color32}; use epi::Renderer as _;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View file

@ -1,5 +1,6 @@
use egui::{ClippedPrimitive, Rgba}; use egui::{ClippedPrimitive, Rgba};
use egui_glow::glow; use egui_glow::glow;
use epi::Renderer as _;
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
use wasm_bindgen::JsValue; use wasm_bindgen::JsValue;
use web_sys::HtmlCanvasElement; use web_sys::HtmlCanvasElement;

View file

@ -374,16 +374,22 @@ pub struct IntegrationInfo {
pub native_pixels_per_point: Option<f32>, pub native_pixels_per_point: Option<f32>,
} }
/// Abstraction for platform dependent texture reference /// The rendering backend of `eframe`.
pub trait NativeTexture { ///
/// The native texture type. /// This is a wrapper around [`glow`](https://github.com/grovesNL/glow)
type Texture; /// that also handles texture allocations.
pub trait Renderer {
/// Access the shared glow context.
fn gl(&self) -> &std::rc::Rc<glow::Context>;
/// Get the [`glow::Texture`] bound to a [`egui::TextureId`].
fn texture(&self, texture_id: egui::TextureId) -> Option<glow::Texture>;
/// Bind native texture to an egui texture id. /// Bind native texture to an egui texture id.
fn register_native_texture(&mut self, native: Self::Texture) -> egui::TextureId; fn register_native_texture(&mut self, native: glow::Texture) -> egui::TextureId;
/// Change what texture the given id refers to. /// Change what texture the given id refers to.
fn replace_native_texture(&mut self, id: egui::TextureId, replacing: Self::Texture); fn replace_native_texture(&mut self, id: egui::TextureId, replacing: glow::Texture);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------