From ff8b849957ed63e6a19522597903f6bf55788426 Mon Sep 17 00:00:00 2001 From: Micha White Date: Fri, 30 Sep 2022 21:20:08 -0400 Subject: Set up instances with texture information --- src/instance.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/instance.rs') diff --git a/src/instance.rs b/src/instance.rs index 6ea5321..eded8cf 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -12,6 +12,12 @@ pub struct Instance { pub position: [f32; 2], /// Relative size pub size: [f32; 2], + /// The location of the texture in the texture atlas + pub texture_coordinates: [f32; 2], + /// The size of the sprite's texture + pub texture_size: [f32; 2], + /// The index of the texture atlas to use + pub texture_atlas_index: u32, /// Rotation, in radians pub rotation: f32, /// z-index @@ -25,14 +31,19 @@ impl Default for Instance { size: [1.0; 2], rotation: 0.0, z_index: 0, + texture_coordinates: [0.0; 2], + texture_size: [1.0; 2], + texture_atlas_index: 0, } } } impl Instance { // whenever this is updated, please also update `sprite.wgsl` - const ATTRIBUTES: [wgpu::VertexAttribute; 4] = - wgpu::vertex_attr_array![1 => Float32x2, 2 => Float32x2, 3 => Float32, 4 => Uint32]; + const ATTRIBUTES: [wgpu::VertexAttribute; 7] = wgpu::vertex_attr_array![ + 1 => Float32x2, 2 => Float32x2, 3 => Float32x2, 4 => Float32x2, + 5 => Uint32, 6 => Float32, 7 => Uint32 + ]; pub(crate) fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { // make sure these two don't conflict -- cgit v1.2.3