From 1068750bbcab73b8d10f005c0d205e416da08743 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 1 Apr 2021 22:11:29 +0200 Subject: [PATCH] Clean up egui_web code a bit --- egui_web/src/backend.rs | 23 +++++++++++++---------- egui_web/src/webgl1.rs | 7 +++---- egui_web/src/webgl2.rs | 7 +++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/egui_web/src/backend.rs b/egui_web/src/backend.rs index 5b5bfcaf..4f5d89ec 100644 --- a/egui_web/src/backend.rs +++ b/egui_web/src/backend.rs @@ -198,18 +198,21 @@ impl AppRunner { resize_canvas_to_screen_size(self.web_backend.canvas_id(), self.app.max_size_points()); let canvas_size = canvas_size_in_points(self.web_backend.canvas_id()); let raw_input = self.input.new_frame(canvas_size); + + let info = epi::IntegrationInfo { + web_info: Some(epi::WebInfo { + web_location_hash: location_hash().unwrap_or_default(), + }), + cpu_usage: self.web_backend.previous_frame_time, + seconds_since_midnight: Some(seconds_since_midnight()), + native_pixels_per_point: Some(native_pixels_per_point()), + }; + self.web_backend.begin_frame(raw_input); let mut app_output = epi::backend::AppOutput::default(); let mut frame = epi::backend::FrameBuilder { - info: epi::IntegrationInfo { - web_info: Some(epi::WebInfo { - web_location_hash: location_hash().unwrap_or_default(), - }), - cpu_usage: self.web_backend.previous_frame_time, - seconds_since_midnight: Some(seconds_since_midnight()), - native_pixels_per_point: Some(native_pixels_per_point()), - }, + info, tex_allocator: self.web_backend.painter.as_tex_allocator(), #[cfg(feature = "http")] http: self.http.clone(), @@ -218,9 +221,9 @@ impl AppRunner { } .build(); - let egui_ctx = &self.web_backend.ctx; - self.app.update(egui_ctx, &mut frame); + self.app.update(&self.web_backend.ctx, &mut frame); let (egui_output, clipped_meshes) = self.web_backend.end_frame()?; + if self.web_backend.ctx.memory().options.screen_reader { self.screen_reader.speak(&egui_output.events_description()); } diff --git a/egui_web/src/webgl1.rs b/egui_web/src/webgl1.rs index 770b3568..e0d37efb 100644 --- a/egui_web/src/webgl1.rs +++ b/egui_web/src/webgl1.rs @@ -189,6 +189,7 @@ impl WebGlPainter { } } } + 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) { @@ -200,20 +201,18 @@ impl WebGlPainter { } egui::TextureId::User(id as u64) } + fn paint_mesh(&self, mesh: &egui::epaint::Mesh16) -> Result<(), JsValue> { debug_assert!(mesh.is_valid()); let mut positions: Vec = Vec::with_capacity(2 * mesh.vertices.len()); let mut tex_coords: Vec = Vec::with_capacity(2 * mesh.vertices.len()); + let mut colors: Vec = Vec::with_capacity(4 * mesh.vertices.len()); for v in &mesh.vertices { positions.push(v.pos.x); positions.push(v.pos.y); tex_coords.push(v.uv.x); tex_coords.push(v.uv.y); - } - - let mut colors: Vec = Vec::with_capacity(4 * mesh.vertices.len()); - for v in &mesh.vertices { colors.push(v.color[0]); colors.push(v.color[1]); colors.push(v.color[2]); diff --git a/egui_web/src/webgl2.rs b/egui_web/src/webgl2.rs index b0553c09..0e0a5472 100644 --- a/egui_web/src/webgl2.rs +++ b/egui_web/src/webgl2.rs @@ -192,6 +192,7 @@ impl WebGl2Painter { } } } + 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) { @@ -203,20 +204,18 @@ impl WebGl2Painter { } egui::TextureId::User(id as u64) } + fn paint_mesh(&self, mesh: &egui::epaint::Mesh16) -> Result<(), JsValue> { debug_assert!(mesh.is_valid()); let mut positions: Vec = Vec::with_capacity(2 * mesh.vertices.len()); let mut tex_coords: Vec = Vec::with_capacity(2 * mesh.vertices.len()); + let mut colors: Vec = Vec::with_capacity(4 * mesh.vertices.len()); for v in &mesh.vertices { positions.push(v.pos.x); positions.push(v.pos.y); tex_coords.push(v.uv.x); tex_coords.push(v.uv.y); - } - - let mut colors: Vec = Vec::with_capacity(4 * mesh.vertices.len()); - for v in &mesh.vertices { colors.push(v.color[0]); colors.push(v.color[1]); colors.push(v.color[2]);