[committed] GLException when swapping buffers with the JOGL renderer

Hi!



My previous fix does not work anymore because Woody calls JOGLRenderer.checkCardError() when swapping buffers and JOGL does not throw any GLException when using an invalid enumerant  :? Therefore, I suggest a cleaner fix, give it a look please:


Index: /home/julien/workspace/jme/src/com/jme/renderer/jogl/JOGLContextCapabilities.java
===================================================================
--- /home/julien/workspace/jme/src/com/jme/renderer/jogl/JOGLContextCapabilities.java   (revision 4483)
+++ /home/julien/workspace/jme/src/com/jme/renderer/jogl/JOGLContextCapabilities.java   (working copy)
@@ -37,7 +37,6 @@
 
 import javax.media.opengl.GL;
 import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLException;
 
 import com.jme.util.geom.BufferUtils;
 
@@ -208,47 +207,55 @@
         GL_ARB_vertex_shader = gl.isExtensionAvailable("GL_ARB_vertex_shader");
         GL_ARB_shading_language_100 = gl
                 .isExtensionAvailable("GL_ARB_shading_language_100");
-
+        if(GL_ARB_shading_language_100){
+            GL_SHADING_LANGUAGE_VERSION_ARB = gl
+            .glGetString(GL.GL_SHADING_LANGUAGE_VERSION_ARB);
+        } else {
+            GL_SHADING_LANGUAGE_VERSION_ARB = "";
+        }
+       
         // See TextureState
         GL_ARB_depth_texture = gl.isExtensionAvailable("GL_ARB_depth_texture");
         GL_ARB_shadow = gl.isExtensionAvailable("GL_ARB_shadow");
-
-        try {
+          
+        if(gl.isExtensionAvailable( "GL_ARB_vertex_shader" )) {
             gl.glGetIntegerv(GL.GL_MAX_VERTEX_ATTRIBS_ARB, intBuf);
             GL_MAX_VERTEX_ATTRIBS_ARB = intBuf.get(0);
-        } catch(GLException gle) {
-            GL_MAX_VERTEX_ATTRIBS_ARB=0;
-        }
-       
-
-        try {
             gl.glGetIntegerv(GL.GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, intBuf);
             GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB = intBuf.get(0);
-        } catch(GLException gle){
-            GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB=0;
+            gl.glGetIntegerv(GL.GL_MAX_VARYING_FLOATS_ARB, intBuf);
+            GL_MAX_VARYING_FLOATS_ARB = intBuf.get(0);
+            gl.glGetIntegerv(GL.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, intBuf);
+            GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB = intBuf.get(0);
+            gl.glGetIntegerv(GL.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, intBuf);
+            GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB = intBuf.get(0);
+            gl.glGetIntegerv(GL.GL_MAX_TEXTURE_IMAGE_UNITS_ARB, intBuf);
+            GL_MAX_TEXTURE_IMAGE_UNITS_ARB = intBuf.get(0);
+            gl.glGetIntegerv(GL.GL_MAX_TEXTURE_COORDS_ARB, intBuf);
+            GL_MAX_TEXTURE_COORDS_ARB = intBuf.get(0);
+        } else {
+            GL_MAX_VERTEX_ATTRIBS_ARB = 0;
+            GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB = 0;
+            GL_MAX_VARYING_FLOATS_ARB = 0;
+            GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB = 0;
+            GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB = 0;
+            GL_MAX_TEXTURE_IMAGE_UNITS_ARB = 0;
+            GL_MAX_TEXTURE_COORDS_ARB = 0;
         }
-
-        try {
+        if( gl.isExtensionAvailable( "GL_ARB_fragment_shader" )) {
             gl.glGetIntegerv(GL.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, intBuf);
             GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB = intBuf.get(0);
-        } catch(GLException gle) {
-            GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB=0;
+        } else {
+            GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB = 0;
         }
-
-        try {
-            gl.glGetIntegerv(GL.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, intBuf);
-            GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB = intBuf.get(0);
-        } catch(GLException gle) {
-            GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB=0;
-        }
-
-        try {
-            gl.glGetIntegerv(GL.GL_MAX_VARYING_FLOATS_ARB, intBuf);
-            GL_MAX_VARYING_FLOATS_ARB = intBuf.get(0);
-        } catch(GLException gle) {
-            GL_MAX_VARYING_FLOATS_ARB=0;
+       
+        if( gl.isExtensionAvailable( "GL_EXT_texture_filter_anisotropic" )) {
+            // FIXME I don't think this was necessary: floatBuf.rewind();
+            gl.glGetFloatv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, floatBuf);
+            GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = floatBuf.get(0);
+        } else {
+            GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0;
         }
-
         // See StencilState
         GL_EXT_stencil_two_side = gl
                 .isExtensionAvailable("GL_EXT_stencil_two_side");
@@ -253,9 +260,15 @@
         GL_EXT_stencil_two_side = gl
                 .isExtensionAvailable("GL_EXT_stencil_two_side");
         GL_EXT_stencil_wrap = gl.isExtensionAvailable("GL_EXT_stencil_wrap");
-
+       
         // See TextureState
         GL_ARB_multitexture = gl.isExtensionAvailable("GL_ARB_multitexture");
+        if(GL_ARB_multitexture) {
+            gl.glGetIntegerv(GL.GL_MAX_TEXTURE_UNITS, intBuf);
+            GL_MAX_TEXTURE_UNITS = intBuf.get(0);
+        } else {
+            GL_MAX_TEXTURE_UNITS = 1;
+        }   
         GL_ARB_texture_env_dot3 = gl
                 .isExtensionAvailable("GL_ARB_texture_env_dot3");
         GL_ARB_texture_env_combine = gl
@@ -273,46 +286,6 @@
                 .isExtensionAvailable("GL_ARB_texture_non_power_of_two");
         GL_ARB_texture_rectangle = gl
                 .isExtensionAvailable("GL_ARB_texture_rectangle");
-
-        gl.glGetIntegerv(GL.GL_MAX_TEXTURE_UNITS, intBuf);
-        GL_MAX_TEXTURE_UNITS = intBuf.get(0);
-
-        try {
-            gl.glGetIntegerv(GL.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, intBuf);
-            GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB = intBuf.get(0);
-        } catch(GLException gle) {
-            GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB=0;
-        }
-
-        try {
-            gl.glGetIntegerv(GL.GL_MAX_TEXTURE_IMAGE_UNITS_ARB, intBuf);
-            GL_MAX_TEXTURE_IMAGE_UNITS_ARB = intBuf.get(0);
-        } catch(GLException gle) {
-            GL_MAX_TEXTURE_IMAGE_UNITS_ARB=0;
-        }
-
-        try {
-            gl.glGetIntegerv(GL.GL_MAX_TEXTURE_COORDS_ARB, intBuf);
-            GL_MAX_TEXTURE_COORDS_ARB = intBuf.get(0);
-        } catch(GLException gle) {
-            GL_MAX_TEXTURE_COORDS_ARB=0;
-        }
-
-        try {
-            GL_SHADING_LANGUAGE_VERSION_ARB = gl
-            .glGetString(GL.GL_SHADING_LANGUAGE_VERSION_ARB);
-        } catch(GLException gle) {
-            GL_SHADING_LANGUAGE_VERSION_ARB="";
-        }
-
-        // FIXME I don't think this was necessary: floatBuf.rewind();
-        try {
-            gl.glGetFloatv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, floatBuf);
-            GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = floatBuf.get(0);
-        } catch(GLException gle) {
-            GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT=0;
-        }
-
         // See VertexProgram
         GL_ARB_vertex_program = gl
                 .isExtensionAvailable("GL_ARB_vertex_program");
@@ -324,7 +297,7 @@
                 .isExtensionAvailable("GL_EXT_texture_mirror_clamp");
         GL_ARB_texture_border_clamp = gl
                 .isExtensionAvailable("GL_ARB_texture_border_clamp");
-
+       
         GL_EXT_compiled_vertex_array = gl.isExtensionAvailable("GL_EXT_compiled_vertex_array");
     }
 

Intelligently determining what configuration information should be queried makes a lot of sense.  Another option would be to make sure to call glGetError() before returning from this method so that the error flag would be reset to GL_NO_ERROR.



When I was tracking down the issues around shadow and water rendering, I noticed that the LWJGL library internally checks the error status when performing the buffer swap.  Assuming a DebugGL isn't being used, being able to detect an error within the first frame that it occurs isn't a bad idea.

This is almost the only method that might cause an error because of the use of invalid enumerant.