start a way to upload once, draw many times

This commit is contained in:
Dustin Carlino 2019-01-25 09:09:55 -08:00
parent b21852875e
commit 4882e98933
2 changed files with 19 additions and 3 deletions

View File

@ -163,6 +163,11 @@ impl<'a> GfxCtx<'a> {
}
pub fn draw_polygon_batch(&mut self, list: Vec<(Color, &Polygon)>) {
let obj = self.prerender(list);
self.draw(&obj);
}
pub fn prerender(&mut self, list: Vec<(Color, &Polygon)>) -> Drawable {
let mut vertices: Vec<Vertex> = Vec::new();
let mut indices: Vec<u32> = Vec::new();
@ -189,10 +194,15 @@ impl<'a> GfxCtx<'a> {
.unwrap();
self.num_new_uploads += 1;
Drawable {
vertex_buffer, index_buffer, }
}
pub fn draw(&mut self, obj: &Drawable) {
self.target
.draw(
&vertex_buffer,
&index_buffer,
&obj.vertex_buffer,
&obj.index_buffer,
&self.program,
&self.uniforms,
&self.params,
@ -201,3 +211,9 @@ impl<'a> GfxCtx<'a> {
self.num_draw_calls += 1;
}
}
// Something that's been sent to the GPU already.
pub struct Drawable {
vertex_buffer: glium::VertexBuffer<Vertex>,
index_buffer: glium::IndexBuffer<u32>,
}

View File

@ -15,7 +15,7 @@ mod wizard;
pub use crate::canvas::{Canvas, HorizontalAlignment, VerticalAlignment, BOTTOM_LEFT, CENTERED};
pub use crate::color::Color;
pub use crate::drawing::GfxCtx;
pub use crate::drawing::{Drawable, GfxCtx};
pub use crate::event::{Event, Key};
pub use crate::input::{ModalMenu, UserInput};
pub use crate::log_scroller::LogScroller;