use of net.modificationstation.stationapi.api.util.profiler.Profiler in project StationAPI by ModificationStation.
the class SpriteAtlasTexture method stitch.
public Data stitch(TexturePack resourceManager, Stream<Identifier> idStream, Profiler profiler, int mipmapLevel) {
int p;
profiler.push("preparing");
Set<Identifier> set = idStream.peek(identifier -> {
if (identifier == null) {
throw new IllegalArgumentException("Location cannot be null!");
}
}).collect(Collectors.toSet());
int i = this.maxTextureSize;
TextureStitcher textureStitcher = new TextureStitcher(i, i, mipmapLevel);
int j = Integer.MAX_VALUE;
int k = 1 << mipmapLevel;
profiler.swap("extracting_frames");
for (Sprite.Info info2 : this.loadSprites(resourceManager, set)) {
j = Math.min(j, Math.min(info2.getWidth(), info2.getHeight()));
int l = Math.min(Integer.lowestOneBit(info2.getWidth()), Integer.lowestOneBit(info2.getHeight()));
if (l < k) {
LOGGER.warn("Texture {} with size {}x{} limits mip level from {} to {}", info2.getId(), info2.getWidth(), info2.getHeight(), MathHelper.log2(k), MathHelper.log2(l));
k = l;
}
textureStitcher.add(info2);
}
int m = Math.min(j, k);
int n = MathHelper.log2(m);
if (n < mipmapLevel) {
LOGGER.warn("{}: dropping miplevel from {} to {}, because of minimum power of two: {}", this.id, mipmapLevel, n, m);
p = n;
} else {
p = mipmapLevel;
}
profiler.swap("register");
textureStitcher.add(MissingSprite.getMissingInfo());
profiler.swap("stitching");
try {
textureStitcher.stitch();
} catch (TextureStitcherCannotFitException textureStitcherCannotFitException) {
CrashReport crashReport = CrashReport.create(textureStitcherCannotFitException, "Stitching");
CrashReportSection crashReportSection = crashReport.addElement("Stitcher");
crashReportSection.add("Sprites", textureStitcherCannotFitException.getSprites().stream().map(info -> String.format("%s[%dx%d]", info.getId(), info.getWidth(), info.getHeight())).collect(Collectors.joining(",")));
crashReportSection.add("Max Texture Size", i);
throw new CrashException(crashReport);
}
profiler.swap("loading");
List<Sprite> list = this.loadSprites(resourceManager, textureStitcher, p);
profiler.pop();
return new Data(set, textureStitcher.getWidth(), textureStitcher.getHeight(), p, list);
}
Aggregations