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,28 +109,15 @@ 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 {
|
xpos: image.x,
|
||||||
// Some atlas entries may be written twice here,
|
ypos: image.y,
|
||||||
// but that's not really a problem. They're all the same!
|
width: image.w,
|
||||||
//
|
height: image.h,
|
||||||
// This happens rarely---only when two different sections
|
atlas_texture: image.atlas,
|
||||||
// use the same frame.
|
_padding: Default::default(),
|
||||||
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(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
|
|
Loading…
Reference in New Issue