mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-26 14:53:14 +00:00
add close() to ShaderProgram to free resources (#140)
This commit is contained in:
1 file changed
+13
-1
@@ -3,6 +3,7 @@ package com.gtnewhorizon.gtnhlib.client.renderer.shader;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
@@ -12,9 +13,10 @@ import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLib;
|
||||
import com.gtnewhorizon.gtnhlib.bytebuf.MemoryStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ShaderProgram {
|
||||
public class ShaderProgram implements AutoCloseable {
|
||||
|
||||
final private int program;
|
||||
|
||||
@@ -156,4 +158,14 @@ public class ShaderProgram {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try (MemoryStack stack = MemoryStack.stackPush()) {
|
||||
IntBuffer shaders = stack.mallocInt(GL20.glGetProgrami(program, GL20.GL_ATTACHED_SHADERS));
|
||||
GL20.glGetAttachedShaders(program, null, shaders);
|
||||
GL20.glDeleteProgram(program);
|
||||
for (int i : shaders.array()) {
|
||||
GL20.glDeleteShader(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user