Skip to content

Commit 2722ccc

Browse files
committed
Remove indices of immediate mod line meshes
With bevyengine/bevy#3415 it is now possible to upload meshes to GPU without `indices` set. Before, it would panic. Removing `indices` enables us to simply remove the `ImmLinesStorage::fill_indices` code, since the ordering is exactly as the GPU would interpret the mesh otherwise.
1 parent 95ee329 commit 2722ccc

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exclude = ["demo.gif", "demo_2.png", "demo_2.webm"]
1616
bevy = { version = "0.5", default-features = false, features = [ "render" ] }
1717

1818
[patch.crates-io]
19-
bevy = { git = "https://github.com/bevyengine/bevy", rev = "a3c53e689d62a2fd403bf0236b5638e569bd5600" }
19+
bevy = { git = "https://github.com/nicopap/bevy", branch = "implement-non-indexed-drawing" }
2020

2121
[features]
2222
example_deps = [

examples/3d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn setup(mut commands: Commands, mut lines: DebugLines) {
2323
Vec3::new(-1.0, 1.0, 1.0),
2424
100.0,
2525
Color::CYAN,
26-
Color::ORANGE_RED,
26+
Color::MIDNIGHT_BLUE,
2727
);
2828
}
2929

src/lib.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ pub const MAX_LINES: usize = MAX_POINTS / 2;
7373
pub const MAX_POINTS: usize = MAX_POINTS_PER_MESH * DEBUG_LINES_MESH_COUNT;
7474

7575
fn spawn_debug_lines_mesh(meshes: &mut Assets<Mesh>, retain: DebugLinesMesh) -> impl Bundle {
76+
let is_immediate = matches!(retain, DebugLinesMesh::Immediate(_));
7677
(
77-
meshes.add(debug_lines_mesh()),
78+
meshes.add(debug_lines_mesh(is_immediate)),
7879
Transform::default(),
7980
GlobalTransform::default(),
8081
Visibility::default(),
@@ -111,7 +112,7 @@ fn update_debug_lines_mesh(
111112
}
112113

113114
/// Initialize [`DebugLinesMesh`]'s [`Mesh`].
114-
fn debug_lines_mesh() -> Mesh {
115+
fn debug_lines_mesh(is_immediate: bool) -> Mesh {
115116
let mut mesh = Mesh::new(PrimitiveTopology::LineList);
116117
mesh.set_attribute(
117118
Mesh::ATTRIBUTE_POSITION,
@@ -121,7 +122,9 @@ fn debug_lines_mesh() -> Mesh {
121122
Mesh::ATTRIBUTE_COLOR,
122123
VertexAttributeValues::Float32x4(Vec::with_capacity(256)),
123124
);
124-
mesh.set_indices(Some(Indices::U16(Vec::with_capacity(256))));
125+
if !is_immediate {
126+
mesh.set_indices(Some(Indices::U16(Vec::with_capacity(256))));
127+
}
125128
mesh
126129
}
127130

@@ -194,23 +197,6 @@ impl ImmLinesStorage {
194197
}
195198
}
196199

197-
fn fill_indices(&self, buffer: &mut Vec<u16>, mesh: usize) {
198-
buffer.clear();
199-
let start = mesh << 16;
200-
let end = (mesh + 1) << 16;
201-
let buffer_size = self.positions.len();
202-
let indices = if start < buffer_size && buffer_size >= end {
203-
// Because MAX_POINTS_PER_MESH == 2^16
204-
0xFFFF_u16
205-
} else if start < buffer_size && buffer_size < end {
206-
(buffer_size - start) as u16
207-
} else {
208-
0
209-
};
210-
// Because MAX_POINTS_PER_MESH == 2^16, this needs to be inclusive
211-
buffer.extend(0..=indices);
212-
}
213-
214200
fn mark_expired(&mut self) {
215201
self.positions.clear();
216202
self.colors.clear();
@@ -232,9 +218,6 @@ impl ImmLinesStorage {
232218

233219
fn fill_attributes(&self, mesh: &mut Mesh, mesh_index: usize) {
234220
use VertexAttributeValues::{Float32x3, Float32x4};
235-
if let Some(Indices::U16(indices)) = mesh.indices_mut() {
236-
self.fill_indices(indices, mesh_index);
237-
}
238221
if let Some(Float32x3(vbuffer)) = mesh.attribute_mut(Mesh::ATTRIBUTE_POSITION) {
239222
self.fill_vertexes(vbuffer, mesh_index);
240223
}
@@ -458,7 +441,7 @@ impl SpecializedPipeline for DebugLinePipeline {
458441
descriptor.fragment.as_mut().unwrap().shader = self.shader.clone_weak();
459442
descriptor.primitive.topology = PrimitiveTopology::LineList;
460443
descriptor.primitive.cull_mode = None;
461-
// TODO: set this to None to remove depth check
444+
// TODO: set this to a large value to remove depth check
462445
descriptor.depth_stencil.as_mut().unwrap().bias.slope_scale = 1.0;
463446
descriptor
464447
}

0 commit comments

Comments
 (0)