mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
only upload widget backgrounds once
This commit is contained in:
parent
194dbae66f
commit
2a8c657770
@ -457,8 +457,7 @@ impl<'a> Prerender<'a> {
|
||||
}
|
||||
|
||||
fn actually_upload(&self, permanent: bool, list: Vec<(Color, &Polygon)>) -> Drawable {
|
||||
//let bt = format!("{:?}", backtrace::Backtrace::new());
|
||||
//println!("{}", bt);
|
||||
// println!("{:?}", backtrace::Backtrace::new());
|
||||
|
||||
self.num_uploads.set(self.num_uploads.get() + 1);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::layout::Widget;
|
||||
use crate::{
|
||||
Button, Color, DrawBoth, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, JustDraw,
|
||||
Plot, ScreenDims, ScreenPt, ScreenRectangle, Slider, Text, VerticalAlignment,
|
||||
Button, Color, DrawBoth, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, JustDraw, Plot,
|
||||
ScreenDims, ScreenPt, ScreenRectangle, Slider, Text, VerticalAlignment,
|
||||
};
|
||||
use geom::{Distance, Duration, Polygon};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@ -13,7 +13,7 @@ pub struct ManagedWidget {
|
||||
widget: WidgetType,
|
||||
style: LayoutStyle,
|
||||
rect: ScreenRectangle,
|
||||
bg: Option<Drawable>,
|
||||
bg: Option<DrawBoth>,
|
||||
}
|
||||
|
||||
enum WidgetType {
|
||||
@ -204,9 +204,7 @@ impl ManagedWidget {
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, sliders: &HashMap<String, &Slider>) {
|
||||
if let Some(ref bg) = self.bg {
|
||||
g.fork_screenspace();
|
||||
g.redraw(bg);
|
||||
g.unfork();
|
||||
bg.redraw(ScreenPt::new(self.rect.x1, self.rect.y1), g);
|
||||
}
|
||||
|
||||
match self.widget {
|
||||
@ -300,17 +298,18 @@ impl ManagedWidget {
|
||||
ScreenDims::new(width, height),
|
||||
);
|
||||
if let Some(color) = self.style.bg_color {
|
||||
let mut batch = GeomBatch::new();
|
||||
batch.push(
|
||||
color,
|
||||
Polygon::rounded_rectangle(
|
||||
Distance::meters(width),
|
||||
Distance::meters(height),
|
||||
Distance::meters(5.0),
|
||||
)
|
||||
.translate(x + dx, y + dy),
|
||||
);
|
||||
self.bg = Some(batch.upload(ctx));
|
||||
// Assume widgets don't dynamically change, so we just upload the background once.
|
||||
if self.bg.is_none() {
|
||||
let batch = GeomBatch::from(vec![(
|
||||
color,
|
||||
Polygon::rounded_rectangle(
|
||||
Distance::meters(width),
|
||||
Distance::meters(height),
|
||||
Distance::meters(5.0),
|
||||
),
|
||||
)]);
|
||||
self.bg = Some(DrawBoth::new(ctx, batch, Vec::new()));
|
||||
}
|
||||
}
|
||||
|
||||
match self.widget {
|
||||
|
@ -131,7 +131,7 @@ impl GUI for Game {
|
||||
}
|
||||
|
||||
/*println!(
|
||||
"{} uploads, {} draw calls",
|
||||
"----- {} uploads, {} draw calls -----",
|
||||
g.get_num_uploads(),
|
||||
g.num_draw_calls
|
||||
);*/
|
||||
|
Loading…
Reference in New Issue
Block a user