Skip to content

Commit

Permalink
Fix packed asset never power of two
Browse files Browse the repository at this point in the history
Since setting power of two is never used anywhere, add logic check and process power of two for texture size.
  • Loading branch information
JenovaSolier authored Nov 21, 2024
1 parent dbad6e7 commit 877df46
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/assetpack/src/texture-packer/packer/fitTextureToPacker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PackTexturesOptions, PixiPacker } from './packTextures.js';

export function fitTextureToPacker(bin: PixiPacker, { width, height, fixedSize, padding }: PackTexturesOptions)
export function fitTextureToPacker(bin: PixiPacker, { width, height, fixedSize, padding, powerOfTwo }: PackTexturesOptions)
{
if (!fixedSize)
{
Expand All @@ -27,6 +27,21 @@ export function fitTextureToPacker(bin: PixiPacker, { width, height, fixedSize,
height += padding ?? 0;
width += padding ?? 0;
}


if (powerOfTwo)
{
height = nearestPowerOf2(height);
width = nearestPowerOf2(width);
}

return { width, height } as { width: number, height: number};
}

function nearestPowerOf2(x) {
if (x <= 1) return 1;
let power = 1;
while (power < x) {
power <<= 1;
}
return power;
}

0 comments on commit 877df46

Please sign in to comment.