use of net.minecraft.client.renderer.texture.Stitcher in project ForestryMC by ForestryMC.
the class TextureMapForestry method loadTextureAtlas.
@Override
public void loadTextureAtlas(IResourceManager resourceManager) {
int i = Minecraft.getGLMaximumTextureSize();
Stitcher stitcher = new Stitcher(i, i, 0, 0);
this.mapUploadedSprites.clear();
this.listAnimatedSprites.clear();
ProgressManager.ProgressBar bar = ProgressManager.push("Texture stitching", this.mapRegisteredSprites.size());
for (Map.Entry<String, TextureAtlasSprite> entry : this.mapRegisteredSprites.entrySet()) {
TextureAtlasSprite textureatlassprite = entry.getValue();
ResourceLocation resourcelocation = this.getResourceLocation(textureatlassprite);
bar.step(resourcelocation.getResourcePath());
IResource iresource = null;
if (textureatlassprite.hasCustomLoader(resourceManager, resourcelocation)) {
if (textureatlassprite.load(resourceManager, resourcelocation, l -> mapRegisteredSprites.get(l.toString()))) {
continue;
}
} else
try {
PngSizeInfo pngsizeinfo = PngSizeInfo.makeFromResource(resourceManager.getResource(resourcelocation));
iresource = resourceManager.getResource(resourcelocation);
boolean flag = iresource.getMetadata("animation") != null;
textureatlassprite.loadSprite(pngsizeinfo, flag);
} catch (RuntimeException runtimeexception) {
FMLClientHandler.instance().trackBrokenTexture(resourcelocation, runtimeexception.getMessage());
continue;
} catch (IOException ioexception) {
FMLClientHandler.instance().trackMissingTexture(resourcelocation);
continue;
} finally {
IOUtils.closeQuietly(iresource);
}
stitcher.addSprite(textureatlassprite);
}
ProgressManager.pop(bar);
this.missingImage.generateMipmaps(0);
stitcher.addSprite(this.missingImage);
bar = ProgressManager.push("Texture creation", 2);
bar.step("Stitching");
stitcher.doStitch();
Log.info("Created: {}x{} {}-atlas", stitcher.getCurrentWidth(), stitcher.getCurrentHeight(), this.basePath);
bar.step("Allocating GL texture");
TextureUtil.allocateTextureImpl(this.getGlTextureId(), 0, stitcher.getCurrentWidth(), stitcher.getCurrentHeight());
Map<String, TextureAtlasSprite> map = Maps.newHashMap(this.mapRegisteredSprites);
ProgressManager.pop(bar);
bar = ProgressManager.push("Texture mipmap and upload", stitcher.getStichSlots().size());
for (TextureAtlasSprite textureatlassprite1 : stitcher.getStichSlots()) {
bar.step(textureatlassprite1.getIconName());
if (textureatlassprite1 == this.missingImage || this.generateMipmaps(resourceManager, textureatlassprite1)) {
String s = textureatlassprite1.getIconName();
map.remove(s);
this.mapUploadedSprites.put(s, textureatlassprite1);
try {
TextureUtil.uploadTextureMipmap(textureatlassprite1.getFrameTextureData(0), textureatlassprite1.getIconWidth(), textureatlassprite1.getIconHeight(), textureatlassprite1.getOriginX(), textureatlassprite1.getOriginY(), false, false);
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Stitching texture atlas");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Texture being stitched together");
crashreportcategory.addCrashSection("Atlas path", this.basePath);
crashreportcategory.addCrashSection("Sprite", textureatlassprite1);
throw new ReportedException(crashreport);
}
if (textureatlassprite1.hasAnimationMetadata()) {
this.listAnimatedSprites.add(textureatlassprite1);
}
}
}
for (TextureAtlasSprite textureatlassprite2 : map.values()) {
textureatlassprite2.copyFrom(this.missingImage);
}
ProgressManager.pop(bar);
}
Aggregations