Skip to content

Commit

Permalink
egui_web: always use the glow painter, and remove the old WebGL code. (
Browse files Browse the repository at this point in the history
…#1356)

* egui_web: always use the glow painter, and remove the old WebGL code.
* Clean up the WebPainter trait
* Clarify WebGL1 warning text in color test

The glow painter became standard in egui 0.17, and I've heard no complaints! So let's simplify and go all in on glow.

Part of #1198
  • Loading branch information
emilk authored Mar 11, 2022
1 parent 52b4ab4 commit 50539bd
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 1,514 deletions.
4 changes: 1 addition & 3 deletions eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = fa

# web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
egui_web = { version = "0.17.0", path = "../egui_web", default-features = false, features = [
"glow",
] }
egui_web = { version = "0.17.0", path = "../egui_web", default-features = false }


[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion egui_demo_lib/src/apps/color_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl epi::App for ColorTest {
egui::CentralPanel::default().show(ctx, |ui| {
if frame.is_web() {
ui.label(
"NOTE: The WebGL1 backend without sRGB support does NOT pass the color test.",
"NOTE: Some old browsers stuck on WebGL1 without sRGB support will not pass the color test.",
);
ui.separator();
}
Expand Down
3 changes: 0 additions & 3 deletions egui_demo_lib/src/backend_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ fn show_integration_name(ui: &mut egui::Ui, integration_info: &epi::IntegrationI
format!("https://github.com/emilk/egui/tree/master/{}", name),
);
}
name if name.starts_with("egui_web") => {
ui.hyperlink_to(name, "https://github.com/emilk/egui/tree/master/egui_web");
}
name => {
ui.label(name);
}
Expand Down
1 change: 1 addition & 0 deletions egui_web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the `egui_web` integration will be noted in this file.

## Unreleased
* egui code will no longer be called after panic ([#1306](https://github.com/emilk/egui/pull/1306))
* Remove the "webgl" feature. `egui_web` now always use `glow` (which in turn wraps WebGL) ([#1356](https://github.com/emilk/egui/pull/1356)).


## 0.17.0 - 2022-02-22
Expand Down
17 changes: 2 additions & 15 deletions egui_web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ crate-type = ["cdylib", "rlib"]


[features]
default = ["default_fonts", "glow"]
default = ["default_fonts"]

# If set, egui will use `include_bytes!` to bundle some fonts.
# If you plan on specifying your own fonts you may disable this feature.
default_fonts = ["egui/default_fonts"]

# Use glow as the renderer.
glow = ["egui_glow", "egui_glow/epi"]

# Alternative to the glow renderer.
webgl = []

# enable persisting egui memory
persistence = ["egui/persistence", "ron", "serde"]

Expand All @@ -52,7 +46,7 @@ egui = { version = "0.17.0", path = "../egui", default-features = false, feature
"single_threaded",
"tracing",
] }
egui_glow = { version = "0.17.0", path = "../egui_glow", optional = true, default-features = false }
egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false }
epi = { version = "0.17.0", path = "../epi" }

bytemuck = "1.7"
Expand Down Expand Up @@ -106,15 +100,8 @@ features = [
"TouchEvent",
"TouchList",
"WebGl2RenderingContext",
"WebGlBuffer",
"WebglDebugRendererInfo",
"WebGlFramebuffer",
"WebGlProgram",
"WebGlRenderingContext",
"WebGlShader",
"WebGlTexture",
"WebGlUniformLocation",
"WebGlVertexArrayObject",
"WheelEvent",
"Window",
]
2 changes: 1 addition & 1 deletion egui_web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Check out [eframe_template](https://github.com/emilk/eframe_template) for an exa

## Downsides with using egui on the web

`egui_web` uses WebGL and WASM, and almost nothing else from the web tech stack. This has some benefits, but also produces some challanges and serious downsides.
`egui_web` uses WebGL (via [`glow`](https://crates.io/crates/glow)) and WASM, and almost nothing else from the web tech stack. This has some benefits, but also produces some challanges and serious downsides.

* Rendering: Getting pixel-perfect rendering right on the web is very difficult.
* Search: you cannot search an egui web page like you would a normal web page.
Expand Down
23 changes: 4 additions & 19 deletions egui_web/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,10 @@ pub use egui::{pos2, Color32};

// ----------------------------------------------------------------------------

fn create_painter(canvas_id: &str) -> Result<Box<dyn Painter>, JsValue> {
// Glow takes precedence:
#[cfg(all(feature = "glow"))]
return Ok(Box::new(
fn create_painter(canvas_id: &str) -> Result<Box<dyn WebPainter>, JsValue> {
Ok(Box::new(
crate::glow_wrapping::WrappedGlowPainter::new(canvas_id).map_err(JsValue::from)?,
));

#[cfg(all(feature = "webgl", not(feature = "glow")))]
if let Ok(webgl2_painter) = webgl2::WebGl2Painter::new(canvas_id) {
tracing::debug!("Using WebGL2 backend");
Ok(Box::new(webgl2_painter))
} else {
tracing::debug!("Falling back to WebGL1 backend");
let webgl1_painter = webgl1::WebGlPainter::new(canvas_id)?;
Ok(Box::new(webgl1_painter))
}

#[cfg(all(not(feature = "webgl"), not(feature = "glow")))]
compile_error!("Either the 'glow' or 'webgl' feature of egui_web must be enabled!");
))
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -155,7 +140,7 @@ fn test_parse_query() {
pub struct AppRunner {
pub(crate) frame: epi::Frame,
egui_ctx: egui::Context,
painter: Box<dyn Painter>,
painter: Box<dyn WebPainter>,
pub(crate) input: WebInput,
app: Box<dyn epi::App>,
pub(crate) needs_repaint: std::sync::Arc<NeedRepaint>,
Expand Down
26 changes: 9 additions & 17 deletions egui_web/src/glow_wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ impl WrappedGlowPainter {
}
}

impl crate::Painter for WrappedGlowPainter {
impl crate::WebPainter for WrappedGlowPainter {
fn name(&self) -> &'static str {
"egui_web"
}

fn max_texture_side(&self) -> usize {
self.painter.max_texture_side()
}

fn canvas_id(&self) -> &str {
&self.canvas_id
}

fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta) {
self.painter.set_texture(&self.glow_ctx, tex_id, delta);
}
Expand All @@ -45,18 +53,6 @@ impl crate::Painter for WrappedGlowPainter {
self.painter.free_texture(&self.glow_ctx, tex_id);
}

fn debug_info(&self) -> String {
format!(
"Stored canvas size: {} x {}",
self.canvas.width(),
self.canvas.height(),
)
}

fn canvas_id(&self) -> &str {
&self.canvas_id
}

fn clear(&mut self, clear_color: Rgba) {
let canvas_dimension = [self.canvas.width(), self.canvas.height()];
egui_glow::painter::clear(&self.glow_ctx, canvas_dimension, clear_color)
Expand All @@ -76,10 +72,6 @@ impl crate::Painter for WrappedGlowPainter {
);
Ok(())
}

fn name(&self) -> &'static str {
"egui_web (glow)"
}
}

/// Returns glow context and shader prefix.
Expand Down
8 changes: 1 addition & 7 deletions egui_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,20 @@
#![warn(clippy::all, rustdoc::missing_crate_level_docs, rust_2018_idioms)]

pub mod backend;
#[cfg(feature = "glow")]
mod glow_wrapping;
mod input;
mod painter;
pub mod screen_reader;
mod text_agent;

#[cfg(feature = "webgl")]
pub mod webgl1;
#[cfg(feature = "webgl")]
pub mod webgl2;

pub use backend::*;

use egui::mutex::{Mutex, MutexGuard};
pub use wasm_bindgen;
pub use web_sys;

use input::*;
pub use painter::Painter;
pub use painter::WebPainter;
use web_sys::EventTarget;

use std::collections::BTreeMap;
Expand Down
15 changes: 7 additions & 8 deletions egui_web/src/painter.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use wasm_bindgen::prelude::JsValue;

pub trait Painter {
/// What is needed to paint egui.
pub trait WebPainter {
fn name(&self) -> &'static str;

/// Max size of one side of a texture.
fn max_texture_side(&self) -> usize;

/// id of the canvas html element containing the rendering
fn canvas_id(&self) -> &str;

fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta);

fn free_texture(&mut self, tex_id: egui::TextureId);

fn debug_info(&self) -> String;

/// id of the canvas html element containing the rendering
fn canvas_id(&self) -> &str;

fn clear(&mut self, clear_color: egui::Rgba);

fn paint_meshes(
Expand All @@ -21,8 +22,6 @@ pub trait Painter {
pixels_per_point: f32,
) -> Result<(), JsValue>;

fn name(&self) -> &'static str;

fn paint_and_update_textures(
&mut self,
clipped_meshes: Vec<egui::ClippedMesh>,
Expand Down
58 changes: 0 additions & 58 deletions egui_web/src/shader/fragment_100es.glsl

This file was deleted.

13 changes: 0 additions & 13 deletions egui_web/src/shader/main_fragment_100es.glsl

This file was deleted.

31 changes: 0 additions & 31 deletions egui_web/src/shader/main_vertex_100es.glsl

This file was deleted.

26 changes: 0 additions & 26 deletions egui_web/src/shader/post_fragment_100es.glsl

This file was deleted.

8 changes: 0 additions & 8 deletions egui_web/src/shader/post_vertex_100es.glsl

This file was deleted.

Loading

0 comments on commit 50539bd

Please sign in to comment.