fix some atlas bugs

This commit is contained in:
griffi-gh 2024-03-06 20:58:50 +01:00
parent 7a70b0ccb2
commit cd6d421909
2 changed files with 6 additions and 7 deletions

View file

@ -95,10 +95,9 @@ impl BufferPair {
self.vertex_count = vtx.len(); self.vertex_count = vtx.len();
self.index_count = idx.len(); self.index_count = idx.len();
// self.vertex_buffer.invalidate();
// self.index_buffer.invalidate();
if self.vertex_count == 0 || self.index_count == 0 { if self.vertex_count == 0 || self.index_count == 0 {
self.vertex_buffer.invalidate();
self.index_buffer.invalidate();
return return
} }

View file

@ -83,12 +83,12 @@ impl TextureAtlasManager {
log::warn!("Texture atlas is already the requested size"); log::warn!("Texture atlas is already the requested size");
return return
} }
if new_size.x > self.size.x && new_size.y > self.size.y{ if new_size.x > self.size.x && new_size.y > self.size.y {
self.packer.resize(new_size.x as i32, new_size.y as i32); self.packer.resize(new_size.x as i32, new_size.y as i32);
//Resize the data array in-place //Resize the data array in-place
self.data.resize((new_size.x * new_size.y * RGBA_CHANNEL_COUNT) as usize, 0); self.data.resize((new_size.x * new_size.y * RGBA_CHANNEL_COUNT) as usize, 0);
for y in (1..self.size.y).rev() { for y in (0..self.size.y).rev() {
for x in (0..self.size.x).rev() { for x in (1..self.size.x).rev() {
let idx = ((y * self.size.x + x) * RGBA_CHANNEL_COUNT) as usize; let idx = ((y * self.size.x + x) * RGBA_CHANNEL_COUNT) as usize;
let new_idx = ((y * new_size.x + x) * RGBA_CHANNEL_COUNT) as usize; let new_idx = ((y * new_size.x + x) * RGBA_CHANNEL_COUNT) as usize;
for c in 0..(RGBA_CHANNEL_COUNT as usize) { for c in 0..(RGBA_CHANNEL_COUNT as usize) {
@ -111,7 +111,7 @@ impl TextureAtlasManager {
// TODO: implement these // TODO: implement these
// Plan C: resize the atlas // Plan C: resize the atlas
let mut new_size = self.size; let mut new_size = self.size;
while !self.packer.can_pack(size.x as i32, size.y as i32, true) { while !self.packer.can_pack(size.x as i32, size.y as i32, ALLOW_ROTATION) {
new_size *= 2; new_size *= 2;
self.packer.resize(new_size.x as i32, new_size.y as i32); self.packer.resize(new_size.x as i32, new_size.y as i32);
} }