mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
wallet: working z_index in renderer
This commit is contained in:
@@ -183,6 +183,7 @@ pub enum DrawInstruction {
|
||||
pub struct DrawCall {
|
||||
pub instrs: Vec<DrawInstruction>,
|
||||
pub dcs: Vec<u64>,
|
||||
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,
|
||||
|
||||
@@ -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<Self> {
|
||||
// Test if it works
|
||||
let _ = prop.get_u32(idx)?;
|
||||
|
||||
Ok(Self { prop, idx })
|
||||
}
|
||||
|
||||
pub fn wrap(node: &SceneNode, prop_name: &str, idx: usize) -> Result<Self> {
|
||||
let prop = node.get_property(prop_name).ok_or(Error::PropertyNotFound)?;
|
||||
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -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<Self>| {
|
||||
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(),
|
||||
},
|
||||
)],
|
||||
})
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user