Skip to content

Commit

Permalink
Fix optimized stitcher ignoring maximum atlas size
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Mar 26, 2024
1 parent d2680cf commit 7e9ace3
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.embeddedt.modernfix.common.mixin.perf.faster_texture_stitching;

import com.google.common.collect.ImmutableList;
import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.client.renderer.texture.Stitcher;
import net.minecraft.client.renderer.texture.StitcherException;
import org.embeddedt.modernfix.ModernFix;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
Expand All @@ -17,6 +19,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

@Mixin(Stitcher.class)
@ClientOnlyMixin
Expand All @@ -28,6 +31,8 @@ public class StitcherMixin {
@Shadow private int storageY;

@Shadow @Final private static Comparator<Stitcher.Holder> HOLDER_COMPARATOR;
@Shadow @Final private int maxWidth;
@Shadow @Final private int maxHeight;
private List<StbStitcher.LoadableSpriteInfo> loadableSpriteInfos;

/**
Expand All @@ -48,6 +53,13 @@ private void stitchFast(CallbackInfo ci) {
Pair<Pair<Integer, Integer>, List<StbStitcher.LoadableSpriteInfo>> packingInfo = StbStitcher.packRects(aholder);
this.storageX = packingInfo.getFirst().getFirst();
this.storageY = packingInfo.getFirst().getSecond();

// Detect an oversized atlas generated in the previous step.
if(this.storageX > this.maxWidth || this.storageY > this.maxHeight) {
ModernFix.LOGGER.error("Requested atlas size {}x{} exceeds maximum of {}x{}", this.storageX, this.storageY, this.maxWidth, this.maxHeight);
throw new StitcherException(aholder[0].spriteInfo, Stream.of(aholder).map(arg -> arg.spriteInfo).collect(ImmutableList.toImmutableList()));
}

this.loadableSpriteInfos = packingInfo.getSecond();
}

Expand Down

0 comments on commit 7e9ace3

Please sign in to comment.