mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Make wgpu the default renderer for eframe and egui.rs (#7615)
* Closes https://github.com/emilk/egui/issues/5889 See the above issue for motivation. To use glow instead, disable the default features of `eframe` and opt-in to `glow`. This also changes egui.rs to use wgpu, which means WebGPU when available, and WebGL otherwise
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
use egui::{TexturesDelta, UserData, ViewportCommand};
|
||||
|
||||
use crate::{App, epi};
|
||||
use crate::{App, epi, web::web_painter::WebPainter};
|
||||
|
||||
use super::{NeedRepaint, now_sec, text_agent::TextAgent, web_painter::WebPainter as _};
|
||||
use super::{NeedRepaint, now_sec, text_agent::TextAgent};
|
||||
|
||||
pub struct AppRunner {
|
||||
#[allow(dead_code, clippy::allow_attributes)]
|
||||
pub(crate) web_options: crate::WebOptions,
|
||||
pub(crate) frame: epi::Frame,
|
||||
egui_ctx: egui::Context,
|
||||
painter: super::ActiveWebPainter,
|
||||
painter: Box<dyn WebPainter>,
|
||||
pub(crate) input: super::WebInput,
|
||||
app: Box<dyn epi::App>,
|
||||
pub(crate) needs_repaint: std::sync::Arc<NeedRepaint>,
|
||||
@@ -34,6 +34,10 @@ impl Drop for AppRunner {
|
||||
impl AppRunner {
|
||||
/// # Errors
|
||||
/// Failure to initialize WebGL renderer, or failure to create app.
|
||||
#[cfg_attr(
|
||||
not(feature = "wgpu_no_default_features"),
|
||||
expect(clippy::unused_async)
|
||||
)]
|
||||
pub async fn new(
|
||||
canvas: web_sys::HtmlCanvasElement,
|
||||
web_options: crate::WebOptions,
|
||||
@@ -41,7 +45,41 @@ impl AppRunner {
|
||||
text_agent: TextAgent,
|
||||
) -> Result<Self, String> {
|
||||
let egui_ctx = egui::Context::default();
|
||||
let painter = super::ActiveWebPainter::new(egui_ctx.clone(), canvas, &web_options).await?;
|
||||
|
||||
#[allow(clippy::allow_attributes, unused_assignments)]
|
||||
#[cfg(feature = "glow")]
|
||||
let mut gl = None;
|
||||
|
||||
#[allow(clippy::allow_attributes, unused_assignments)]
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
let mut wgpu_render_state = None;
|
||||
|
||||
let painter = match web_options.renderer {
|
||||
#[cfg(feature = "glow")]
|
||||
epi::Renderer::Glow => {
|
||||
log::debug!("Using the glow renderer");
|
||||
let painter = super::web_painter_glow::WebPainterGlow::new(
|
||||
egui_ctx.clone(),
|
||||
canvas,
|
||||
&web_options,
|
||||
)?;
|
||||
gl = Some(painter.gl().clone());
|
||||
Box::new(painter) as Box<dyn WebPainter>
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
epi::Renderer::Wgpu => {
|
||||
log::debug!("Using the wgpu renderer");
|
||||
let painter = super::web_painter_wgpu::WebPainterWgpu::new(
|
||||
egui_ctx.clone(),
|
||||
canvas,
|
||||
&web_options,
|
||||
)
|
||||
.await?;
|
||||
wgpu_render_state = painter.render_state();
|
||||
Box::new(painter) as Box<dyn WebPainter>
|
||||
}
|
||||
};
|
||||
|
||||
let info = epi::IntegrationInfo {
|
||||
web_info: epi::WebInfo {
|
||||
@@ -79,15 +117,13 @@ impl AppRunner {
|
||||
storage: Some(&storage),
|
||||
|
||||
#[cfg(feature = "glow")]
|
||||
gl: Some(painter.gl().clone()),
|
||||
gl: gl.clone(),
|
||||
|
||||
#[cfg(feature = "glow")]
|
||||
get_proc_address: None,
|
||||
|
||||
#[cfg(all(feature = "wgpu_no_default_features", not(feature = "glow")))]
|
||||
wgpu_render_state: painter.render_state(),
|
||||
#[cfg(all(feature = "wgpu_no_default_features", feature = "glow"))]
|
||||
wgpu_render_state: None,
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
wgpu_render_state: wgpu_render_state.clone(),
|
||||
};
|
||||
let app = app_creator(&cc).map_err(|err| err.to_string())?;
|
||||
|
||||
@@ -96,12 +132,10 @@ impl AppRunner {
|
||||
storage: Some(Box::new(storage)),
|
||||
|
||||
#[cfg(feature = "glow")]
|
||||
gl: Some(painter.gl().clone()),
|
||||
gl,
|
||||
|
||||
#[cfg(all(feature = "wgpu_no_default_features", not(feature = "glow")))]
|
||||
wgpu_render_state: painter.render_state(),
|
||||
#[cfg(all(feature = "wgpu_no_default_features", feature = "glow"))]
|
||||
wgpu_render_state: None,
|
||||
#[cfg(feature = "wgpu_no_default_features")]
|
||||
wgpu_render_state,
|
||||
};
|
||||
|
||||
let needs_repaint: std::sync::Arc<NeedRepaint> =
|
||||
|
||||
Reference in New Issue
Block a user