package codechicken.lib.render;

import org.lwjgl.opengl.ContextCapabilities;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GLContext;

import static org.lwjgl.opengl.GL20.GL_INFO_LOG_LENGTH;

/**
 * Most of this is available in later LWJGL versions..
 * But.. Mojang..
 * Also contains some utilities.
 *
 * Created by covers1624 on 20/06/2017.
 */
public class OpenGLUtils {

    public static boolean openGL20;
    public static boolean openGL32;
    public static boolean openGL40;
    public static boolean openGL43;
    public static boolean openGL44;
    public static boolean openGL45;

    public static void loadCaps() {
        ContextCapabilities caps = GLContext.getCapabilities();
        openGL20 = caps.OpenGL20;
        openGL32 = caps.OpenGL32;
        openGL40 = caps.OpenGL40;
        openGL43 = caps.OpenGL43;
        openGL44 = caps.OpenGL44;
        openGL45 = caps.OpenGL45;
    }

    /**
     * <p><a href="http://www.opengl.org/sdk/docs/man/html/glGetProgramInfoLog.xhtml">OpenGL SDK Reference</a></p>
     *
     * Returns the information log for a program object.
     *
     * @param program the program object whose information log is to be queried
     */
    public static String glGetProgramInfoLog(int program) {
        int maxLength = GL20.glGetProgrami(program, GL_INFO_LOG_LENGTH);
        return GL20.glGetProgramInfoLog(program, maxLength);
    }

    /**
     * <p><a href="http://www.opengl.org/sdk/docs/man/html/glGetShaderInfoLog.xhtml">OpenGL SDK Reference</a></p>
     *
     * Returns the information log for a shader object.
     *
     * @param shader the shader object whose information log is to be queried
     */
    public static String glGetShaderInfoLog(int shader) {
        int maxLength = GL20.glGetShaderi(shader, GL_INFO_LOG_LENGTH);
        return GL20.glGetShaderInfoLog(shader, maxLength);
    }
}

@@ -26,16 +26,95 @@
 ender;%0A%0A
+import codechicken.lib.internal.CCLLog;%0Aimport org.apache.logging.log4j.Level;%0A
 import o
@@ -150,16 +150,16 @@
 lities;%0A
-
 import o
@@ -216,16 +216,60 @@
 ntext;%0A%0A
+import java.util.function.BooleanSupplier;%0A%0A
 import s
@@ -910,123 +910,371 @@
 0 = 
-caps.OpenGL40;%0A        openGL43 = caps.OpenGL43;%0A        openGL44 = caps.OpenGL44;%0A        openGL45 = caps.OpenGL45
+tryGet(() -%3E caps.OpenGL40, %22LWJGL Outdated, OpenGL 4.0 is not supported.%22);%0A        openGL43 = tryGet(() -%3E caps.OpenGL43, %22LWJGL Outdated, OpenGL 4.3 is not supported.%22);%0A        openGL44 = tryGet(() -%3E caps.OpenGL44, %22LWJGL Outdated, OpenGL 4.4 is not supported.%22);%0A        openGL45 = tryGet(() -%3E caps.OpenGL45, %22LWJGL Outdated, OpenGL 4.5 is not supported.%22)
 ;%0A  
@@ -2160,32 +2160,32 @@
 FO_LOG_LENGTH);%0A
-
         return G
@@ -2232,11 +2232,255 @@
 );%0A    %7D
+%0A%0A    private static boolean tryGet(BooleanSupplier sup, String log) %7B%0A        try %7B%0A            return sup.getAsBoolean();%0A        %7D catch (Throwable ignored) %7B%0A            CCLLog.log(Level.INFO, log);%0A            return false;%0A        %7D%0A    %7D
 %0A%7D%0A

Fix crashes with people using outdated LWJGL versions.