From a065c63ad788e8e3ff74a8c6ae2d74a47497f936 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 25 Jan 2019 08:01:08 -0800 Subject: [PATCH] batching sidewalk lines. fix the very silly batching bug --- editor/src/render/lane.rs | 9 ++++----- ezgui/src/drawing.rs | 8 ++++---- geom/src/line.rs | 6 +++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/editor/src/render/lane.rs b/editor/src/render/lane.rs index 3f7f981c94..da00b6c51f 100644 --- a/editor/src/render/lane.rs +++ b/editor/src/render/lane.rs @@ -143,21 +143,20 @@ fn calculate_sidewalk_lines(lane: &Lane) -> Marking { let length = lane.length(); - let mut lines = Vec::new(); + let mut draw = Vec::new(); // Start away from the intersections let mut dist_along = tile_every; while dist_along < length - tile_every { let (pt, angle) = lane.dist_along(dist_along); // Reuse perp_line. Project away an arbitrary amount let pt2 = pt.project_away(1.0, angle); - lines.push(perp_line(Line::new(pt, pt2), LANE_THICKNESS)); + draw.push(perp_line(Line::new(pt, pt2), LANE_THICKNESS).make_polygons(0.25)); dist_along += tile_every; } Box::new(move |g, cs| { - for line in &lines { - g.draw_line(cs.get_def("sidewalk lines", Color::grey(0.7)), 0.25, line); - } + let color = cs.get_def("sidewalk lines", Color::grey(0.7)); + g.draw_polygon_batch(draw.iter().map(|poly| (color, poly)).collect()) }) } diff --git a/ezgui/src/drawing.rs b/ezgui/src/drawing.rs index ba22f0fbc8..411f998e5e 100644 --- a/ezgui/src/drawing.rs +++ b/ezgui/src/drawing.rs @@ -102,7 +102,7 @@ impl<'a> GfxCtx<'a> { // Use graphics::Line internally for now, but make it easy to switch to something else by // picking this API now. pub fn draw_line(&mut self, color: Color, thickness: f64, line: &Line) { - self.draw_polygon(color, &line.to_polyline().make_polygons(thickness)); + self.draw_polygon(color, &line.make_polygons(thickness)); } pub fn draw_rounded_line(&mut self, color: Color, thickness: f64, line: &Line) { @@ -110,7 +110,7 @@ impl<'a> GfxCtx<'a> { self.draw_circle(color, &Circle::new(line.pt1(), thickness / 2.0)); self.draw_circle(color, &Circle::new(line.pt2(), thickness / 2.0)); /*self.draw_polygon_batch(vec![ - (color, &line.to_polyline().make_polygons(thickness)), + (color, &line.make_polygons(thickness)), ( color, &Circle::new(line.pt1(), thickness / 2.0).to_polygon(TRIANGLES_PER_CIRCLE), @@ -168,6 +168,7 @@ impl<'a> GfxCtx<'a> { let mut indices: Vec = Vec::new(); for (color, poly) in list { + let idx_offset = vertices.len(); let (pts, raw_indices) = poly.raw_for_rendering(); for pt in pts { vertices.push(Vertex { @@ -175,9 +176,8 @@ impl<'a> GfxCtx<'a> { color: color.0, }); } - let offset = indices.len(); for idx in raw_indices { - indices.push((offset + *idx) as u32); + indices.push((idx_offset + *idx) as u32); } } diff --git a/geom/src/line.rs b/geom/src/line.rs index caf00d8316..86000a202d 100644 --- a/geom/src/line.rs +++ b/geom/src/line.rs @@ -1,4 +1,4 @@ -use crate::{line_intersection, Angle, PolyLine, Pt2D, EPSILON_DIST}; +use crate::{line_intersection, Angle, PolyLine, Polygon, Pt2D, EPSILON_DIST}; use dimensioned::si; use serde_derive::{Deserialize, Serialize}; use std::fmt; @@ -30,6 +30,10 @@ impl Line { PolyLine::new(self.points()) } + pub fn make_polygons(&self, thickness: f64) -> Polygon { + self.to_polyline().make_polygons(thickness) + } + // TODO valid to do euclidean distance on world-space points that're formed from // Haversine? pub fn length(&self) -> si::Meter {