From 4dda34e66cceef0877481bdd0f5500807a926600 Mon Sep 17 00:00:00 2001 From: setzer22 Date: Sat, 16 Dec 2023 18:47:12 +0100 Subject: [PATCH] Use BTreeMap for deterministic MeshKey iteration to prevent z-fighting --- comfy-core/src/render_queues.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/comfy-core/src/render_queues.rs b/comfy-core/src/render_queues.rs index b2ce4e7..073c5c7 100644 --- a/comfy-core/src/render_queues.rs +++ b/comfy-core/src/render_queues.rs @@ -71,7 +71,7 @@ pub fn get_current_shader() -> Option { *CURRENT_SHADER.borrow() } -use std::sync::atomic::AtomicU64; +use std::{sync::atomic::AtomicU64, collections::BTreeMap}; static SHADER_IDS: AtomicU64 = AtomicU64::new(0); @@ -87,7 +87,7 @@ pub fn gen_shader_id() -> ShaderId { /// Represents a set of shader uniform parameters. /// /// u32 ID is exposed for debugging purposes only, do not modify by hand. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ShaderInstanceId(pub u32); static TEXT_QUEUE: Lazy>> = @@ -108,10 +108,10 @@ pub type RenderQueue = Vec; #[derive(Default)] struct RenderQueues { - data: HashMap, + data: BTreeMap, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct MeshGroupKey { pub z_index: i32, pub blend_mode: BlendMode, @@ -120,9 +120,9 @@ pub struct MeshGroupKey { pub render_target: Option, } -pub fn consume_render_queues() -> HashMap { +pub fn consume_render_queues() -> BTreeMap { let mut queues = RENDER_QUEUES.borrow_mut(); - let mut new_data = HashMap::new(); + let mut new_data = BTreeMap::new(); std::mem::swap(&mut new_data, &mut queues.data); new_data }