mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
use the pts/indices for rendering
This commit is contained in:
parent
559d568acd
commit
49f0c64ef4
@ -66,12 +66,13 @@
|
||||
## Switch to OpenGL (for speed)
|
||||
|
||||
- speed
|
||||
- make polygon store points and indices efficiently
|
||||
- change ezgui API to allow uploading geometry once
|
||||
- event loop feels sticky
|
||||
- what about color then? get fancy and plumb an override color uniform?
|
||||
- sleep better in the event loop
|
||||
- first make UserInput borrow state and not need to consume
|
||||
- experiment with batching and not passing colors
|
||||
- measure performance of huge maps
|
||||
- specialized things for common shapes like circles?
|
||||
- quality
|
||||
- need padding around text
|
||||
- text entry needs to draw the cursor differently
|
||||
|
@ -214,27 +214,15 @@ impl<'a> GfxCtx<'a> {
|
||||
}
|
||||
|
||||
pub fn draw_polygon(&mut self, color: Color, poly: &Polygon) {
|
||||
let mut vertices: Vec<Vertex> = Vec::new();
|
||||
let mut indices: Vec<u32> = Vec::new();
|
||||
for (idx, tri) in poly.triangles().into_iter().enumerate() {
|
||||
vertices.push(Vertex {
|
||||
position: [tri.pt1.x() as f32, tri.pt1.y() as f32],
|
||||
let (pts, raw_indices) = poly.raw_for_rendering();
|
||||
let vertices: Vec<Vertex> = pts
|
||||
.iter()
|
||||
.map(|pt| Vertex {
|
||||
position: [pt.x() as f32, pt.y() as f32],
|
||||
color: color.0,
|
||||
});
|
||||
vertices.push(Vertex {
|
||||
position: [tri.pt2.x() as f32, tri.pt2.y() as f32],
|
||||
color: color.0,
|
||||
});
|
||||
vertices.push(Vertex {
|
||||
position: [tri.pt3.x() as f32, tri.pt3.y() as f32],
|
||||
color: color.0,
|
||||
});
|
||||
|
||||
let i = (3 * idx) as u32;
|
||||
indices.push(i);
|
||||
indices.push(i + 1);
|
||||
indices.push(i + 2);
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let indices: Vec<u32> = raw_indices.iter().map(|i| *i as u32).collect();
|
||||
|
||||
let vertex_buffer = glium::VertexBuffer::new(self.display, &vertices).unwrap();
|
||||
let index_buffer = glium::IndexBuffer::new(
|
||||
|
@ -94,6 +94,10 @@ impl Polygon {
|
||||
triangles
|
||||
}
|
||||
|
||||
pub fn raw_for_rendering(&self) -> (&Vec<Pt2D>, &Vec<usize>) {
|
||||
(&self.points, &self.indices)
|
||||
}
|
||||
|
||||
pub fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.triangles().into_iter().any(|tri| tri.contains_pt(pt))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user