Skip to content

Commit 50539bd

Browse files
authored
egui_web: always use the glow painter, and remove the old WebGL code. (#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
1 parent 52b4ab4 commit 50539bd

18 files changed

+28
-1514
lines changed

eframe/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = fa
5959

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

6664

6765
[dev-dependencies]

egui_demo_lib/src/apps/color_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl epi::App for ColorTest {
3838
egui::CentralPanel::default().show(ctx, |ui| {
3939
if frame.is_web() {
4040
ui.label(
41-
"NOTE: The WebGL1 backend without sRGB support does NOT pass the color test.",
41+
"NOTE: Some old browsers stuck on WebGL1 without sRGB support will not pass the color test.",
4242
);
4343
ui.separator();
4444
}

egui_demo_lib/src/backend_panel.rs

-3
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@ fn show_integration_name(ui: &mut egui::Ui, integration_info: &epi::IntegrationI
274274
format!("https://github.com/emilk/egui/tree/master/{}", name),
275275
);
276276
}
277-
name if name.starts_with("egui_web") => {
278-
ui.hyperlink_to(name, "https://github.com/emilk/egui/tree/master/egui_web");
279-
}
280277
name => {
281278
ui.label(name);
282279
}

egui_web/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to the `egui_web` integration will be noted in this file.
44

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

89

910
## 0.17.0 - 2022-02-22

egui_web/Cargo.toml

+2-15
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ crate-type = ["cdylib", "rlib"]
2727

2828

2929
[features]
30-
default = ["default_fonts", "glow"]
30+
default = ["default_fonts"]
3131

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

36-
# Use glow as the renderer.
37-
glow = ["egui_glow", "egui_glow/epi"]
38-
39-
# Alternative to the glow renderer.
40-
webgl = []
41-
4236
# enable persisting egui memory
4337
persistence = ["egui/persistence", "ron", "serde"]
4438

@@ -52,7 +46,7 @@ egui = { version = "0.17.0", path = "../egui", default-features = false, feature
5246
"single_threaded",
5347
"tracing",
5448
] }
55-
egui_glow = { version = "0.17.0", path = "../egui_glow", optional = true, default-features = false }
49+
egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false }
5650
epi = { version = "0.17.0", path = "../epi" }
5751

5852
bytemuck = "1.7"
@@ -106,15 +100,8 @@ features = [
106100
"TouchEvent",
107101
"TouchList",
108102
"WebGl2RenderingContext",
109-
"WebGlBuffer",
110103
"WebglDebugRendererInfo",
111-
"WebGlFramebuffer",
112-
"WebGlProgram",
113104
"WebGlRenderingContext",
114-
"WebGlShader",
115-
"WebGlTexture",
116-
"WebGlUniformLocation",
117-
"WebGlVertexArrayObject",
118105
"WheelEvent",
119106
"Window",
120107
]

egui_web/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Check out [eframe_template](https://github.com/emilk/eframe_template) for an exa
1414

1515
## Downsides with using egui on the web
1616

17-
`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.
17+
`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.
1818

1919
* Rendering: Getting pixel-perfect rendering right on the web is very difficult.
2020
* Search: you cannot search an egui web page like you would a normal web page.

egui_web/src/backend.rs

+4-19
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,10 @@ pub use egui::{pos2, Color32};
55

66
// ----------------------------------------------------------------------------
77

8-
fn create_painter(canvas_id: &str) -> Result<Box<dyn Painter>, JsValue> {
9-
// Glow takes precedence:
10-
#[cfg(all(feature = "glow"))]
11-
return Ok(Box::new(
8+
fn create_painter(canvas_id: &str) -> Result<Box<dyn WebPainter>, JsValue> {
9+
Ok(Box::new(
1210
crate::glow_wrapping::WrappedGlowPainter::new(canvas_id).map_err(JsValue::from)?,
13-
));
14-
15-
#[cfg(all(feature = "webgl", not(feature = "glow")))]
16-
if let Ok(webgl2_painter) = webgl2::WebGl2Painter::new(canvas_id) {
17-
tracing::debug!("Using WebGL2 backend");
18-
Ok(Box::new(webgl2_painter))
19-
} else {
20-
tracing::debug!("Falling back to WebGL1 backend");
21-
let webgl1_painter = webgl1::WebGlPainter::new(canvas_id)?;
22-
Ok(Box::new(webgl1_painter))
23-
}
24-
25-
#[cfg(all(not(feature = "webgl"), not(feature = "glow")))]
26-
compile_error!("Either the 'glow' or 'webgl' feature of egui_web must be enabled!");
11+
))
2712
}
2813

2914
// ----------------------------------------------------------------------------
@@ -155,7 +140,7 @@ fn test_parse_query() {
155140
pub struct AppRunner {
156141
pub(crate) frame: epi::Frame,
157142
egui_ctx: egui::Context,
158-
painter: Box<dyn Painter>,
143+
painter: Box<dyn WebPainter>,
159144
pub(crate) input: WebInput,
160145
app: Box<dyn epi::App>,
161146
pub(crate) needs_repaint: std::sync::Arc<NeedRepaint>,

egui_web/src/glow_wrapping.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ impl WrappedGlowPainter {
3232
}
3333
}
3434

35-
impl crate::Painter for WrappedGlowPainter {
35+
impl crate::WebPainter for WrappedGlowPainter {
36+
fn name(&self) -> &'static str {
37+
"egui_web"
38+
}
39+
3640
fn max_texture_side(&self) -> usize {
3741
self.painter.max_texture_side()
3842
}
3943

44+
fn canvas_id(&self) -> &str {
45+
&self.canvas_id
46+
}
47+
4048
fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta) {
4149
self.painter.set_texture(&self.glow_ctx, tex_id, delta);
4250
}
@@ -45,18 +53,6 @@ impl crate::Painter for WrappedGlowPainter {
4553
self.painter.free_texture(&self.glow_ctx, tex_id);
4654
}
4755

48-
fn debug_info(&self) -> String {
49-
format!(
50-
"Stored canvas size: {} x {}",
51-
self.canvas.width(),
52-
self.canvas.height(),
53-
)
54-
}
55-
56-
fn canvas_id(&self) -> &str {
57-
&self.canvas_id
58-
}
59-
6056
fn clear(&mut self, clear_color: Rgba) {
6157
let canvas_dimension = [self.canvas.width(), self.canvas.height()];
6258
egui_glow::painter::clear(&self.glow_ctx, canvas_dimension, clear_color)
@@ -76,10 +72,6 @@ impl crate::Painter for WrappedGlowPainter {
7672
);
7773
Ok(())
7874
}
79-
80-
fn name(&self) -> &'static str {
81-
"egui_web (glow)"
82-
}
8375
}
8476

8577
/// Returns glow context and shader prefix.

egui_web/src/lib.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,20 @@
1515
#![warn(clippy::all, rustdoc::missing_crate_level_docs, rust_2018_idioms)]
1616

1717
pub mod backend;
18-
#[cfg(feature = "glow")]
1918
mod glow_wrapping;
2019
mod input;
2120
mod painter;
2221
pub mod screen_reader;
2322
mod text_agent;
2423

25-
#[cfg(feature = "webgl")]
26-
pub mod webgl1;
27-
#[cfg(feature = "webgl")]
28-
pub mod webgl2;
29-
3024
pub use backend::*;
3125

3226
use egui::mutex::{Mutex, MutexGuard};
3327
pub use wasm_bindgen;
3428
pub use web_sys;
3529

3630
use input::*;
37-
pub use painter::Painter;
31+
pub use painter::WebPainter;
3832
use web_sys::EventTarget;
3933

4034
use std::collections::BTreeMap;

egui_web/src/painter.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use wasm_bindgen::prelude::JsValue;
22

3-
pub trait Painter {
3+
/// What is needed to paint egui.
4+
pub trait WebPainter {
5+
fn name(&self) -> &'static str;
6+
47
/// Max size of one side of a texture.
58
fn max_texture_side(&self) -> usize;
69

10+
/// id of the canvas html element containing the rendering
11+
fn canvas_id(&self) -> &str;
12+
713
fn set_texture(&mut self, tex_id: egui::TextureId, delta: &egui::epaint::ImageDelta);
814

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

11-
fn debug_info(&self) -> String;
12-
13-
/// id of the canvas html element containing the rendering
14-
fn canvas_id(&self) -> &str;
15-
1617
fn clear(&mut self, clear_color: egui::Rgba);
1718

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

24-
fn name(&self) -> &'static str;
25-
2625
fn paint_and_update_textures(
2726
&mut self,
2827
clipped_meshes: Vec<egui::ClippedMesh>,

egui_web/src/shader/fragment_100es.glsl

-58
This file was deleted.

egui_web/src/shader/main_fragment_100es.glsl

-13
This file was deleted.

egui_web/src/shader/main_vertex_100es.glsl

-31
This file was deleted.

egui_web/src/shader/post_fragment_100es.glsl

-26
This file was deleted.

egui_web/src/shader/post_vertex_100es.glsl

-8
This file was deleted.

0 commit comments

Comments
 (0)