From ad423b22e9dfac78c14ad543d5ca36df37f5ad66 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 20 Aug 2020 16:59:54 -0700 Subject: [PATCH] Remove the glium backend, now that @michaelkirk has gotten the glow native/wasm backends ship-shape. Got rid of the glutin fallback behavior for now; need to ideally upstream something there for #103 --- Cargo.lock | 32 ---- README.md | 2 +- ezgui/Cargo.toml | 2 - ezgui/README.md | 10 +- ezgui/src/backend_glium.rs | 305 ------------------------------- ezgui/src/backend_glow_native.rs | 5 +- ezgui/src/lib.rs | 5 - game/Cargo.toml | 2 +- map_editor/Cargo.toml | 2 +- 9 files changed, 10 insertions(+), 355 deletions(-) delete mode 100644 ezgui/src/backend_glium.rs diff --git a/Cargo.lock b/Cargo.lock index cbb8f41f43..154c545ad7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -777,7 +777,6 @@ dependencies = [ "abstutil 0.1.0", "downcast-rs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "geom 0.1.0", - "glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)", "glow 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.24.1 (registry+https://github.com/rust-lang/crates.io-index)", "htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1173,21 +1172,6 @@ dependencies = [ "xml-rs 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "glium" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace 0.3.46 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", - "glutin 0.24.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "takeable-option 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "glob" version = "0.3.0" @@ -1871,14 +1855,6 @@ dependencies = [ "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "memoffset" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "mime" version = "0.3.16" @@ -3172,11 +3148,6 @@ name = "take_mut" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "takeable-option" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "tempfile" version = "3.1.0" @@ -4000,7 +3971,6 @@ dependencies = [ "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" "checksum gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a" "checksum gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" -"checksum glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)" = "030bb23a12fac7e589b002c5e131e89348df88f91b56e3f3dbc4249527eeebf9" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "checksum glow 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a86c1086850aab0767f4ef01df03c7bdb1cefe18af303571ec144115b733b7b" "checksum glutin 0.24.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9a9666c8fd9afd008f6559e2468c35e11aad1d110d525bb3b354e4138ec0e20f" @@ -4071,7 +4041,6 @@ dependencies = [ "checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" "checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" "checksum memmap2 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b70ca2a6103ac8b665dc150b142ef0e4e89df640c9e6cf295d189c3caebe5a" -"checksum memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8" "checksum mime 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" "checksum mime_guess 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" "checksum miniz_oxide 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aa679ff6578b1cddee93d7e82e263b94a575e0bfced07284eb0c037c1d2416a5" @@ -4221,7 +4190,6 @@ dependencies = [ "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" -"checksum takeable-option 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "36ae8932fcfea38b7d3883ae2ab357b0d57a02caaa18ebb4f5ece08beaec4aa0" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum tendril 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4ce04c250d202db8004921e3d3bc95eaa4f2126c6937a428ae39d12d0e38df62" "checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1" diff --git a/README.md b/README.md index 05f6128ac3..a5b915c946 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ Core team: - Dustin Carlino () - [Yuwen Li](https://www.yuwen-li.com/) (UX) +- [Michael Kirk](https://github.com/michaelkirk) Others: @@ -114,7 +115,6 @@ Others: - Game design advice from Christopher Klein - OSM expertise courtesy [Mateusz Konieczny](https://github.com/matkoniecz) - Lots of helpful PRs from [Javed Nissar](https://github.com/RestitutorOrbis) - and [Michael Kirk](https://github.com/michaelkirk) - Lots of help with rendering SVG and fonts from [RazrFalcon](https://github.com/RazrFalcon) and [nical](https://github.com/nical) diff --git a/ezgui/Cargo.toml b/ezgui/Cargo.toml index 9a30537342..e15b1a894e 100644 --- a/ezgui/Cargo.toml +++ b/ezgui/Cargo.toml @@ -6,7 +6,6 @@ edition = "2018" [features] default = ["glow-backend"] -glium-backend = ["glium", "glutin", "usvg/text"] glow-backend = ["glow", "glutin", "usvg/text"] wasm-backend = ["glow/stdweb", "instant/stdweb", "stdweb", "webgl_stdweb", "winit/stdweb"] @@ -15,7 +14,6 @@ abstutil = { path = "../abstutil" } # backtrace = "0.3.40" downcast-rs = "1.1.1" geom = { path = "../geom" } -glium = { version = "0.27.0", optional = true } glow = { version = "0.5.0", optional = true, default-features=false } glutin = { version = "0.24.1", optional = true } htmlescape = "0.3.1" diff --git a/ezgui/README.md b/ezgui/README.md index 4fbacf885b..000bb9a8f0 100644 --- a/ezgui/README.md +++ b/ezgui/README.md @@ -25,17 +25,15 @@ If you want a more thorough idea of what this crate can do, see ### Runs in lots of places -Runs on Linux, Mac, Windows via [glium](https://github.com/glium/glium/). Also -works in the browser using WebAssembly and -[glow](https://github.com/grovesNL/glow/), but text support still coming in +Runs on Linux, Mac, Windows via [glow](https://github.com/grovesNL/glow/). Also +works in the browser using WebAssembly, but text support still coming in [a few months](https://github.com/RazrFalcon/resvg/issues/229). Why OpenGL? My requirements are super simple; I don't need the power of Vulkan or other new stuff. I want something simple that runs everywhere. If you want to make this work with WGPU or something else, it should be easy. The backends are -each about 300 lines — [Glium](src/backend_glium.rs) running on native OpenGL, -and [Glow](src/backend_glow.rs) running either [on -native](src/backend_glow_native.rs) or [on wasm](src/backend_glow_wasm.rs). +a few hundred lines -- [Glow](src/backend_glow.rs) running either +[on native](src/backend_glow_native.rs) or [on wasm](src/backend_glow_wasm.rs). ### 2D drawing diff --git a/ezgui/src/backend_glium.rs b/ezgui/src/backend_glium.rs deleted file mode 100644 index d4e7a21bea..0000000000 --- a/ezgui/src/backend_glium.rs +++ /dev/null @@ -1,305 +0,0 @@ -use crate::drawing::Uniforms; -use crate::{Canvas, Color, GeomBatch, ScreenDims, ScreenRectangle}; -use glium::uniforms::UniformValue; -use glium::Surface; -use std::cell::Cell; - -pub fn setup(window_title: &str) -> (PrerenderInnards, winit::event_loop::EventLoop<()>) { - let event_loop = winit::event_loop::EventLoop::new(); - let display = match glium::Display::new( - winit::window::WindowBuilder::new() - .with_title(window_title) - .with_maximized(true), - // multisampling: 2 looks bad, 4 looks fine - glutin::ContextBuilder::new() - .with_multisampling(4) - .with_depth_buffer(2), - &event_loop, - ) { - Ok(d) => d, - Err(err1) => match glium::Display::new( - winit::window::WindowBuilder::new() - .with_title(window_title) - .with_maximized(true), - glutin::ContextBuilder::new(), - &event_loop, - ) { - Ok(d) => { - println!("Preferred glutin context failed, falling back on default"); - d - } - Err(err2) => match glium::Display::new( - winit::window::WindowBuilder::new() - .with_title(window_title) - .with_maximized(true), - { - let mut ctx = glutin::ContextBuilder::new(); - ctx.pf_reqs.color_bits = None; - ctx.pf_reqs.alpha_bits = None; - ctx.pf_reqs.depth_bits = Some(16); - ctx.pf_reqs.stencil_bits = None; - ctx - }, - &event_loop, - ) { - Ok(d) => { - println!("Preferred glutin context failed, falling back on default"); - d - } - Err(err3) => { - panic!("Can't create an OpenGL window. Please file an issue at https://github.com/dabreegster/abstreet/issues/ and include output.txt. First attempt {}, second attempt {}, third attempt {}", err1, err2, err3); - } - }, - }, - }; - - let (vertex_shader, fragment_shader) = - if display.is_glsl_version_supported(&glium::Version(glium::Api::Gl, 1, 4)) { - ( - include_str!("shaders/vertex_140.glsl"), - include_str!("shaders/fragment_140.glsl"), - ) - } else { - panic!( - "GLSL 140 not supported. Try {:?} or {:?}", - display.get_opengl_version(), - display.get_supported_glsl_version() - ); - }; - - // To quickly iterate on shaders without recompiling... - /*let mut vert = String::new(); - let mut frag = String::new(); - let (vertex_shader, fragment_shader) = { - use std::io::Read; - - let mut f1 = std::fs::File:: open("../ezgui/src/shaders/vertex_140.glsl").unwrap(); - f1.read_to_string(&mut vert).unwrap(); - - let mut f2 = std::fs::File:: open("../ezgui/src/shaders/fragment_140.glsl").unwrap(); - f2.read_to_string(&mut frag).unwrap(); - - (&vert, &frag) - };*/ - - let program = glium::Program::new( - &display, - glium::program::ProgramCreationInput::SourceCode { - vertex_shader, - tessellation_control_shader: None, - tessellation_evaluation_shader: None, - geometry_shader: None, - fragment_shader, - transform_feedback_varyings: None, - // Without this, SRGB gets enabled and post-processes the color from the fragment - // shader. - outputs_srgb: true, - uses_point_size: false, - }, - ) - .unwrap(); - - ( - PrerenderInnards { - display, - program, - total_bytes_uploaded: Cell::new(0), - }, - event_loop, - ) -} - -struct InnerUniforms<'a> { - values: &'a Uniforms, -} - -impl<'b> glium::uniforms::Uniforms for InnerUniforms<'b> { - fn visit_values<'a, F: FnMut(&str, UniformValue<'a>)>(&'a self, mut output: F) { - output("transform", UniformValue::Vec3(self.values.transform)); - output("window", UniformValue::Vec3(self.values.window)); - } -} - -// Represents one frame that's gonna be drawn -pub struct GfxCtxInnards<'a> { - target: glium::Frame, - params: glium::DrawParameters<'a>, -} - -impl<'a> GfxCtxInnards<'a> { - pub fn clear(&mut self, c: Color) { - // Without this, SRGB gets enabled and post-processes the color from the fragment - // shader. - self.target - .clear_color_srgb_and_depth((c.r, c.g, c.b, c.a), 1.0); - } - - pub fn redraw(&mut self, obj: &Drawable, uniforms: &Uniforms, prerender: &PrerenderInnards) { - self.target - .draw( - &obj.vertex_buffer, - &obj.index_buffer, - &prerender.program, - &InnerUniforms { values: uniforms }, - &self.params, - ) - .unwrap(); - } - - pub fn enable_clipping(&mut self, rect: ScreenRectangle, scale_factor: f64, canvas: &Canvas) { - assert!(self.params.scissor.is_none()); - // The scissor rectangle is in units of physical pixles, as opposed to logical pixels - self.params.scissor = Some(glium::Rect { - left: (rect.x1 * scale_factor) as u32, - // Y-inversion - bottom: ((canvas.window_height - rect.y2) * scale_factor) as u32, - width: ((rect.x2 - rect.x1) * scale_factor) as u32, - height: ((rect.y2 - rect.y1) * scale_factor) as u32, - }); - } - - pub fn disable_clipping(&mut self, _scale_factor: f64, _: &Canvas) { - assert!(self.params.scissor.is_some()); - self.params.scissor = None; - } - - pub fn take_clip(&mut self) -> Option { - self.params.scissor.take() - } - pub fn restore_clip(&mut self, clip: Option) { - self.params.scissor = clip; - } - - pub fn finish(self) { - self.target.finish().unwrap(); - } -} - -// Something that's been sent to the GPU already. -pub struct Drawable { - vertex_buffer: glium::VertexBuffer, - index_buffer: glium::IndexBuffer, -} - -#[derive(Copy, Clone)] -struct Vertex { - position: [f32; 2], - // RGBA - // TODO Make this u8? - style: [f32; 4], -} - -glium::implement_vertex!(Vertex, position, style); - -pub struct PrerenderInnards { - display: glium::Display, - program: glium::Program, - - // TODO Prerender doesn't know what things are temporary and permanent. Could make the API more - // detailed. - pub total_bytes_uploaded: Cell, -} - -impl PrerenderInnards { - pub fn actually_upload(&self, permanent: bool, batch: GeomBatch) -> Drawable { - let mut vertices: Vec = Vec::new(); - let mut indices: Vec = Vec::new(); - - for (color, poly) in batch.consume() { - let idx_offset = vertices.len(); - let (pts, raw_indices) = poly.raw_for_rendering(); - for pt in pts { - vertices.push(Vertex { - position: [pt.x() as f32, pt.y() as f32], - style: color.style(*pt), - }); - } - for idx in raw_indices { - indices.push((idx_offset + *idx) as u32); - } - } - - let vertex_buffer = if permanent { - glium::VertexBuffer::immutable(&self.display, &vertices).unwrap() - } else { - glium::VertexBuffer::new(&self.display, &vertices).unwrap() - }; - let index_buffer = if permanent { - glium::IndexBuffer::immutable( - &self.display, - glium::index::PrimitiveType::TrianglesList, - &indices, - ) - .unwrap() - } else { - glium::IndexBuffer::new( - &self.display, - glium::index::PrimitiveType::TrianglesList, - &indices, - ) - .unwrap() - }; - - if permanent { - self.total_bytes_uploaded.set( - self.total_bytes_uploaded.get() - + vertex_buffer.get_size() - + index_buffer.get_size(), - ); - } - - Drawable { - vertex_buffer, - index_buffer, - } - } - - pub fn request_redraw(&self) { - self.display.gl_window().window().request_redraw(); - } - - pub fn set_cursor_icon(&self, icon: winit::window::CursorIcon) { - self.display.gl_window().window().set_cursor_icon(icon); - } - - pub fn draw_new_frame<'a>(&self) -> GfxCtxInnards<'a> { - GfxCtxInnards { - target: self.display.draw(), - params: glium::DrawParameters { - blend: glium::Blend::alpha_blending(), - depth: glium::Depth { - test: glium::DepthTest::IfLessOrEqual, - write: true, - ..Default::default() - }, - ..Default::default() - }, - } - } - - pub fn window_resized(&self, _new_size: ScreenDims, _scale_factor: f64) {} - - pub fn window_size(&self, scale_factor: f64) -> ScreenDims { - self.display - .gl_window() - .window() - .inner_size() - .to_logical(scale_factor) - .into() - } - - pub fn set_window_icon(&self, icon: winit::window::Icon) { - self.display - .gl_window() - .window() - .set_window_icon(Some(icon)); - } - - pub fn monitor_scale_factor(&self) -> f64 { - self.display.gl_window().window().scale_factor() - } - - pub fn draw_finished(&self, gfx_ctx_innards: GfxCtxInnards) { - gfx_ctx_innards.finish() - } -} diff --git a/ezgui/src/backend_glow_native.rs b/ezgui/src/backend_glow_native.rs index 39a5114086..b3dda44655 100644 --- a/ezgui/src/backend_glow_native.rs +++ b/ezgui/src/backend_glow_native.rs @@ -8,8 +8,9 @@ pub fn setup(window_title: &str) -> (PrerenderInnards, winit::event_loop::EventL let window = winit::window::WindowBuilder::new() .with_title(window_title) .with_maximized(true); - // TODO Need the same fallback as backend_glium - // multisampling: 2 looks bad, 4 looks fine + // TODO If people are hitting problems with context not matching what their GPU provides, dig up + // backend_glium.rs from git and bring the fallback behavior here. (Ideally, there'd be + // something in glutin to directly express this.) multisampling: 2 looks bad, 4 looks fine let context = glutin::ContextBuilder::new() .with_multisampling(4) .with_depth_buffer(2) diff --git a/ezgui/src/lib.rs b/ezgui/src/lib.rs index 01970a2c44..37a9d67eab 100644 --- a/ezgui/src/lib.rs +++ b/ezgui/src/lib.rs @@ -25,8 +25,6 @@ //#![warn(missing_docs)] mod assets; -#[cfg(feature = "glium-backend")] -mod backend_glium; #[cfg(any(feature = "glow-backend", feature = "wasm-backend"))] mod backend_glow; #[cfg(feature = "glow-backend")] @@ -50,9 +48,6 @@ mod tools; mod widgets; mod backend { - #[cfg(feature = "glium-backend")] - pub use crate::backend_glium::*; - #[cfg(any(feature = "glow-backend", feature = "wasm-backend"))] pub use crate::backend_glow::*; } diff --git a/game/Cargo.toml b/game/Cargo.toml index 601ac69251..f81904f07c 100644 --- a/game/Cargo.toml +++ b/game/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # TODO Can't toggle based on target_arch. https://github.com/rust-lang/cargo/issues/2524 # cargo web start --target wasm32-unknown-unknown --no-default-features --features wasm [features] -default = ["built", "ezgui/glium-backend", "reqwest", "webbrowser"] +default = ["built", "ezgui/glow-backend", "reqwest", "webbrowser"] wasm = ["ezgui/wasm-backend"] glow = ["built", "ezgui/glow-backend", "reqwest", "webbrowser"] diff --git a/map_editor/Cargo.toml b/map_editor/Cargo.toml index 7d986177bf..abec4b8d75 100644 --- a/map_editor/Cargo.toml +++ b/map_editor/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" # TODO Can't toggle based on target_arch. https://github.com/rust-lang/cargo/issues/2524 # cargo web start --target wasm32-unknown-unknown --no-default-features --features wasm [features] -default = ["ezgui/glium-backend"] +default = ["ezgui/glow-backend"] wasm = ["ezgui/wasm-backend"] [dependencies]