aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:24 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:24 +0100
commitdf4271047b6e482cbeaa099f819c797860b96d18 (patch)
tree4de48fd8c3e38789bc2fbd7b990bf24585480dbd /stockton-render/src
parent1d0dbcd1750cb1dd0060fc8dfa3ba8a64b7f8afe (diff)
fix(ui): fix drawing multiple meshes for ui
ui is still broken, because egui is giving bad uv coords
Diffstat (limited to 'stockton-render/src')
-rw-r--r--stockton-render/src/ui.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/stockton-render/src/ui.rs b/stockton-render/src/ui.rs
index 0d53c4f..8401f63 100644
--- a/stockton-render/src/ui.rs
+++ b/stockton-render/src/ui.rs
@@ -123,19 +123,22 @@ impl<'a, P: PassPosition> DrawPass<P> for UiDrawPass<'a> {
.ok_or_else(|| anyhow!("UI not set up properly."))?;
let shapes = ui.ctx().tessellate(shapes);
+ let mut next_idx_idx = 0;
+ let mut next_vert_idx = 0;
for ClippedMesh(rect, tris) in shapes.iter() {
assert!(tris.texture_id == TextureId::Egui);
// Copy triangles/indicies
for i in (0..tris.indices.len()).step_by(3) {
- self.draw_buffers.index_buffer[i / 3] = (
+ self.draw_buffers.index_buffer[next_idx_idx + (i / 3)] = (
tris.indices[i].try_into()?,
tris.indices[i + 1].try_into()?,
tris.indices[i + 2].try_into()?,
);
}
+
for (i, vertex) in tris.vertices.iter().enumerate() {
- self.draw_buffers.vertex_buffer[i] = UiPoint(
+ self.draw_buffers.vertex_buffer[next_vert_idx + i] = UiPoint(
Vector2::new(vertex.pos.x, vertex.pos.y),
Vector2::new(vertex.uv.x, vertex.uv.y),
[
@@ -146,6 +149,7 @@ impl<'a, P: PassPosition> DrawPass<P> for UiDrawPass<'a> {
],
);
}
+
// TODO: *Properly* deal with textures
if let Some(ds) = self.repo.attempt_get_descriptor_set(0) {
unsafe {
@@ -172,11 +176,18 @@ impl<'a, P: PassPosition> DrawPass<P> for UiDrawPass<'a> {
empty(),
);
// Call draw
- cmd_buffer.draw_indexed(0..tris.indices.len() as u32, 0, 0..1);
+ cmd_buffer.draw_indexed(
+ (next_idx_idx as u32 * 3)..((next_idx_idx * 3) + tris.indices.len()) as u32,
+ next_vert_idx as i32,
+ 0..1,
+ );
}
} else {
self.repo.queue_load(0)?;
}
+
+ next_idx_idx += tris.indices.len() / 3;
+ next_vert_idx += tris.vertices.len();
}
unsafe {