Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Use BTreeMap for deterministic MeshKey iteration to prevent z-fighting #80

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions comfy-core/src/render_queues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn get_current_shader() -> Option<ShaderInstanceId> {
*CURRENT_SHADER.borrow()
}

use std::sync::atomic::AtomicU64;
use std::{sync::atomic::AtomicU64, collections::BTreeMap};

static SHADER_IDS: AtomicU64 = AtomicU64::new(0);

Expand All @@ -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<AtomicRefCell<Vec<DrawText>>> =
Expand All @@ -108,10 +108,10 @@ pub type RenderQueue = Vec<Mesh>;

#[derive(Default)]
struct RenderQueues {
data: HashMap<MeshGroupKey, RenderQueue>,
data: BTreeMap<MeshGroupKey, RenderQueue>,
}

#[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,
Expand All @@ -120,9 +120,9 @@ pub struct MeshGroupKey {
pub render_target: Option<RenderTargetId>,
}

pub fn consume_render_queues() -> HashMap<MeshGroupKey, RenderQueue> {
pub fn consume_render_queues() -> BTreeMap<MeshGroupKey, RenderQueue> {
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
}
Expand Down
Loading