Fixed texture loader
parent
d09158a324
commit
8ae584b87e
|
@ -303,6 +303,11 @@ impl Content {
|
||||||
return &self.sprite_atlas.atlas_list;
|
return &self.sprite_atlas.atlas_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get sprite atlas metadata
|
||||||
|
pub fn get_atlas(&self) -> &SpriteAtlas {
|
||||||
|
return &self.sprite_atlas;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get a texture by its index
|
/// Get a texture by its index
|
||||||
pub fn get_image(&self, idx: NonZeroU32) -> &SpriteAtlasImage {
|
pub fn get_image(&self, idx: NonZeroU32) -> &SpriteAtlasImage {
|
||||||
&self.sprite_atlas.get_by_idx(idx)
|
&self.sprite_atlas.get_by_idx(idx)
|
||||||
|
|
|
@ -76,6 +76,11 @@ impl SpriteAtlas {
|
||||||
self.path_map.get(path).map(|x| *x)
|
self.path_map.get(path).map(|x| *x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Iterate all images in this atlas
|
||||||
|
pub fn iter_images(&self) -> impl Iterator<Item = &SpriteAtlasImage> {
|
||||||
|
self.index.iter()
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the number of images in this atlas
|
/// Get the number of images in this atlas
|
||||||
pub fn len(&self) -> u32 {
|
pub fn len(&self) -> u32 {
|
||||||
self.index.len() as u32
|
self.index.len() as u32
|
||||||
|
|
|
@ -109,18 +109,8 @@ impl TextureArray {
|
||||||
let mut image_locations = AtlasArray::zeroed();
|
let mut image_locations = AtlasArray::zeroed();
|
||||||
|
|
||||||
println!("sending to gpu");
|
println!("sending to gpu");
|
||||||
for sprite in &ct.sprites {
|
for image in ct.get_atlas().iter_images() {
|
||||||
for section in sprite.iter_sections() {
|
image_locations.data[image.idx.get() as usize] = AtlasImageLocation {
|
||||||
for idx in §ion.frames {
|
|
||||||
// Some atlas entries may be written twice here,
|
|
||||||
// but that's not really a problem. They're all the same!
|
|
||||||
//
|
|
||||||
// This happens rarely---only when two different sections
|
|
||||||
// use the same frame.
|
|
||||||
let idx = NonZeroU32::new(*idx);
|
|
||||||
if idx.is_some() {
|
|
||||||
let image = ct.get_image(idx.unwrap());
|
|
||||||
image_locations.data[idx.unwrap().get() as usize] = AtlasImageLocation {
|
|
||||||
xpos: image.x,
|
xpos: image.x,
|
||||||
ypos: image.y,
|
ypos: image.y,
|
||||||
width: image.w,
|
width: image.w,
|
||||||
|
@ -129,9 +119,6 @@ impl TextureArray {
|
||||||
_padding: Default::default(),
|
_padding: Default::default(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||||
|
|
Loading…
Reference in New Issue