summaryrefslogtreecommitdiff
path: root/src/instance.rs
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2022-09-30 21:20:08 -0400
committerMicha White <botahamec@outlook.com>2022-09-30 21:20:08 -0400
commitff8b849957ed63e6a19522597903f6bf55788426 (patch)
tree6e8ef2589c71e430e95fb2cb1853f05c41761536 /src/instance.rs
parent867b344a6c05ec3bf8751bda0c2f2e2b3c3778c2 (diff)
Set up instances with texture information
Diffstat (limited to 'src/instance.rs')
-rw-r--r--src/instance.rs15
1 files changed, 13 insertions, 2 deletions
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