Fixed texture loader
parent
d09158a324
commit
8ae584b87e
|
@ -303,6 +303,11 @@ impl Content {
|
|||
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
|
||||
pub fn get_image(&self, idx: NonZeroU32) -> &SpriteAtlasImage {
|
||||
&self.sprite_atlas.get_by_idx(idx)
|
||||
|
|
|
@ -76,6 +76,11 @@ impl SpriteAtlas {
|
|||
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
|
||||
pub fn len(&self) -> u32 {
|
||||
self.index.len() as u32
|
||||
|
|
|
@ -109,28 +109,15 @@ impl TextureArray {
|
|||
let mut image_locations = AtlasArray::zeroed();
|
||||
|
||||
println!("sending to gpu");
|
||||
for sprite in &ct.sprites {
|
||||
for section in sprite.iter_sections() {
|
||||
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,
|
||||
ypos: image.y,
|
||||
width: image.w,
|
||||
height: image.h,
|
||||
atlas_texture: image.atlas,
|
||||
_padding: Default::default(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
for image in ct.get_atlas().iter_images() {
|
||||
image_locations.data[image.idx.get() as usize] = AtlasImageLocation {
|
||||
xpos: image.x,
|
||||
ypos: image.y,
|
||||
width: image.w,
|
||||
height: image.h,
|
||||
atlas_texture: image.atlas,
|
||||
_padding: Default::default(),
|
||||
};
|
||||
}
|
||||
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
|
|
Loading…
Reference in New Issue