diff --git a/bin/darkwallet/src/gfx2.rs b/bin/darkwallet/src/gfx2.rs index 4385644fd..17586069a 100644 --- a/bin/darkwallet/src/gfx2.rs +++ b/bin/darkwallet/src/gfx2.rs @@ -183,6 +183,7 @@ pub enum DrawInstruction { pub struct DrawCall { pub instrs: Vec, pub dcs: Vec, + pub z_index: u32, } struct RenderContext<'a> { @@ -258,8 +259,11 @@ impl<'a> RenderContext<'a> { } } - for dc_key in &draw_call.dcs { - let dc = &self.draw_calls[dc_key]; + let mut draw_calls: Vec<_> = + draw_call.dcs.iter().map(|key| &self.draw_calls[key]).collect(); + draw_calls.sort_unstable_by_key(|dc| dc.z_index); + + for dc in draw_calls { self.draw_call(dc, indent + 1); } } @@ -375,7 +379,7 @@ impl Stage { ctx, pipeline, white_texture, - draw_calls: HashMap::from([(0, DrawCall { instrs: vec![], dcs: vec![] })]), + draw_calls: HashMap::from([(0, DrawCall { instrs: vec![], dcs: vec![], z_index: 0 })]), last_draw_time: None, method_rep, event_pub, diff --git a/bin/darkwallet/src/prop/wrap.rs b/bin/darkwallet/src/prop/wrap.rs index 251014329..48a595a32 100644 --- a/bin/darkwallet/src/prop/wrap.rs +++ b/bin/darkwallet/src/prop/wrap.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use super::Property; +use super::{Property, PropertyPtr}; use crate::{ error::{Error, Result}, scene::SceneNode, @@ -36,6 +36,13 @@ pub struct PropertyUint32 { } impl PropertyUint32 { + pub fn from(prop: PropertyPtr, idx: usize) -> Result { + // Test if it works + let _ = prop.get_u32(idx)?; + + Ok(Self { prop, idx }) + } + pub fn wrap(node: &SceneNode, prop_name: &str, idx: usize) -> Result { let prop = node.get_property(prop_name).ok_or(Error::PropertyNotFound)?; diff --git a/bin/darkwallet/src/ui/layer.rs b/bin/darkwallet/src/ui/layer.rs index f425a2294..8d1d96184 100644 --- a/bin/darkwallet/src/ui/layer.rs +++ b/bin/darkwallet/src/ui/layer.rs @@ -128,7 +128,11 @@ impl RenderLayer { child_calls.push(draw_update.key); } - let dc = DrawCall { instrs: vec![DrawInstruction::ApplyViewport(rect)], dcs: child_calls }; + let dc = DrawCall { + instrs: vec![DrawInstruction::ApplyViewport(rect)], + dcs: child_calls, + z_index: 0, + }; draw_calls.push((self.dc_key, dc)); Some(DrawUpdate { key: self.dc_key, draw_calls }) } diff --git a/bin/darkwallet/src/ui/mesh.rs b/bin/darkwallet/src/ui/mesh.rs index 1dc9d0a4b..5cee125fa 100644 --- a/bin/darkwallet/src/ui/mesh.rs +++ b/bin/darkwallet/src/ui/mesh.rs @@ -3,7 +3,7 @@ use std::sync::{Arc, Weak}; use crate::{ gfx2::{DrawCall, DrawInstruction, DrawMesh, Rectangle, RenderApiPtr, Vertex}, - prop::PropertyPtr, + prop::{PropertyPtr, PropertyUint32}, scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId}, }; @@ -25,6 +25,7 @@ pub struct Mesh { node_id: SceneNodeId, rect: PropertyPtr, + z_index: PropertyUint32, } impl Mesh { @@ -44,11 +45,14 @@ impl Mesh { let node = scene_graph.get_node(node_id).unwrap(); let node_name = node.name.clone(); let rect = node.get_property("rect").expect("RenderLayer::rect"); + let z_index_prop = node.get_property("z_index").expect("RenderLayer::z_index"); + let z_index = PropertyUint32::from(z_index_prop.clone(), 0).unwrap(); drop(scene_graph); let self_ = Arc::new_cyclic(|me: &Weak| { let mut on_modify = OnModify::new(ex, node_name, node_id, me.clone()); on_modify.when_change(rect.clone(), Self::redraw); + on_modify.when_change(z_index_prop, Self::redraw); Self { sg, @@ -60,6 +64,7 @@ impl Mesh { dc_key: OsRng.gen(), node_id, rect, + z_index, } }); @@ -119,6 +124,7 @@ impl Mesh { DrawCall { instrs: vec![DrawInstruction::ApplyMatrix(model), DrawInstruction::Draw(mesh)], dcs: vec![], + z_index: self.z_index.get(), }, )], }) diff --git a/bin/darkwallet/src/ui/win.rs b/bin/darkwallet/src/ui/win.rs index e62aa660a..6fb48f519 100644 --- a/bin/darkwallet/src/ui/win.rs +++ b/bin/darkwallet/src/ui/win.rs @@ -114,7 +114,7 @@ impl Window { child_calls.push(draw_update.key); } - let root_dc = DrawCall { instrs: vec![], dcs: child_calls }; + let root_dc = DrawCall { instrs: vec![], dcs: child_calls, z_index: 0 }; draw_calls.push((0, root_dc)); //debug!(" => {:?}", draw_calls);