summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/camera.rs2
-rw-r--r--src/instance.rs12
-rw-r--r--src/lib.rs2
-rw-r--r--src/renderer.rs1
4 files changed, 10 insertions, 7 deletions
diff --git a/src/camera.rs b/src/camera.rs
index 3ae33b4..e77da40 100644
--- a/src/camera.rs
+++ b/src/camera.rs
@@ -175,7 +175,7 @@ impl Camera {
let projection_matrix = Matrix4::new(
self.inverse_aspect_ratio * self.zoom, 0.0, 0.0, 0.0,
0.0, self.zoom, 0.0, 0.0,
- 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0 / 256.0, 0.0,
0.0, 0.0, 0.0, 1.0
);
diff --git a/src/instance.rs b/src/instance.rs
index bacad56..2bff797 100644
--- a/src/instance.rs
+++ b/src/instance.rs
@@ -21,7 +21,7 @@ pub struct Instance {
/// Rotation, in radians
pub rotation: f32,
/// z-index
- pub z_index: u32, // TODO something more interesting with z-axis
+ pub z_index: f32,
}
impl Default for Instance {
@@ -30,7 +30,7 @@ impl Default for Instance {
position: [0.0; 2],
size: [1.0; 2],
rotation: 0.0,
- z_index: 0,
+ z_index: 0.0,
texture_coordinates: [0.0; 2],
texture_size: [1.0; 2],
texture_atlas_index: 0,
@@ -42,7 +42,7 @@ impl Instance {
// whenever this is updated, please also update `sprite.wgsl`
const ATTRIBUTES: [wgpu::VertexAttribute; 7] = wgpu::vertex_attr_array![
1 => Float32x2, 2 => Float32x2, 3 => Float32x2, 4 => Float32x2,
- 5 => Uint32, 6 => Float32, 7 => Uint32
+ 5 => Uint32, 6 => Float32, 7 => Float32
];
pub(crate) fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
@@ -135,10 +135,14 @@ impl InstanceBuffer {
self.expand_buffer(device);
}
+ // the instances must be sorted by z-index before being handed to the GPU
+ let mut sorted = self.instances.clone();
+ sorted.sort_by(|a, b| a.z_index.total_cmp(&b.z_index));
+
queue.write_buffer(
&self.instance_buffer,
0 as wgpu::BufferAddress,
- bytemuck::cast_slice(&self.instances),
+ bytemuck::cast_slice(&sorted),
);
}
}
diff --git a/src/lib.rs b/src/lib.rs
index aefcb70..f5403f2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,7 +5,7 @@
#![warn(clippy::nursery)]
#![allow(clippy::module_name_repetitions)]
-pub mod camera;
+mod camera;
pub mod config;
pub mod instance;
pub mod renderer;
diff --git a/src/renderer.rs b/src/renderer.rs
index 544b01b..e97b0fd 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -114,7 +114,6 @@ fn sprite_render_pipeline(
})
}
-// TODO make this more complete
impl Renderer {
/// Initializes the renderer
///