package org.helioviewer.jhv.opengl;

import org.helioviewer.jhv.base.logging.Log;

import com.jogamp.nativewindow.ScalableSurface;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.glu.GLU;

public class GLInfo {

    public static final int GLSAMPLES = 4;

    public static int[] pixelScale = new int[] { 1, 1 };
    public static float[] pixelScaleFloat = new float[] { 1f, 1f };

    static int maxTextureSize;

    public static void update(GL2 gl) {
        String version = gl.glGetString(GL2.GL_VERSION);
        Log.debug("GLInfo > Version string: " + version);
        String extensionStr = gl.glGetString(GL2.GL_EXTENSIONS);
        Log.debug("GLInfo.update(GL) > Extensions: " + extensionStr);

        if (!gl.isExtensionAvailable("GL_VERSION_2_1")) {
            String err = "OpenGL 2.1 not supported. JHelioviewer is not able to run.";
            Log.error("GLInfo.update(GL) > " + err);
            throw new GLException(err);
        }

        int[] out = new int[] { 0 };
        gl.glGetIntegerv(GL2.GL_MAX_TEXTURE_SIZE, out, 0);
        maxTextureSize = out[0];
        Log.debug("GLInfo > max texture size: " + out[0]);
    }

    public static void updatePixelScale(ScalableSurface surface) {
        surface.getCurrentSurfaceScale(pixelScaleFloat);
        pixelScale[0] = (int) pixelScaleFloat[0];
        pixelScale[1] = (int) pixelScaleFloat[1];
    }

    public static boolean checkGLErrors(GL2 gl, String message) {
        GLU glu = new GLU();
        int glErrorCode, errors = 0;

        while ((glErrorCode = gl.glGetError()) != GL2.GL_NO_ERROR) {
            Log.error("GL Error (" + glErrorCode + "): " + glu.gluErrorString(glErrorCode) + " - @" + message);
            errors++;
        }
        return errors != 0;
    }

}

@@ -452,16 +452,58 @@
 eSize;%0A%0A
+    private static boolean first = true;%0A%0A
     publ
@@ -530,24 +530,77 @@
 e(GL2 gl) %7B%0A
+        if (first) %7B%0A            first = false;%0A%0A    
         Stri
@@ -644,32 +644,36 @@
 RSION);%0A        
+ 
+   
 Log.debug(%22GLInf
@@ -706,32 +706,36 @@
 rsion);%0A        
+   
+ 
 String extension
@@ -775,32 +775,36 @@
 SIONS);%0A        
+    
 Log.debug(%22GLInf
@@ -808,26 +808,24 @@
 Info.update(
-GL
 ) %3E Extensio
@@ -852,24 +852,28 @@
 );%0A%0A        
+    
 if (!gl.isEx
@@ -914,32 +914,36 @@
 ) %7B%0A            
+  
+  
 String err = %22Op
@@ -1005,32 +1005,36 @@
 .%22;%0A            
+    
 Log.error(%22GLInf
@@ -1042,18 +1042,16 @@
 .update(
-GL
 ) %3E %22 + 
@@ -1052,24 +1052,28 @@
 %3E %22 + err);%0A
+    
             
@@ -1104,27 +1104,35 @@
 r);%0A        
+ 
-%7D%0A%0A
+   %7D%0A%0A    
         int%5B
@@ -1152,24 +1152,28 @@
 nt%5B%5D %7B 0 %7D;%0A
+    
         gl.g
@@ -1227,16 +1227,20 @@
         
+  
+  
 maxTextu
@@ -1252,24 +1252,28 @@
 e = out%5B0%5D;%0A
+    
         Log.
@@ -1319,16 +1319,73 @@
 ut%5B0%5D);%0A
+        %7D else%0A            Log.debug(%22GLInfo.update()%22);%0A
     %7D%0A%0A 

Reduce verbosity