mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 14:28:43 -06:00
fix crash, ui core multi-draw call
This commit is contained in:
parent
d852c48e4a
commit
547759d6b2
|
@ -30,11 +30,11 @@ impl From<UiVertex> for Vertex {
|
|||
implement_vertex!(Vertex, position, color);
|
||||
|
||||
pub struct GliumUiRenderer {
|
||||
pub program: glium::Program,
|
||||
pub vertex_buffer: glium::VertexBuffer<Vertex>,
|
||||
pub index_buffer: glium::IndexBuffer<u32>,
|
||||
pub vertex_count: usize,
|
||||
pub index_count: usize,
|
||||
program: glium::Program,
|
||||
vertex_buffer: glium::VertexBuffer<Vertex>,
|
||||
index_buffer: glium::IndexBuffer<u32>,
|
||||
vertex_count: usize,
|
||||
index_count: usize,
|
||||
}
|
||||
|
||||
impl GliumUiRenderer {
|
||||
|
@ -73,18 +73,26 @@ impl GliumUiRenderer {
|
|||
|
||||
fn write_buffer_data(&mut self, vtx: &[Vertex], idx: &[u32]) {
|
||||
log::debug!("uploading {} vertices and {} indices", vtx.len(), idx.len());
|
||||
self.ensure_buffer_size(vtx.len(), idx.len());
|
||||
self.vertex_buffer.invalidate();
|
||||
self.vertex_buffer.slice_mut(0..vtx.len()).unwrap().write(vtx);
|
||||
|
||||
self.vertex_count = vtx.len();
|
||||
self.index_buffer.invalidate();
|
||||
self.index_buffer.slice_mut(0..idx.len()).unwrap().write(idx);
|
||||
self.index_count = idx.len();
|
||||
|
||||
self.vertex_buffer.invalidate();
|
||||
self.index_buffer.invalidate();
|
||||
|
||||
if self.vertex_count == 0 || self.index_count == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
self.ensure_buffer_size(vtx.len(), idx.len());
|
||||
self.vertex_buffer.slice_mut(0..vtx.len()).unwrap().write(vtx);
|
||||
self.index_buffer.slice_mut(0..idx.len()).unwrap().write(idx);
|
||||
}
|
||||
|
||||
pub fn update(&mut self, plan: &UiDrawPlan) {
|
||||
let data_vtx = &plan.vertices.iter().copied().map(Vertex::from).collect::<Vec<_>>();
|
||||
let data_idx = &plan.indices;
|
||||
assert!(plan.calls.len() == 1, "multiple draw calls not supported yet");
|
||||
let data_vtx = &plan.calls[0].vertices.iter().copied().map(Vertex::from).collect::<Vec<_>>();
|
||||
let data_idx = &plan.calls[0].indices;
|
||||
self.write_buffer_data(data_vtx, data_idx);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,20 +34,25 @@ pub struct UiVertex {
|
|||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UiDrawPlan {
|
||||
pub struct UiDrawCall {
|
||||
pub vertices: Vec<UiVertex>,
|
||||
pub indices: Vec<u32>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UiDrawPlan {
|
||||
pub calls: Vec<UiDrawCall>
|
||||
}
|
||||
|
||||
impl UiDrawPlan {
|
||||
pub fn build(calls: &UiDrawCommands) -> Self {
|
||||
let mut plan = Self::default();
|
||||
for call in &calls.commands {
|
||||
match call {
|
||||
let mut call = UiDrawCall::default();
|
||||
for command in &calls.commands {
|
||||
match command {
|
||||
UiDrawCommand::Rectangle { position, size, color } => {
|
||||
let idx = plan.vertices.len() as u32;
|
||||
plan.indices.extend([idx, idx + 1, idx + 2, idx, idx + 2, idx + 3]);
|
||||
plan.vertices.extend([
|
||||
let idx = call.vertices.len() as u32;
|
||||
call.indices.extend([idx, idx + 1, idx + 2, idx, idx + 2, idx + 3]);
|
||||
call.vertices.extend([
|
||||
UiVertex {
|
||||
position: *position,
|
||||
color: *color,
|
||||
|
@ -68,6 +73,8 @@ impl UiDrawPlan {
|
|||
}
|
||||
}
|
||||
}
|
||||
plan
|
||||
Self {
|
||||
calls: vec![call]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue