Skip to content
Open
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions src/main/java/net/minecraftforge/fml/client/SplashProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.lwjgl.opengl.GL12.*;

import java.awt.image.BufferedImage;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand All @@ -35,6 +36,7 @@
import java.lang.Thread.UncaughtExceptionHandler;
import java.nio.IntBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.concurrent.Semaphore;
Expand Down Expand Up @@ -260,7 +262,7 @@ public void run()
logoTexture = new Texture(logoLoc, null, false);
forgeTexture = new Texture(forgeLoc, forgeFallbackLoc);
glEnable(GL_TEXTURE_2D);
fontRenderer = new SplashFontRenderer();
fontRenderer = new SplashFontRenderer(false);
glDisable(GL_TEXTURE_2D);
while(!done)
{
Expand Down Expand Up @@ -405,6 +407,7 @@ public void run()
Display.sync(100);
}
}
fontRenderer.clear();
Comment thread
Ecdcaeb marked this conversation as resolved.
Outdated
clearGL();
}

Expand Down Expand Up @@ -743,7 +746,7 @@ private static IResourcePack createResourcePack(File file)
private static final IntBuffer buf = BufferUtils.createIntBuffer(4 * 1024 * 1024);

@SuppressWarnings("unused")
private static class Texture
private static class Texture implements Closeable
{
private final ResourceLocation location;
private final int name;
Expand Down Expand Up @@ -891,21 +894,30 @@ public void texCoord(int frame, float u, float v)
{
glTexCoord2f(getU(frame, u), getV(frame, v));
}

@Override
public void close(){
this.delete();
}
}

private static class SplashFontRenderer extends FontRenderer
public static class SplashFontRenderer extends FontRenderer implements Closeable
{
public SplashFontRenderer()
public HashMap<ResourceLocation, Texture> cachedImages;
public SplashFontRenderer(boolean isForcedUnicode)
{
super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, false);
super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, isForcedUnicode);
super.onResourceManagerReload(null);
}

@Override
protected void bindTexture(@Nonnull ResourceLocation location)
{
if(location != locationFontTexture) throw new IllegalArgumentException();
fontTexture.bind();
if(cachedImages == null) cachedImages = new HashMap<>();
if (!cachedImages.containsKey(location)) {
cachedImages.put(location, new Texture(location, null));
}
cachedImages.get(location).bind();
Comment thread
Ecdcaeb marked this conversation as resolved.
Outdated
}

@Nonnull
Expand All @@ -915,6 +927,21 @@ protected IResource getResource(@Nonnull ResourceLocation location) throws IOExc
DefaultResourcePack pack = Minecraft.getMinecraft().defaultResourcePack;
return new SimpleResource(pack.getPackName(), location, pack.getInputStream(location), null, null);
}

public void clear(){
if(cachedImages != null){
for(Texture texture : cachedImages.values()){
texture.delete();
}
cachedImages.clear();
cachedImages = null;
Comment thread
Ecdcaeb marked this conversation as resolved.
}
}

@Override
public void close(){
this.clear();
Comment thread
Ecdcaeb marked this conversation as resolved.
Outdated
}
}

public static void drawVanillaScreen(TextureManager renderEngine) throws LWJGLException
Expand Down Expand Up @@ -966,4 +993,4 @@ private static int bytesToMb(long bytes)
{
return (int) (bytes / 1024L / 1024L);
}
}
}