make clipping be a stateful API, as prep for clipping composites

This commit is contained in:
Dustin Carlino 2020-01-13 16:57:09 -08:00
parent 90300c655e
commit 8a7e3cecff
4 changed files with 20 additions and 36 deletions

View File

@ -205,25 +205,21 @@ impl<'a> GfxCtx<'a> {
// println!("{:?}", backtrace::Backtrace::new());
}
pub fn redraw_clipped(&mut self, obj: &Drawable, rect: &ScreenRectangle) {
let mut params = self.params.clone();
params.scissor = Some(glium::Rect {
// TODO Stateful API :(
pub fn enable_clipping(&mut self, rect: ScreenRectangle) {
assert!(self.params.scissor.is_none());
self.params.scissor = Some(glium::Rect {
left: (self.canvas.hidpi_factor * rect.x1) as u32,
// Y-inversion
bottom: (self.canvas.hidpi_factor * (self.canvas.window_height - rect.y2)) as u32,
width: (self.canvas.hidpi_factor * (rect.x2 - rect.x1)) as u32,
height: (self.canvas.hidpi_factor * (rect.y2 - rect.y1)) as u32,
});
self.target
.draw(
&obj.vertex_buffer,
&obj.index_buffer,
&self.program,
&self.uniforms,
&params,
)
.unwrap();
self.num_draw_calls += 1;
}
pub fn disable_clipping(&mut self) {
assert!(self.params.scissor.is_some());
self.params.scissor = None;
}
// Canvas stuff.

View File

@ -209,16 +209,14 @@ impl Minimap {
ScreenPt::new(inner_rect.x1, inner_rect.y1),
self.zoom,
);
g.redraw_clipped(&ui.primary.draw_map.boundary_polygon, &inner_rect);
g.redraw_clipped(&ui.primary.draw_map.draw_all_areas, &inner_rect);
g.redraw_clipped(&ui.primary.draw_map.draw_all_thick_roads, &inner_rect);
g.redraw_clipped(
&ui.primary.draw_map.draw_all_unzoomed_intersections,
&inner_rect,
);
g.redraw_clipped(&ui.primary.draw_map.draw_all_buildings, &inner_rect);
g.enable_clipping(inner_rect);
g.redraw(&ui.primary.draw_map.boundary_polygon);
g.redraw(&ui.primary.draw_map.draw_all_areas);
g.redraw(&ui.primary.draw_map.draw_all_thick_roads);
g.redraw(&ui.primary.draw_map.draw_all_unzoomed_intersections);
g.redraw(&ui.primary.draw_map.draw_all_buildings);
if let Some(ref c) = colorer {
g.redraw_clipped(&c.unzoomed, &inner_rect);
g.redraw(&c.unzoomed);
}
let mut cache = ui.primary.draw_map.agents.borrow_mut();
@ -227,7 +225,6 @@ impl Minimap {
&ui.primary.map,
&ui.agent_cs,
g,
Some(&inner_rect),
self.zoom,
Distance::meters(5.0),
);
@ -265,6 +262,7 @@ impl Minimap {
// TODO Happens when we're quite out-of-bounds. Maybe stop allowing this at all?
println!("Warning: Minimap cursor is just a point right now");
}
g.disable_clipping();
g.unfork();
}
}

View File

@ -10,7 +10,7 @@ use crate::render::Renderable;
use crate::ui::Flags;
use aabb_quadtree::QuadTree;
use abstutil::{Cloneable, Timer};
use ezgui::{Color, Drawable, EventCtx, GeomBatch, GfxCtx, ScreenRectangle};
use ezgui::{Color, Drawable, EventCtx, GeomBatch, GfxCtx};
use geom::{Bounds, Circle, Distance, Duration, FindClosest, Time};
use map_model::{
AreaID, BuildingID, BusStopID, DirectedRoadID, Intersection, IntersectionID, LaneID, Map, Road,
@ -333,18 +333,13 @@ impl AgentCache {
map: &Map,
acs: &AgentColorScheme,
g: &mut GfxCtx,
clip: Option<&ScreenRectangle>,
cam_zoom: f64,
radius: Distance,
) {
let now = source.time();
if let Some((time, z, r, ref orig_acs, ref draw)) = self.unzoomed {
if cam_zoom == z && now == time && radius == r && acs == orig_acs {
if let Some(ref rect) = clip {
g.redraw_clipped(draw, rect);
} else {
g.redraw(draw);
}
g.redraw(draw);
return;
}
}
@ -362,11 +357,7 @@ impl AgentCache {
}
let draw = g.upload(batch);
if let Some(ref rect) = clip {
g.redraw_clipped(&draw, rect);
} else {
g.redraw(&draw);
}
g.redraw(&draw);
self.unzoomed = Some((now, cam_zoom, radius, acs.clone(), draw));
}
}

View File

@ -160,7 +160,6 @@ impl UI {
&self.primary.map,
&self.agent_cs,
g,
None,
g.canvas.cam_zoom,
Distance::meters(10.0),
);