--- JoglPipelineOLD.java	2016-11-07 16:27:54.000000000 +0100
+++ JoglPipeline.java	2017-12-28 22:54:49.000000000 +0100
@@ -26,23 +26,19 @@
 
 package javax.media.j3d;
 
-import java.awt.BorderLayout;
-import java.awt.Canvas;
-import java.awt.DisplayMode;
-import java.awt.EventQueue;
-import java.awt.Frame;
-import java.awt.GraphicsConfigTemplate;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.nativewindow.*;
+import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
+import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
+import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
+import com.jogamp.nativewindow.awt.JAWTWindow;
+import com.jogamp.opengl.*;
+
+import java.awt.*;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.DoubleBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
+import java.nio.*;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -52,35 +48,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import com.jogamp.common.nio.Buffers;
-import com.jogamp.nativewindow.AbstractGraphicsDevice;
-import com.jogamp.nativewindow.AbstractGraphicsScreen;
-import com.jogamp.nativewindow.CapabilitiesChooser;
-import com.jogamp.nativewindow.GraphicsConfigurationFactory;
-import com.jogamp.nativewindow.NativeSurface;
-import com.jogamp.nativewindow.NativeWindowFactory;
-import com.jogamp.nativewindow.ProxySurface;
-import com.jogamp.nativewindow.UpstreamSurfaceHook;
-import com.jogamp.nativewindow.VisualIDHolder;
-import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
-import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
-import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
-import com.jogamp.nativewindow.awt.JAWTWindow;
-import com.jogamp.opengl.DefaultGLCapabilitiesChooser;
-import com.jogamp.opengl.FBObject;
-import com.jogamp.opengl.GL;
-import com.jogamp.opengl.GL2;
-import com.jogamp.opengl.GLCapabilities;
-import com.jogamp.opengl.GLCapabilitiesChooser;
-import com.jogamp.opengl.GLCapabilitiesImmutable;
-import com.jogamp.opengl.GLContext;
-import com.jogamp.opengl.GLDrawable;
-import com.jogamp.opengl.GLDrawableFactory;
-import com.jogamp.opengl.GLException;
-import com.jogamp.opengl.GLFBODrawable;
-import com.jogamp.opengl.GLProfile;
-import com.jogamp.opengl.Threading;
-
 /**
  * Concrete implementation of Pipeline class for the JOGL rendering
  * pipeline.
@@ -98,10 +65,297 @@
     private static final int WAIT_TIME = 1000;
     // Configurable constant just in case we want to change this later
     private static final int MIN_FRAME_SIZE = 1;
+    private static final float[] black = new float[4];
+    private static final int screen_door[][] = {
+            /* 0 / 16 */
+            {
+                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
+                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
+                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
+                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
+                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
+                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
+                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
+                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
+            },
+            /* 1 / 16 */
+            {
+                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
+                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
+                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
+                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
+                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
+                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
+                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
+                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
+            },
+            /* 2 / 16 */
+            {
+                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
+                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
+                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
+                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
+                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
+                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
+                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
+                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
+            },
+            /* 3 / 16 */
+            {
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
+            },
+            /* 4 / 16 */
+            {
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+            },
+            /* 5 / 16 */
+            {
+                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
+            },
+            /* 6 / 16 */
+            {
+                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+            },
+            /* 7 / 16 */
+            {
+                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
+            },
+            /* 8 / 16 */
+            {
+                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+            },
+            /* 9 / 16 */
+            {
+                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
+            },
+            /* 10 / 16 */
+            {
+                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+            },
+            /* 11 / 16 */
+            {
+                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
+            },
+            /* 12 / 16 */
+            {
+                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
+            },
+            /* 13 / 16 */
+            {
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
+            },
+            /* 14 / 16 */
+            {
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
+            },
+            /* 15 / 16 */
+            {
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
+            },
+            /* 16 / 16 */
+            {
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
+                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
+            },
+    };
+    private static final ByteBuffer[] screen_door_table = new ByteBuffer[screen_door.length];
+    private static final int[] blendFunctionTable = new int[TransparencyAttributes.MAX_BLEND_FUNC_TABLE_SIZE];
 
-    private GLProfile profile;
+    // ---------------------------------------------------------------------
+
+    //
+    // GeometryArrayRetained methods
+    //
+    // mapping from java enum to gl enum
+    private static final int[] _gl_combineRgbSrcIndex = {
+            GL2.GL_SOURCE0_RGB,
+            GL2.GL_SOURCE1_RGB,
+            GL2.GL_SOURCE2_RGB,
+    };
+    private static final int[] _gl_combineAlphaSrcIndex = {
+            GL2.GL_SOURCE0_ALPHA,
+            GL2.GL_SOURCE1_ALPHA,
+            GL2.GL_SOURCE2_ALPHA,
+    };
+    private static final int[] _gl_combineRgbOpIndex = {
+            GL2.GL_OPERAND0_RGB,
+            GL2.GL_OPERAND1_RGB,
+            GL2.GL_OPERAND2_RGB,
+    };
+    private static final int[] _gl_combineAlphaOpIndex = {
+            GL2.GL_OPERAND0_ALPHA,
+            GL2.GL_OPERAND1_ALPHA,
+            GL2.GL_OPERAND2_ALPHA,
+    };
+    private static final int[] _gl_combineSrc = {
+            GL2.GL_PRIMARY_COLOR,      // TextureAttributes.COMBINE_OBJECT_COLOR
+            GL.GL_TEXTURE,            // TextureAttributes.COMBINE_TEXTURE
+            GL2.GL_CONSTANT,           // TextureAttributes.COMBINE_CONSTANT_COLOR
+            GL2.GL_PREVIOUS,           // TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE
+    };
+    private static final int[] _gl_combineFcn = {
+            GL.GL_SRC_COLOR,              // TextureAttributes.COMBINE_SRC_COLOR
+            GL.GL_ONE_MINUS_SRC_COLOR,    // TextureAttributes.COMBINE_ONE_MINUS_SRC_COLOR
+            GL.GL_SRC_ALPHA,              // TextureAttributes.COMBINE_SRC_ALPHA
+            GL.GL_ONE_MINUS_SRC_ALPHA,    // TextureAttributes.COMBINE_ONE_MINUS_SRC_ALPHA
+    };
+    // mapping from java enum to gl enum
+    private static final int[] _gl_textureCubeMapFace = {
+            GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
+            GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
+            GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+            GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
+            GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
+            GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
+    };
+
+    //----------------------------------------------------------------------
+    // Private helper methods for GeometryArrayRetained
+    //
+    private static ThreadLocal<FloatBuffer> nioVertexTemp = new ThreadLocal<FloatBuffer>();
+    private static ThreadLocal<DoubleBuffer> nioVertexDoubleTemp = new ThreadLocal<DoubleBuffer>();
+    private static ThreadLocal<FloatBuffer> nioColorTemp = new ThreadLocal<FloatBuffer>();
+    private static ThreadLocal<ByteBuffer> nioColorByteTemp = new ThreadLocal<ByteBuffer>();
+    private static ThreadLocal<FloatBuffer> nioNormalTemp = new ThreadLocal<FloatBuffer>();
+    private static ThreadLocal<FloatBuffer[]> nioTexCoordSetTemp = new ThreadLocal<FloatBuffer[]>();
+    private static ThreadLocal<FloatBuffer[]> nioVertexAttrSetTemp = new ThreadLocal<FloatBuffer[]>();
+
+    static {
+        int eachLen = screen_door[0].length * Buffers.SIZEOF_INT;
+        ByteBuffer buf = Buffers.newDirectByteBuffer(screen_door.length * eachLen);
+        IntBuffer intBuf = buf.asIntBuffer();
+        for (int i = 0; i < screen_door.length; i++) {
+            intBuf.put(screen_door[i]);
+        }
+        buf.rewind();
+        for (int i = 0; i < screen_door.length; i++) {
+            buf.position(i * eachLen);
+            buf.limit((i + 1) * eachLen);
+            screen_door_table[i] = buf.slice();
+        }
+    }
+
+    static {
+        blendFunctionTable[TransparencyAttributes.BLEND_ZERO] = GL.GL_ZERO;
+        blendFunctionTable[TransparencyAttributes.BLEND_ONE] = GL.GL_ONE;
+        blendFunctionTable[TransparencyAttributes.BLEND_SRC_ALPHA] = GL.GL_SRC_ALPHA;
+        blendFunctionTable[TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA] = GL.GL_ONE_MINUS_SRC_ALPHA;
+        blendFunctionTable[TransparencyAttributes.BLEND_DST_COLOR] = GL.GL_DST_COLOR;
+        blendFunctionTable[TransparencyAttributes.BLEND_ONE_MINUS_DST_COLOR] = GL.GL_ONE_MINUS_DST_COLOR;
+        blendFunctionTable[TransparencyAttributes.BLEND_SRC_COLOR] = GL.GL_SRC_COLOR;
+        blendFunctionTable[TransparencyAttributes.BLEND_ONE_MINUS_SRC_COLOR] = GL.GL_ONE_MINUS_SRC_COLOR;
+        blendFunctionTable[TransparencyAttributes.BLEND_CONSTANT_COLOR] = GL2.GL_CONSTANT_COLOR;
+    }
 
+    int numInvalidLists = 0;
+    private GLProfile profile;
     private Object mainThreadContext;    // Fix for Bug 983
+    private boolean checkedForGetScreenMethod = false;
+
+
+    // ---------------------------------------------------------------------
+
+    //
+    // IndexedGeometryArrayRetained methods
+    //
+    private Method getScreenMethod = null;
 
     /**
      * Constructor for singleton JoglPipeline instance
@@ -116,6 +370,250 @@
         }
     }
 
+    private static final String getFilterName(int filter) {
+        switch (filter) {
+            case Texture.FASTEST:
+                return "Texture.FASTEST";
+            case Texture.NICEST:
+                return "Texture.NICEST";
+            case Texture.BASE_LEVEL_POINT:
+                return "Texture.BASE_LEVEL_POINT";
+            case Texture.BASE_LEVEL_LINEAR:
+                return "Texture.BASE_LEVEL_LINEAR";
+            case Texture.MULTI_LEVEL_POINT:
+                return "Texture.MULTI_LEVEL_POINT";
+            case Texture.MULTI_LEVEL_LINEAR:
+                return "Texture.MULTI_LEVEL_LINEAR";
+            case Texture.FILTER4:
+                return "Texture.FILTER4";
+            case Texture.LINEAR_SHARPEN:
+                return "Texture.LINEAR_SHARPEN";
+            case Texture.LINEAR_SHARPEN_RGB:
+                return "Texture.LINEAR_SHARPEN_RGB";
+            case Texture.LINEAR_SHARPEN_ALPHA:
+                return "Texture.LINEAR_SHARPEN_ALPHA";
+            case Texture2D.LINEAR_DETAIL:
+                return "Texture.LINEAR_DETAIL";
+            case Texture2D.LINEAR_DETAIL_RGB:
+                return "Texture.LINEAR_DETAIL_RGB";
+            case Texture2D.LINEAR_DETAIL_ALPHA:
+                return "Texture.LINEAR_DETAIL_ALPHA";
+            default:
+                return "(unknown)";
+        }
+    }
+
+    static boolean isOffscreenLayerSurfaceEnabled(Canvas3D cv) {
+        if (cv.drawable == null || cv.offScreen)
+            return false;
+
+        JoglDrawable joglDrawble = (JoglDrawable) cv.drawable;
+        JAWTWindow jawtwindow = (JAWTWindow) joglDrawble.getNativeWindow();
+        if (jawtwindow == null)
+            return false;
+
+        return jawtwindow.isOffscreenLayerSurfaceEnabled();
+    }
+
+    static boolean hasFBObjectSizeChanged(JoglDrawable jdraw, int width, int height) {
+        if (!(jdraw.getGLDrawable() instanceof GLFBODrawable))
+            return false;
+
+        FBObject fboBack = ((GLFBODrawable) jdraw.getGLDrawable()).getFBObject(GL.GL_BACK);
+        if (fboBack == null)
+            return false;
+
+        return (width != fboBack.getWidth() || height != fboBack.getHeight());
+    }
+
+
+    //----------------------------------------------------------------------
+    //
+    // Helper routines for IndexedGeometryArrayRetained
+    //
+
+    private static AWTGraphicsConfiguration createAwtGraphicsConfiguration(GLCapabilities capabilities,
+                                                                           CapabilitiesChooser chooser,
+                                                                           AbstractGraphicsScreen screen) {
+        GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class, GLCapabilities.class);
+        AWTGraphicsConfiguration awtGraphicsConfiguration = (AWTGraphicsConfiguration) factory.chooseGraphicsConfiguration(capabilities, capabilities,
+                chooser, screen, VisualIDHolder.VID_UNDEFINED);
+        return awtGraphicsConfiguration;
+    }
+
+    private static FloatBuffer getVertexArrayBuffer(float[] vertexArray) {
+        return getVertexArrayBuffer(vertexArray, true);
+    }
+
+
+    // ---------------------------------------------------------------------
+
+    //
+    // GraphicsContext3D methods
+    //
+
+    private static FloatBuffer getVertexArrayBuffer(float[] vertexArray, boolean copyData) {
+        return getNIOBuffer(vertexArray, nioVertexTemp, copyData);
+    }
+
+    // ---------------------------------------------------------------------
+
+    //
+    // GLSLShaderProgramRetained methods
+    //
+
+    // ShaderAttributeValue methods
+
+    private static DoubleBuffer getVertexArrayBuffer(double[] vertexArray) {
+        return getVertexArrayBuffer(vertexArray, true);
+    }
+
+    private static DoubleBuffer getVertexArrayBuffer(double[] vertexArray, boolean copyData) {
+        return getNIOBuffer(vertexArray, nioVertexDoubleTemp, true);
+    }
+
+    private static FloatBuffer getColorArrayBuffer(float[] colorArray) {
+        return getColorArrayBuffer(colorArray, true);
+    }
+
+    private static FloatBuffer getColorArrayBuffer(float[] colorArray, boolean copyData) {
+        return getNIOBuffer(colorArray, nioColorTemp, true);
+    }
+
+    private static ByteBuffer getColorArrayBuffer(byte[] colorArray) {
+        return getColorArrayBuffer(colorArray, true);
+    }
+
+    private static ByteBuffer getColorArrayBuffer(byte[] colorArray, boolean copyData) {
+        return getNIOBuffer(colorArray, nioColorByteTemp, true);
+    }
+
+    private static FloatBuffer getNormalArrayBuffer(float[] normalArray) {
+        return getNormalArrayBuffer(normalArray, true);
+    }
+
+    private static FloatBuffer getNormalArrayBuffer(float[] normalArray, boolean copyData) {
+        return getNIOBuffer(normalArray, nioNormalTemp, true);
+    }
+
+    private static FloatBuffer[] getTexCoordSetBuffer(Object[] texCoordSet) {
+        return getNIOBuffer(texCoordSet, nioTexCoordSetTemp);
+    }
+
+    private static FloatBuffer[] getVertexAttrSetBuffer(Object[] vertexAttrSet) {
+        return getNIOBuffer(vertexAttrSet, nioVertexAttrSetTemp);
+    }
+
+    // ShaderAttributeArray methods
+
+    private static FloatBuffer getNIOBuffer(float[] array, ThreadLocal<FloatBuffer> threadLocal, boolean copyData) {
+        if (array == null) {
+            return null;
+        }
+        FloatBuffer buf = threadLocal.get();
+        if (buf == null) {
+            buf = Buffers.newDirectFloatBuffer(array.length);
+            threadLocal.set(buf);
+        } else {
+            buf.rewind();
+            if (buf.remaining() < array.length) {
+                int newSize = Math.max(2 * buf.remaining(), array.length);
+                buf = Buffers.newDirectFloatBuffer(newSize);
+                threadLocal.set(buf);
+            }
+        }
+        if (copyData) {
+            buf.put(array);
+            buf.rewind();
+        }
+        return buf;
+    }
+
+    private static DoubleBuffer getNIOBuffer(double[] array, ThreadLocal<DoubleBuffer> threadLocal, boolean copyData) {
+        if (array == null) {
+            return null;
+        }
+        DoubleBuffer buf = threadLocal.get();
+        if (buf == null) {
+            buf = Buffers.newDirectDoubleBuffer(array.length);
+            threadLocal.set(buf);
+        } else {
+            buf.rewind();
+            if (buf.remaining() < array.length) {
+                int newSize = Math.max(2 * buf.remaining(), array.length);
+                buf = Buffers.newDirectDoubleBuffer(newSize);
+                threadLocal.set(buf);
+            }
+        }
+        if (copyData) {
+            buf.put(array);
+            buf.rewind();
+        }
+        return buf;
+    }
+
+    private static ByteBuffer getNIOBuffer(byte[] array, ThreadLocal<ByteBuffer> threadLocal, boolean copyData) {
+        if (array == null) {
+            return null;
+        }
+        ByteBuffer buf = threadLocal.get();
+        if (buf == null) {
+            buf = Buffers.newDirectByteBuffer(array.length);
+            threadLocal.set(buf);
+        } else {
+            buf.rewind();
+            if (buf.remaining() < array.length) {
+                int newSize = Math.max(2 * buf.remaining(), array.length);
+                buf = Buffers.newDirectByteBuffer(newSize);
+                threadLocal.set(buf);
+            }
+        }
+        if (copyData) {
+            buf.put(array);
+            buf.rewind();
+        }
+        return buf;
+    }
+
+    private static FloatBuffer[] getNIOBuffer(Object[] array, ThreadLocal<FloatBuffer[]> threadLocal) {
+        if (array == null) {
+            return null;
+        }
+        FloatBuffer[] bufs = threadLocal.get();
+
+        // First resize array of FloatBuffers
+        if (bufs == null) {
+            bufs = new FloatBuffer[array.length];
+            threadLocal.set(bufs);
+        } else if (bufs.length < array.length) {
+            FloatBuffer[] newBufs = new FloatBuffer[array.length];
+            System.arraycopy(bufs, 0, newBufs, 0, bufs.length);
+            bufs = newBufs;
+            threadLocal.set(bufs);
+        }
+
+        // Now go down array of arrays, converting each into a direct FloatBuffer
+        for (int i = 0; i < array.length; i++) {
+            float[] cur = (float[]) array[i];
+            FloatBuffer buf = bufs[i];
+            if (buf == null) {
+                buf = Buffers.newDirectFloatBuffer(cur.length);
+                bufs[i] = buf;
+            } else {
+                buf.rewind();
+                if (buf.remaining() < cur.length) {
+                    int newSize = Math.max(2 * buf.remaining(), cur.length);
+                    buf = Buffers.newDirectFloatBuffer(newSize);
+                    bufs[i] = buf;
+                }
+            }
+            buf.put(cur);
+            buf.rewind();
+        }
+
+        return bufs;
+    }
+
     /**
      * Initialize the pipeline
      */
@@ -132,26 +630,20 @@
         // TODO: finish this with any other needed initialization
     }
 
-    // ---------------------------------------------------------------------
-
-    //
-    // GeometryArrayRetained methods
-    //
-
     // used for GeometryArrays by Copy or interleaved
     @Override
     void execute(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean useAlpha,
-            boolean ignoreVertexColors,
-            int startVIndex, int vcount, int vformat,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int texCoordSetMapLen,
-            int[] texUnitOffset,
-            int numActiveTexUnitState,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            float[] varray, float[] carray, int cDirty) {
+                 GeometryArrayRetained geo, int geo_type,
+                 boolean isNonUniformScale,
+                 boolean useAlpha,
+                 boolean ignoreVertexColors,
+                 int startVIndex, int vcount, int vformat,
+                 int texCoordSetCount, int[] texCoordSetMap,
+                 int texCoordSetMapLen,
+                 int[] texUnitOffset,
+                 int numActiveTexUnitState,
+                 int vertexAttrCount, int[] vertexAttrSizes,
+                 float[] varray, float[] carray, int cDirty) {
         if (VERBOSE) System.err.println("JoglPipeline.execute()");
 
         executeGeometryArray(ctx, geo, geo_type, isNonUniformScale, useAlpha,
@@ -165,31 +657,31 @@
     // used by GeometryArray by Reference with java arrays
     @Override
     void executeVA(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean ignoreVertexColors,
-            int vcount,
-            int vformat,
-            int vdefined,
-            int initialCoordIndex, float[] vfcoords, double[] vdcoords,
-            int initialColorIndex, float[] cfdata, byte[] cbdata,
-            int initialNormalIndex, float[] ndata,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            int[] vertexAttrIndices, float[][] vertexAttrData,
-            int texCoordMapLength,
-            int[] texcoordoffset,
-            int numActiveTexUnitState,
-            int[] texIndex, int texstride, Object[] texCoords,
-            int cdirty) {
+                   GeometryArrayRetained geo, int geo_type,
+                   boolean isNonUniformScale,
+                   boolean ignoreVertexColors,
+                   int vcount,
+                   int vformat,
+                   int vdefined,
+                   int initialCoordIndex, float[] vfcoords, double[] vdcoords,
+                   int initialColorIndex, float[] cfdata, byte[] cbdata,
+                   int initialNormalIndex, float[] ndata,
+                   int vertexAttrCount, int[] vertexAttrSizes,
+                   int[] vertexAttrIndices, float[][] vertexAttrData,
+                   int texCoordMapLength,
+                   int[] texcoordoffset,
+                   int numActiveTexUnitState,
+                   int[] texIndex, int texstride, Object[] texCoords,
+                   int cdirty) {
         if (VERBOSE) System.err.println("JoglPipeline.executeVA()");
 
-        boolean floatCoordDefined  = ((vdefined & GeometryArrayRetained.COORD_FLOAT)    != 0);
-        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE)   != 0);
-        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT)    != 0);
-        boolean byteColorsDefined  = ((vdefined & GeometryArrayRetained.COLOR_BYTE)     != 0);
-        boolean normalsDefined     = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT)   != 0);
-        boolean vattrDefined       = ((vdefined & GeometryArrayRetained.VATTR_FLOAT)    != 0);
-        boolean textureDefined     = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
+        boolean floatCoordDefined = ((vdefined & GeometryArrayRetained.COORD_FLOAT) != 0);
+        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE) != 0);
+        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT) != 0);
+        boolean byteColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_BYTE) != 0);
+        boolean normalsDefined = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT) != 0);
+        boolean vattrDefined = ((vdefined & GeometryArrayRetained.VATTR_FLOAT) != 0);
+        boolean textureDefined = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
 
         FloatBuffer fverts = null;
         DoubleBuffer dverts = null;
@@ -232,7 +724,7 @@
         int[] start_array = null;
         int strip_len = 0;
         if (geo_type == GeometryRetained.GEO_TYPE_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_LINE_STRIP_SET) {
             sarray = ((GeometryStripArrayRetained) geo).stripVertexCounts;
             strip_len = sarray.length;
@@ -256,34 +748,34 @@
     // used by GeometryArray by Reference with NIO buffer
     @Override
     void executeVABuffer(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean ignoreVertexColors,
-            int vcount,
-            int vformat,
-            int vdefined,
-            int initialCoordIndex,
-            Buffer vcoords,
-            int initialColorIndex,
-            Buffer cdataBuffer,
-            float[] cfdata, byte[] cbdata,
-            int initialNormalIndex, FloatBuffer ndata,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            int[] vertexAttrIndices, FloatBuffer[] vertexAttrData,
-            int texCoordMapLength,
-            int[] texcoordoffset,
-            int numActiveTexUnitState,
-            int[] texIndex, int texstride, Object[] texCoords,
-            int cdirty) {
+                         GeometryArrayRetained geo, int geo_type,
+                         boolean isNonUniformScale,
+                         boolean ignoreVertexColors,
+                         int vcount,
+                         int vformat,
+                         int vdefined,
+                         int initialCoordIndex,
+                         Buffer vcoords,
+                         int initialColorIndex,
+                         Buffer cdataBuffer,
+                         float[] cfdata, byte[] cbdata,
+                         int initialNormalIndex, FloatBuffer ndata,
+                         int vertexAttrCount, int[] vertexAttrSizes,
+                         int[] vertexAttrIndices, FloatBuffer[] vertexAttrData,
+                         int texCoordMapLength,
+                         int[] texcoordoffset,
+                         int numActiveTexUnitState,
+                         int[] texIndex, int texstride, Object[] texCoords,
+                         int cdirty) {
         if (VERBOSE) System.err.println("JoglPipeline.executeVABuffer()");
 
-        boolean floatCoordDefined  = ((vdefined & GeometryArrayRetained.COORD_FLOAT)    != 0);
-        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE)   != 0);
-        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT)    != 0);
-        boolean byteColorsDefined  = ((vdefined & GeometryArrayRetained.COLOR_BYTE)     != 0);
-        boolean normalsDefined     = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT)   != 0);
-        boolean vattrDefined       = ((vdefined & GeometryArrayRetained.VATTR_FLOAT)    != 0);
-        boolean textureDefined     = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
+        boolean floatCoordDefined = ((vdefined & GeometryArrayRetained.COORD_FLOAT) != 0);
+        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE) != 0);
+        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT) != 0);
+        boolean byteColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_BYTE) != 0);
+        boolean normalsDefined = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT) != 0);
+        boolean vattrDefined = ((vdefined & GeometryArrayRetained.VATTR_FLOAT) != 0);
+        boolean textureDefined = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
 
         FloatBuffer fverts = null;
         DoubleBuffer dverts = null;
@@ -338,7 +830,7 @@
         int[] start_array = null;
         int strip_len = 0;
         if (geo_type == GeometryRetained.GEO_TYPE_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_LINE_STRIP_SET) {
             sarray = ((GeometryStripArrayRetained) geo).stripVertexCounts;
             strip_len = sarray.length;
@@ -362,16 +854,16 @@
     // used by GeometryArray by Reference in interleaved format with NIO buffer
     @Override
     void executeInterleavedBuffer(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean useAlpha,
-            boolean ignoreVertexColors,
-            int startVIndex, int vcount, int vformat,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int texCoordSetMapLen,
-            int[] texUnitOffset,
-            int numActiveTexUnit,
-            FloatBuffer varray, float[] cdata, int cdirty) {
+                                  GeometryArrayRetained geo, int geo_type,
+                                  boolean isNonUniformScale,
+                                  boolean useAlpha,
+                                  boolean ignoreVertexColors,
+                                  int startVIndex, int vcount, int vformat,
+                                  int texCoordSetCount, int[] texCoordSetMap,
+                                  int texCoordSetMapLen,
+                                  int[] texUnitOffset,
+                                  int numActiveTexUnit,
+                                  FloatBuffer varray, float[] cdata, int cdirty) {
         if (VERBOSE) System.err.println("JoglPipeline.executeInterleavedBuffer()");
 
         executeGeometryArray(ctx, geo, geo_type,
@@ -384,10 +876,10 @@
 
     @Override
     void setVertexFormat(Context ctx, GeometryArrayRetained geo,
-            int vformat, boolean useAlpha, boolean ignoreVertexColors) {
+                         int vformat, boolean useAlpha, boolean ignoreVertexColors) {
         if (VERBOSE) System.err.println("JoglPipeline.setVertexFormat()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         // Enable and disable the appropriate pointers
         if ((vformat & GeometryArray.NORMALS) != 0) {
@@ -411,20 +903,20 @@
     // used for GeometryArrays
     @Override
     void buildGA(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale, boolean updateAlpha,
-            float alpha,
-            boolean ignoreVertexColors,
-            int startVIndex,
-            int vcount, int vformat,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int texCoordSetMapLen, int[] texCoordSetMapOffset,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            double[] xform, double[] nxform,
-            float[] varray) {
+                 GeometryArrayRetained geo, int geo_type,
+                 boolean isNonUniformScale, boolean updateAlpha,
+                 float alpha,
+                 boolean ignoreVertexColors,
+                 int startVIndex,
+                 int vcount, int vformat,
+                 int texCoordSetCount, int[] texCoordSetMap,
+                 int texCoordSetMapLen, int[] texCoordSetMapOffset,
+                 int vertexAttrCount, int[] vertexAttrSizes,
+                 double[] xform, double[] nxform,
+                 float[] varray) {
         if (VERBOSE) System.err.println("JoglPipeline.buildGA()");
         JoglContext jctx = (JoglContext) ctx;
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         FloatBuffer verts = null;
         int stride = 0, coordoff = 0, normoff = 0, coloroff = 0, texCoordoff = 0;
         int texStride = 0;
@@ -481,7 +973,7 @@
             texCoordoff += vAttrStride;
         }
 
-		int bstride = stride * Buffers.SIZEOF_FLOAT;
+        int bstride = stride * Buffers.SIZEOF_FLOAT;
         // Start sending down from the startVIndex
         int initialOffset = startVIndex * stride;
         normoff += initialOffset;
@@ -497,19 +989,19 @@
         }
 
         if (geo_type == GeometryRetained.GEO_TYPE_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_LINE_STRIP_SET) {
             int[] sarray = ((GeometryStripArrayRetained) geo).stripVertexCounts;
 
             int primType = 0;
             switch (geo_type) {
-                case GeometryRetained.GEO_TYPE_TRI_STRIP_SET :
+                case GeometryRetained.GEO_TYPE_TRI_STRIP_SET:
                     primType = GL.GL_TRIANGLE_STRIP;
                     break;
-                case GeometryRetained.GEO_TYPE_TRI_FAN_SET :
+                case GeometryRetained.GEO_TYPE_TRI_FAN_SET:
                     primType = GL.GL_TRIANGLE_FAN;
                     break;
-                case GeometryRetained.GEO_TYPE_LINE_STRIP_SET :
+                case GeometryRetained.GEO_TYPE_LINE_STRIP_SET:
                     primType = GL.GL_LINE_STRIP;
                     break;
             }
@@ -524,35 +1016,35 @@
                     if ((vformat & GeometryArray.NORMALS) != 0) {
                         if (nxform != null) {
                             float nx = (float) (nxform[0] * varray[normoff] +
-                                    nxform[1] * varray[normoff+1] +
-                                    nxform[2] * varray[normoff+2]);
+                                    nxform[1] * varray[normoff + 1] +
+                                    nxform[2] * varray[normoff + 2]);
                             float ny = (float) (nxform[4] * varray[normoff] +
-                                    nxform[5] * varray[normoff+1] +
-                                    nxform[6] * varray[normoff+2]);
+                                    nxform[5] * varray[normoff + 1] +
+                                    nxform[6] * varray[normoff + 2]);
                             float nz = (float) (nxform[8] * varray[normoff] +
-                                    nxform[9] * varray[normoff+1] +
-                                    nxform[10] * varray[normoff+2]);
+                                    nxform[9] * varray[normoff + 1] +
+                                    nxform[10] * varray[normoff + 2]);
                             gl.glNormal3f(nx, ny, nz);
                         } else {
-                            gl.glNormal3f(varray[normoff], varray[normoff+1], varray[normoff+2]);
+                            gl.glNormal3f(varray[normoff], varray[normoff + 1], varray[normoff + 2]);
                         }
                     }
                     if ((vformat & GeometryArray.COLOR) != 0) {
                         if (useAlpha) {
                             gl.glColor4f(varray[coloroff],
-                                    varray[coloroff+1],
-                                    varray[coloroff+2],
-                                    varray[coloroff+3] * alpha);
+                                    varray[coloroff + 1],
+                                    varray[coloroff + 2],
+                                    varray[coloroff + 3] * alpha);
                         } else {
                             if ((vformat & GeometryArray.WITH_ALPHA) != 0) { // alpha is present
                                 gl.glColor4f(varray[coloroff],
-                                        varray[coloroff+1],
-                                        varray[coloroff+2],
-                                        varray[coloroff+3]);
+                                        varray[coloroff + 1],
+                                        varray[coloroff + 2],
+                                        varray[coloroff + 3]);
                             } else {
                                 gl.glColor3f(varray[coloroff],
-                                        varray[coloroff+1],
-                                        varray[coloroff+2]);
+                                        varray[coloroff + 1],
+                                        varray[coloroff + 2]);
                             }
                         }
                     }
@@ -640,22 +1132,22 @@
                     if ((vformat & GeometryArray.COORDINATES) != 0) {
                         if (xform != null) {
                             // transform the vertex data with the static transform
-                            float w    = (float) (xform[12] * varray[coordoff] +
-                                    xform[13] * varray[coordoff+1] +
-                                    xform[14] * varray[coordoff+2] +
+                            float w = (float) (xform[12] * varray[coordoff] +
+                                    xform[13] * varray[coordoff + 1] +
+                                    xform[14] * varray[coordoff + 2] +
                                     xform[15]);
-                            float winv = 1.0f/w;
+                            float winv = 1.0f / w;
                             float vx = (float) (xform[0] * varray[coordoff] +
-                                    xform[1] * varray[coordoff+1] +
-                                    xform[2] * varray[coordoff+2] +
+                                    xform[1] * varray[coordoff + 1] +
+                                    xform[2] * varray[coordoff + 2] +
                                     xform[3]) * winv;
                             float vy = (float) (xform[4] * varray[coordoff] +
-                                    xform[5] * varray[coordoff+1] +
-                                    xform[6] * varray[coordoff+2] +
+                                    xform[5] * varray[coordoff + 1] +
+                                    xform[6] * varray[coordoff + 2] +
                                     xform[7]) * winv;
                             float vz = (float) (xform[8] * varray[coordoff] +
-                                    xform[9] * varray[coordoff+1] +
-                                    xform[10] * varray[coordoff+2] +
+                                    xform[9] * varray[coordoff + 1] +
+                                    xform[10] * varray[coordoff + 2] +
                                     xform[11]) * winv;
                             gl.glVertex3f(vx, vy, vz);
                         } else {
@@ -676,16 +1168,16 @@
                 (geo_type == GeometryRetained.GEO_TYPE_LINE_SET)) {
             int primType = 0;
             switch (geo_type) {
-                case GeometryRetained.GEO_TYPE_QUAD_SET :
+                case GeometryRetained.GEO_TYPE_QUAD_SET:
                     primType = GL2.GL_QUADS;
                     break;
-                case GeometryRetained.GEO_TYPE_TRI_SET :
+                case GeometryRetained.GEO_TYPE_TRI_SET:
                     primType = GL.GL_TRIANGLES;
                     break;
-                case GeometryRetained.GEO_TYPE_POINT_SET :
+                case GeometryRetained.GEO_TYPE_POINT_SET:
                     primType = GL.GL_POINTS;
                     break;
-                case GeometryRetained.GEO_TYPE_LINE_SET :
+                case GeometryRetained.GEO_TYPE_LINE_SET:
                     primType = GL.GL_LINES;
                     break;
             }
@@ -699,14 +1191,14 @@
                 if ((vformat & GeometryArray.NORMALS) != 0) {
                     if (nxform != null) {
                         float nx = (float) (nxform[0] * varray[normoff] +
-                                nxform[1] * varray[normoff+1] +
-                                nxform[2] * varray[normoff+2]);
+                                nxform[1] * varray[normoff + 1] +
+                                nxform[2] * varray[normoff + 2]);
                         float ny = (float) (nxform[4] * varray[normoff] +
-                                nxform[5] * varray[normoff+1] +
-                                nxform[6] * varray[normoff+2]);
+                                nxform[5] * varray[normoff + 1] +
+                                nxform[6] * varray[normoff + 2]);
                         float nz = (float) (nxform[8] * varray[normoff] +
-                                nxform[9] * varray[normoff+1] +
-                                nxform[10] * varray[normoff+2]);
+                                nxform[9] * varray[normoff + 1] +
+                                nxform[10] * varray[normoff + 2]);
                         gl.glNormal3f(nx, ny, nz);
                     } else {
                         gl.glNormal3f(varray[normoff], varray[normoff + 1], varray[normoff + 2]);
@@ -825,21 +1317,21 @@
                     if (xform != null) {
                         // transform the vertex data with the static transform
                         float w = (float) (xform[12] * varray[coordoff] +
-                                xform[13] * varray[coordoff+1] +
-                                xform[14] * varray[coordoff+2] +
+                                xform[13] * varray[coordoff + 1] +
+                                xform[14] * varray[coordoff + 2] +
                                 xform[15]);
-                        float winv = 1.0f/w;
+                        float winv = 1.0f / w;
                         float vx = (float) (xform[0] * varray[coordoff] +
-                                xform[1] * varray[coordoff+1] +
-                                xform[2] * varray[coordoff+2] +
+                                xform[1] * varray[coordoff + 1] +
+                                xform[2] * varray[coordoff + 2] +
                                 xform[3]) * winv;
                         float vy = (float) (xform[4] * varray[coordoff] +
-                                xform[5] * varray[coordoff+1] +
-                                xform[6] * varray[coordoff+2] +
+                                xform[5] * varray[coordoff + 1] +
+                                xform[6] * varray[coordoff + 2] +
                                 xform[7]) * winv;
                         float vz = (float) (xform[8] * varray[coordoff] +
-                                xform[9] * varray[coordoff+1] +
-                                xform[10] * varray[coordoff+2] +
+                                xform[9] * varray[coordoff + 1] +
+                                xform[10] * varray[coordoff + 2] +
                                 xform[11]) * winv;
                         gl.glVertex3f(vx, vy, vz);
                     } else {
@@ -859,33 +1351,33 @@
     // used to Build Dlist GeometryArray by Reference with java arrays
     @Override
     void buildGAForByRef(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,  boolean updateAlpha,
-            float alpha,
-            boolean ignoreVertexColors,
-            int vcount,
-            int vformat,
-            int vdefined,
-            int initialCoordIndex, float[] vfcoords, double[] vdcoords,
-            int initialColorIndex, float[] cfdata, byte[] cbdata,
-            int initialNormalIndex, float[] ndata,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            int[] vertexAttrIndices, float[][] vertexAttrData,
-            int texCoordMapLength,
-            int[] tcoordsetmap,
-            int[] texIndices, int texStride, Object[] texCoords,
-            double[] xform, double[] nxform) {
+                         GeometryArrayRetained geo, int geo_type,
+                         boolean isNonUniformScale, boolean updateAlpha,
+                         float alpha,
+                         boolean ignoreVertexColors,
+                         int vcount,
+                         int vformat,
+                         int vdefined,
+                         int initialCoordIndex, float[] vfcoords, double[] vdcoords,
+                         int initialColorIndex, float[] cfdata, byte[] cbdata,
+                         int initialNormalIndex, float[] ndata,
+                         int vertexAttrCount, int[] vertexAttrSizes,
+                         int[] vertexAttrIndices, float[][] vertexAttrData,
+                         int texCoordMapLength,
+                         int[] tcoordsetmap,
+                         int[] texIndices, int texStride, Object[] texCoords,
+                         double[] xform, double[] nxform) {
         if (VERBOSE) System.err.println("JoglPipeline.buildGAForByRef()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
-        boolean floatCoordDefined  = ((vdefined & GeometryArrayRetained.COORD_FLOAT)    != 0);
-        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE)   != 0);
-        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT)    != 0);
-        boolean byteColorsDefined  = ((vdefined & GeometryArrayRetained.COLOR_BYTE)     != 0);
-        boolean normalsDefined     = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT)   != 0);
-        boolean vattrDefined       = ((vdefined & GeometryArrayRetained.VATTR_FLOAT)    != 0);
-        boolean textureDefined     = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
+        boolean floatCoordDefined = ((vdefined & GeometryArrayRetained.COORD_FLOAT) != 0);
+        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE) != 0);
+        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT) != 0);
+        boolean byteColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_BYTE) != 0);
+        boolean normalsDefined = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT) != 0);
+        boolean vattrDefined = ((vdefined & GeometryArrayRetained.VATTR_FLOAT) != 0);
+        boolean textureDefined = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
 
         FloatBuffer fverts = null;
         DoubleBuffer dverts = null;
@@ -915,7 +1407,7 @@
         int[] start_array = null;
         int strip_len = 0;
         if (geo_type == GeometryRetained.GEO_TYPE_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_LINE_STRIP_SET) {
             sarray = ((GeometryStripArrayRetained) geo).stripVertexCounts;
             strip_len = sarray.length;
@@ -935,15 +1427,15 @@
             if (xform != null) {
                 // Must copy in and transform data
                 for (int i = initialCoordIndex; i < vcount * 3; i += 3) {
-                    fverts.put(i  , (float) (xform[0]  * vfcoords[i] +
-                            xform[1]  * vfcoords[i+1] +
-                            xform[2]  * vfcoords[i+2]));
-                    fverts.put(i+1, (float) (xform[4]  * vfcoords[i] +
-                            xform[5]  * vfcoords[i+1] +
-                            xform[6]  * vfcoords[i+2]));
-                    fverts.put(i+2, (float) (xform[8]  * vfcoords[i] +
-                            xform[9]  * vfcoords[i+1] +
-                            xform[10] * vfcoords[i+2]));
+                    fverts.put(i, (float) (xform[0] * vfcoords[i] +
+                            xform[1] * vfcoords[i + 1] +
+                            xform[2] * vfcoords[i + 2]));
+                    fverts.put(i + 1, (float) (xform[4] * vfcoords[i] +
+                            xform[5] * vfcoords[i + 1] +
+                            xform[6] * vfcoords[i + 2]));
+                    fverts.put(i + 2, (float) (xform[8] * vfcoords[i] +
+                            xform[9] * vfcoords[i + 1] +
+                            xform[10] * vfcoords[i + 2]));
                 }
             }
         } else if (doubleCoordDefined) {
@@ -952,15 +1444,15 @@
             if (xform != null) {
                 // Must copy in and transform data
                 for (int i = initialCoordIndex; i < vcount * 3; i += 3) {
-                    dverts.put(i  , (xform[0]  * vdcoords[i] +
-                            xform[1]  * vdcoords[i+1] +
-                            xform[2]  * vdcoords[i+2]));
-                    dverts.put(i+1, (xform[4]  * vdcoords[i] +
-                            xform[5]  * vdcoords[i+1] +
-                            xform[6]  * vdcoords[i+2]));
-                    dverts.put(i+2, (xform[8]  * vdcoords[i] +
-                            xform[9]  * vdcoords[i+1] +
-                            xform[10] * vdcoords[i+2]));
+                    dverts.put(i, (xform[0] * vdcoords[i] +
+                            xform[1] * vdcoords[i + 1] +
+                            xform[2] * vdcoords[i + 2]));
+                    dverts.put(i + 1, (xform[4] * vdcoords[i] +
+                            xform[5] * vdcoords[i + 1] +
+                            xform[6] * vdcoords[i + 2]));
+                    dverts.put(i + 2, (xform[8] * vdcoords[i] +
+                            xform[9] * vdcoords[i + 1] +
+                            xform[10] * vdcoords[i + 2]));
                 }
             }
         } else {
@@ -975,18 +1467,18 @@
                 // Must copy in and modify color data
                 if ((vformat & GeometryArray.WITH_ALPHA) != 0) {
                     for (int i = initialColorIndex; i < vcount * 4; i += 4) {
-                        fclrs.put(i  , cfdata[i]);
-                        fclrs.put(i+1, cfdata[i+1]);
-                        fclrs.put(i+2, cfdata[i+2]);
-                        fclrs.put(i+3, alpha * cfdata[i+3]);
+                        fclrs.put(i, cfdata[i]);
+                        fclrs.put(i + 1, cfdata[i + 1]);
+                        fclrs.put(i + 2, cfdata[i + 2]);
+                        fclrs.put(i + 3, alpha * cfdata[i + 3]);
                     }
                 } else {
                     int k = 0;
                     for (int i = initialColorIndex; i < vcount * 4; i += 4) {
-                        fclrs.put(i  , cfdata[k++]);
-                        fclrs.put(i+1, cfdata[k++]);
-                        fclrs.put(i+2, cfdata[k++]);
-                        fclrs.put(i+3, alpha);
+                        fclrs.put(i, cfdata[k++]);
+                        fclrs.put(i + 1, cfdata[k++]);
+                        fclrs.put(i + 2, cfdata[k++]);
+                        fclrs.put(i + 3, alpha);
                     }
                 }
                 vformat |= GeometryArray.WITH_ALPHA;
@@ -998,18 +1490,18 @@
                 // Must copy in and modify color data
                 if ((vformat & GeometryArray.WITH_ALPHA) != 0) {
                     for (int i = initialColorIndex; i < vcount * 4; i += 4) {
-                        bclrs.put(i  , cbdata[i]);
-                        bclrs.put(i+1, cbdata[i+1]);
-                        bclrs.put(i+2, cbdata[i+2]);
-                        bclrs.put(i+3, (byte) (alpha * (int) (cbdata[i+3] & 0xFF)));
+                        bclrs.put(i, cbdata[i]);
+                        bclrs.put(i + 1, cbdata[i + 1]);
+                        bclrs.put(i + 2, cbdata[i + 2]);
+                        bclrs.put(i + 3, (byte) (alpha * (int) (cbdata[i + 3] & 0xFF)));
                     }
                 } else {
                     int k = 0;
                     for (int i = initialColorIndex; i < vcount * 4; i += 4) {
-                        bclrs.put(i  , cbdata[k++]);
-                        bclrs.put(i+1, cbdata[k++]);
-                        bclrs.put(i+2, cbdata[k++]);
-                        bclrs.put(i+3, (byte) (alpha * 255.0f));
+                        bclrs.put(i, cbdata[k++]);
+                        bclrs.put(i + 1, cbdata[k++]);
+                        bclrs.put(i + 2, cbdata[k++]);
+                        bclrs.put(i + 3, (byte) (alpha * 255.0f));
                     }
                 }
                 vformat |= GeometryArray.WITH_ALPHA;
@@ -1025,15 +1517,15 @@
             if (nxform != null) {
                 // Must copy in and transform data
                 for (int i = initialNormalIndex; i < vcount * 3; i += 3) {
-                    norms.put(i  , (float) (nxform[0]  * ndata[i] +
-                            nxform[1]  * ndata[i+1] +
-                            nxform[2]  * ndata[i+2]));
-                    norms.put(i+1, (float) (nxform[4]  * ndata[i] +
-                            nxform[5]  * ndata[i+1] +
-                            nxform[6]  * ndata[i+2]));
-                    norms.put(i+2, (float) (nxform[8]  * ndata[i] +
-                            nxform[9]  * ndata[i+1] +
-                            nxform[10] * ndata[i+2]));
+                    norms.put(i, (float) (nxform[0] * ndata[i] +
+                            nxform[1] * ndata[i + 1] +
+                            nxform[2] * ndata[i + 2]));
+                    norms.put(i + 1, (float) (nxform[4] * ndata[i] +
+                            nxform[5] * ndata[i + 1] +
+                            nxform[6] * ndata[i + 2]));
+                    norms.put(i + 2, (float) (nxform[8] * ndata[i] +
+                            nxform[9] * ndata[i + 1] +
+                            nxform[10] * ndata[i + 2]));
                 }
             }
         } else {
@@ -1054,69 +1546,71 @@
                 sarray, strip_len, start_array);
     }
 
-    //----------------------------------------------------------------------
-    // Private helper methods for GeometryArrayRetained
-    //
-
     private void
-            testForInterleavedArrays(int vformat,
-            boolean[] useInterleavedArrays,
-            int[] iaFormat) {
+    testForInterleavedArrays(int vformat,
+                             boolean[] useInterleavedArrays,
+                             int[] iaFormat) {
         if (VERBOSE) System.err.println("JoglPipeline.testForInterleavedArrays()");
         useInterleavedArrays[0] = true;
         switch (vformat) {
-            case GeometryArray.COORDINATES :
-                iaFormat[0] = GL2.GL_V3F; break;
-            case (GeometryArray.COORDINATES | GeometryArray.NORMALS) :
-                iaFormat[0] = GL2.GL_N3F_V3F; break;
-            case (GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2) :
-                iaFormat[0] = GL2.GL_T2F_V3F; break;
-            case (GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR) :
-            case (GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR | GeometryArray.WITH_ALPHA) :
-                iaFormat[0] = GL2.GL_C4F_N3F_V3F; break;
-            case (GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2) :
-                iaFormat[0] = GL2.GL_T2F_N3F_V3F; break;
+            case GeometryArray.COORDINATES:
+                iaFormat[0] = GL2.GL_V3F;
+                break;
+            case (GeometryArray.COORDINATES | GeometryArray.NORMALS):
+                iaFormat[0] = GL2.GL_N3F_V3F;
+                break;
+            case (GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2):
+                iaFormat[0] = GL2.GL_T2F_V3F;
+                break;
+            case (GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR):
+            case (GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR | GeometryArray.WITH_ALPHA):
+                iaFormat[0] = GL2.GL_C4F_N3F_V3F;
+                break;
+            case (GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2):
+                iaFormat[0] = GL2.GL_T2F_N3F_V3F;
+                break;
             case (GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR | GeometryArray.TEXTURE_COORDINATE_2):
             case (GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR | GeometryArray.WITH_ALPHA | GeometryArray.TEXTURE_COORDINATE_2):
-                iaFormat[0] = GL2.GL_T2F_C4F_N3F_V3F; break;
+                iaFormat[0] = GL2.GL_T2F_C4F_N3F_V3F;
+                break;
             default:
-                useInterleavedArrays[0] = false; break;
+                useInterleavedArrays[0] = false;
+                break;
         }
     }
 
     private void
-            enableTexCoordPointer(GL2 gl,
-            int texUnit,
-            int texSize,
-            int texDataType,
-            int stride,
-            Buffer pointer) {
+    enableTexCoordPointer(GL2 gl,
+                          int texUnit,
+                          int texSize,
+                          int texDataType,
+                          int stride,
+                          Buffer pointer) {
         if (VERBOSE) System.err.println("JoglPipeline.enableTexCoordPointer()");
         clientActiveTextureUnit(gl, texUnit);
         gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
         gl.glTexCoordPointer(texSize, texDataType, stride, pointer);
     }
 
-	private void disableTexCoordPointer(GL2 gl, int texUnit) {
+    private void disableTexCoordPointer(GL2 gl, int texUnit) {
         if (VERBOSE) System.err.println("JoglPipeline.disableTexCoordPointer()");
         clientActiveTextureUnit(gl, texUnit);
         gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
     }
 
-	private void clientActiveTextureUnit(GL2 gl, int texUnit) {
+    private void clientActiveTextureUnit(GL2 gl, int texUnit) {
         if (VERBOSE) System.err.println("JoglPipeline.clientActiveTextureUnit()");
         if (gl.isExtensionAvailable("GL_VERSION_1_3")) {
             gl.glClientActiveTexture(texUnit + GL.GL_TEXTURE0);
         }
     }
 
-
     private void
-            executeTexture(int texCoordSetMapLen,
-            int texSize, int bstride, int texCoordoff,
-            int[] texCoordSetMapOffset,
-            int numActiveTexUnit,
-            FloatBuffer verts, GL2 gl) {
+    executeTexture(int texCoordSetMapLen,
+                   int texSize, int bstride, int texCoordoff,
+                   int[] texCoordSetMapOffset,
+                   int numActiveTexUnit,
+                   FloatBuffer verts, GL2 gl) {
         if (VERBOSE) System.err.println("JoglPipeline.executeTexture()");
         int tus = 0;  /* texture unit state index */
 
@@ -1124,11 +1618,11 @@
 
             tus = i;
 
-      /*
-       * it's possible thattexture unit state index (tus)
-       * is greater than the texCoordSetMapOffsetLen, in this
-       * case, just disable TexCoordPointer.
-       */
+            /*
+             * it's possible thattexture unit state index (tus)
+             * is greater than the texCoordSetMapOffsetLen, in this
+             * case, just disable TexCoordPointer.
+             */
             if ((tus < texCoordSetMapLen) &&
                     (texCoordSetMapOffset[tus] != -1)) {
                 if (EXTRA_DEBUGGING) {
@@ -1144,7 +1638,7 @@
         }
     }
 
-	private void resetTexture(GL2 gl, JoglContext ctx) {
+    private void resetTexture(GL2 gl, JoglContext ctx) {
         if (VERBOSE) System.err.println("JoglPipeline.resetTexture()");
         /* Disable texture coordinate arrays for all texture units */
         for (int i = 0; i < ctx.getMaxTexCoordSets(); i++) {
@@ -1155,23 +1649,23 @@
     }
 
     private void
-            executeGeometryArray(Context absCtx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean useAlpha,
-            boolean ignoreVertexColors,
-            int startVIndex, int vcount, int vformat,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int texCoordSetMapLen,
-            int[] texCoordSetMapOffset,
-            int numActiveTexUnitState,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            float[] varray, FloatBuffer varrayBuffer,
-            float[] carray, int cDirty) {
+    executeGeometryArray(Context absCtx,
+                         GeometryArrayRetained geo, int geo_type,
+                         boolean isNonUniformScale,
+                         boolean useAlpha,
+                         boolean ignoreVertexColors,
+                         int startVIndex, int vcount, int vformat,
+                         int texCoordSetCount, int[] texCoordSetMap,
+                         int texCoordSetMapLen,
+                         int[] texCoordSetMapOffset,
+                         int numActiveTexUnitState,
+                         int vertexAttrCount, int[] vertexAttrSizes,
+                         float[] varray, FloatBuffer varrayBuffer,
+                         float[] carray, int cDirty) {
         if (VERBOSE) System.err.println("JoglPipeline.executeGeometryArray()");
         JoglContext ctx = (JoglContext) absCtx;
         GLContext context = context(ctx);
-		GL2 gl = context.getGL().getGL2();
+        GL2 gl = context.getGL().getGL2();
 
         boolean useInterleavedArrays;
         int iaFormat = 0;
@@ -1182,7 +1676,7 @@
         int vAttrStride = 0;
         int bstride = 0, cbstride = 0;
         FloatBuffer verts = null;
-        FloatBuffer clrs  = null;
+        FloatBuffer clrs = null;
         int[] sarray = null;
         int[] start_array = null;
 
@@ -1204,7 +1698,7 @@
             coordoff += 3;
         }
         if ((vformat & GeometryArray.COLOR) != 0) {
-            if ((vformat & GeometryArray.WITH_ALPHA) != 0 ) {
+            if ((vformat & GeometryArray.WITH_ALPHA) != 0) {
                 stride += 4;
                 normoff += 4;
                 coordoff += 4;
@@ -1244,10 +1738,10 @@
             texCoordoff += vAttrStride;
         }
 
-		bstride = stride * Buffers.SIZEOF_FLOAT;
+        bstride = stride * Buffers.SIZEOF_FLOAT;
 
         if (geo_type == GeometryRetained.GEO_TYPE_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_LINE_STRIP_SET) {
             sarray = ((GeometryStripArrayRetained) geo).stripVertexCounts;
             start_array = ((GeometryStripArrayRetained) geo).stripStartOffsetIndices;
@@ -1273,26 +1767,26 @@
             clrs = verts;
         }
 
-		cbstride = cstride * Buffers.SIZEOF_FLOAT;
+        cbstride = cstride * Buffers.SIZEOF_FLOAT;
 
         // Enable normalize for non-uniform scale (which rescale can't handle)
         if (isNonUniformScale) {
             gl.glEnable(GL2.GL_NORMALIZE);
         }
 
-        int startVertex = stride  * startVIndex;
-        int startClrs   = cstride * startVIndex;
+        int startVertex = stride * startVIndex;
+        int startClrs = cstride * startVIndex;
         if (clrs == verts) {
             startClrs += coloroff;
         }
 
         /*** Handle non-indexed strip GeometryArray first *******/
         if (geo_type == GeometryRetained.GEO_TYPE_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_LINE_STRIP_SET) {
             if (ignoreVertexColors || (carray != null) ||
                     ((vformat & GeometryArray.TEXTURE_COORDINATE) != 0 && ((texCoordSetMapLen > 1) ||
-                    (texCoordSetCount > 1)))) {
+                            (texCoordSetCount > 1)))) {
                 useInterleavedArrays = false;
             } else {
                 boolean[] tmp = new boolean[1];
@@ -1371,7 +1865,7 @@
             /******* Handle non-indexed non-striped GeometryArray now *****/
             if (ignoreVertexColors || (carray != null) ||
                     ((vformat & GeometryArray.TEXTURE_COORDINATE) != 0 && ((texCoordSetMapLen > 1) ||
-                    (texCoordSetCount > 1)))) {
+                            (texCoordSetCount > 1)))) {
                 useInterleavedArrays = false;
             } else {
                 boolean[] tmp = new boolean[1];
@@ -1430,11 +1924,19 @@
                     }
                 }
             }
-            switch (geo_type){
-                case GeometryRetained.GEO_TYPE_QUAD_SET : gl.glDrawArrays(GL2.GL_QUADS,     0, vcount); break;
-                case GeometryRetained.GEO_TYPE_TRI_SET  : gl.glDrawArrays(GL.GL_TRIANGLES, 0, vcount); break;
-                case GeometryRetained.GEO_TYPE_POINT_SET: gl.glDrawArrays(GL.GL_POINTS,    0, vcount); break;
-                case GeometryRetained.GEO_TYPE_LINE_SET : gl.glDrawArrays(GL.GL_LINES,     0, vcount); break;
+            switch (geo_type) {
+                case GeometryRetained.GEO_TYPE_QUAD_SET:
+                    gl.glDrawArrays(GL2.GL_QUADS, 0, vcount);
+                    break;
+                case GeometryRetained.GEO_TYPE_TRI_SET:
+                    gl.glDrawArrays(GL.GL_TRIANGLES, 0, vcount);
+                    break;
+                case GeometryRetained.GEO_TYPE_POINT_SET:
+                    gl.glDrawArrays(GL.GL_POINTS, 0, vcount);
+                    break;
+                case GeometryRetained.GEO_TYPE_LINE_SET:
+                    gl.glDrawArrays(GL.GL_LINES, 0, vcount);
+                    break;
             }
         }
 
@@ -1452,7 +1954,6 @@
         }
     }
 
-
     // glLockArrays() is invoked only for indexed geometry, and the
     // vertexCount is guarenteed to be >= 0.
     private void lockArray(GL2 gl, int vertexCount) {
@@ -1468,38 +1969,38 @@
     }
 
     private void
-            executeGeometryArrayVA(Context absCtx,
-            GeometryArrayRetained geo,
-            int geo_type,
-            boolean isNonUniformScale,
-            boolean ignoreVertexColors,
-            int vcount,
-            int vformat,
-            int vdefined,
-            int initialCoordIndex, FloatBuffer fverts, DoubleBuffer dverts,
-            int initialColorIndex, FloatBuffer fclrs, ByteBuffer bclrs,
-            int initialNormalIndex, FloatBuffer norms,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            int[] vertexAttrIndices, FloatBuffer[] vertexAttrData,
-            int texCoordMapLength,
-            int[] texCoordSetMap,
-            int numActiveTexUnit,
-            int[] texindices, int texStride, FloatBuffer[] texCoords,
-            int cdirty,
-            int[] sarray,
-            int strip_len,
-            int[] start_array) {
+    executeGeometryArrayVA(Context absCtx,
+                           GeometryArrayRetained geo,
+                           int geo_type,
+                           boolean isNonUniformScale,
+                           boolean ignoreVertexColors,
+                           int vcount,
+                           int vformat,
+                           int vdefined,
+                           int initialCoordIndex, FloatBuffer fverts, DoubleBuffer dverts,
+                           int initialColorIndex, FloatBuffer fclrs, ByteBuffer bclrs,
+                           int initialNormalIndex, FloatBuffer norms,
+                           int vertexAttrCount, int[] vertexAttrSizes,
+                           int[] vertexAttrIndices, FloatBuffer[] vertexAttrData,
+                           int texCoordMapLength,
+                           int[] texCoordSetMap,
+                           int numActiveTexUnit,
+                           int[] texindices, int texStride, FloatBuffer[] texCoords,
+                           int cdirty,
+                           int[] sarray,
+                           int strip_len,
+                           int[] start_array) {
         JoglContext ctx = (JoglContext) absCtx;
         GLContext context = context(ctx);
-		GL2 gl = context.getGL().getGL2();
+        GL2 gl = context.getGL().getGL2();
 
-        boolean floatCoordDefined  = ((vdefined & GeometryArrayRetained.COORD_FLOAT)    != 0);
-        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE)   != 0);
-        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT)    != 0);
-        boolean byteColorsDefined  = ((vdefined & GeometryArrayRetained.COLOR_BYTE)     != 0);
-        boolean normalsDefined     = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT)   != 0);
-        boolean vattrDefined       = ((vdefined & GeometryArrayRetained.VATTR_FLOAT)    != 0);
-        boolean textureDefined     = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
+        boolean floatCoordDefined = ((vdefined & GeometryArrayRetained.COORD_FLOAT) != 0);
+        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE) != 0);
+        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT) != 0);
+        boolean byteColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_BYTE) != 0);
+        boolean normalsDefined = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT) != 0);
+        boolean vattrDefined = ((vdefined & GeometryArrayRetained.VATTR_FLOAT) != 0);
+        boolean textureDefined = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
 
         // Enable normalize for non-uniform scale (which rescale can't handle)
         if (isNonUniformScale) {
@@ -1511,7 +2012,7 @@
         if (floatCoordDefined) {
             fverts.position(coordoff);
             gl.glVertexPointer(3, GL.GL_FLOAT, 0, fverts);
-        } else if (doubleCoordDefined){
+        } else if (doubleCoordDefined) {
             dverts.position(coordoff);
             gl.glVertexPointer(3, GL2.GL_DOUBLE, 0, dverts);
         }
@@ -1561,7 +2062,7 @@
         if (textureDefined) {
             int texSet = 0;
             for (int i = 0; i < numActiveTexUnit; i++) {
-                if (( i < texCoordMapLength) &&
+                if ((i < texCoordMapLength) &&
                         ((texSet = texCoordSetMap[i]) != -1)) {
                     FloatBuffer buf = texCoords[texSet];
                     buf.position(texStride * texindices[texSet]);
@@ -1577,7 +2078,7 @@
         }
 
         if (geo_type == GeometryRetained.GEO_TYPE_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_LINE_STRIP_SET) {
             int primType = 0;
             switch (geo_type) {
@@ -1601,11 +2102,19 @@
                 }
             }
         } else {
-            switch (geo_type){
-                case GeometryRetained.GEO_TYPE_QUAD_SET  : gl.glDrawArrays(GL2.GL_QUADS, 0, vcount);     break;
-                case GeometryRetained.GEO_TYPE_TRI_SET   : gl.glDrawArrays(GL.GL_TRIANGLES, 0, vcount); break;
-                case GeometryRetained.GEO_TYPE_POINT_SET : gl.glDrawArrays(GL.GL_POINTS, 0, vcount);    break;
-                case GeometryRetained.GEO_TYPE_LINE_SET  : gl.glDrawArrays(GL.GL_LINES, 0, vcount);     break;
+            switch (geo_type) {
+                case GeometryRetained.GEO_TYPE_QUAD_SET:
+                    gl.glDrawArrays(GL2.GL_QUADS, 0, vcount);
+                    break;
+                case GeometryRetained.GEO_TYPE_TRI_SET:
+                    gl.glDrawArrays(GL.GL_TRIANGLES, 0, vcount);
+                    break;
+                case GeometryRetained.GEO_TYPE_POINT_SET:
+                    gl.glDrawArrays(GL.GL_POINTS, 0, vcount);
+                    break;
+                case GeometryRetained.GEO_TYPE_LINE_SET:
+                    gl.glDrawArrays(GL.GL_LINES, 0, vcount);
+                    break;
             }
         }
 
@@ -1625,31 +2134,45 @@
 
     private String getVertexDescription(int vformat) {
         String res = "";
-        if ((vformat & GeometryArray.COORDINATES)          != 0) res += "COORDINATES ";
-        if ((vformat & GeometryArray.NORMALS)              != 0) res += "NORMALS ";
-        if ((vformat & GeometryArray.COLOR)                != 0) res += "COLOR ";
-        if ((vformat & GeometryArray.WITH_ALPHA)           != 0) res += "(WITH_ALPHA) ";
-        if ((vformat & GeometryArray.TEXTURE_COORDINATE)   != 0) res += "TEXTURE_COORDINATE ";
+        if ((vformat & GeometryArray.COORDINATES) != 0) res += "COORDINATES ";
+        if ((vformat & GeometryArray.NORMALS) != 0) res += "NORMALS ";
+        if ((vformat & GeometryArray.COLOR) != 0) res += "COLOR ";
+        if ((vformat & GeometryArray.WITH_ALPHA) != 0) res += "(WITH_ALPHA) ";
+        if ((vformat & GeometryArray.TEXTURE_COORDINATE) != 0) res += "TEXTURE_COORDINATE ";
         if ((vformat & GeometryArray.TEXTURE_COORDINATE_2) != 0) res += "(2) ";
         if ((vformat & GeometryArray.TEXTURE_COORDINATE_3) != 0) res += "(3) ";
         if ((vformat & GeometryArray.TEXTURE_COORDINATE_4) != 0) res += "(4) ";
-        if ((vformat & GeometryArray.VERTEX_ATTRIBUTES)    != 0) res += "VERTEX_ATTRIBUTES ";
+        if ((vformat & GeometryArray.VERTEX_ATTRIBUTES) != 0) res += "VERTEX_ATTRIBUTES ";
         return res;
     }
 
     private String getGeometryDescription(int geo_type) {
         switch (geo_type) {
-            case GeometryRetained.GEO_TYPE_TRI_STRIP_SET : return "GEO_TYPE_TRI_STRIP_SET";
-            case GeometryRetained.GEO_TYPE_TRI_FAN_SET   : return "GEO_TYPE_TRI_FAN_SET";
-            case GeometryRetained.GEO_TYPE_LINE_STRIP_SET: return "GEO_TYPE_LINE_STRIP_SET";
-            case GeometryRetained.GEO_TYPE_QUAD_SET      : return "GEO_TYPE_QUAD_SET";
-            case GeometryRetained.GEO_TYPE_TRI_SET       : return "GEO_TYPE_TRI_SET";
-            case GeometryRetained.GEO_TYPE_POINT_SET     : return "GEO_TYPE_POINT_SET";
-            case GeometryRetained.GEO_TYPE_LINE_SET      : return "GEO_TYPE_LINE_SET";
-            default: return "(unknown " + geo_type + ")";
+            case GeometryRetained.GEO_TYPE_TRI_STRIP_SET:
+                return "GEO_TYPE_TRI_STRIP_SET";
+            case GeometryRetained.GEO_TYPE_TRI_FAN_SET:
+                return "GEO_TYPE_TRI_FAN_SET";
+            case GeometryRetained.GEO_TYPE_LINE_STRIP_SET:
+                return "GEO_TYPE_LINE_STRIP_SET";
+            case GeometryRetained.GEO_TYPE_QUAD_SET:
+                return "GEO_TYPE_QUAD_SET";
+            case GeometryRetained.GEO_TYPE_TRI_SET:
+                return "GEO_TYPE_TRI_SET";
+            case GeometryRetained.GEO_TYPE_POINT_SET:
+                return "GEO_TYPE_POINT_SET";
+            case GeometryRetained.GEO_TYPE_LINE_SET:
+                return "GEO_TYPE_LINE_SET";
+            default:
+                return "(unknown " + geo_type + ")";
         }
     }
 
+    // ---------------------------------------------------------------------
+
+    //
+    // ColoringAttributesRetained methods
+    //
+
     private void resetVertexAttrs(GL gl, JoglContext ctx, int vertexAttrCount) {
         // Disable specified vertex attr arrays
         for (int i = 0; i < vertexAttrCount; i++) {
@@ -1661,27 +2184,27 @@
     // ---------------------------------------------------------------------
 
     //
-    // IndexedGeometryArrayRetained methods
+    // DirectionalLightRetained methods
     //
 
     // by-copy or interleaved, by reference, Java arrays
     @Override
     void executeIndexedGeometry(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean useAlpha,
-            boolean ignoreVertexColors,
-            int initialIndexIndex,
-            int indexCount,
-            int vertexCount, int vformat,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int texCoordSetMapLen,
-            int[] texCoordSetOffset,
-            int numActiveTexUnitState,
-            float[] varray, float[] carray,
-            int cdirty,
-            int[] indexCoord) {
+                                GeometryArrayRetained geo, int geo_type,
+                                boolean isNonUniformScale,
+                                boolean useAlpha,
+                                boolean ignoreVertexColors,
+                                int initialIndexIndex,
+                                int indexCount,
+                                int vertexCount, int vformat,
+                                int vertexAttrCount, int[] vertexAttrSizes,
+                                int texCoordSetCount, int[] texCoordSetMap,
+                                int texCoordSetMapLen,
+                                int[] texCoordSetOffset,
+                                int numActiveTexUnitState,
+                                float[] varray, float[] carray,
+                                int cdirty,
+                                int[] indexCoord) {
         if (VERBOSE) System.err.println("JoglPipeline.executeIndexedGeometry()");
 
         executeIndexedGeometryArray(ctx, geo, geo_type,
@@ -1699,20 +2222,20 @@
     // interleaved, by reference, nio buffer
     @Override
     void executeIndexedGeometryBuffer(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean useAlpha,
-            boolean ignoreVertexColors,
-            int initialIndexIndex,
-            int indexCount,
-            int vertexCount, int vformat,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int texCoordSetMapLen,
-            int[] texCoordSetOffset,
-            int numActiveTexUnitState,
-            FloatBuffer vdata, float[] carray,
-            int cDirty,
-            int[] indexCoord) {
+                                      GeometryArrayRetained geo, int geo_type,
+                                      boolean isNonUniformScale,
+                                      boolean useAlpha,
+                                      boolean ignoreVertexColors,
+                                      int initialIndexIndex,
+                                      int indexCount,
+                                      int vertexCount, int vformat,
+                                      int texCoordSetCount, int[] texCoordSetMap,
+                                      int texCoordSetMapLen,
+                                      int[] texCoordSetOffset,
+                                      int numActiveTexUnitState,
+                                      FloatBuffer vdata, float[] carray,
+                                      int cDirty,
+                                      int[] indexCoord) {
         if (VERBOSE) System.err.println("JoglPipeline.executeIndexedGeometryBuffer()");
 
         executeIndexedGeometryArray(ctx, geo, geo_type,
@@ -1725,37 +2248,44 @@
                 cDirty, indexCoord);
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // PointLightRetained methods
+    //
+
     // non interleaved, by reference, Java arrays
     @Override
     void executeIndexedGeometryVA(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean ignoreVertexColors,
-            int initialIndexIndex,
-            int validIndexCount,
-            int vertexCount,
-            int vformat,
-            int vdefined,
-            float[] vfcoords, double[] vdcoords,
-            float[] cfdata, byte[] cbdata,
-            float[] ndata,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            float[][] vertexAttrData,
-            int texCoordMapLength,
-            int[] texcoordoffset,
-            int numActiveTexUnitState,
-            int texStride, Object[] texCoords,
-            int cdirty,
-            int[] indexCoord) {
+                                  GeometryArrayRetained geo, int geo_type,
+                                  boolean isNonUniformScale,
+                                  boolean ignoreVertexColors,
+                                  int initialIndexIndex,
+                                  int validIndexCount,
+                                  int vertexCount,
+                                  int vformat,
+                                  int vdefined,
+                                  float[] vfcoords, double[] vdcoords,
+                                  float[] cfdata, byte[] cbdata,
+                                  float[] ndata,
+                                  int vertexAttrCount, int[] vertexAttrSizes,
+                                  float[][] vertexAttrData,
+                                  int texCoordMapLength,
+                                  int[] texcoordoffset,
+                                  int numActiveTexUnitState,
+                                  int texStride, Object[] texCoords,
+                                  int cdirty,
+                                  int[] indexCoord) {
         if (VERBOSE) System.err.println("JoglPipeline.executeIndexedGeometryVA()");
 
-        boolean floatCoordDefined  = ((vdefined & GeometryArrayRetained.COORD_FLOAT)    != 0);
-        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE)   != 0);
-        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT)    != 0);
-        boolean byteColorsDefined  = ((vdefined & GeometryArrayRetained.COLOR_BYTE)     != 0);
-        boolean normalsDefined     = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT)   != 0);
-        boolean vattrDefined       = ((vdefined & GeometryArrayRetained.VATTR_FLOAT)    != 0);
-        boolean textureDefined     = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
+        boolean floatCoordDefined = ((vdefined & GeometryArrayRetained.COORD_FLOAT) != 0);
+        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE) != 0);
+        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT) != 0);
+        boolean byteColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_BYTE) != 0);
+        boolean normalsDefined = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT) != 0);
+        boolean vattrDefined = ((vdefined & GeometryArrayRetained.VATTR_FLOAT) != 0);
+        boolean textureDefined = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
 
         FloatBuffer fverts = null;
         DoubleBuffer dverts = null;
@@ -1778,7 +2308,7 @@
         int[] sarray = null;
         int strip_len = 0;
         if (geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_INDEXED_LINE_STRIP_SET) {
             sarray = ((IndexedGeometryStripArrayRetained) geo).stripIndexCounts;
             strip_len = sarray.length;
@@ -1818,38 +2348,45 @@
                 sarray, strip_len);
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // SpotLightRetained methods
+    //
+
     // non interleaved, by reference, nio buffer
     @Override
     void executeIndexedGeometryVABuffer(Context ctx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean ignoreVertexColors,
-            int initialIndexIndex,
-            int validIndexCount,
-            int vertexCount,
-            int vformat,
-            int vdefined,
-            Buffer vcoords,
-            Buffer cdataBuffer,
-            float[] cfdata, byte[] cbdata,
-            FloatBuffer ndata,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            FloatBuffer[] vertexAttrData,
-            int texCoordMapLength,
-            int[] texcoordoffset,
-            int numActiveTexUnitState,
-            int texStride, Object[] texCoords,
-            int cdirty,
-            int[] indexCoord) {
+                                        GeometryArrayRetained geo, int geo_type,
+                                        boolean isNonUniformScale,
+                                        boolean ignoreVertexColors,
+                                        int initialIndexIndex,
+                                        int validIndexCount,
+                                        int vertexCount,
+                                        int vformat,
+                                        int vdefined,
+                                        Buffer vcoords,
+                                        Buffer cdataBuffer,
+                                        float[] cfdata, byte[] cbdata,
+                                        FloatBuffer ndata,
+                                        int vertexAttrCount, int[] vertexAttrSizes,
+                                        FloatBuffer[] vertexAttrData,
+                                        int texCoordMapLength,
+                                        int[] texcoordoffset,
+                                        int numActiveTexUnitState,
+                                        int texStride, Object[] texCoords,
+                                        int cdirty,
+                                        int[] indexCoord) {
         if (VERBOSE) System.err.println("JoglPipeline.executeIndexedGeometryVABuffer()");
 
-        boolean floatCoordDefined  = ((vdefined & GeometryArrayRetained.COORD_FLOAT)    != 0);
-        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE)   != 0);
-        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT)    != 0);
-        boolean byteColorsDefined  = ((vdefined & GeometryArrayRetained.COLOR_BYTE)     != 0);
-        boolean normalsDefined     = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT)   != 0);
-        boolean vattrDefined       = ((vdefined & GeometryArrayRetained.VATTR_FLOAT)    != 0);
-        boolean textureDefined     = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
+        boolean floatCoordDefined = ((vdefined & GeometryArrayRetained.COORD_FLOAT) != 0);
+        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE) != 0);
+        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT) != 0);
+        boolean byteColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_BYTE) != 0);
+        boolean normalsDefined = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT) != 0);
+        boolean vattrDefined = ((vdefined & GeometryArrayRetained.VATTR_FLOAT) != 0);
+        boolean textureDefined = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
 
         FloatBuffer fverts = null;
         DoubleBuffer dverts = null;
@@ -1886,7 +2423,7 @@
         int[] sarray = null;
         int strip_len = 0;
         if (geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_INDEXED_LINE_STRIP_SET) {
             sarray = ((IndexedGeometryStripArrayRetained) geo).stripIndexCounts;
             strip_len = sarray.length;
@@ -1925,27 +2462,34 @@
                 sarray, strip_len);
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // ExponentialFogRetained methods
+    //
+
     // by-copy geometry
     @Override
     void buildIndexedGeometry(Context absCtx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale, boolean updateAlpha,
-            float alpha,
-            boolean ignoreVertexColors,
-            int initialIndexIndex,
-            int validIndexCount,
-            int vertexCount,
-            int vformat,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int texCoordSetMapLen,
-            int[] texCoordSetMapOffset,
-            double[] xform, double[] nxform,
-            float[] varray, int[] indexCoord) {
+                              GeometryArrayRetained geo, int geo_type,
+                              boolean isNonUniformScale, boolean updateAlpha,
+                              float alpha,
+                              boolean ignoreVertexColors,
+                              int initialIndexIndex,
+                              int validIndexCount,
+                              int vertexCount,
+                              int vformat,
+                              int vertexAttrCount, int[] vertexAttrSizes,
+                              int texCoordSetCount, int[] texCoordSetMap,
+                              int texCoordSetMapLen,
+                              int[] texCoordSetMapOffset,
+                              double[] xform, double[] nxform,
+                              float[] varray, int[] indexCoord) {
         if (VERBOSE) System.err.println("JoglPipeline.buildIndexedGeometry()");
 
         JoglContext ctx = (JoglContext) absCtx;
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         boolean useInterleavedArrays;
         int iaFormat = 0;
@@ -1956,7 +2500,7 @@
         int vAttrStride = 0;
         int bstride = 0, cbstride = 0;
         FloatBuffer verts = null;
-        FloatBuffer clrs  = null;
+        FloatBuffer clrs = null;
         int[] sarray = null;
         int strip_len = 0;
         boolean useAlpha = false;
@@ -2013,7 +2557,7 @@
             texCoordoff += vAttrStride;
         }
 
-		bstride = stride * Buffers.SIZEOF_FLOAT;
+        bstride = stride * Buffers.SIZEOF_FLOAT;
 
         // process alpha for geometryArray without alpha
         if (updateAlpha && !ignoreVertexColors) {
@@ -2021,7 +2565,7 @@
         }
 
         if (geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_INDEXED_LINE_STRIP_SET) {
             sarray = ((IndexedGeometryStripArrayRetained) geo).stripIndexCounts;
             strip_len = sarray.length;
@@ -2033,16 +2577,16 @@
         // Apply normal transform if necessary
         if ((vformat & GeometryArray.NORMALS) != 0 && nxform != null) {
             int off = normoff;
-            for (int i = 0; i < vertexCount * 3; i+=3) {
-                verts.put(off  , (float) (nxform[0] * varray[off] +
-                        nxform[1] * varray[off+1] +
-                        nxform[2] * varray[off+2]));
-                verts.put(off+1, (float) (nxform[4] * varray[off] +
-                        nxform[5] * varray[off+1] +
-                        nxform[6] * varray[off+2]));
-                verts.put(off+2, (float) (nxform[8] * varray[off] +
-                        nxform[9] * varray[off+1] +
-                        nxform[10] * varray[off+2]));
+            for (int i = 0; i < vertexCount * 3; i += 3) {
+                verts.put(off, (float) (nxform[0] * varray[off] +
+                        nxform[1] * varray[off + 1] +
+                        nxform[2] * varray[off + 2]));
+                verts.put(off + 1, (float) (nxform[4] * varray[off] +
+                        nxform[5] * varray[off + 1] +
+                        nxform[6] * varray[off + 2]));
+                verts.put(off + 2, (float) (nxform[8] * varray[off] +
+                        nxform[9] * varray[off + 1] +
+                        nxform[10] * varray[off + 2]));
                 off += stride;
             }
         }
@@ -2050,29 +2594,29 @@
         // Apply coordinate transform if necessary
         if ((vformat & GeometryArray.COORDINATES) != 0 && xform != null) {
             int off = coordoff;
-            for (int i = 0; i < vertexCount * 3; i+=3) {
-                verts.put(off  , (float) (xform[0] * varray[off] +
-                        xform[1] * varray[off+1] +
-                        xform[2] * varray[off+2]));
-                verts.put(off+1, (float) (xform[4] * varray[off] +
-                        xform[5] * varray[off+1] +
-                        xform[6] * varray[off+2]));
-                verts.put(off+2, (float) (xform[8] * varray[off] +
-                        xform[9] * varray[off+1] +
-                        xform[10] * varray[off+2]));
+            for (int i = 0; i < vertexCount * 3; i += 3) {
+                verts.put(off, (float) (xform[0] * varray[off] +
+                        xform[1] * varray[off + 1] +
+                        xform[2] * varray[off + 2]));
+                verts.put(off + 1, (float) (xform[4] * varray[off] +
+                        xform[5] * varray[off + 1] +
+                        xform[6] * varray[off + 2]));
+                verts.put(off + 2, (float) (xform[8] * varray[off] +
+                        xform[9] * varray[off + 1] +
+                        xform[10] * varray[off + 2]));
                 off += stride;
             }
         }
 
         if (geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_INDEXED_LINE_STRIP_SET) {
             // Note we can use interleaved arrays even if we have a
             // non-null xform since we use the same data layout unlike the
             // C code
             if (ignoreVertexColors ||
                     (((vformat & GeometryArray.TEXTURE_COORDINATE) != 0) && ((texCoordSetMapLen > 1) ||
-                    (texCoordSetCount > 1)))) {
+                            (texCoordSetCount > 1)))) {
                 useInterleavedArrays = false;
             } else {
                 boolean[] tmp = new boolean[1];
@@ -2155,7 +2699,7 @@
             // C code
             if (ignoreVertexColors ||
                     (((vformat & GeometryArray.TEXTURE_COORDINATE) != 0) && ((texCoordSetMapLen > 1) ||
-                    (texCoordSetCount > 1)))) {
+                            (texCoordSetCount > 1)))) {
                 useInterleavedArrays = false;
             } else {
                 boolean[] tmp = new boolean[1];
@@ -2205,16 +2749,16 @@
                 }
 
                 switch (geo_type) {
-                    case GeometryRetained.GEO_TYPE_INDEXED_QUAD_SET :
+                    case GeometryRetained.GEO_TYPE_INDEXED_QUAD_SET:
                         primType = GL2.GL_QUADS;
                         break;
-                    case GeometryRetained.GEO_TYPE_INDEXED_TRI_SET :
+                    case GeometryRetained.GEO_TYPE_INDEXED_TRI_SET:
                         primType = GL.GL_TRIANGLES;
                         break;
-                    case GeometryRetained.GEO_TYPE_INDEXED_POINT_SET :
+                    case GeometryRetained.GEO_TYPE_INDEXED_POINT_SET:
                         primType = GL.GL_POINTS;
                         break;
-                    case GeometryRetained.GEO_TYPE_INDEXED_LINE_SET :
+                    case GeometryRetained.GEO_TYPE_INDEXED_LINE_SET:
                         primType = GL.GL_LINES;
                         break;
                 }
@@ -2239,29 +2783,30 @@
     }
 
 
-    //----------------------------------------------------------------------
+    // ---------------------------------------------------------------------
+
     //
-    // Helper routines for IndexedGeometryArrayRetained
+    // LinearFogRetained methods
     //
 
     private void executeIndexedGeometryArray(Context absCtx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean useAlpha,
-            boolean ignoreVertexColors,
-            int initialIndexIndex,
-            int indexCount,
-            int vertexCount, int vformat,
-            int vertexAttrCount, int[] vertexAttrSizes,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int texCoordSetMapLen,
-            int[] texCoordSetOffset,
-            int numActiveTexUnitState,
-            float[] varray, FloatBuffer vdata, float[] carray,
-            int cDirty,
-            int[] indexCoord) {
+                                             GeometryArrayRetained geo, int geo_type,
+                                             boolean isNonUniformScale,
+                                             boolean useAlpha,
+                                             boolean ignoreVertexColors,
+                                             int initialIndexIndex,
+                                             int indexCount,
+                                             int vertexCount, int vformat,
+                                             int vertexAttrCount, int[] vertexAttrSizes,
+                                             int texCoordSetCount, int[] texCoordSetMap,
+                                             int texCoordSetMapLen,
+                                             int[] texCoordSetOffset,
+                                             int numActiveTexUnitState,
+                                             float[] varray, FloatBuffer vdata, float[] carray,
+                                             int cDirty,
+                                             int[] indexCoord) {
         JoglContext ctx = (JoglContext) absCtx;
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         boolean useInterleavedArrays;
         int iaFormat = 0;
@@ -2272,7 +2817,7 @@
         int vAttrStride = 0;
         int bstride = 0, cbstride = 0;
         FloatBuffer verts = null;
-        FloatBuffer clrs  = null;
+        FloatBuffer clrs = null;
         int[] sarray = null;
         int strip_len = 0;
 
@@ -2324,10 +2869,10 @@
             texCoordoff += vAttrStride;
         }
 
-		bstride = stride * Buffers.SIZEOF_FLOAT;
+        bstride = stride * Buffers.SIZEOF_FLOAT;
 
         if (geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_INDEXED_LINE_STRIP_SET) {
             sarray = ((IndexedGeometryStripArrayRetained) geo).stripIndexCounts;
             strip_len = sarray.length;
@@ -2353,7 +2898,7 @@
             clrs = verts;
         }
 
-		cbstride = cstride * Buffers.SIZEOF_FLOAT;
+        cbstride = cstride * Buffers.SIZEOF_FLOAT;
 
         // Enable normalize for non-uniform scale (which rescale can't handle)
         if (isNonUniformScale) {
@@ -2362,11 +2907,11 @@
 
         /*** Handle non-indexed strip GeometryArray first *******/
         if (geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_INDEXED_LINE_STRIP_SET) {
             if (ignoreVertexColors || (carray != null) ||
                     ((vformat & GeometryArray.TEXTURE_COORDINATE) != 0 && ((texCoordSetMapLen > 1) ||
-                    (texCoordSetCount > 1)))) {
+                            (texCoordSetCount > 1)))) {
                 useInterleavedArrays = false;
             } else {
                 boolean[] tmp = new boolean[1];
@@ -2451,7 +2996,7 @@
             /******* Handle non-indexed non-striped GeometryArray now *****/
             if (ignoreVertexColors || (carray != null) ||
                     ((vformat & GeometryArray.TEXTURE_COORDINATE) != 0 && ((texCoordSetMapLen > 1) ||
-                    (texCoordSetCount > 1)))) {
+                            (texCoordSetCount > 1)))) {
                 useInterleavedArrays = false;
             } else {
                 boolean[] tmp = new boolean[1];
@@ -2509,11 +3054,19 @@
             lockArray(gl, vertexCount);
             IntBuffer buf = IntBuffer.wrap(indexCoord);
             buf.position(initialIndexIndex);
-            switch (geo_type){
-                case GeometryRetained.GEO_TYPE_INDEXED_QUAD_SET : gl.glDrawElements(GL2.GL_QUADS,     indexCount, GL.GL_UNSIGNED_INT, buf); break;
-                case GeometryRetained.GEO_TYPE_INDEXED_TRI_SET  : gl.glDrawElements(GL.GL_TRIANGLES, indexCount, GL.GL_UNSIGNED_INT, buf); break;
-                case GeometryRetained.GEO_TYPE_INDEXED_POINT_SET: gl.glDrawElements(GL.GL_POINTS,    indexCount, GL.GL_UNSIGNED_INT, buf); break;
-                case GeometryRetained.GEO_TYPE_INDEXED_LINE_SET : gl.glDrawElements(GL.GL_LINES,     indexCount, GL.GL_UNSIGNED_INT, buf); break;
+            switch (geo_type) {
+                case GeometryRetained.GEO_TYPE_INDEXED_QUAD_SET:
+                    gl.glDrawElements(GL2.GL_QUADS, indexCount, GL.GL_UNSIGNED_INT, buf);
+                    break;
+                case GeometryRetained.GEO_TYPE_INDEXED_TRI_SET:
+                    gl.glDrawElements(GL.GL_TRIANGLES, indexCount, GL.GL_UNSIGNED_INT, buf);
+                    break;
+                case GeometryRetained.GEO_TYPE_INDEXED_POINT_SET:
+                    gl.glDrawElements(GL.GL_POINTS, indexCount, GL.GL_UNSIGNED_INT, buf);
+                    break;
+                case GeometryRetained.GEO_TYPE_INDEXED_LINE_SET:
+                    gl.glDrawElements(GL.GL_LINES, indexCount, GL.GL_UNSIGNED_INT, buf);
+                    break;
             }
         }
 
@@ -2534,32 +3087,38 @@
     }
 
 
+    // ---------------------------------------------------------------------
+
+    //
+    // LineAttributesRetained methods
+    //
+
     private void executeIndexedGeometryArrayVA(Context absCtx,
-            GeometryArrayRetained geo, int geo_type,
-            boolean isNonUniformScale,
-            boolean ignoreVertexColors,
-            int initialIndexIndex,
-            int validIndexCount,
-            int vertexCount, int vformat, int vdefined,
-            FloatBuffer fverts, DoubleBuffer dverts,
-            FloatBuffer fclrs, ByteBuffer bclrs,
-            FloatBuffer norms,
-            int vertexAttrCount, int[] vertexAttrSizes, FloatBuffer[] vertexAttrBufs,
-            int texCoordSetCount, int[] texCoordSetMap,
-            int numActiveTexUnitState,
-            int texStride,
-            FloatBuffer[] texCoords,
-            int cDirty, int[] indexCoord, int[] sarray, int strip_len) {
+                                               GeometryArrayRetained geo, int geo_type,
+                                               boolean isNonUniformScale,
+                                               boolean ignoreVertexColors,
+                                               int initialIndexIndex,
+                                               int validIndexCount,
+                                               int vertexCount, int vformat, int vdefined,
+                                               FloatBuffer fverts, DoubleBuffer dverts,
+                                               FloatBuffer fclrs, ByteBuffer bclrs,
+                                               FloatBuffer norms,
+                                               int vertexAttrCount, int[] vertexAttrSizes, FloatBuffer[] vertexAttrBufs,
+                                               int texCoordSetCount, int[] texCoordSetMap,
+                                               int numActiveTexUnitState,
+                                               int texStride,
+                                               FloatBuffer[] texCoords,
+                                               int cDirty, int[] indexCoord, int[] sarray, int strip_len) {
         JoglContext ctx = (JoglContext) absCtx;
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
-        boolean floatCoordDefined  = ((vdefined & GeometryArrayRetained.COORD_FLOAT)    != 0);
-        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE)   != 0);
-        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT)    != 0);
-        boolean byteColorsDefined  = ((vdefined & GeometryArrayRetained.COLOR_BYTE)     != 0);
-        boolean normalsDefined     = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT)   != 0);
-        boolean vattrDefined       = ((vdefined & GeometryArrayRetained.VATTR_FLOAT)    != 0);
-        boolean textureDefined     = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
+        boolean floatCoordDefined = ((vdefined & GeometryArrayRetained.COORD_FLOAT) != 0);
+        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE) != 0);
+        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT) != 0);
+        boolean byteColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_BYTE) != 0);
+        boolean normalsDefined = ((vdefined & GeometryArrayRetained.NORMAL_FLOAT) != 0);
+        boolean vattrDefined = ((vdefined & GeometryArrayRetained.VATTR_FLOAT) != 0);
+        boolean textureDefined = ((vdefined & GeometryArrayRetained.TEXCOORD_FLOAT) != 0);
 
         // Enable normalize for non-uniform scale (which rescale can't handle)
         if (isNonUniformScale) {
@@ -2570,7 +3129,7 @@
         if (floatCoordDefined) {
             fverts.position(0);
             gl.glVertexPointer(3, GL.GL_FLOAT, 0, fverts);
-        } else if (doubleCoordDefined){
+        } else if (doubleCoordDefined) {
             dverts.position(0);
             gl.glVertexPointer(3, GL2.GL_DOUBLE, 0, dverts);
         }
@@ -2625,7 +3184,7 @@
         lockArray(gl, vertexCount);
 
         if (geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_STRIP_SET ||
-                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET   ||
+                geo_type == GeometryRetained.GEO_TYPE_INDEXED_TRI_FAN_SET ||
                 geo_type == GeometryRetained.GEO_TYPE_INDEXED_LINE_STRIP_SET) {
             int primType = 0;
             switch (geo_type) {
@@ -2654,11 +3213,19 @@
         } else {
             IntBuffer buf = IntBuffer.wrap(indexCoord);
             buf.position(initialIndexIndex);
-            switch (geo_type){
-                case GeometryRetained.GEO_TYPE_INDEXED_QUAD_SET : gl.glDrawElements(GL2.GL_QUADS,     validIndexCount, GL.GL_UNSIGNED_INT, buf); break;
-                case GeometryRetained.GEO_TYPE_INDEXED_TRI_SET  : gl.glDrawElements(GL.GL_TRIANGLES, validIndexCount, GL.GL_UNSIGNED_INT, buf); break;
-                case GeometryRetained.GEO_TYPE_INDEXED_POINT_SET: gl.glDrawElements(GL.GL_POINTS,    validIndexCount, GL.GL_UNSIGNED_INT, buf); break;
-                case GeometryRetained.GEO_TYPE_INDEXED_LINE_SET : gl.glDrawElements(GL.GL_LINES,     validIndexCount, GL.GL_UNSIGNED_INT, buf); break;
+            switch (geo_type) {
+                case GeometryRetained.GEO_TYPE_INDEXED_QUAD_SET:
+                    gl.glDrawElements(GL2.GL_QUADS, validIndexCount, GL.GL_UNSIGNED_INT, buf);
+                    break;
+                case GeometryRetained.GEO_TYPE_INDEXED_TRI_SET:
+                    gl.glDrawElements(GL.GL_TRIANGLES, validIndexCount, GL.GL_UNSIGNED_INT, buf);
+                    break;
+                case GeometryRetained.GEO_TYPE_INDEXED_POINT_SET:
+                    gl.glDrawElements(GL.GL_POINTS, validIndexCount, GL.GL_UNSIGNED_INT, buf);
+                    break;
+                case GeometryRetained.GEO_TYPE_INDEXED_LINE_SET:
+                    gl.glDrawElements(GL.GL_LINES, validIndexCount, GL.GL_UNSIGNED_INT, buf);
+                    break;
             }
         }
 
@@ -2682,28 +3249,28 @@
     // ---------------------------------------------------------------------
 
     //
-    // GraphicsContext3D methods
+    // MaterialRetained methods
     //
 
     // Native method for readRaster
     @Override
     void readRaster(Context ctx,
-            int type, int xSrcOffset, int ySrcOffset,
-            int width, int height, int hCanvas,
-            int imageDataType,
-            int imageFormat,
-            Object imageBuffer,
-            int depthFormat,
-            Object depthBuffer) {
+                    int type, int xSrcOffset, int ySrcOffset,
+                    int width, int height, int hCanvas,
+                    int imageDataType,
+                    int imageFormat,
+                    Object imageBuffer,
+                    int depthFormat,
+                    Object depthBuffer) {
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, width);
         gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
         int yAdjusted = hCanvas - height - ySrcOffset;
 
         if ((type & Raster.RASTER_COLOR) != 0) {
             int oglFormat = 0;
-            if(imageDataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
+            if (imageDataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
 
                 switch (imageFormat) {
                     case ImageComponentRetained.TYPE_BYTE_BGR:
@@ -2742,7 +3309,7 @@
                         oglFormat, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[]) imageBuffer));
 
 
-            } else if(imageDataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
+            } else if (imageDataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
                 int intType = GL2.GL_UNSIGNED_INT_8_8_8_8;
                 boolean forceAlphaToOne = false;
 
@@ -2760,7 +3327,7 @@
                         oglFormat = GL2.GL_BGRA;
                         intType = GL2.GL_UNSIGNED_INT_8_8_8_8_REV;
                         break;
-                        /* This method only supports 3 and 4 components formats and INT types. */
+                    /* This method only supports 3 and 4 components formats and INT types. */
                     case ImageComponentRetained.TYPE_BYTE_LA:
                     case ImageComponentRetained.TYPE_BYTE_GRAY:
                     case ImageComponentRetained.TYPE_USHORT_GRAY:
@@ -2774,7 +3341,7 @@
                 }
 
                 /* Force Alpha to 1.0 if needed */
-                if(forceAlphaToOne) {
+                if (forceAlphaToOne) {
                     gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 0.0f);
                     gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 1.0f);
                 }
@@ -2783,7 +3350,7 @@
                         oglFormat, intType, IntBuffer.wrap((int[]) imageBuffer));
 
                 /* Restore Alpha scale and bias */
-                if(forceAlphaToOne) {
+                if (forceAlphaToOne) {
                     gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 1.0f);
                     gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 0.0f);
                 }
@@ -2809,270 +3376,311 @@
 
     }
 
+
     // ---------------------------------------------------------------------
 
     //
-    // GLSLShaderProgramRetained methods
+    // ModelClipRetained methods
     //
 
-    // ShaderAttributeValue methods
-
     @Override
     ShaderError setGLSLUniform1i(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int value) {
+                                 ShaderProgramId shaderProgramId,
+                                 ShaderAttrLoc uniformLocation,
+                                 int value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform1i()");
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform1iARB(unbox(uniformLocation), value);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform1iARB(unbox(uniformLocation), value);
         return null;
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // PointAttributesRetained methods
+    //
+
     @Override
     ShaderError setGLSLUniform1f(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            float value) {
+                                 ShaderProgramId shaderProgramId,
+                                 ShaderAttrLoc uniformLocation,
+                                 float value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform1f()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform1fARB(unbox(uniformLocation), value);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform1fARB(unbox(uniformLocation), value);
         return null;
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // PolygonAttributesRetained methods
+    //
+
     @Override
     ShaderError setGLSLUniform2i(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int[] value) {
+                                 ShaderProgramId shaderProgramId,
+                                 ShaderAttrLoc uniformLocation,
+                                 int[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform2i()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform2iARB(unbox(uniformLocation), value[0], value[1]);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform2iARB(unbox(uniformLocation), value[0], value[1]);
         return null;
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // RenderingAttributesRetained methods
+    //
+
     @Override
     ShaderError setGLSLUniform2f(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            float[] value) {
+                                 ShaderProgramId shaderProgramId,
+                                 ShaderAttrLoc uniformLocation,
+                                 float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform2f()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform2fARB(unbox(uniformLocation), value[0], value[1]);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform2fARB(unbox(uniformLocation), value[0], value[1]);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniform3i(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int[] value) {
+                                 ShaderProgramId shaderProgramId,
+                                 ShaderAttrLoc uniformLocation,
+                                 int[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform3i()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform3iARB(unbox(uniformLocation), value[0], value[1], value[2]);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform3iARB(unbox(uniformLocation), value[0], value[1], value[2]);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniform3f(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            float[] value) {
+                                 ShaderProgramId shaderProgramId,
+                                 ShaderAttrLoc uniformLocation,
+                                 float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform3f()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform3fARB(unbox(uniformLocation), value[0], value[1], value[2]);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform3fARB(unbox(uniformLocation), value[0], value[1], value[2]);
         return null;
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // TexCoordGenerationRetained methods
+    //
+
     @Override
     ShaderError setGLSLUniform4i(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int[] value) {
+                                 ShaderProgramId shaderProgramId,
+                                 ShaderAttrLoc uniformLocation,
+                                 int[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform4i()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform4iARB(unbox(uniformLocation), value[0], value[1], value[2], value[3]);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform4iARB(unbox(uniformLocation), value[0], value[1], value[2], value[3]);
         return null;
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // TransparencyAttributesRetained methods
+    //
+
     @Override
     ShaderError setGLSLUniform4f(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            float[] value) {
+                                 ShaderProgramId shaderProgramId,
+                                 ShaderAttrLoc uniformLocation,
+                                 float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform4f()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform4fARB(unbox(uniformLocation), value[0], value[1], value[2], value[3]);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform4fARB(unbox(uniformLocation), value[0], value[1], value[2], value[3]);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniformMatrix3f(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            float[] value) {
+                                       ShaderProgramId shaderProgramId,
+                                       ShaderAttrLoc uniformLocation,
+                                       float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniformMatrix3f()");
 
         // Load attribute
         // transpose is true : each matrix is supplied in row major order
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniformMatrix3fvARB(unbox(uniformLocation), 1, true, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniformMatrix3fvARB(unbox(uniformLocation), 1, true, value, 0);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniformMatrix4f(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            float[] value) {
+                                       ShaderProgramId shaderProgramId,
+                                       ShaderAttrLoc uniformLocation,
+                                       float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniformMatrix4f()");
 
         // Load attribute
         // transpose is true : each matrix is supplied in row major order
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniformMatrix4fvARB(unbox(uniformLocation), 1, true, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniformMatrix4fvARB(unbox(uniformLocation), 1, true, value, 0);
         return null;
     }
 
-    // ShaderAttributeArray methods
-
     @Override
     ShaderError setGLSLUniform1iArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            int[] value) {
+                                      ShaderProgramId shaderProgramId,
+                                      ShaderAttrLoc uniformLocation,
+                                      int numElements,
+                                      int[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform1iArray()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform1ivARB(unbox(uniformLocation), numElements, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform1ivARB(unbox(uniformLocation), numElements, value, 0);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniform1fArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            float[] value) {
+                                      ShaderProgramId shaderProgramId,
+                                      ShaderAttrLoc uniformLocation,
+                                      int numElements,
+                                      float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform1fArray()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform1fvARB(unbox(uniformLocation), numElements, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform1fvARB(unbox(uniformLocation), numElements, value, 0);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniform2iArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            int[] value) {
+                                      ShaderProgramId shaderProgramId,
+                                      ShaderAttrLoc uniformLocation,
+                                      int numElements,
+                                      int[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform2iArray()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform2ivARB(unbox(uniformLocation), numElements, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform2ivARB(unbox(uniformLocation), numElements, value, 0);
         return null;
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // TextureAttributesRetained methods
+    //
+
     @Override
     ShaderError setGLSLUniform2fArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            float[] value) {
+                                      ShaderProgramId shaderProgramId,
+                                      ShaderAttrLoc uniformLocation,
+                                      int numElements,
+                                      float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform2fArray()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform2fvARB(unbox(uniformLocation), numElements, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform2fvARB(unbox(uniformLocation), numElements, value, 0);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniform3iArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            int[] value) {
+                                      ShaderProgramId shaderProgramId,
+                                      ShaderAttrLoc uniformLocation,
+                                      int numElements,
+                                      int[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform3iArray()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform3ivARB(unbox(uniformLocation), numElements, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform3ivARB(unbox(uniformLocation), numElements, value, 0);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniform3fArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            float[] value) {
+                                      ShaderProgramId shaderProgramId,
+                                      ShaderAttrLoc uniformLocation,
+                                      int numElements,
+                                      float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform3fArray()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform3fvARB(unbox(uniformLocation), numElements, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform3fvARB(unbox(uniformLocation), numElements, value, 0);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniform4iArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            int[] value) {
+                                      ShaderProgramId shaderProgramId,
+                                      ShaderAttrLoc uniformLocation,
+                                      int numElements,
+                                      int[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform4iArray()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform4ivARB(unbox(uniformLocation), numElements, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform4ivARB(unbox(uniformLocation), numElements, value, 0);
         return null;
     }
 
+    // Helper routines for above
+
     @Override
     ShaderError setGLSLUniform4fArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            float[] value) {
+                                      ShaderProgramId shaderProgramId,
+                                      ShaderAttrLoc uniformLocation,
+                                      int numElements,
+                                      float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniform4fArray()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniform4fvARB(unbox(uniformLocation), numElements, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniform4fvARB(unbox(uniformLocation), numElements, value, 0);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniformMatrix3fArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            float[] value) {
+                                            ShaderProgramId shaderProgramId,
+                                            ShaderAttrLoc uniformLocation,
+                                            int numElements,
+                                            float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniformMatrix3fArray()");
 
         // Load attribute
         // transpose is true : each matrix is supplied in row major order
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniformMatrix3fvARB(unbox(uniformLocation), numElements, true, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniformMatrix3fvARB(unbox(uniformLocation), numElements, true, value, 0);
         return null;
     }
 
     @Override
     ShaderError setGLSLUniformMatrix4fArray(Context ctx,
-            ShaderProgramId shaderProgramId,
-            ShaderAttrLoc uniformLocation,
-            int numElements,
-            float[] value) {
+                                            ShaderProgramId shaderProgramId,
+                                            ShaderAttrLoc uniformLocation,
+                                            int numElements,
+                                            float[] value) {
         if (VERBOSE) System.err.println("JoglPipeline.setGLSLUniformMatrix4fArray()");
 
         // Load attribute
         // transpose is true : each matrix is supplied in row major order
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUniformMatrix4fvARB(unbox(uniformLocation), numElements, true, value, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUniformMatrix4fvARB(unbox(uniformLocation), numElements, true, value, 0);
         return null;
     }
 
@@ -3081,7 +3689,7 @@
     ShaderError createGLSLShader(Context ctx, int shaderType, ShaderId[] shaderId) {
         if (VERBOSE) System.err.println("JoglPipeline.createGLSLShader()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int shaderHandle = 0;
         if (shaderType == Shader.SHADER_TYPE_VERTEX) {
@@ -3098,14 +3706,16 @@
         shaderId[0] = new JoglShaderObject(shaderHandle);
         return null;
     }
+
     @Override
     ShaderError destroyGLSLShader(Context ctx, ShaderId shaderId) {
         if (VERBOSE) System.err.println("JoglPipeline.destroyGLSLShader()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glDeleteObjectARB(unbox(shaderId));
         return null;
     }
+
     @Override
     ShaderError compileGLSLShader(Context ctx, ShaderId shaderId, String program) {
         if (VERBOSE) System.err.println("JoglPipeline.compileGLSLShader()");
@@ -3119,8 +3729,8 @@
             throw new AssertionError("shader program string is null");
         }
 
-		GL2 gl = context(ctx).getGL().getGL2();
-        gl.glShaderSourceARB(id, 1, new String[] { program }, null, 0);
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glShaderSourceARB(id, 1, new String[]{program}, null, 0);
         gl.glCompileShaderARB(id);
         int[] status = new int[1];
         gl.glGetObjectParameterivARB(id, GL2.GL_OBJECT_COMPILE_STATUS_ARB, status, 0);
@@ -3138,7 +3748,7 @@
     ShaderError createGLSLShaderProgram(Context ctx, ShaderProgramId[] shaderProgramId) {
         if (VERBOSE) System.err.println("JoglPipeline.createGLSLShaderProgram()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int shaderProgramHandle = (int) gl.glCreateProgramObjectARB();
         if (shaderProgramHandle == 0) {
@@ -3148,19 +3758,62 @@
         shaderProgramId[0] = new JoglShaderObject(shaderProgramHandle);
         return null;
     }
+
+// FIXME: GL_NV_register_combiners
+//    private int getCombinerArg(GL gl, int arg, int textureUnit, int combUnit) {
+//        int comb = 0;
+//
+//        switch (arg) {
+//            case TextureAttributes.COMBINE_OBJECT_COLOR:
+//                if (combUnit == GL.GL_COMBINER0_NV) {
+//                    comb = GL.GL_PRIMARY_COLOR_NV;
+//                } else {
+//                    comb = GL.GL_SPARE0_NV;
+//                }
+//                break;
+//            case TextureAttributes.COMBINE_TEXTURE_COLOR:
+//                comb = textureUnit;
+//                break;
+//            case TextureAttributes.COMBINE_CONSTANT_COLOR:
+//                comb = GL.GL_CONSTANT_COLOR0_NV;
+//                break;
+//            case TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE:
+//                comb = textureUnit -1;
+//                break;
+//        }
+//
+//        return comb;
+//    }
+
+
+    // ---------------------------------------------------------------------
+
+    //
+    // TextureUnitStateRetained methods
+    //
+
     @Override
     ShaderError destroyGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId) {
         if (VERBOSE) System.err.println("JoglPipeline.destroyGLSLShaderProgram()");
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glDeleteObjectARB(unbox(shaderProgramId));
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glDeleteObjectARB(unbox(shaderProgramId));
         return null;
     }
+
+
+    // ---------------------------------------------------------------------
+
+    //
+    // TextureRetained methods
+    // Texture2DRetained methods
+    //
+
     @Override
     ShaderError linkGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId,
-            ShaderId[] shaderIds) {
+                                      ShaderId[] shaderIds) {
         if (VERBOSE) System.err.println("JoglPipeline.linkGLSLShaderProgram()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         int id = unbox(shaderProgramId);
         for (int i = 0; i < shaderIds.length; i++) {
             gl.glAttachObjectARB(id, unbox(shaderIds[i]));
@@ -3177,21 +3830,23 @@
         }
         return null;
     }
+
     @Override
     ShaderError bindGLSLVertexAttrName(Context ctx, ShaderProgramId shaderProgramId,
-            String attrName, int attrIndex) {
+                                       String attrName, int attrIndex) {
         if (VERBOSE) System.err.println("JoglPipeline.bindGLSLVertexAttrName()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glBindAttribLocation(unbox(shaderProgramId),
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glBindAttribLocation(unbox(shaderProgramId),
                 attrIndex + VirtualUniverse.mc.glslVertexAttrOffset,
                 attrName);
         return null;
     }
+
     @Override
     void lookupGLSLShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId,
-            int numAttrNames, String[] attrNames, ShaderAttrLoc[] locArr,
-            int[] typeArr, int[] sizeArr, boolean[] isArrayArr) {
+                                   int numAttrNames, String[] attrNames, ShaderAttrLoc[] locArr,
+                                   int[] typeArr, int[] sizeArr, boolean[] isArrayArr) {
         if (VERBOSE) System.err.println("JoglPipeline.lookupGLSLShaderAttrNames()");
 
         // set the loc, type, and size arrays to out-of-bound values
@@ -3214,7 +3869,7 @@
         int[] tmp = new int[1];
         int[] tmp2 = new int[1];
         int[] tmp3 = new int[1];
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glGetObjectParameterivARB(id,
                 GL2.GL_OBJECT_ACTIVE_UNIFORMS_ARB,
                 tmp, 0);
@@ -3274,8 +3929,8 @@
     ShaderError useGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId) {
         if (VERBOSE) System.err.println("JoglPipeline.useGLSLShaderProgram()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		gl.glUseProgramObjectARB(unbox(shaderProgramId));
+        GL2 gl = context(ctx).getGL().getGL2();
+        gl.glUseProgramObjectARB(unbox(shaderProgramId));
         ((JoglContext) ctx).setShaderProgram((JoglShaderObject) shaderProgramId);
         return null;
     }
@@ -3351,7 +4006,7 @@
             case GL2.GL_FLOAT_VEC4_ARB:
                 return ShaderAttributeObjectRetained.TYPE_TUPLE4F;
 
-                // case GL.GL_FLOAT_MAT2_ARB:
+            // case GL.GL_FLOAT_MAT2_ARB:
 
             case GL2.GL_FLOAT_MAT3_ARB:
                 return ShaderAttributeObjectRetained.TYPE_MATRIX3F;
@@ -3359,41 +4014,39 @@
             case GL2.GL_FLOAT_MAT4_ARB:
                 return ShaderAttributeObjectRetained.TYPE_MATRIX4F;
 
-                // Java 3D does not support the following sampler types:
-                //
-                // case GL.GL_SAMPLER_1D_ARB:
-                // case GL.GL_SAMPLER_1D_SHADOW_ARB:
-                // case GL.GL_SAMPLER_2D_SHADOW_ARB:
-                // case GL.GL_SAMPLER_2D_RECT_ARB:
-                // case GL.GL_SAMPLER_2D_RECT_SHADOW_ARB:
+            // Java 3D does not support the following sampler types:
+            //
+            // case GL.GL_SAMPLER_1D_ARB:
+            // case GL.GL_SAMPLER_1D_SHADOW_ARB:
+            // case GL.GL_SAMPLER_2D_SHADOW_ARB:
+            // case GL.GL_SAMPLER_2D_RECT_ARB:
+            // case GL.GL_SAMPLER_2D_RECT_SHADOW_ARB:
         }
 
         return -1;
     }
 
-    // ---------------------------------------------------------------------
-
-    //
-    // ColoringAttributesRetained methods
-    //
-
     @Override
     void updateColoringAttributes(Context ctx,
-            float dRed, float dGreen, float dBlue,
-            float red, float green, float blue,
-            float alpha,
-            boolean lightEnable,
-            int shadeModel) {
+                                  float dRed, float dGreen, float dBlue,
+                                  float red, float green, float blue,
+                                  float alpha,
+                                  boolean lightEnable,
+                                  int shadeModel) {
         if (VERBOSE) System.err.println("JoglPipeline.updateColoringAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         float cr, cg, cb;
 
         if (lightEnable) {
-            cr = dRed; cg = dGreen; cb = dBlue;
-        } else {
-            cr = red; cg = green; cb = blue;
+            cr = dRed;
+            cg = dGreen;
+            cb = dBlue;
+        } else {
+            cr = red;
+            cg = green;
+            cb = blue;
         }
         gl.glColor4f(cr, cg, cb, alpha);
         if (shadeModel == ColoringAttributes.SHADE_FLAT) {
@@ -3403,21 +4056,13 @@
         }
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // DirectionalLightRetained methods
-    //
-
-    private static final float[] black = new float[4];
     @Override
     void updateDirectionalLight(Context ctx,
-            int lightSlot, float red, float green,
-            float blue, float dirx, float diry, float dirz) {
+                                int lightSlot, float red, float green,
+                                float blue, float dirx, float diry, float dirz) {
         if (VERBOSE) System.err.println("JoglPipeline.updateDirectionalLight()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int lightNum = GL2.GL_LIGHT0 + lightSlot;
         float[] values = new float[4];
@@ -3441,21 +4086,14 @@
         gl.glLightf(lightNum, GL2.GL_SPOT_CUTOFF, 180.0f);
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // PointLightRetained methods
-    //
-
     @Override
     void updatePointLight(Context ctx,
-            int lightSlot, float red, float green,
-            float blue, float attenx, float atteny, float attenz,
-            float posx, float posy, float posz) {
+                          int lightSlot, float red, float green,
+                          float blue, float attenx, float atteny, float attenz,
+                          float posx, float posy, float posz) {
         if (VERBOSE) System.err.println("JoglPipeline.updatePointLight()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int lightNum = GL2.GL_LIGHT0 + lightSlot;
         float[] values = new float[4];
@@ -3478,23 +4116,16 @@
         gl.glLightf(lightNum, GL2.GL_SPOT_CUTOFF, 180.0f);
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // SpotLightRetained methods
-    //
-
     @Override
     void updateSpotLight(Context ctx,
-            int lightSlot, float red, float green,
-            float blue, float attenx, float atteny, float attenz,
-            float posx, float posy, float posz, float spreadAngle,
-            float concentration, float dirx, float diry,
-            float dirz) {
+                         int lightSlot, float red, float green,
+                         float blue, float attenx, float atteny, float attenz,
+                         float posx, float posy, float posz, float spreadAngle,
+                         float concentration, float dirx, float diry,
+                         float dirz) {
         if (VERBOSE) System.err.println("JoglPipeline.updateSpotLight()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int lightNum = GL2.GL_LIGHT0 + lightSlot;
         float[] values = new float[4];
@@ -3521,20 +4152,19 @@
         gl.glLightf(lightNum, GL2.GL_SPOT_CUTOFF, (float) (spreadAngle * 180.0f / Math.PI));
     }
 
-
     // ---------------------------------------------------------------------
 
     //
-    // ExponentialFogRetained methods
+    // Texture3DRetained methods
     //
 
     @Override
     void updateExponentialFog(Context ctx,
-            float red, float green, float blue,
-            float density) {
+                              float red, float green, float blue,
+                              float density) {
         if (VERBOSE) System.err.println("JoglPipeline.updateExponentialFog()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         float[] color = new float[3];
         color[0] = red;
@@ -3546,20 +4176,13 @@
         gl.glEnable(GL2.GL_FOG);
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // LinearFogRetained methods
-    //
-
     @Override
     void updateLinearFog(Context ctx,
-            float red, float green, float blue,
-            double fdist, double bdist) {
+                         float red, float green, float blue,
+                         double fdist, double bdist) {
         if (VERBOSE) System.err.println("JoglPipeline.updateLinearFog()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         float[] color = new float[3];
         color[0] = red;
@@ -3572,22 +4195,15 @@
         gl.glEnable(GL2.GL_FOG);
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // LineAttributesRetained methods
-    //
-
     @Override
     void updateLineAttributes(Context ctx,
-            float lineWidth, int linePattern,
-            int linePatternMask,
-            int linePatternScaleFactor,
-            boolean lineAntialiasing) {
+                              float lineWidth, int linePattern,
+                              int linePatternMask,
+                              int linePatternScaleFactor,
+                              boolean lineAntialiasing) {
         if (VERBOSE) System.err.println("JoglPipeline.updateLineAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glLineWidth(lineWidth);
 
         if (linePattern == LineAttributes.PATTERN_SOLID) {
@@ -3613,26 +4229,19 @@
         }
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // MaterialRetained methods
-    //
-
     @Override
     void updateMaterial(Context ctx,
-            float red, float green, float blue, float alpha,
-            float aRed, float aGreen, float aBlue,
-            float eRed, float eGreen, float eBlue,
-            float dRed, float dGreen, float dBlue,
-            float sRed, float sGreen, float sBlue,
-            float shininess, int colorTarget, boolean lightEnable) {
+                        float red, float green, float blue, float alpha,
+                        float aRed, float aGreen, float aBlue,
+                        float eRed, float eGreen, float eBlue,
+                        float dRed, float dGreen, float dBlue,
+                        float sRed, float sGreen, float sBlue,
+                        float shininess, int colorTarget, boolean lightEnable) {
         if (VERBOSE) System.err.println("JoglPipeline.updateMaterial()");
 
         float[] color = new float[4];
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, shininess);
         switch (colorTarget) {
@@ -3653,19 +4262,29 @@
                 break;
         }
 
-        color[0] = eRed; color[1] = eGreen; color[2] = eBlue;
+        color[0] = eRed;
+        color[1] = eGreen;
+        color[2] = eBlue;
         gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_EMISSION, color, 0);
 
-        color[0] = aRed; color[1] = aGreen; color[2] = aBlue;
+        color[0] = aRed;
+        color[1] = aGreen;
+        color[2] = aBlue;
         gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, color, 0);
 
-        color[0] = sRed; color[1] = sGreen; color[2] = sBlue;
+        color[0] = sRed;
+        color[1] = sGreen;
+        color[2] = sBlue;
         gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, color, 0);
 
         if (lightEnable) {
-            color[0] = dRed; color[1] = dGreen; color[2] = dBlue;
-        } else {
-            color[0] = red; color[1] = green; color[2] = blue;
+            color[0] = dRed;
+            color[1] = dGreen;
+            color[2] = dBlue;
+        } else {
+            color[0] = red;
+            color[1] = green;
+            color[2] = blue;
         }
         color[3] = alpha;
         gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, color, 0);
@@ -3678,19 +4297,12 @@
         }
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // ModelClipRetained methods
-    //
-
     @Override
     void updateModelClip(Context ctx, int planeNum, boolean enableFlag,
-            double A, double B, double C, double D) {
+                         double A, double B, double C, double D) {
         if (VERBOSE) System.err.println("JoglPipeline.updateModelClip()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         double[] equation = new double[4];
         int pl = GL2.GL_CLIP_PLANE0 + planeNum;
@@ -3708,18 +4320,11 @@
         }
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // PointAttributesRetained methods
-    //
-
     @Override
     void updatePointAttributes(Context ctx, float pointSize, boolean pointAntialiasing) {
         if (VERBOSE) System.err.println("JoglPipeline.updatePointAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glPointSize(pointSize);
 
         // XXXX: Polygon Mode check, blend enable
@@ -3730,22 +4335,15 @@
         }
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // PolygonAttributesRetained methods
-    //
-
     @Override
     void updatePolygonAttributes(Context ctx,
-            int polygonMode, int cullFace,
-            boolean backFaceNormalFlip,
-            float polygonOffset,
-            float polygonOffsetFactor) {
+                                 int polygonMode, int cullFace,
+                                 boolean backFaceNormalFlip,
+                                 float polygonOffset,
+                                 float polygonOffsetFactor) {
         if (VERBOSE) System.err.println("JoglPipeline.updatePolygonAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         if (cullFace == PolygonAttributes.CULL_NONE) {
             gl.glDisable(GL.GL_CULL_FACE);
@@ -3799,30 +4397,23 @@
         }
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // RenderingAttributesRetained methods
-    //
-
     @Override
     void updateRenderingAttributes(Context ctx,
-            boolean depthBufferWriteEnableOverride,
-            boolean depthBufferEnableOverride,
-            boolean depthBufferEnable,
-            boolean depthBufferWriteEnable,
-            int depthTestFunction,
-            float alphaTestValue, int alphaTestFunction,
-            boolean ignoreVertexColors,
-            boolean rasterOpEnable, int rasterOp,
-            boolean userStencilAvailable, boolean stencilEnable,
-            int stencilFailOp, int stencilZFailOp, int stencilZPassOp,
-            int stencilFunction, int stencilReferenceValue,
-            int stencilCompareMask, int stencilWriteMask ) {
+                                   boolean depthBufferWriteEnableOverride,
+                                   boolean depthBufferEnableOverride,
+                                   boolean depthBufferEnable,
+                                   boolean depthBufferWriteEnable,
+                                   int depthTestFunction,
+                                   float alphaTestValue, int alphaTestFunction,
+                                   boolean ignoreVertexColors,
+                                   boolean rasterOpEnable, int rasterOp,
+                                   boolean userStencilAvailable, boolean stencilEnable,
+                                   int stencilFailOp, int stencilZFailOp, int stencilZPassOp,
+                                   int stencilFunction, int stencilReferenceValue,
+                                   int stencilCompareMask, int stencilWriteMask) {
         if (VERBOSE) System.err.println("JoglPipeline.updateRenderingAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         if (!depthBufferEnableOverride) {
             if (depthBufferEnable) {
@@ -3989,7 +4580,7 @@
     // ---------------------------------------------------------------------
 
     //
-    // TexCoordGenerationRetained methods
+    // TextureCubeMapRetained methods
     //
 
     /**
@@ -3999,15 +4590,15 @@
      */
     @Override
     void updateTexCoordGeneration(Context ctx,
-            boolean enable, int genMode, int format,
-            float planeSx, float planeSy, float planeSz, float planeSw,
-            float planeTx, float planeTy, float planeTz, float planeTw,
-            float planeRx, float planeRy, float planeRz, float planeRw,
-            float planeQx, float planeQy, float planeQz, float planeQw,
-            double[] vworldToEc) {
+                                  boolean enable, int genMode, int format,
+                                  float planeSx, float planeSy, float planeSz, float planeSw,
+                                  float planeTx, float planeTy, float planeTz, float planeTw,
+                                  float planeRx, float planeRy, float planeRz, float planeRw,
+                                  float planeQx, float planeQy, float planeQz, float planeQw,
+                                  double[] vworldToEc) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexCoordGeneration()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         float[] planeS = new float[4];
         float[] planeT = new float[4];
@@ -4029,18 +4620,28 @@
             }
 
             if (genMode != TexCoordGeneration.SPHERE_MAP) {
-                planeS[0] = planeSx; planeS[1] = planeSy;
-                planeS[2] = planeSz; planeS[3] = planeSw;
-                planeT[0] = planeTx; planeT[1] = planeTy;
-                planeT[2] = planeTz; planeT[3] = planeTw;
+                planeS[0] = planeSx;
+                planeS[1] = planeSy;
+                planeS[2] = planeSz;
+                planeS[3] = planeSw;
+                planeT[0] = planeTx;
+                planeT[1] = planeTy;
+                planeT[2] = planeTz;
+                planeT[3] = planeTw;
                 if (format == TexCoordGeneration.TEXTURE_COORDINATE_3) {
-                    planeR[0] = planeRx; planeR[1] = planeRy;
-                    planeR[2] = planeRz; planeR[3] = planeRw;
+                    planeR[0] = planeRx;
+                    planeR[1] = planeRy;
+                    planeR[2] = planeRz;
+                    planeR[3] = planeRw;
                 } else if (format == TexCoordGeneration.TEXTURE_COORDINATE_4) {
-                    planeR[0] = planeRx; planeR[1] = planeRy;
-                    planeR[2] = planeRz; planeR[3] = planeRw;
-                    planeQ[0] = planeQx; planeQ[1] = planeQy;
-                    planeQ[2] = planeQz; planeQ[3] = planeQw;
+                    planeR[0] = planeRx;
+                    planeR[1] = planeRy;
+                    planeR[2] = planeRz;
+                    planeR[3] = planeRw;
+                    planeQ[0] = planeQx;
+                    planeQ[1] = planeQy;
+                    planeQ[2] = planeQz;
+                    planeQ[3] = planeQw;
                 }
             }
 
@@ -4130,257 +4731,32 @@
         }
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // TransparencyAttributesRetained methods
-    //
-
-    private static final int screen_door[][] = {
-        /* 0 / 16 */
-        {
-            0x00000000, 0x00000000, 0x00000000, 0x00000000,
-                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
-                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
-                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
-                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
-                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
-                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
-                    0x00000000, 0x00000000, 0x00000000, 0x00000000,
-        },
-        /* 1 / 16 */
-        {
-            0x00000000, 0x22222222, 0x00000000, 0x00000000,
-                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
-                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
-                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
-                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
-                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
-                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
-                    0x00000000, 0x22222222, 0x00000000, 0x00000000,
-        },
-        /* 2 / 16 */
-        {
-            0x00000000, 0x22222222, 0x00000000, 0x88888888,
-                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
-                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
-                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
-                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
-                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
-                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
-                    0x00000000, 0x22222222, 0x00000000, 0x88888888,
-        },
-        /* 3 / 16 */
-        {
-            0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0x88888888,
-        },
-        /* 4 / 16 */
-        {
-            0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x00000000, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-        },
-        /* 5 / 16 */
-        {
-            0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x00000000, 0xaaaaaaaa,
-        },
-        /* 6 / 16 */
-        {
-            0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x11111111, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-        },
-        /* 7 / 16 */
-        {
-            0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x44444444, 0xaaaaaaaa,
-        },
-        /* 8 / 16 */
-        {
-            0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-        },
-        /* 9 / 16 */
-        {
-            0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
-        },
-        /* 10 / 16 */
-        {
-            0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0x77777777, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-        },
-        /* 11 / 16 */
-        {
-            0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xdddddddd, 0xaaaaaaaa,
-        },
-        /* 12 / 16 */
-        {
-            0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xaaaaaaaa, 0xffffffff, 0xaaaaaaaa,
-        },
-        /* 13 / 16 */
-        {
-            0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xaaaaaaaa,
-        },
-        /* 14 / 16 */
-        {
-            0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xbbbbbbbb, 0xffffffff, 0xeeeeeeee,
-        },
-        /* 15 / 16 */
-        {
-            0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xeeeeeeee,
-        },
-        /* 16 / 16 */
-        {
-            0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
-                    0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
-        },
-    };
-    private static final ByteBuffer[] screen_door_table = new ByteBuffer[screen_door.length];
-    static {
-		int eachLen = screen_door[0].length * Buffers.SIZEOF_INT;
-		ByteBuffer buf = Buffers.newDirectByteBuffer(screen_door.length * eachLen);
-        IntBuffer intBuf = buf.asIntBuffer();
-        for (int i = 0; i < screen_door.length; i++) {
-            intBuf.put(screen_door[i]);
-        }
-        buf.rewind();
-        for (int i = 0; i < screen_door.length; i++) {
-            buf.position(i * eachLen);
-            buf.limit((i+1) * eachLen);
-            screen_door_table[i] = buf.slice();
-        }
-    }
-
-    private static final int[] blendFunctionTable = new int[TransparencyAttributes.MAX_BLEND_FUNC_TABLE_SIZE];
-    static {
-        blendFunctionTable[TransparencyAttributes.BLEND_ZERO] = GL.GL_ZERO;
-        blendFunctionTable[TransparencyAttributes.BLEND_ONE] = GL.GL_ONE;
-        blendFunctionTable[TransparencyAttributes.BLEND_SRC_ALPHA] = GL.GL_SRC_ALPHA;
-        blendFunctionTable[TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA] = GL.GL_ONE_MINUS_SRC_ALPHA;
-        blendFunctionTable[TransparencyAttributes.BLEND_DST_COLOR] = GL.GL_DST_COLOR;
-        blendFunctionTable[TransparencyAttributes.BLEND_ONE_MINUS_DST_COLOR] = GL.GL_ONE_MINUS_DST_COLOR;
-        blendFunctionTable[TransparencyAttributes.BLEND_SRC_COLOR] = GL.GL_SRC_COLOR;
-        blendFunctionTable[TransparencyAttributes.BLEND_ONE_MINUS_SRC_COLOR] = GL.GL_ONE_MINUS_SRC_COLOR;
-        blendFunctionTable[TransparencyAttributes.BLEND_CONSTANT_COLOR] = GL2.GL_CONSTANT_COLOR;
-    }
-
     @Override
     void updateTransparencyAttributes(Context ctx,
-            float alpha, int geometryType,
-            int polygonMode,
-            boolean lineAA, boolean pointAA,
-            int transparencyMode,
-            int srcBlendFunction,
-            int dstBlendFunction) {
+                                      float alpha, int geometryType,
+                                      int polygonMode,
+                                      boolean lineAA, boolean pointAA,
+                                      int transparencyMode,
+                                      int srcBlendFunction,
+                                      int dstBlendFunction) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTransparencyAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         if (transparencyMode != TransparencyAttributes.SCREEN_DOOR) {
             gl.glDisable(GL2.GL_POLYGON_STIPPLE);
-        } else  {
+        } else {
             gl.glEnable(GL2.GL_POLYGON_STIPPLE);
-            gl.glPolygonStipple(screen_door_table[(int)(alpha * 16)]);
+            gl.glPolygonStipple(screen_door_table[(int) (alpha * 16)]);
         }
 
         if ((transparencyMode < TransparencyAttributes.SCREEN_DOOR) ||
                 ((((geometryType & RenderMolecule.LINE) != 0) ||
-                (polygonMode == PolygonAttributes.POLYGON_LINE))
-                && lineAA) ||
+                        (polygonMode == PolygonAttributes.POLYGON_LINE))
+                        && lineAA) ||
                 ((((geometryType & RenderMolecule.POINT) != 0) ||
-                (polygonMode == PolygonAttributes.POLYGON_POINT))
-                && pointAA)) {
+                        (polygonMode == PolygonAttributes.POLYGON_POINT))
+                        && pointAA)) {
             gl.glEnable(GL.GL_BLEND);
             // valid range of blendFunction 0..3 is already verified in shared code.
             gl.glBlendFunc(blendFunctionTable[srcBlendFunction], blendFunctionTable[dstBlendFunction]);
@@ -4389,25 +4765,18 @@
         }
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // TextureAttributesRetained methods
-    //
-
     @Override
     void updateTextureAttributes(Context ctx,
-            double[] transform, boolean isIdentity, int textureMode,
-            int perspCorrectionMode,
-            float textureBlendColorRed,
-            float textureBlendColorGreen,
-            float textureBlendColorBlue,
-            float textureBlendColorAlpha,
-            int textureFormat) {
+                                 double[] transform, boolean isIdentity, int textureMode,
+                                 int perspCorrectionMode,
+                                 float textureBlendColorRed,
+                                 float textureBlendColorGreen,
+                                 float textureBlendColorBlue,
+                                 float textureBlendColorAlpha,
+                                 int textureFormat) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT,
                 (perspCorrectionMode == TextureAttributes.NICEST) ? GL.GL_NICEST : GL.GL_FASTEST);
 
@@ -4462,17 +4831,17 @@
 
     @Override
     void updateRegisterCombiners(Context absCtx,
-            double[] transform, boolean isIdentity, int textureMode,
-            int perspCorrectionMode,
-            float textureBlendColorRed,
-            float textureBlendColorGreen,
-            float textureBlendColorBlue,
-            float textureBlendColorAlpha,
-            int textureFormat,
-            int combineRgbMode, int combineAlphaMode,
-            int[] combineRgbSrc, int[] combineAlphaSrc,
-            int[] combineRgbFcn, int[] combineAlphaFcn,
-            int combineRgbScale, int combineAlphaScale) {
+                                 double[] transform, boolean isIdentity, int textureMode,
+                                 int perspCorrectionMode,
+                                 float textureBlendColorRed,
+                                 float textureBlendColorGreen,
+                                 float textureBlendColorBlue,
+                                 float textureBlendColorAlpha,
+                                 int textureFormat,
+                                 int combineRgbMode, int combineAlphaMode,
+                                 int[] combineRgbSrc, int[] combineAlphaSrc,
+                                 int[] combineRgbFcn, int[] combineAlphaFcn,
+                                 int combineRgbScale, int combineAlphaScale) {
 // FIXME: GL_NV_register_combiners
 //        if (VERBOSE) System.err.println("JoglPipeline.updateRegisterCombiners()");
 //
@@ -4676,8 +5045,8 @@
 
     @Override
     void updateTextureColorTable(Context ctx, int numComponents,
-            int colorTableSize,
-            int[] textureColorTable) {
+                                 int colorTableSize,
+                                 int[] textureColorTable) {
 // FIXME: GL_SGI_texture_color_table
 //        if (VERBOSE) System.err.println("JoglPipeline.updateTextureColorTable()");
 //
@@ -4696,13 +5065,13 @@
 
     @Override
     void updateCombiner(Context ctx,
-            int combineRgbMode, int combineAlphaMode,
-            int[] combineRgbSrc, int[] combineAlphaSrc,
-            int[] combineRgbFcn, int[] combineAlphaFcn,
-            int combineRgbScale, int combineAlphaScale) {
+                        int combineRgbMode, int combineAlphaMode,
+                        int[] combineRgbSrc, int[] combineAlphaSrc,
+                        int[] combineRgbFcn, int[] combineAlphaFcn,
+                        int combineRgbScale, int combineAlphaScale) {
         if (VERBOSE) System.err.println("JoglPipeline.updateCombiner()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         int[] GLrgbMode = new int[1];
         int[] GLalphaMode = new int[1];
         getGLCombineMode(gl, combineRgbMode, combineAlphaMode,
@@ -4745,10 +5114,8 @@
         gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_ALPHA_SCALE, combineAlphaScale);
     }
 
-    // Helper routines for above
-
     private void getGLCombineMode(GL gl, int combineRgbMode, int combineAlphaMode,
-            int[] GLrgbMode, int[] GLalphaMode) {
+                                  int[] GLrgbMode, int[] GLalphaMode) {
         switch (combineRgbMode) {
             case TextureAttributes.COMBINE_REPLACE:
                 GLrgbMode[0] = GL.GL_REPLACE;
@@ -4808,83 +5175,11 @@
         }
     }
 
-    // mapping from java enum to gl enum
-    private static final int[] _gl_combineRgbSrcIndex = {
-        GL2.GL_SOURCE0_RGB,
-        GL2.GL_SOURCE1_RGB,
-        GL2.GL_SOURCE2_RGB,
-    };
-
-    private static final int[] _gl_combineAlphaSrcIndex = {
-        GL2.GL_SOURCE0_ALPHA,
-        GL2.GL_SOURCE1_ALPHA,
-        GL2.GL_SOURCE2_ALPHA,
-    };
-
-    private static final int[] _gl_combineRgbOpIndex = {
-        GL2.GL_OPERAND0_RGB,
-        GL2.GL_OPERAND1_RGB,
-        GL2.GL_OPERAND2_RGB,
-    };
-
-    private static final int[] _gl_combineAlphaOpIndex = {
-        GL2.GL_OPERAND0_ALPHA,
-        GL2.GL_OPERAND1_ALPHA,
-        GL2.GL_OPERAND2_ALPHA,
-    };
-
-    private static final int[] _gl_combineSrc = {
-        GL2.GL_PRIMARY_COLOR,      // TextureAttributes.COMBINE_OBJECT_COLOR
-        GL.GL_TEXTURE,            // TextureAttributes.COMBINE_TEXTURE
-        GL2.GL_CONSTANT,           // TextureAttributes.COMBINE_CONSTANT_COLOR
-        GL2.GL_PREVIOUS,           // TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE
-    };
-
-    private static final int[] _gl_combineFcn = {
-        GL.GL_SRC_COLOR,              // TextureAttributes.COMBINE_SRC_COLOR
-        GL.GL_ONE_MINUS_SRC_COLOR,    // TextureAttributes.COMBINE_ONE_MINUS_SRC_COLOR
-        GL.GL_SRC_ALPHA,              // TextureAttributes.COMBINE_SRC_ALPHA
-        GL.GL_ONE_MINUS_SRC_ALPHA,    // TextureAttributes.COMBINE_ONE_MINUS_SRC_ALPHA
-    };
-
-// FIXME: GL_NV_register_combiners
-//    private int getCombinerArg(GL gl, int arg, int textureUnit, int combUnit) {
-//        int comb = 0;
-//
-//        switch (arg) {
-//            case TextureAttributes.COMBINE_OBJECT_COLOR:
-//                if (combUnit == GL.GL_COMBINER0_NV) {
-//                    comb = GL.GL_PRIMARY_COLOR_NV;
-//                } else {
-//                    comb = GL.GL_SPARE0_NV;
-//                }
-//                break;
-//            case TextureAttributes.COMBINE_TEXTURE_COLOR:
-//                comb = textureUnit;
-//                break;
-//            case TextureAttributes.COMBINE_CONSTANT_COLOR:
-//                comb = GL.GL_CONSTANT_COLOR0_NV;
-//                break;
-//            case TextureAttributes.COMBINE_PREVIOUS_TEXTURE_UNIT_STATE:
-//                comb = textureUnit -1;
-//                break;
-//        }
-//
-//        return comb;
-//    }
-
-
-    // ---------------------------------------------------------------------
-
-    //
-    // TextureUnitStateRetained methods
-    //
-
     @Override
     void updateTextureUnitState(Context ctx, int index, boolean enable) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureUnitState()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         if (index >= 0 && gl.isExtensionAvailable("GL_VERSION_1_3")) {
             gl.glActiveTexture(index + GL.GL_TEXTURE0);
@@ -4909,14 +5204,6 @@
         // in the bindTexture call
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // TextureRetained methods
-    // Texture2DRetained methods
-    //
-
     @Override
     void bindTexture2D(Context ctx, int objectId, boolean enable) {
         if (VERBOSE) System.err.println("JoglPipeline.bindTexture2D(objectId=" + objectId + ",enable=" + enable + ")");
@@ -4935,25 +5222,31 @@
 
     @Override
     void updateTexture2DImage(Context ctx,
-            int numLevels, int level,
-            int textureFormat, int imageFormat,
-            int width, int height,
-            int boundaryWidth,
-            int dataType, Object data, boolean useAutoMipMap) {
-        if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DImage(width=" + width + ",height=" + height + ",level=" + level + ")");
+                              int numLevels, int level,
+                              int textureFormat, int imageFormat,
+                              int width, int height,
+                              int boundaryWidth,
+                              int dataType, Object data, boolean useAutoMipMap) {
+        if (VERBOSE)
+            System.err.println("JoglPipeline.updateTexture2DImage(width=" + width + ",height=" + height + ",level=" + level + ")");
 
         updateTexture2DImage(ctx, GL.GL_TEXTURE_2D,
                 numLevels, level, textureFormat, imageFormat,
                 width, height, boundaryWidth, dataType, data, useAutoMipMap);
     }
 
+    //----------------------------------------------------------------------
+    //
+    // Helper routines for above texture methods
+    //
+
     @Override
     void updateTexture2DSubImage(Context ctx,
-            int level, int xoffset, int yoffset,
-            int textureFormat, int imageFormat,
-            int imgXOffset, int imgYOffset,
-            int tilew, int width, int height,
-            int dataType, Object data, boolean useAutoMipMap) {
+                                 int level, int xoffset, int yoffset,
+                                 int textureFormat, int imageFormat,
+                                 int imgXOffset, int imgYOffset,
+                                 int tilew, int width, int height,
+                                 int dataType, Object data, boolean useAutoMipMap) {
 
         /* Note: useAutoMipMap is not use for SubImage in the jogl pipe */
 
@@ -4968,8 +5261,8 @@
 
     @Override
     void updateTexture2DLodRange(Context ctx,
-            int baseLevel, int maximumLevel,
-            float minimumLOD, float maximumLOD) {
+                                 int baseLevel, int maximumLevel,
+                                 float minimumLOD, float maximumLOD) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DLodRange()");
 
         updateTextureLodRange(ctx, GL.GL_TEXTURE_2D,
@@ -4979,8 +5272,8 @@
 
     @Override
     void updateTexture2DLodOffset(Context ctx,
-            float lodOffsetS, float lodOffsetT,
-            float lodOffsetR) {
+                                  float lodOffsetS, float lodOffsetT,
+                                  float lodOffsetR) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DLodOffset()");
 
         updateTextureLodOffset(ctx, GL.GL_TEXTURE_2D,
@@ -4989,9 +5282,9 @@
 
     @Override
     void updateTexture2DBoundary(Context ctx,
-            int boundaryModeS, int boundaryModeT,
-            float boundaryRed, float boundaryGreen,
-            float boundaryBlue, float boundaryAlpha) {
+                                 int boundaryModeS, int boundaryModeT,
+                                 float boundaryRed, float boundaryGreen,
+                                 float boundaryBlue, float boundaryAlpha) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DBoundary()");
 
         updateTextureBoundary(ctx, GL.GL_TEXTURE_2D,
@@ -5002,7 +5295,7 @@
 
     @Override
     void updateTexture2DFilterModes(Context ctx,
-            int minFilter, int magFilter) {
+                                    int minFilter, int magFilter) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DFilterModes()");
 
         updateTextureFilterModes(ctx, GL.GL_TEXTURE_2D, minFilter, magFilter);
@@ -5010,8 +5303,8 @@
 
     @Override
     void updateTexture2DSharpenFunc(Context ctx,
-            int numSharpenTextureFuncPts,
-            float[] sharpenTextureFuncPts) {
+                                    int numSharpenTextureFuncPts,
+                                    float[] sharpenTextureFuncPts) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DSharpenFunc()");
 
         updateTextureSharpenFunc(ctx, GL.GL_TEXTURE_2D,
@@ -5020,8 +5313,8 @@
 
     @Override
     void updateTexture2DFilter4Func(Context ctx,
-            int numFilter4FuncPts,
-            float[] filter4FuncPts) {
+                                    int numFilter4FuncPts,
+                                    float[] filter4FuncPts) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture2DFilter4Func()");
 
         updateTextureFilter4Func(ctx, GL.GL_TEXTURE_2D,
@@ -5035,10 +5328,16 @@
         updateTextureAnisotropicFilter(ctx, GL.GL_TEXTURE_2D, degree);
     }
 
+    // ---------------------------------------------------------------------
+
+    //
+    // MasterControl methods
+    //
+
     private void updateTextureLodRange(Context ctx,
-            int target,
-            int baseLevel, int maximumLevel,
-            float minimumLOD, float maximumLOD) {
+                                       int target,
+                                       int baseLevel, int maximumLevel,
+                                       float minimumLOD, float maximumLOD) {
         GL gl = context(ctx).getGL();
         // checking of the availability of the extension is already done
         // in the shared code
@@ -5048,10 +5347,17 @@
         gl.glTexParameterf(target, GL2.GL_TEXTURE_MAX_LOD, maximumLOD);
     }
 
+
+    // ---------------------------------------------------------------------
+
+    //
+    // Canvas3D methods - native wrappers
+    //
+
     private void updateTextureLodOffset(Context ctx,
-            int target,
-            float lodOffsetS, float lodOffsetT,
-            float lodOffsetR) {
+                                        int target,
+                                        float lodOffsetS, float lodOffsetT,
+                                        float lodOffsetR) {
 // FIXME: GL_SGIX_texture_lod_bias
 //        GL gl = context(ctx).getGL();
         // checking of the availability of the extension is already done
@@ -5070,12 +5376,6 @@
                 degree);
     }
 
-    // ---------------------------------------------------------------------
-
-    //
-    // Texture3DRetained methods
-    //
-
     @Override
     void bindTexture3D(Context ctx, int objectId, boolean enable) {
         if (VERBOSE) System.err.println("JoglPipeline.bindTexture3D()");
@@ -5094,15 +5394,15 @@
 
     @Override
     void updateTexture3DImage(Context ctx,
-            int numLevels, int level,
-            int textureFormat, int imageFormat,
-            int width, int height, int depth,
-            int boundaryWidth,
-            int dataType, Object data, boolean useAutoMipMap) {
+                              int numLevels, int level,
+                              int textureFormat, int imageFormat,
+                              int width, int height, int depth,
+                              int boundaryWidth,
+                              int dataType, Object data, boolean useAutoMipMap) {
 
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DImage()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int format = 0;
         int internalFormat = 0;
@@ -5135,12 +5435,11 @@
 
         if (useAutoMipMap) {
             gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE);
-        }
-        else {
+        } else {
             gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL2.GL_GENERATE_MIPMAP, GL.GL_FALSE);
         }
 
-        if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
+        if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_BUFFER)) {
 
             switch (imageFormat) {
@@ -5169,7 +5468,7 @@
                 case ImageComponentRetained.TYPE_BYTE_GRAY:
                     if (internalFormat == GL.GL_ALPHA) {
                         format = GL.GL_ALPHA;
-                    } else  {
+                    } else {
                         format = GL.GL_LUMINANCE;
                     }
                     break;
@@ -5182,21 +5481,20 @@
                     return;
             }
 
-	    if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
+            if (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
 
-            gl.glTexImage3D(GL2.GL_TEXTURE_3D,
-                    level, internalFormat,
-                    width, height, depth, boundaryWidth,
-                    format, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[]) data));
-            }
-	    else {
                 gl.glTexImage3D(GL2.GL_TEXTURE_3D,
-                    level, internalFormat,
-                    width, height, depth, boundaryWidth,
-                    format, GL.GL_UNSIGNED_BYTE, (ByteBuffer) data);
-	    }
+                        level, internalFormat,
+                        width, height, depth, boundaryWidth,
+                        format, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[]) data));
+            } else {
+                gl.glTexImage3D(GL2.GL_TEXTURE_3D,
+                        level, internalFormat,
+                        width, height, depth, boundaryWidth,
+                        format, GL.GL_UNSIGNED_BYTE, (ByteBuffer) data);
+            }
 
-        } else if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
+        } else if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_BUFFER)) {
 
             switch (imageFormat) {
@@ -5213,7 +5511,7 @@
                     format = GL2.GL_BGRA;
                     type = GL2.GL_UNSIGNED_INT_8_8_8_8_REV;
                     break;
-                    /* This method only supports 3 and 4 components formats and INT types. */
+                /* This method only supports 3 and 4 components formats and INT types. */
                 case ImageComponentRetained.TYPE_BYTE_LA:
                 case ImageComponentRetained.TYPE_BYTE_GRAY:
                 case ImageComponentRetained.TYPE_USHORT_GRAY:
@@ -5227,12 +5525,12 @@
             }
 
             /* Force Alpha to 1.0 if needed */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 0.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 1.0f);
             }
 
-            if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
+            if (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
                 gl.glTexImage3D(GL2.GL_TEXTURE_3D,
                         level, internalFormat,
                         width, height, depth, boundaryWidth,
@@ -5245,7 +5543,7 @@
             }
 
             /* Restore Alpha scale and bias */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 1.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 0.0f);
             }
@@ -5256,19 +5554,19 @@
 
     @Override
     void updateTexture3DSubImage(Context ctx,
-            int level,
-            int xoffset, int yoffset, int zoffset,
-            int textureFormat, int imageFormat,
-            int imgXOffset, int imgYOffset, int imgZOffset,
-            int tilew, int tileh,
-            int width, int height, int depth,
-            int dataType, Object data, boolean useAutoMipMap) {
+                                 int level,
+                                 int xoffset, int yoffset, int zoffset,
+                                 int textureFormat, int imageFormat,
+                                 int imgXOffset, int imgYOffset, int imgZOffset,
+                                 int tilew, int tileh,
+                                 int width, int height, int depth,
+                                 int dataType, Object data, boolean useAutoMipMap) {
 
         /* Note: useAutoMipMap is not use for SubImage in the jogl pipe */
 
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DSubImage()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int format = 0;
         int internalFormat = 0;
@@ -5305,7 +5603,7 @@
                 assert false;
         }
 
-        if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
+        if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_BUFFER)) {
 
             switch (imageFormat) {
@@ -5340,7 +5638,7 @@
                     if (internalFormat == GL.GL_ALPHA) {
                         format = GL.GL_ALPHA;
                         numBytes = 1;
-                    } else  {
+                    } else {
                         format = GL.GL_LUMINANCE;
                         numBytes = 1;
                     }
@@ -5355,10 +5653,9 @@
             }
 
             ByteBuffer buf = null;
-            if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
+            if (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
                 buf = ByteBuffer.wrap((byte[]) data);
-            }
-            else {
+            } else {
                 buf = (ByteBuffer) data;
             }
 
@@ -5371,7 +5668,7 @@
                     format, GL.GL_UNSIGNED_BYTE,
                     buf);
 
-        } else if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
+        } else if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_BUFFER)) {
 
             switch (imageFormat) {
@@ -5388,7 +5685,7 @@
                     format = GL2.GL_BGRA;
                     type = GL2.GL_UNSIGNED_INT_8_8_8_8_REV;
                     break;
-                    /* This method only supports 3 and 4 components formats and INT types. */
+                /* This method only supports 3 and 4 components formats and INT types. */
                 case ImageComponentRetained.TYPE_BYTE_LA:
                 case ImageComponentRetained.TYPE_BYTE_GRAY:
                 case ImageComponentRetained.TYPE_USHORT_GRAY:
@@ -5402,16 +5699,15 @@
             }
 
             /* Force Alpha to 1.0 if needed */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 0.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 1.0f);
             }
 
             IntBuffer buf = null;
-            if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
+            if (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
                 buf = IntBuffer.wrap((int[]) data);
-            }
-            else {
+            } else {
                 buf = (IntBuffer) data;
             }
 
@@ -5425,7 +5721,7 @@
                     buf);
 
             /* Restore Alpha scale and bias */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 1.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 0.0f);
             }
@@ -5440,11 +5736,10 @@
 
     }
 
-
     @Override
     void updateTexture3DLodRange(Context ctx,
-            int baseLevel, int maximumLevel,
-            float minimumLod, float maximumLod) {
+                                 int baseLevel, int maximumLevel,
+                                 float minimumLod, float maximumLod) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DLodRange()");
 
         updateTextureLodRange(ctx, GL2.GL_TEXTURE_3D,
@@ -5454,8 +5749,8 @@
 
     @Override
     void updateTexture3DLodOffset(Context ctx,
-            float lodOffsetS, float lodOffsetT,
-            float lodOffsetR) {
+                                  float lodOffsetS, float lodOffsetT,
+                                  float lodOffsetR) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DLodOffset()");
 
         updateTextureLodOffset(ctx, GL2.GL_TEXTURE_3D,
@@ -5464,10 +5759,10 @@
 
     @Override
     void updateTexture3DBoundary(Context ctx,
-            int boundaryModeS, int boundaryModeT,
-            int boundaryModeR, float boundaryRed,
-            float boundaryGreen, float boundaryBlue,
-            float boundaryAlpha) {
+                                 int boundaryModeS, int boundaryModeT,
+                                 int boundaryModeR, float boundaryRed,
+                                 float boundaryGreen, float boundaryBlue,
+                                 float boundaryAlpha) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DBoundary()");
 
         updateTextureBoundary(ctx, GL2.GL_TEXTURE_3D,
@@ -5478,7 +5773,7 @@
 
     @Override
     void updateTexture3DFilterModes(Context ctx,
-            int minFilter, int magFilter) {
+                                    int minFilter, int magFilter) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DFilterModes()");
 
         updateTextureFilterModes(ctx, GL2.GL_TEXTURE_3D,
@@ -5487,8 +5782,8 @@
 
     @Override
     void updateTexture3DSharpenFunc(Context ctx,
-            int numSharpenTextureFuncPts,
-            float[] sharpenTextureFuncPts) {
+                                    int numSharpenTextureFuncPts,
+                                    float[] sharpenTextureFuncPts) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DSharpenFunc()");
 
         updateTextureSharpenFunc(ctx, GL2.GL_TEXTURE_3D,
@@ -5497,8 +5792,8 @@
 
     @Override
     void updateTexture3DFilter4Func(Context ctx,
-            int numFilter4FuncPts,
-            float[] filter4FuncPts) {
+                                    int numFilter4FuncPts,
+                                    float[] filter4FuncPts) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DFilter4Func()");
 
         updateTextureFilter4Func(ctx, GL2.GL_TEXTURE_3D,
@@ -5512,13 +5807,6 @@
         updateTextureAnisotropicFilter(ctx, GL2.GL_TEXTURE_3D, degree);
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // TextureCubeMapRetained methods
-    //
-
     @Override
     void bindTextureCubeMap(Context ctx, int objectId, boolean enable) {
         if (VERBOSE) System.err.println("JoglPipeline.bindTextureCubeMap()");
@@ -5536,11 +5824,11 @@
 
     @Override
     void updateTextureCubeMapImage(Context ctx,
-            int face, int numLevels, int level,
-            int textureFormat, int imageFormat,
-            int width, int height,
-            int boundaryWidth,
-            int dataType, Object data, boolean useAutoMipMap) {
+                                   int face, int numLevels, int level,
+                                   int textureFormat, int imageFormat,
+                                   int width, int height,
+                                   int boundaryWidth,
+                                   int dataType, Object data, boolean useAutoMipMap) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapImage()");
 
         updateTexture2DImage(ctx, _gl_textureCubeMapFace[face],
@@ -5550,11 +5838,11 @@
 
     @Override
     void updateTextureCubeMapSubImage(Context ctx,
-            int face, int level, int xoffset, int yoffset,
-            int textureFormat,int imageFormat,
-            int imgXOffset, int imgYOffset,
-            int tilew, int width, int height,
-            int dataType, Object data, boolean useAutoMipMap) {
+                                      int face, int level, int xoffset, int yoffset,
+                                      int textureFormat, int imageFormat,
+                                      int imgXOffset, int imgYOffset,
+                                      int tilew, int width, int height,
+                                      int dataType, Object data, boolean useAutoMipMap) {
 
         /* Note: useAutoMipMap is not use for SubImage in the jogl pipe */
 
@@ -5568,8 +5856,8 @@
 
     @Override
     void updateTextureCubeMapLodRange(Context ctx,
-            int baseLevel, int maximumLevel,
-            float minimumLod, float maximumLod) {
+                                      int baseLevel, int maximumLevel,
+                                      float minimumLod, float maximumLod) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapLodRange()");
 
         updateTextureLodRange(ctx,
@@ -5580,8 +5868,8 @@
 
     @Override
     void updateTextureCubeMapLodOffset(Context ctx,
-            float lodOffsetS, float lodOffsetT,
-            float lodOffsetR) {
+                                       float lodOffsetS, float lodOffsetT,
+                                       float lodOffsetR) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapLodOffset()");
 
         updateTextureLodOffset(ctx,
@@ -5591,9 +5879,9 @@
 
     @Override
     void updateTextureCubeMapBoundary(Context ctx,
-            int boundaryModeS, int boundaryModeT,
-            float boundaryRed, float boundaryGreen,
-            float boundaryBlue, float boundaryAlpha) {
+                                      int boundaryModeS, int boundaryModeT,
+                                      float boundaryRed, float boundaryGreen,
+                                      float boundaryBlue, float boundaryAlpha) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapBoundary()");
 
         updateTextureBoundary(ctx,
@@ -5603,9 +5891,11 @@
                 boundaryBlue, boundaryAlpha);
     }
 
+    // The following three methods are used in multi-pass case
+
     @Override
     void updateTextureCubeMapFilterModes(Context ctx,
-            int minFilter, int magFilter) {
+                                         int minFilter, int magFilter) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapFilterModes()");
 
         updateTextureFilterModes(ctx,
@@ -5615,8 +5905,8 @@
 
     @Override
     void updateTextureCubeMapSharpenFunc(Context ctx,
-            int numSharpenTextureFuncPts,
-            float[] sharpenTextureFuncPts) {
+                                         int numSharpenTextureFuncPts,
+                                         float[] sharpenTextureFuncPts) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapSharpenFunc()");
 
         updateTextureSharpenFunc(ctx,
@@ -5626,8 +5916,8 @@
 
     @Override
     void updateTextureCubeMapFilter4Func(Context ctx,
-            int numFilter4FuncPts,
-            float[] filter4FuncPts) {
+                                         int numFilter4FuncPts,
+                                         float[] filter4FuncPts) {
         if (VERBOSE) System.err.println("JoglPipeline.updateTextureCubeMapFilter4Func()");
 
         updateTextureFilter4Func(ctx,
@@ -5644,24 +5934,19 @@
                 degree);
     }
 
-    //----------------------------------------------------------------------
-    //
-    // Helper routines for above texture methods
-    //
-
     private void updateTexture2DImage(Context ctx,
-            int target,
-            int numLevels,
-            int level,
-            int textureFormat,
-            int imageFormat,
-            int width,
-            int height,
-            int boundaryWidth,
-            int dataType,
-            Object data,
-            boolean useAutoMipMap) {
-		GL2 gl = context(ctx).getGL().getGL2();
+                                      int target,
+                                      int numLevels,
+                                      int level,
+                                      int textureFormat,
+                                      int imageFormat,
+                                      int width,
+                                      int height,
+                                      int boundaryWidth,
+                                      int dataType,
+                                      Object data,
+                                      boolean useAutoMipMap) {
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int format = 0, internalFormat = 0;
         int type = GL2.GL_UNSIGNED_INT_8_8_8_8;
@@ -5692,12 +5977,11 @@
 
         if (useAutoMipMap) {
             gl.glTexParameteri(target, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE);
-        }
-        else {
+        } else {
             gl.glTexParameteri(target, GL2.GL_GENERATE_MIPMAP, GL.GL_FALSE);
         }
 
-        if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
+        if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_BUFFER)) {
 
             switch (imageFormat) {
@@ -5726,7 +6010,7 @@
                 case ImageComponentRetained.TYPE_BYTE_GRAY:
                     if (internalFormat == GL.GL_ALPHA) {
                         format = GL.GL_ALPHA;
-                    } else  {
+                    } else {
                         format = GL.GL_LUMINANCE;
                     }
                     break;
@@ -5739,18 +6023,18 @@
                     return;
             }
 
-            if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
+            if (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
 
                 gl.glTexImage2D(target, level, internalFormat,
                         width, height, boundaryWidth,
-                        format, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[])data));
+                        format, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[]) data));
             } else {
                 gl.glTexImage2D(target, level, internalFormat,
                         width, height, boundaryWidth,
                         format, GL.GL_UNSIGNED_BYTE, (Buffer) data);
             }
 
-        } else if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
+        } else if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_BUFFER)) {
 
             switch (imageFormat) {
@@ -5767,7 +6051,7 @@
                     format = GL2.GL_BGRA;
                     type = GL2.GL_UNSIGNED_INT_8_8_8_8_REV;
                     break;
-                    /* This method only supports 3 and 4 components formats and INT types. */
+                /* This method only supports 3 and 4 components formats and INT types. */
                 case ImageComponentRetained.TYPE_BYTE_LA:
                 case ImageComponentRetained.TYPE_BYTE_GRAY:
                 case ImageComponentRetained.TYPE_USHORT_GRAY:
@@ -5781,15 +6065,15 @@
             }
 
             /* Force Alpha to 1.0 if needed */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 0.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 1.0f);
             }
 
-            if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
+            if (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
                 gl.glTexImage2D(target, level, internalFormat,
                         width, height, boundaryWidth,
-                        format, type, IntBuffer.wrap((int[])data));
+                        format, type, IntBuffer.wrap((int[]) data));
             } else {
                 gl.glTexImage2D(target, level, internalFormat,
                         width, height, boundaryWidth,
@@ -5797,7 +6081,7 @@
             }
 
             /* Restore Alpha scale and bias */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 1.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 0.0f);
             }
@@ -5807,15 +6091,15 @@
     }
 
     private void updateTexture2DSubImage(Context ctx,
-            int target,
-            int level, int xoffset, int yoffset,
-            int textureFormat, int imageFormat,
-            int imgXOffset, int imgYOffset,
-            int tilew, int width, int height,
-            int dataType, Object data) {
-		GL2 gl = context(ctx).getGL().getGL2();
+                                         int target,
+                                         int level, int xoffset, int yoffset,
+                                         int textureFormat, int imageFormat,
+                                         int imgXOffset, int imgYOffset,
+                                         int tilew, int width, int height,
+                                         int dataType, Object data) {
+        GL2 gl = context(ctx).getGL().getGL2();
 
-        int format = 0, internalFormat=0;
+        int format = 0, internalFormat = 0;
         int numBytes = 0;
         int type = GL2.GL_UNSIGNED_INT_8_8_8_8;
         boolean forceAlphaToOne = false;
@@ -5849,7 +6133,7 @@
                 assert false;
         }
 
-        if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
+        if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_BUFFER)) {
 
             switch (imageFormat) {
@@ -5884,7 +6168,7 @@
                     if (internalFormat == GL.GL_ALPHA) {
                         format = GL.GL_ALPHA;
                         numBytes = 1;
-                    } else  {
+                    } else {
                         format = GL.GL_LUMINANCE;
                         numBytes = 1;
                     }
@@ -5899,10 +6183,9 @@
             }
 
             ByteBuffer buf = null;
-            if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
+            if (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
                 buf = ByteBuffer.wrap((byte[]) data);
-            }
-            else {
+            } else {
                 buf = (ByteBuffer) data;
             }
 
@@ -5911,7 +6194,7 @@
             gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height,
                     format, GL.GL_UNSIGNED_BYTE, buf);
 
-        } else if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
+        } else if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_BUFFER)) {
 
             switch (imageFormat) {
@@ -5928,7 +6211,7 @@
                     format = GL2.GL_BGRA;
                     type = GL2.GL_UNSIGNED_INT_8_8_8_8_REV;
                     break;
-                    /* This method only supports 3 and 4 components formats and INT types. */
+                /* This method only supports 3 and 4 components formats and INT types. */
                 case ImageComponentRetained.TYPE_BYTE_LA:
                 case ImageComponentRetained.TYPE_BYTE_GRAY:
                 case ImageComponentRetained.TYPE_USHORT_GRAY:
@@ -5941,16 +6224,15 @@
                     return;
             }
             /* Force Alpha to 1.0 if needed */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 0.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 1.0f);
             }
 
             IntBuffer buf = null;
-            if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
+            if (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
                 buf = IntBuffer.wrap((int[]) data);
-            }
-            else {
+            } else {
                 buf = (IntBuffer) data;
             }
 
@@ -5960,7 +6242,7 @@
                     format, type, buf);
 
             /* Restore Alpha scale and bias */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 1.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 0.0f);
             }
@@ -5976,9 +6258,9 @@
     }
 
     void updateTextureFilterModes(Context ctx,
-            int target,
-            int minFilter,
-            int magFilter) {
+                                  int target,
+                                  int minFilter,
+                                  int magFilter) {
         GL gl = context(ctx).getGL();
 
         if (EXTRA_DEBUGGING) {
@@ -6065,14 +6347,14 @@
     }
 
     void updateTextureBoundary(Context ctx,
-            int target,
-            int boundaryModeS,
-            int boundaryModeT,
-            int boundaryModeR,
-            float boundaryRed,
-            float boundaryGreen,
-            float boundaryBlue,
-            float boundaryAlpha) {
+                               int target,
+                               int boundaryModeS,
+                               int boundaryModeT,
+                               int boundaryModeR,
+                               float boundaryRed,
+                               float boundaryGreen,
+                               float boundaryBlue,
+                               float boundaryAlpha) {
         GL gl = context(ctx).getGL();
 
         // set texture wrap parameter
@@ -6148,43 +6430,10 @@
         }
     }
 
-    private static final String getFilterName(int filter) {
-        switch (filter) {
-            case Texture.FASTEST:
-                return "Texture.FASTEST";
-            case Texture.NICEST:
-                return "Texture.NICEST";
-            case Texture.BASE_LEVEL_POINT:
-                return "Texture.BASE_LEVEL_POINT";
-            case Texture.BASE_LEVEL_LINEAR:
-                return "Texture.BASE_LEVEL_LINEAR";
-            case Texture.MULTI_LEVEL_POINT:
-                return "Texture.MULTI_LEVEL_POINT";
-            case Texture.MULTI_LEVEL_LINEAR:
-                return "Texture.MULTI_LEVEL_LINEAR";
-            case Texture.FILTER4:
-                return "Texture.FILTER4";
-            case Texture.LINEAR_SHARPEN:
-                return "Texture.LINEAR_SHARPEN";
-            case Texture.LINEAR_SHARPEN_RGB:
-                return "Texture.LINEAR_SHARPEN_RGB";
-            case Texture.LINEAR_SHARPEN_ALPHA:
-                return "Texture.LINEAR_SHARPEN_ALPHA";
-            case Texture2D.LINEAR_DETAIL:
-                return "Texture.LINEAR_DETAIL";
-            case Texture2D.LINEAR_DETAIL_RGB:
-                return "Texture.LINEAR_DETAIL_RGB";
-            case Texture2D.LINEAR_DETAIL_ALPHA:
-                return "Texture.LINEAR_DETAIL_ALPHA";
-            default:
-                return "(unknown)";
-        }
-    }
-
     private void updateTextureSharpenFunc(Context ctx,
-            int target,
-            int numPts,
-            float[] pts) {
+                                          int target,
+                                          int numPts,
+                                          float[] pts) {
         // checking of the availability of sharpen texture functionality
         // is already done in shared code
 // FIXME: GL_SGIS_sharpen_texture
@@ -6193,9 +6442,9 @@
     }
 
     private void updateTextureFilter4Func(Context ctx,
-            int target,
-            int numPts,
-            float[] pts) {
+                                          int target,
+                                          int numPts,
+                                          float[] pts) {
         // checking of the availability of filter4 functionality
         // is already done in shared code
 // FIXME: GL_SGIS_texture_filter4
@@ -6204,22 +6453,6 @@
 //                numPts, pts, 0);
     }
 
-    // mapping from java enum to gl enum
-    private static final int[] _gl_textureCubeMapFace = {
-        GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
-        GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
-        GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
-        GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
-        GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
-        GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
-    };
-
-    // ---------------------------------------------------------------------
-
-    //
-    // MasterControl methods
-    //
-
     // Maximum lights supported by the native API
     @Override
     int getMaximumLights() {
@@ -6230,111 +6463,102 @@
         return 8;
     }
 
-
-    // ---------------------------------------------------------------------
-
-    //
-    // Canvas3D methods - native wrappers
-    //
-
     // Mac/JRE 7; called from Renderer when resizing is dedected
     // Implementation follows the approach in jogamp.opengl.GLDrawableHelper.resizeOffscreenDrawable(..)
     @Override
     void resizeOffscreenLayer(Canvas3D cv, int cvWidth, int cvHeight) {
-		if (!isOffscreenLayerSurfaceEnabled(cv))
-			return;
+        if (!isOffscreenLayerSurfaceEnabled(cv))
+            return;
+
+        JoglDrawable joglDrawable = (JoglDrawable) cv.drawable;
+        if (!hasFBObjectSizeChanged(joglDrawable, cvWidth, cvHeight))
+            return;
+
+        int newWidth = Math.max(1, cvWidth);
+        int newHeight = Math.max(1, cvHeight);
 
-		JoglDrawable joglDrawable = (JoglDrawable)cv.drawable;
-		if (!hasFBObjectSizeChanged(joglDrawable, cvWidth, cvHeight))
-			return;
-
-		int newWidth = Math.max(1, cvWidth);
-		int newHeight = Math.max(1, cvHeight);
-
-		GLDrawable glDrawble = joglDrawable.getGLDrawable();
-		GLContext glContext = context(cv.ctx);
-
-		// Assuming glContext != null
-
-		final NativeSurface surface = glDrawble.getNativeSurface();
-	    final ProxySurface proxySurface = (surface instanceof ProxySurface) ? (ProxySurface)surface : null;
-
-		final int lockRes = surface.lockSurface();
-
-		try {
-			// propagate new size - seems not relevant here
-			if (proxySurface != null) {
-				final UpstreamSurfaceHook ush = proxySurface.getUpstreamSurfaceHook();
-				if (ush instanceof UpstreamSurfaceHook.MutableSize) {
-					((UpstreamSurfaceHook.MutableSize)ush).setSurfaceSize(newWidth, newHeight);
-				}
-			}
+        GLDrawable glDrawble = joglDrawable.getGLDrawable();
+        GLContext glContext = context(cv.ctx);
+
+        // Assuming glContext != null
+
+        final NativeSurface surface = glDrawble.getNativeSurface();
+        final ProxySurface proxySurface = (surface instanceof ProxySurface) ? (ProxySurface) surface : null;
+
+        final int lockRes = surface.lockSurface();
+
+        try {
+            // propagate new size - seems not relevant here
+            if (proxySurface != null) {
+                final UpstreamSurfaceHook ush = proxySurface.getUpstreamSurfaceHook();
+                if (ush instanceof UpstreamSurfaceHook.MutableSize) {
+                    ((UpstreamSurfaceHook.MutableSize) ush).setSurfaceSize(newWidth, newHeight);
+                }
+            }
 			/*else if(DEBUG) { // we have to assume surface contains the new size already, hence size check @ bottom
 	              System.err.println("GLDrawableHelper.resizeOffscreenDrawable: Drawable's offscreen surface n.a. ProxySurface, but "+ns.getClass().getName()+": "+ns);
 			}*/
 
-			GL2 gl = glContext.getGL().getGL2();
+            GL2 gl = glContext.getGL().getGL2();
 
-			// FBO : should be the default case on Mac OS X
-			if (glDrawble instanceof GLFBODrawable) {
+            // FBO : should be the default case on Mac OS X
+            if (glDrawble instanceof GLFBODrawable) {
 
-				// Resize GLFBODrawable
-				// TODO msaa gets lost
+                // Resize GLFBODrawable
+                // TODO msaa gets lost
 //				((GLFBODrawable)glDrawble).resetSize(gl);
 
-				// Alternative: resize GL_BACK FBObject directly,
-				// if multisampled the FBO sink (GL_FRONT) will be resized before the swap is executed
-				int numSamples = ((GLFBODrawable)glDrawble).getChosenGLCapabilities().getNumSamples();
-				FBObject fboObjectBack = ((GLFBODrawable)glDrawble).getFBObject( GL.GL_BACK );
-				fboObjectBack.reset(gl, newWidth, newHeight, numSamples/*, false*/); // false = don't reset SamplingSinkFBO immediately
-				fboObjectBack.bind(gl);
-
-				// If double buffered without antialiasing the GL_FRONT FBObject
-				// will be resized by glDrawble after the next swap-call
-			}
-			// pbuffer - not tested because Mac OS X 10.7+ supports FBO
-			else {
-				// Create new GLDrawable (pbuffer) and update the coresponding GLContext
-
-				final GLContext currentContext = GLContext.getCurrent();
-				final GLDrawableFactory factory = glDrawble.getFactory();
-
-				// Ensure to sync GL command stream
-				if (currentContext != glContext) {
-					glContext.makeCurrent();
-				}
-	         	gl.glFinish();
-	         	glContext.release();
-
-	         	if (proxySurface != null) {
-	         		proxySurface.enableUpstreamSurfaceHookLifecycle(false);
-	         	}
-
-	         	try {
-	         		glDrawble.setRealized(false);
-	         		// New GLDrawable
-	         		glDrawble = factory.createGLDrawable(surface);
-	         		glDrawble.setRealized(true);
-
-	         		joglDrawable.setGLDrawable(glDrawble);
-	         	}
-	         	finally {
-	         		if (proxySurface != null) {
-	         			proxySurface.enableUpstreamSurfaceHookLifecycle(true);
-	         		}
-	         	}
-
-	         	glContext.setGLDrawable(glDrawble, true); // re-association
-
-	         	// make current last current context
-	         	if (currentContext != null) {
-	         		currentContext.makeCurrent();
-	         	}
-			}
-		}
-		finally {
-			surface.unlockSurface();
-		}
+                // Alternative: resize GL_BACK FBObject directly,
+                // if multisampled the FBO sink (GL_FRONT) will be resized before the swap is executed
+                int numSamples = ((GLFBODrawable) glDrawble).getChosenGLCapabilities().getNumSamples();
+                FBObject fboObjectBack = ((GLFBODrawable) glDrawble).getFBObject(GL.GL_BACK);
+                fboObjectBack.reset(gl, newWidth, newHeight, numSamples/*, false*/); // false = don't reset SamplingSinkFBO immediately
+                fboObjectBack.bind(gl);
+
+                // If double buffered without antialiasing the GL_FRONT FBObject
+                // will be resized by glDrawble after the next swap-call
+            }
+            // pbuffer - not tested because Mac OS X 10.7+ supports FBO
+            else {
+                // Create new GLDrawable (pbuffer) and update the coresponding GLContext
+
+                final GLContext currentContext = GLContext.getCurrent();
+                final GLDrawableFactory factory = glDrawble.getFactory();
+
+                // Ensure to sync GL command stream
+                if (currentContext != glContext) {
+                    glContext.makeCurrent();
+                }
+                gl.glFinish();
+                glContext.release();
+
+                if (proxySurface != null) {
+                    proxySurface.enableUpstreamSurfaceHookLifecycle(false);
+                }
+
+                try {
+                    glDrawble.setRealized(false);
+                    // New GLDrawable
+                    glDrawble = factory.createGLDrawable(surface);
+                    glDrawble.setRealized(true);
+
+                    joglDrawable.setGLDrawable(glDrawble);
+                } finally {
+                    if (proxySurface != null) {
+                        proxySurface.enableUpstreamSurfaceHookLifecycle(true);
+                    }
+                }
+
+                glContext.setGLDrawable(glDrawble, true); // re-association
+
+                // make current last current context
+                if (currentContext != null) {
+                    currentContext.makeCurrent();
+                }
+            }
+        } finally {
+            surface.unlockSurface();
+        }
     }
 
     // Fix for Bug 983
@@ -6350,7 +6574,7 @@
             if (appContextClass.getMethod("getAppContext").invoke(null) == null) {
                 final Field field = appContextClass.getDeclaredField("threadGroup2appContext");
                 field.setAccessible(true);
-                final Map threadGroup2appContext = (Map)field.get(null);
+                final Map threadGroup2appContext = (Map) field.get(null);
                 final ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
                 threadGroup2appContext.put(currentThreadGroup, mainThreadContext);
             }
@@ -6364,41 +6588,39 @@
     // This is the native method for creating the underlying graphics context.
     @Override
     Context createNewContext(Canvas3D cv, Drawable drawable,
-            Context shareCtx, boolean isSharedCtx,
-            boolean offScreen) {
+                             Context shareCtx, boolean isSharedCtx,
+                             boolean offScreen) {
         if (VERBOSE) System.err.println("JoglPipeline.createNewContext()");
 
         checkAppContext();
-	    GLDrawable	glDrawable 	= null;
-	    GLContext 	glContext	= null;
+        GLDrawable glDrawable = null;
+        GLContext glContext = null;
 
-	    if (offScreen) {
-	    	glDrawable = drawable(cv.drawable); // cv.drawable != null, set in 'createOffScreenBuffer'
-			glContext = glDrawable.createContext(context(shareCtx));
-        }
-	    else {
-	    	// determined in 'getBestConfiguration'
-			GraphicsConfigInfo gcInf0 = Canvas3D.graphicsConfigTable.get(cv.graphicsConfiguration);
-			AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration)gcInf0.getPrivateData();
-
-		    // JAWTWindow
-			JAWTWindow nativeWindow = (JAWTWindow)NativeWindowFactory.getNativeWindow(cv, awtConfig);
-			nativeWindow.lockSurface();
-		    try {
-	    		glDrawable = GLDrawableFactory.getFactory(profile).createGLDrawable(nativeWindow);
-	    		glContext = glDrawable.createContext(context(shareCtx));
-		    }
-		    finally {
-		    	nativeWindow.unlockSurface();
-		    }
+        if (offScreen) {
+            glDrawable = drawable(cv.drawable); // cv.drawable != null, set in 'createOffScreenBuffer'
+            glContext = glDrawable.createContext(context(shareCtx));
+        } else {
+            // determined in 'getBestConfiguration'
+            GraphicsConfigInfo gcInf0 = Canvas3D.graphicsConfigTable.get(cv.graphicsConfiguration);
+            AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration) gcInf0.getPrivateData();
+
+            // JAWTWindow
+            JAWTWindow nativeWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(cv, awtConfig);
+            nativeWindow.lockSurface();
+            try {
+                glDrawable = GLDrawableFactory.getFactory(profile).createGLDrawable(nativeWindow);
+                glContext = glDrawable.createContext(context(shareCtx));
+            } finally {
+                nativeWindow.unlockSurface();
+            }
 
-	    	cv.drawable = new JoglDrawable(glDrawable, nativeWindow);
+            cv.drawable = new JoglDrawable(glDrawable, nativeWindow);
         }
 
         // assuming that this only gets called after addNotify has been called
-    	glDrawable.setRealized(true);
+        glDrawable.setRealized(true);
 
-    	// Apparently we are supposed to make the context current at this point
+        // Apparently we are supposed to make the context current at this point
         // and set up a bunch of properties
 
         // Work around for some low end graphics driver bug, such as Intel Chipset.
@@ -6415,8 +6637,7 @@
                 ++failCount;
                 try {
                     Thread.sleep(100);
-                }
-                catch (InterruptedException e) {
+                } catch (InterruptedException e) {
                 }
             }
         } while (failed && (failCount < MAX_FAIL_COUNT));
@@ -6434,7 +6655,7 @@
                 throw new IllegalRenderingStateException("Unable to fetch properties from current OpenGL context");
             }
 
-            if(!isSharedCtx){
+            if (!isSharedCtx) {
                 // Set up fields in Canvas3D
                 setupCanvasProperties(cv, ctx, gl);
             }
@@ -6466,41 +6687,39 @@
             // Mac OS X / JRE 7 : onscreen rendering = offscreen rendering
             // bind FBO
             if (!offScreen && glDrawable instanceof GLFBODrawable) {
-            	GLFBODrawable fboDrawable = (GLFBODrawable)glDrawable;
-            	// bind GLFBODrawable's drawing FBObject
-            	// GL_BACK returns the correct FBOObject for single/double buffering, incl. multisampling
-            	fboDrawable.getFBObject( GL.GL_BACK ).bind(gl);
+                GLFBODrawable fboDrawable = (GLFBODrawable) glDrawable;
+                // bind GLFBODrawable's drawing FBObject
+                // GL_BACK returns the correct FBOObject for single/double buffering, incl. multisampling
+                fboDrawable.getFBObject(GL.GL_BACK).bind(gl);
             }
 
 
             // FBO or pbuffer
             if (offScreen) {
 
-            	// Final caps
-            	GLCapabilitiesImmutable chosenCaps = glDrawable.getChosenGLCapabilities();
+                // Final caps
+                GLCapabilitiesImmutable chosenCaps = glDrawable.getChosenGLCapabilities();
 
-            	// FBO
-            	if (glDrawable instanceof GLFBODrawable) {
-                	GLFBODrawable fboDrawable = (GLFBODrawable)glDrawable;
-                	// bind GLFBODrawable's drawing FBObject
-                	// GL_BACK returns the correct FBOObject for single/double buffering, incl. multisampling
-                	fboDrawable.getFBObject( GL.GL_BACK ).bind(gl);
-            	}
-            	// pbuffer
-            	else {
-	            	// Double buffering: read from back buffer, as we don't swap
-					// Even this setting is identical to the initially mode it is set explicitly
-					if (chosenCaps.getDoubleBuffered()) {
-						gl.glReadBuffer(GL.GL_BACK);
-					}
-					else {
-						gl.glReadBuffer(GL.GL_FRONT);
-					}
-            	}
+                // FBO
+                if (glDrawable instanceof GLFBODrawable) {
+                    GLFBODrawable fboDrawable = (GLFBODrawable) glDrawable;
+                    // bind GLFBODrawable's drawing FBObject
+                    // GL_BACK returns the correct FBOObject for single/double buffering, incl. multisampling
+                    fboDrawable.getFBObject(GL.GL_BACK).bind(gl);
+                }
+                // pbuffer
+                else {
+                    // Double buffering: read from back buffer, as we don't swap
+                    // Even this setting is identical to the initially mode it is set explicitly
+                    if (chosenCaps.getDoubleBuffered()) {
+                        gl.glReadBuffer(GL.GL_BACK);
+                    } else {
+                        gl.glReadBuffer(GL.GL_FRONT);
+                    }
+                }
             }
-        }
-        finally {
- 			glContext.release();
+        } finally {
+            glContext.release();
         }
 
         return ctx;
@@ -6508,20 +6727,20 @@
 
     @Override
     void createQueryContext(Canvas3D cv, Drawable drawable,
-            boolean offScreen, int width, int height) {
+                            boolean offScreen, int width, int height) {
         if (VERBOSE) System.err.println("JoglPipeline.createQueryContext()");
 
         // Assumes createQueryContext is never called for a drawable != null
 
         if (offScreen) {
 
-         	Drawable offDrawable = createOffScreenBuffer(cv, null, width, height);
+            Drawable offDrawable = createOffScreenBuffer(cv, null, width, height);
 
-         	GLDrawable glDrawable = drawable(offDrawable);
+            GLDrawable glDrawable = drawable(offDrawable);
 
-        	glDrawable.setRealized(true);
+            glDrawable.setRealized(true);
 
-    		GLContext glContext = glDrawable.createContext(null);
+            GLContext glContext = glDrawable.createContext(null);
             glContext.makeCurrent();
 
             JoglContext ctx = new JoglContext(glContext);
@@ -6536,44 +6755,42 @@
             // Done !
 
             glContext.release();
-    		glContext.destroy();
-    		glDrawable.setRealized(false);
-    	}
-        else {
-
-        	// TODO can't find an implementation which avoids the use of QueryCanvas
-        	// JOGL requires a visible Frame for an onscreen context
-
-        Frame f = new Frame();
-        f.setUndecorated(true);
-        f.setLayout(new BorderLayout());
-
-        ContextQuerier querier = new ContextQuerier(cv);
-
-		    AWTGraphicsConfiguration awtConfig =
-		    		(AWTGraphicsConfiguration)Canvas3D.graphicsConfigTable.get(cv.graphicsConfiguration).getPrivateData();
-
-		    QueryCanvas canvas = new QueryCanvas(awtConfig, querier);
-
-        f.add(canvas, BorderLayout.CENTER);
-        f.setSize(MIN_FRAME_SIZE, MIN_FRAME_SIZE);
-        f.setVisible(true);
-        canvas.doQuery();
-        // Attempt to wait for the frame to become visible, but don't block the EDT
-        if (!EventQueue.isDispatchThread()) {
-            synchronized(querier) {
-                if (!querier.done()) {
-                    try {
-                        querier.wait(WAIT_TIME);
-	                    }
-	                    catch (InterruptedException e) {
+            //glContext.destroy();
+            glDrawable.setRealized(false);
+        } else {
+
+            // TODO can't find an implementation which avoids the use of QueryCanvas
+            // JOGL requires a visible Frame for an onscreen context
+
+            Frame f = new Frame();
+            f.setUndecorated(true);
+            f.setLayout(new BorderLayout());
+
+            ContextQuerier querier = new ContextQuerier(cv);
+
+            AWTGraphicsConfiguration awtConfig =
+                    (AWTGraphicsConfiguration) Canvas3D.graphicsConfigTable.get(cv.graphicsConfiguration).getPrivateData();
+
+            QueryCanvas canvas = new QueryCanvas(awtConfig, querier);
+
+            f.add(canvas, BorderLayout.CENTER);
+            f.setSize(MIN_FRAME_SIZE, MIN_FRAME_SIZE);
+            f.setVisible(true);
+            canvas.doQuery();
+            // Attempt to wait for the frame to become visible, but don't block the EDT
+            if (!EventQueue.isDispatchThread()) {
+                synchronized (querier) {
+                    if (!querier.done()) {
+                        try {
+                            querier.wait(WAIT_TIME);
+                        } catch (InterruptedException e) {
+                        }
                     }
                 }
             }
-        }
 
-        disposeOnEDT(f);
-    }
+            disposeOnEDT(f);
+        }
     }
 
     // This is the native for creating an offscreen buffer
@@ -6584,36 +6801,36 @@
         // ctx unused, doesn't exist yet
 
         // Offscreen Canvas3D's JoglGraphicsConfiguration
-        JoglGraphicsConfiguration jgc = (JoglGraphicsConfiguration)cv.graphicsConfiguration;
+        JoglGraphicsConfiguration jgc = (JoglGraphicsConfiguration) cv.graphicsConfiguration;
 
         // Retrieve the offscreen Canvas3D's GraphicsConfigInfo
-		GraphicsConfigInfo gcInf0 = Canvas3D.graphicsConfigTable.get(jgc);
+        GraphicsConfigInfo gcInf0 = Canvas3D.graphicsConfigTable.get(jgc);
 
-		// Offscreen Canvas3D's graphics configuration, determined in 'getBestConfiguration'
-		AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration)gcInf0.getPrivateData();
+        // Offscreen Canvas3D's graphics configuration, determined in 'getBestConfiguration'
+        AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration) gcInf0.getPrivateData();
 
-		// TODO Offscreen Canvas3D's graphics devise, determined in 'getBestConfiguration'
-		//AbstractGraphicsDevice device = awtConfig.getScreen().getDevice();			// throws exception
-		// Alternative: default graphics device
+        // TODO Offscreen Canvas3D's graphics devise, determined in 'getBestConfiguration'
+        //AbstractGraphicsDevice device = awtConfig.getScreen().getDevice();			// throws exception
+        // Alternative: default graphics device
         AbstractGraphicsDevice device = GLDrawableFactory.getDesktopFactory().getDefaultDevice();
 
-		// Offscreen Canvas3D's capabilites, determined in 'getBestConfiguration'
-		GLCapabilities canvasCaps = (GLCapabilities)awtConfig.getChosenCapabilities();
+        // Offscreen Canvas3D's capabilites, determined in 'getBestConfiguration'
+        GLCapabilities canvasCaps = (GLCapabilities) awtConfig.getChosenCapabilities();
 
-		// For further investigations : the user's GraphicsConfigTemplate3D (not used yet)
-		GraphicsConfigTemplate3D gct3D = gcInf0.getGraphicsConfigTemplate3D();
+        // For further investigations : the user's GraphicsConfigTemplate3D (not used yet)
+        GraphicsConfigTemplate3D gct3D = gcInf0.getGraphicsConfigTemplate3D();
 
 
         // Assuming that the offscreen drawable will/can support the chosen GLCapabilities
-    	// of the offscreen Canvas3D
+        // of the offscreen Canvas3D
 
         final GLCapabilities offCaps = new GLCapabilities(profile);
         offCaps.copyFrom(canvasCaps);
 
         // double bufffering only if scene antialiasing is required/preferred and supported
         if (offCaps.getSampleBuffers() == false) {
-        	offCaps.setDoubleBuffered(false);
-        	offCaps.setNumSamples(0);
+            offCaps.setDoubleBuffered(false);
+            offCaps.setNumSamples(0);
         }
 
         // Never stereo
@@ -6621,11 +6838,11 @@
 
         // Set preferred offscreen drawable : framebuffer object (FBO) or pbuffer
         offCaps.setFBO(true); // switches to pbuffer if FBO is not supported
-		// caps.setPBuffer(true);
+        // caps.setPBuffer(true);
 
-		// !! a 'null' capability chooser; JOGL doesn't call a chooser for offscreen drawable
+        // !! a 'null' capability chooser; JOGL doesn't call a chooser for offscreen drawable
 
-		// If FBO : 'offDrawable' is of type com.jogamp.opengl.GLFBODrawable
+        // If FBO : 'offDrawable' is of type com.jogamp.opengl.GLFBODrawable
         GLDrawable offDrawable = GLDrawableFactory.getFactory(profile).createOffscreenDrawable(device, offCaps, null, width, height);
 
 // !! these chosen caps are not final as long as the corresponding context is made current
@@ -6647,30 +6864,30 @@
     void readOffScreenBuffer(Canvas3D cv, Context ctx, int format, int dataType, Object data, int width, int height) {
         if (VERBOSE) System.err.println("JoglPipeline.readOffScreenBuffer()");
 
-    	GLDrawable 				glDrawable  = ((JoglDrawable)cv.drawable).getGLDrawable();
-        GLCapabilitiesImmutable chosenCaps  = glDrawable.getChosenGLCapabilities();
-        GLFBODrawable 			fboDrawable = null;
+        GLDrawable glDrawable = ((JoglDrawable) cv.drawable).getGLDrawable();
+        GLCapabilitiesImmutable chosenCaps = glDrawable.getChosenGLCapabilities();
+        GLFBODrawable fboDrawable = null;
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         // If FBO
         if (chosenCaps.isFBO()) {
 
-        	fboDrawable = (GLFBODrawable)glDrawable;
+            fboDrawable = (GLFBODrawable) glDrawable;
+
+            if (chosenCaps.getDoubleBuffered()) {
+                // swap = resolve multisampling or flip back/front FBO
+                fboDrawable.swapBuffers();
+                // unbind texture render target, we read from FBO
+                gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
+            }
 
-        	if (chosenCaps.getDoubleBuffered()) {
-	        	// swap = resolve multisampling or flip back/front FBO
-	        	fboDrawable.swapBuffers();
-	        	// unbind texture render target, we read from FBO
-	        	gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
-        	}
-
-        	// bind FBO for reading pixel data
-        	// GL_FRONT = SamplingSinkFBO if double buffered and multisampled
-        	// GL_FRONT if double buffered ( = GL_BAck before swap was called)
-        	// GL_FRONT = GL_BACK if single buffered (single FBO)
+            // bind FBO for reading pixel data
+            // GL_FRONT = SamplingSinkFBO if double buffered and multisampled
+            // GL_FRONT if double buffered ( = GL_BAck before swap was called)
+            // GL_FRONT = GL_BACK if single buffered (single FBO)
 
-        	fboDrawable.getFBObject( GL.GL_FRONT ).bind(gl);
+            fboDrawable.getFBObject(GL.GL_FRONT).bind(gl);
         }
         // else pbuffer
 
@@ -6679,7 +6896,7 @@
 
         int type = 0;
 
-        if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
+        if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_BUFFER)) {
 
             switch (format) {
@@ -6690,7 +6907,7 @@
                 case ImageComponentRetained.TYPE_BYTE_RGB:
                     type = GL.GL_RGB;
                     break;
-                    // GL_ABGR_EXT
+                // GL_ABGR_EXT
                 case ImageComponentRetained.TYPE_BYTE_ABGR:
                     if (gl.isExtensionAvailable("GL_EXT_abgr")) { // If false, should never come here!
                         type = GL2.GL_ABGR_EXT;
@@ -6703,7 +6920,7 @@
                     type = GL.GL_RGBA;
                     break;
 
-                    /* This method only supports 3 and 4 components formats and BYTE types. */
+                /* This method only supports 3 and 4 components formats and BYTE types. */
                 case ImageComponentRetained.TYPE_BYTE_LA:
                 case ImageComponentRetained.TYPE_BYTE_GRAY:
                 case ImageComponentRetained.TYPE_USHORT_GRAY:
@@ -6716,8 +6933,7 @@
 
             gl.glReadPixels(0, 0, width, height, type, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[]) data));
 
-        }
-        else if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
+        } else if ((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
                 (dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_BUFFER)) {
 
             int intType = GL2.GL_UNSIGNED_INT_8_8_8_8;
@@ -6737,7 +6953,7 @@
                     type = GL2.GL_BGRA;
                     intType = GL2.GL_UNSIGNED_INT_8_8_8_8_REV;
                     break;
-                    /* This method only supports 3 and 4 components formats and BYTE types. */
+                /* This method only supports 3 and 4 components formats and BYTE types. */
                 case ImageComponentRetained.TYPE_BYTE_LA:
                 case ImageComponentRetained.TYPE_BYTE_GRAY:
                 case ImageComponentRetained.TYPE_USHORT_GRAY:
@@ -6750,46 +6966,45 @@
             }
 
             /* Force Alpha to 1.0 if needed */
-            if(forceAlphaToOne) {
+            if (forceAlphaToOne) {
                 gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 0.0f);
                 gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 1.0f);
             }
 
             gl.glReadPixels(0, 0, width, height, type, intType, IntBuffer.wrap((int[]) data));
 
-	    /* Restore Alpha scale and bias */
-	    if(forceAlphaToOne) {
-		gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 1.0f);
-		gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 0.0f);
-	    }
-        }
-        else {
+            /* Restore Alpha scale and bias */
+            if (forceAlphaToOne) {
+                gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 1.0f);
+                gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 0.0f);
+            }
+        } else {
             throw new AssertionError("illegal image data type " + dataType);
         }
 
         // If FBO
         if (chosenCaps.isFBO()) {
-        	// bind FBO for drawing
-        	fboDrawable.getFBObject( GL.GL_BACK ).bind(gl);
+            // bind FBO for drawing
+            fboDrawable.getFBObject(GL.GL_BACK).bind(gl);
         }
     }
 
-	// The native method for swapBuffers - onscreen only
-@Override
-void swapBuffers(Canvas3D cv, Context ctx, Drawable drawable) {
-	if (VERBOSE) System.err.println("JoglPipeline.swapBuffers()");
-	GLDrawable draw = drawable(drawable);
-	draw.swapBuffers();
-}
+    // The native method for swapBuffers - onscreen only
+    @Override
+    void swapBuffers(Canvas3D cv, Context ctx, Drawable drawable) {
+        if (VERBOSE) System.err.println("JoglPipeline.swapBuffers()");
+        GLDrawable draw = drawable(drawable);
+        draw.swapBuffers();
+    }
 
     // native method for setting Material when no material is present
     @Override
     void updateMaterialColor(Context ctx, float r, float g, float b, float a) {
         if (VERBOSE) System.err.println("JoglPipeline.updateMaterialColor()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
-		// FIXME: Removed call to glColor4f because of segfault issues in Parallels Desktop driver
-		// gl.glColor4f(r, g, b, a);
+        GL2 gl = context(ctx).getGL().getGL2();
+        // FIXME: Removed call to glColor4f because of segfault issues in Parallels Desktop driver
+        // gl.glColor4f(r, g, b, a);
         gl.glDisable(GL2.GL_LIGHTING);
     }
 
@@ -6797,13 +7012,13 @@
     void destroyContext(Drawable drawable, Context ctx) {
         if (VERBOSE) System.err.println("JoglPipeline.destroyContext()");
 
-        JoglDrawable joglDrawable =	(JoglDrawable)drawable;
-        GLContext  context  = context(ctx);
+        JoglDrawable joglDrawable = (JoglDrawable) drawable;
+        GLContext context = context(ctx);
 
         if (GLContext.getCurrent() == context) {
             context.release();
         }
-        context.destroy();
+        //context.destroy();
 
         // assuming this is the right point at which to make this call
         joglDrawable.getGLDrawable().setRealized(false);
@@ -6816,7 +7031,7 @@
     void accum(Context ctx, float value) {
         if (VERBOSE) System.err.println("JoglPipeline.accum()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glReadBuffer(GL.GL_BACK);
         gl.glAccum(GL2.GL_ACCUM, value);
         gl.glReadBuffer(GL.GL_FRONT);
@@ -6827,7 +7042,7 @@
     void accumReturn(Context ctx) {
         if (VERBOSE) System.err.println("JoglPipeline.accumReturn()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glAccum(GL2.GL_RETURN, 1.0f);
     }
 
@@ -6896,7 +7111,7 @@
     void ctxUpdateEyeLightingEnable(Context ctx, boolean localEyeLightingEnable) {
         if (VERBOSE) System.err.println("JoglPipeline.ctxUpdateEyeLightingEnable()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         if (localEyeLightingEnable) {
             gl.glLightModeli(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, GL.GL_TRUE);
@@ -6905,15 +7120,13 @@
         }
     }
 
-    // The following three methods are used in multi-pass case
-
     // native method for setting blend color
     @Override
     void setBlendColor(Context ctx, float red, float green,
-            float blue, float alpha) {
+                       float blue, float alpha) {
         if (VERBOSE) System.err.println("JoglPipeline.setBlendColor()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         if (gl.isExtensionAvailable("GL_ARB_imaging")) {
             gl.glBlendColor(red, green, blue, alpha);
         }
@@ -6964,7 +7177,7 @@
     void updateSeparateSpecularColorEnable(Context ctx, boolean enable) {
         if (VERBOSE) System.err.println("JoglPipeline.updateSeparateSpecularColorEnable()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         if (enable) {
             gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR);
@@ -7015,7 +7228,7 @@
     void setSceneAmbient(Context ctx, float red, float green, float blue) {
         if (VERBOSE) System.err.println("JoglPipeline.setSceneAmbient()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         float[] color = new float[4];
         color[0] = red;
@@ -7052,11 +7265,11 @@
     // native method for setting default RenderingAttributes
     @Override
     void resetRenderingAttributes(Context ctx,
-            boolean depthBufferWriteEnableOverride,
-            boolean depthBufferEnableOverride) {
+                                  boolean depthBufferWriteEnableOverride,
+                                  boolean depthBufferEnableOverride) {
         if (VERBOSE) System.err.println("JoglPipeline.resetRenderingAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         if (!depthBufferWriteEnableOverride) {
             gl.glDepthMask(true);
@@ -7069,7 +7282,7 @@
         gl.glEnable(GL2.GL_COLOR_MATERIAL);
         gl.glDisable(GL.GL_COLOR_LOGIC_OP);
         gl.glDisable(GL.GL_STENCIL_TEST);
-       
+
     }
 
     // native method for setting default texture
@@ -7077,7 +7290,7 @@
     void resetTextureNative(Context ctx, int texUnitIndex) {
         if (VERBOSE) System.err.println("JoglPipeline.resetTextureNative()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         if (texUnitIndex >= 0 &&
                 gl.isExtensionAvailable("GL_VERSION_1_3")) {
             gl.glActiveTexture(texUnitIndex + GL.GL_TEXTURE0);
@@ -7095,7 +7308,7 @@
     void activeTextureUnit(Context ctx, int texUnitIndex) {
         if (VERBOSE) System.err.println("JoglPipeline.activeTextureUnit()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         if (gl.isExtensionAvailable("GL_VERSION_1_3")) {
             gl.glActiveTexture(texUnitIndex + GL.GL_TEXTURE0);
             gl.glClientActiveTexture(texUnitIndex + GL.GL_TEXTURE0);
@@ -7114,12 +7327,16 @@
         gl.glDisable(GL2.GL_TEXTURE_GEN_Q);
     }
 
+    //----------------------------------------------------------------------
+    // Helper private functions for Canvas3D
+    //
+
     // native method for setting default TextureAttributes
     @Override
     void resetTextureAttributes(Context ctx) {
         if (VERBOSE) System.err.println("JoglPipeline.resetTextureAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         float[] color = new float[4];
 
@@ -7147,7 +7364,7 @@
     void resetPolygonAttributes(Context ctx) {
         if (VERBOSE) System.err.println("JoglPipeline.resetPolygonAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         gl.glCullFace(GL.GL_BACK);
         gl.glEnable(GL.GL_CULL_FACE);
@@ -7162,6 +7379,20 @@
         gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
     }
 
+// FIXME: GL_SGI_texture_color_table
+//    private int getTextureColorTableSize(GL gl) {
+//        if (!gl.isExtensionAvailable("GL_ARB_imaging")) {
+//            return 0;
+//        }
+//
+//        gl.glColorTable(GL.GL_PROXY_TEXTURE_COLOR_TABLE_SGI, GL.GL_RGBA, 256, GL.GL_RGB,
+//                GL2.GL_INT, null);
+//        int[] tmp = new int[1];
+//        gl.glGetColorTableParameteriv(GL.GL_PROXY_TEXTURE_COLOR_TABLE_SGI,
+//                GL2.GL_COLOR_TABLE_WIDTH, tmp, 0);
+//        return tmp[0];
+//    }
+
     // native method for setting default LineAttributes
     @Override
     void resetLineAttributes(Context ctx) {
@@ -7180,7 +7411,7 @@
     void resetPointAttributes(Context ctx) {
         if (VERBOSE) System.err.println("JoglPipeline.resetPointAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glPointSize(1.0f);
 
         // XXXX: Polygon Mode check, blend enable
@@ -7190,8 +7421,8 @@
     // native method for setting default TransparencyAttributes
     @Override
     void resetTransparency(Context ctx, int geometryType,
-            int polygonMode, boolean lineAA,
-            boolean pointAA) {
+                           int polygonMode, boolean lineAA,
+                           boolean pointAA) {
         if (VERBOSE) System.err.println("JoglPipeline.resetTransparency()");
 
         GL gl = context(ctx).getGL();
@@ -7200,8 +7431,8 @@
                 (polygonMode == PolygonAttributes.POLYGON_LINE))
                 && lineAA) ||
                 ((((geometryType & RenderMolecule.POINT) != 0) ||
-                (polygonMode == PolygonAttributes.POLYGON_POINT))
-                && pointAA)) {
+                        (polygonMode == PolygonAttributes.POLYGON_POINT))
+                        && pointAA)) {
             gl.glEnable(GL.GL_BLEND);
             gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
         } else {
@@ -7213,23 +7444,23 @@
     // native method for setting default ColoringAttributes
     @Override
     void resetColoringAttributes(Context ctx,
-            float r, float g,
-            float b, float a,
-            boolean enableLight) {
+                                 float r, float g,
+                                 float b, float a,
+                                 boolean enableLight) {
         if (VERBOSE) System.err.println("JoglPipeline.resetColoringAttributes()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
-		if (!enableLight) {
-			// FIXME: Removed call to glColor4f because of segfault issues in Parallels Desktop driver
-			// gl.glColor4f(r, g, b, a);
-		}
+        if (!enableLight) {
+            // FIXME: Removed call to glColor4f because of segfault issues in Parallels Desktop driver
+            // gl.glColor4f(r, g, b, a);
+        }
         gl.glShadeModel(GL2.GL_SMOOTH);
     }
 
     /**
-     *  This native method makes sure that the rendering for this canvas
-     *  gets done now.
+     * This native method makes sure that the rendering for this canvas
+     * gets done now.
      */
     @Override
     void syncRender(Context ctx, boolean wait) {
@@ -7252,6 +7483,13 @@
         return (res != GLContext.CONTEXT_NOT_CURRENT);
     }
 
+    // ---------------------------------------------------------------------
+
+    //
+    // Canvas3D / GraphicsConfigTemplate3D methods - logic dealing with
+    // native graphics configuration or drawing surface
+    //
+
     // Optionally release the context. Returns true if the context was released.
     @Override
     boolean releaseCtx(Context ctx) {
@@ -7267,7 +7505,7 @@
 
         JoglContext jctx = (JoglContext) ctx;
         GLContext context = context(ctx);
-		GL2 gl = context.getGL().getGL2();
+        GL2 gl = context.getGL().getGL2();
 
         // OBSOLETE CLEAR CODE
         /*
@@ -7313,11 +7551,11 @@
 
     @Override
     void textureFillBackground(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV,
-            float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, boolean useBilinearFilter)  {
+                               float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, boolean useBilinearFilter) {
         if (VERBOSE) System.err.println("JoglPipeline.textureFillBackground()");
 
         GLContext context = context(ctx);
-		GL2 gl = context.getGL().getGL2();
+        GL2 gl = context.getGL().getGL2();
 
         // Temporarily disable fragment and most 3D operations
         gl.glPushAttrib(GL2.GL_ENABLE_BIT | GL2.GL_TEXTURE_BIT | GL2.GL_POLYGON_BIT);
@@ -7327,7 +7565,7 @@
         gl.glEnable(GL.GL_TEXTURE_2D);
 
         /* Setup filter mode if needed */
-        if(useBilinearFilter) {
+        if (useBilinearFilter) {
             // System.err.println("JoglPipeline - Background  : use bilinear filter\n");
             gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
             gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
@@ -7349,10 +7587,14 @@
         gl.glLoadIdentity();
 
         gl.glBegin(GL2.GL_QUADS);
-        gl.glTexCoord2f(texMinU, texMinV); gl.glVertex2f(mapMinX,mapMinY);
-        gl.glTexCoord2f(texMaxU, texMinV); gl.glVertex2f(mapMaxX,mapMinY);
-        gl.glTexCoord2f(texMaxU, texMaxV); gl.glVertex2f(mapMaxX,mapMaxY);
-        gl.glTexCoord2f(texMinU, texMaxV); gl.glVertex2f(mapMinX,mapMaxY);
+        gl.glTexCoord2f(texMinU, texMinV);
+        gl.glVertex2f(mapMinX, mapMinY);
+        gl.glTexCoord2f(texMaxU, texMinV);
+        gl.glVertex2f(mapMaxX, mapMinY);
+        gl.glTexCoord2f(texMaxU, texMaxV);
+        gl.glVertex2f(mapMaxX, mapMaxY);
+        gl.glTexCoord2f(texMinU, texMaxV);
+        gl.glVertex2f(mapMinX, mapMaxY);
         gl.glEnd();
 
         // Restore texture Matrix transform
@@ -7366,22 +7608,22 @@
 
     @Override
     void textureFillRaster(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV,
-            float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, float mapZ, float alpha,
-            boolean useBilinearFilter)  {
+                           float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, float mapZ, float alpha,
+                           boolean useBilinearFilter) {
 
         if (VERBOSE) System.err.println("JoglPipeline.textureFillRaster()");
 
         GLContext context = context(ctx);
-		GL2 gl = context.getGL().getGL2();
+        GL2 gl = context.getGL().getGL2();
 
         // Temporarily disable fragment and most 3D operations
         gl.glPushAttrib(GL2.GL_ENABLE_BIT | GL2.GL_TEXTURE_BIT | GL2.GL_POLYGON_BIT |
-                GL2.GL_CURRENT_BIT );
+                GL2.GL_CURRENT_BIT);
 
         disableAttribForRaster(gl);
 
         /* Setup filter mode if needed */
-        if(useBilinearFilter) {
+        if (useBilinearFilter) {
             // System.err.println("JoglPipeline - Raster  : use bilinear filter\n");
             gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
             gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
@@ -7405,10 +7647,14 @@
         gl.glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
 
         gl.glBegin(GL2.GL_QUADS);
-        gl.glTexCoord2f(texMinU, texMinV); gl.glVertex3f(mapMinX,mapMinY, mapZ);
-        gl.glTexCoord2f(texMaxU, texMinV); gl.glVertex3f(mapMaxX,mapMinY, mapZ);
-        gl.glTexCoord2f(texMaxU, texMaxV); gl.glVertex3f(mapMaxX,mapMaxY, mapZ);
-        gl.glTexCoord2f(texMinU, texMaxV); gl.glVertex3f(mapMinX,mapMaxY, mapZ);
+        gl.glTexCoord2f(texMinU, texMinV);
+        gl.glVertex3f(mapMinX, mapMinY, mapZ);
+        gl.glTexCoord2f(texMaxU, texMinV);
+        gl.glVertex3f(mapMaxX, mapMinY, mapZ);
+        gl.glTexCoord2f(texMaxU, texMaxV);
+        gl.glVertex3f(mapMaxX, mapMaxY, mapZ);
+        gl.glTexCoord2f(texMinU, texMaxV);
+        gl.glVertex3f(mapMinX, mapMaxY, mapZ);
         gl.glEnd();
 
         // Restore matrices
@@ -7422,11 +7668,11 @@
 
     @Override
     void executeRasterDepth(Context ctx, float posX, float posY, float posZ,
-            int srcOffsetX, int srcOffsetY, int rasterWidth, int rasterHeight,
-            int depthWidth, int depthHeight, int depthFormat, Object depthData) {
+                            int srcOffsetX, int srcOffsetY, int rasterWidth, int rasterHeight,
+                            int depthWidth, int depthHeight, int depthFormat, Object depthData) {
         if (VERBOSE) System.err.println("JoglPipeline.executeRasterDepth()");
         GLContext context = context(ctx);
-		GL2 gl = context.getGL().getGL2();
+        GL2 gl = context.getGL().getGL2();
 
 
         gl.glRasterPos3f(posX, posY, posZ);
@@ -7450,7 +7696,7 @@
         } else {
             rasterWidth += srcOffsetX;
             if (rasterWidth > depthWidth) {
-                rasterWidth  = depthWidth;
+                rasterWidth = depthWidth;
             }
         }
         if (srcOffsetY >= 0) {
@@ -7459,10 +7705,10 @@
                 rasterHeight = depthHeight - srcOffsetY;
             }
         } else {
-			rasterHeight += srcOffsetY;
-			if (rasterHeight > depthHeight) {
-				rasterHeight = depthHeight;
-			}
+            rasterHeight += srcOffsetY;
+            if (rasterHeight > depthHeight) {
+                rasterHeight = depthHeight;
+            }
         }
 
 
@@ -7488,7 +7734,7 @@
     void setModelViewMatrix(Context ctx, double[] viewMatrix, double[] modelMatrix) {
         if (VERBOSE) System.err.println("JoglPipeline.setModelViewMatrix()");
         GLContext context = context(ctx);
-		GL2 gl = context.getGL().getGL2();
+        GL2 gl = context.getGL().getGL2();
 
         gl.glMatrixMode(GL2.GL_MODELVIEW);
 
@@ -7510,7 +7756,7 @@
     void setProjectionMatrix(Context ctx, double[] projMatrix) {
         if (VERBOSE) System.err.println("JoglPipeline.setProjectionMatrix()");
         GLContext context = context(ctx);
-		GL2 gl = context.getGL().getGL2();
+        GL2 gl = context.getGL().getGL2();
 
         gl.glMatrixMode(GL2.GL_PROJECTION);
 
@@ -7541,30 +7787,6 @@
         }
     }
 
-static boolean isOffscreenLayerSurfaceEnabled(Canvas3D cv) {
-	if (cv.drawable == null || cv.offScreen)
-		return false;
-
-	JoglDrawable joglDrawble = (JoglDrawable)cv.drawable;
-	JAWTWindow jawtwindow = (JAWTWindow)joglDrawble.getNativeWindow();
-	if (jawtwindow == null)
-		return false;
-
-	return jawtwindow.isOffscreenLayerSurfaceEnabled();
-}
-
-static boolean hasFBObjectSizeChanged(JoglDrawable jdraw, int width, int height) {
-	if (!(jdraw.getGLDrawable() instanceof GLFBODrawable))
-		return false;
-
-	FBObject fboBack = ((GLFBODrawable)jdraw.getGLDrawable()).getFBObject(GL.GL_BACK);
-	if (fboBack == null)
-		return false;
-
-	return (width != fboBack.getWidth() || height != fboBack.getHeight());
-}
-
-
     // The native method for setting the Viewport.
     @Override
     void setViewport(Context ctx, int x, int y, int width, int height) {
@@ -7581,18 +7803,17 @@
             System.err.println("JAVA 3D ERROR : glNewList(" + displayListId + ") -- IGNORED");
         }
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glNewList(displayListId, GL2.GL_COMPILE);
     }
 
     @Override
     void endDisplayList(Context ctx) {
         if (VERBOSE) System.err.println("JoglPipeline.endDisplayList()");
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glEndList();
     }
 
-    int numInvalidLists = 0;
     @Override
     void callDisplayList(Context ctx, int id, boolean isNonUniformScale) {
         if (VERBOSE) System.err.println("JoglPipeline.callDisplayList()");
@@ -7607,7 +7828,7 @@
             return;
         }
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         // Set normalization if non-uniform scale
         if (isNonUniformScale) {
             gl.glEnable(GL2.GL_NORMALIZE);
@@ -7628,10 +7849,14 @@
             System.err.println("JAVA 3D ERROR : glDeleteLists(" + id + ",1) -- IGNORED");
         }
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         gl.glDeleteLists(id, 1);
     }
 
+    //----------------------------------------------------------------------
+    // Helper classes and methods to support query context functionality
+    // and pixel format selection
+
     @Override
     void freeTexture(Context ctx, int id) {
         if (VERBOSE) System.err.println("JoglPipeline.freeTexture()");
@@ -7647,32 +7872,32 @@
         }
     }
 
-	@Override
-	int generateTexID(Context ctx) {
-		if (VERBOSE) System.err.println("JoglPipeline.generateTexID()");
-
-		GL gl = context(ctx).getGL();
-		int[] tmp = new int[] { -1 };
-		gl.glGenTextures(1, tmp, 0);
+    @Override
+    int generateTexID(Context ctx) {
+        if (VERBOSE) System.err.println("JoglPipeline.generateTexID()");
 
-		if (tmp[0] < 1)
-			return -1;
+        GL gl = context(ctx).getGL();
+        int[] tmp = new int[]{-1};
+        gl.glGenTextures(1, tmp, 0);
 
-		return tmp[0];
-	}
+        if (tmp[0] < 1)
+            return -1;
+
+        return tmp[0];
+    }
 
     @Override
     void texturemapping(Context ctx,
-            int px, int py,
-            int minX, int minY, int maxX, int maxY,
-            int texWidth, int texHeight,
-            int rasWidth,
-            int format, int objectId,
-            byte[] imageYdown,
-            int winWidth, int winHeight) {
+                        int px, int py,
+                        int minX, int minY, int maxX, int maxY,
+                        int texWidth, int texHeight,
+                        int rasWidth,
+                        int format, int objectId,
+                        byte[] imageYdown,
+                        int winWidth, int winHeight) {
         if (VERBOSE) System.err.println("JoglPipeline.texturemapping()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int glType = GL.GL_RGBA;
 
@@ -7696,11 +7921,11 @@
         gl.glEnable(GL.GL_BLEND);
         gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
 
-		gl.glEnable(GL.GL_TEXTURE_2D);
-		gl.glPushAttrib(GL2.GL_TRANSFORM_BIT);
-		gl.glMatrixMode(GL.GL_TEXTURE);
-		gl.glLoadIdentity();
-		gl.glPopAttrib();
+        gl.glEnable(GL.GL_TEXTURE_2D);
+        gl.glPushAttrib(GL2.GL_TRANSFORM_BIT);
+        gl.glMatrixMode(GL.GL_TEXTURE);
+        gl.glLoadIdentity();
+        gl.glPopAttrib();
 
         // loaded identity modelview and projection matrix
         gl.glMatrixMode(GL2.GL_PROJECTION);
@@ -7734,24 +7959,28 @@
         gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, 0);
         gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, 0);
 
-        float texMinU = (float) minX/ (float) texWidth;
-        float texMinV = (float) minY/ (float) texHeight;
-        float texMaxU = (float) maxX/ (float) texWidth;
-        float texMaxV = (float) maxY/ (float) texHeight;
-        float halfWidth = (float)winWidth/2.0f;
-        float halfHeight = (float)winHeight/2.0f;
-
-        float mapMinX = (float) (((px + minX)- halfWidth)/halfWidth);
-        float mapMinY = (float) ((halfHeight - (py + maxY))/halfHeight);
-        float mapMaxX = (float) ((px + maxX - halfWidth)/halfWidth);
-        float mapMaxY = (float) ((halfHeight - (py + minY))/halfHeight);
+        float texMinU = (float) minX / (float) texWidth;
+        float texMinV = (float) minY / (float) texHeight;
+        float texMaxU = (float) maxX / (float) texWidth;
+        float texMaxV = (float) maxY / (float) texHeight;
+        float halfWidth = (float) winWidth / 2.0f;
+        float halfHeight = (float) winHeight / 2.0f;
+
+        float mapMinX = (float) (((px + minX) - halfWidth) / halfWidth);
+        float mapMinY = (float) ((halfHeight - (py + maxY)) / halfHeight);
+        float mapMaxX = (float) ((px + maxX - halfWidth) / halfWidth);
+        float mapMaxY = (float) ((halfHeight - (py + minY)) / halfHeight);
 
         gl.glBegin(GL2.GL_QUADS);
 
-        gl.glTexCoord2f(texMinU, texMaxV); gl.glVertex2f(mapMinX,mapMinY);
-        gl.glTexCoord2f(texMaxU, texMaxV); gl.glVertex2f(mapMaxX,mapMinY);
-        gl.glTexCoord2f(texMaxU, texMinV); gl.glVertex2f(mapMaxX,mapMaxY);
-        gl.glTexCoord2f(texMinU, texMinV); gl.glVertex2f(mapMinX,mapMaxY);
+        gl.glTexCoord2f(texMinU, texMaxV);
+        gl.glVertex2f(mapMinX, mapMinY);
+        gl.glTexCoord2f(texMaxU, texMaxV);
+        gl.glVertex2f(mapMaxX, mapMinY);
+        gl.glTexCoord2f(texMaxU, texMinV);
+        gl.glVertex2f(mapMaxX, mapMaxY);
+        gl.glTexCoord2f(texMinU, texMinV);
+        gl.glVertex2f(mapMinX, mapMaxY);
         gl.glEnd();
 
         // Java 3D always clears the Z-buffer
@@ -7762,10 +7991,10 @@
 
     @Override
     boolean initTexturemapping(Context ctx, int texWidth,
-            int texHeight, int objectId) {
+                               int texHeight, int objectId) {
         if (VERBOSE) System.err.println("JoglPipeline.initTexturemapping()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
 
         int glType = (gl.isExtensionAvailable("GL_EXT_abgr") ? GL2.GL_ABGR_EXT : GL.GL_RGBA);
 
@@ -7789,7 +8018,6 @@
         return true;
     }
 
-
     // Set internal render mode to one of FIELD_ALL, FIELD_LEFT or
     // FIELD_RIGHT.  Note that it is up to the caller to ensure that
     // stereo is available before setting the mode to FIELD_LEFT or
@@ -7799,7 +8027,7 @@
     void setRenderMode(Context ctx, int mode, boolean doubleBuffer) {
         if (VERBOSE) System.err.println("JoglPipeline.setRenderMode()");
 
-		GL2 gl = context(ctx).getGL().getGL2();
+        GL2 gl = context(ctx).getGL().getGL2();
         int drawBuf = 0;
         if (doubleBuffer) {
             drawBuf = GL.GL_BACK;
@@ -7845,8 +8073,11 @@
         }
     }
 
-    //----------------------------------------------------------------------
-    // Helper private functions for Canvas3D
+
+    // ---------------------------------------------------------------------
+
+    //
+    // DrawingSurfaceObject methods
     //
 
     private boolean getPropertiesFromCurrentContext(JoglContext ctx, GL2 gl) {
@@ -7887,34 +8118,19 @@
                     // Avoid possibly confusing situations by requiring
                     // major version to match
                     if (altMajor == major &&
-                            altMinor >  minor) {
+                            altMinor > minor) {
                         minor = altMinor;
                     }
                 }
             }
         }
-        return new int[] { major, minor };
+        return new int[]{major, minor};
     }
 
-// FIXME: GL_SGI_texture_color_table
-//    private int getTextureColorTableSize(GL gl) {
-//        if (!gl.isExtensionAvailable("GL_ARB_imaging")) {
-//            return 0;
-//        }
-//
-//        gl.glColorTable(GL.GL_PROXY_TEXTURE_COLOR_TABLE_SGI, GL.GL_RGBA, 256, GL.GL_RGB,
-//                GL2.GL_INT, null);
-//        int[] tmp = new int[1];
-//        gl.glGetColorTableParameteriv(GL.GL_PROXY_TEXTURE_COLOR_TABLE_SGI,
-//                GL2.GL_COLOR_TABLE_WIDTH, tmp, 0);
-//        return tmp[0];
-//    }
-
-
     private void checkTextureExtensions(Canvas3D cv,
-            JoglContext ctx,
-            GL gl,
-            boolean gl13) {
+                                        JoglContext ctx,
+                                        GL gl,
+                                        boolean gl13) {
         if (gl13) {
             cv.textureExtendedFeatures |= Canvas3D.TEXTURE_MULTI_TEXTURE;
             cv.multiTexAccelerated = true;
@@ -7982,7 +8198,7 @@
         if (gl.isExtensionAvailable("GL_EXT_texture_filter_anisotropic")) {
             cv.textureExtendedFeatures |= Canvas3D.TEXTURE_ANISOTROPIC_FILTER;
             float[] tmp = new float[1];
-            gl.glGetFloatv(GL. GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, tmp, 0);
+            gl.glGetFloatv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, tmp, 0);
             cv.anisotropicDegreeMax = tmp[0];
         }
 
@@ -8002,18 +8218,21 @@
 
     }
 
+    //----------------------------------------------------------------------
+    // Context-related routines
+    //
 
     private void checkGLSLShaderExtensions(Canvas3D cv,
-            JoglContext ctx,
-            GL gl,
-            boolean hasgl13) {
-
-		// Force shaders to be disabled, since no multitexture support
-		if (!hasgl13)
-			return;
+                                           JoglContext ctx,
+                                           GL gl,
+                                           boolean hasgl13) {
+
+        // Force shaders to be disabled, since no multitexture support
+        if (!hasgl13)
+            return;
 
         if (gl.isExtensionAvailable("GL_ARB_shader_objects") &&
-            gl.isExtensionAvailable("GL_ARB_shading_language_100")) {
+                gl.isExtensionAvailable("GL_ARB_shading_language_100")) {
 
             // FIXME: this isn't complete and would need to set up the
             // JoglContext for dispatch of various routines such as those
@@ -8063,11 +8282,11 @@
         cv.shadingLanguageGLSL = false;
 
         // Now make queries and set up these fields
-        String glVersion  = gl.glGetString(GL.GL_VERSION);
-        String glVendor   = gl.glGetString(GL.GL_VENDOR);
+        String glVersion = gl.glGetString(GL.GL_VERSION);
+        String glVendor = gl.glGetString(GL.GL_VENDOR);
         String glRenderer = gl.glGetString(GL.GL_RENDERER);
-        cv.nativeGraphicsVersion  = glVersion;
-        cv.nativeGraphicsVendor   = glVendor;
+        cv.nativeGraphicsVersion = glVersion;
+        cv.nativeGraphicsVendor = glVendor;
         cv.nativeGraphicsRenderer = glRenderer;
 
         // find out the version, major and minor version number
@@ -8089,7 +8308,7 @@
         if (major < 1 || (major == 1 && minor < 2)) {
             throw new IllegalRenderingStateException(
                     "Java 3D ERROR : OpenGL 1.2 or better is required (GL_VERSION=" +
-                    major + "." + minor + ")");
+                            major + "." + minor + ")");
         }
 
         boolean gl20 = false;
@@ -8193,12 +8412,12 @@
         }
     }
 
-  /*
-   * Function to disable most rendering attributes when doing a 2D
-   * clear, image copy, or image composite operation. Note that the
-   * caller must save/restore the attributes with
-   * pushAttrib(GL_ENABLE_BIT|...) and popAttrib()
-   */
+    /*
+     * Function to disable most rendering attributes when doing a 2D
+     * clear, image copy, or image composite operation. Note that the
+     * caller must save/restore the attributes with
+     * pushAttrib(GL_ENABLE_BIT|...) and popAttrib()
+     */
     private void disableAttribFor2D(GL gl) {
         gl.glDisable(GL2.GL_ALPHA_TEST);
         gl.glDisable(GL.GL_BLEND);
@@ -8235,6 +8454,10 @@
 //        }
     }
 
+    //----------------------------------------------------------------------
+    // General helper routines
+    //
+
     private void disableAttribForRaster(GL gl) {
 
         gl.glDisable(GL2.GL_COLOR_MATERIAL);
@@ -8269,13 +8492,6 @@
         dst[15] = src[15];
     }
 
-    // ---------------------------------------------------------------------
-
-    //
-    // Canvas3D / GraphicsConfigTemplate3D methods - logic dealing with
-    // native graphics configuration or drawing surface
-    //
-
     // Return a graphics config based on the one passed in. Note that we can
     // assert that the input config is non-null and was created from a
     // GraphicsConfigTemplate3D.
@@ -8285,22 +8501,16 @@
     GraphicsConfiguration getGraphicsConfig(GraphicsConfiguration gconfig) {
         if (VERBOSE) System.err.println("JoglPipeline.getGraphicsConfig()");
 
-		GraphicsConfigInfo       gcInf0    = Canvas3D.graphicsConfigTable.get(gconfig);
-		AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration)gcInf0.getPrivateData();
+        GraphicsConfigInfo gcInf0 = Canvas3D.graphicsConfigTable.get(gconfig);
+        AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration) gcInf0.getPrivateData();
 
-    	return awtConfig.getAWTGraphicsConfiguration();
+        return awtConfig.getAWTGraphicsConfiguration();
     }
 
-	private enum DisabledCaps {
-		STEREO,
-		AA,
-		DOUBLE_BUFFER,
-	}
-
     // Get best graphics config from pipeline
     @Override
     GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D gct,
-            GraphicsConfiguration[] gc) {
+                                               GraphicsConfiguration[] gc) {
         if (VERBOSE) System.err.println("JoglPipeline.getBestConfiguration()");
 
         // Create a GLCapabilities based on the GraphicsConfigTemplate3D
@@ -8312,7 +8522,7 @@
 
         // Scene antialiasing only if double buffering
         if (gct.getSceneAntialiasing() != GraphicsConfigTemplate.UNNECESSARY &&
-            gct.getDoubleBuffer() != GraphicsConfigTemplate.UNNECESSARY) {
+                gct.getDoubleBuffer() != GraphicsConfigTemplate.UNNECESSARY) {
             caps.setSampleBuffers(true);
             int numSamples = MasterControl.getIntegerProperty("j3d.numSamples", 2);
             caps.setNumSamples(numSamples);
@@ -8348,7 +8558,7 @@
 
         // if AA is required, so is double buffering.
         if (gct.getSceneAntialiasing() != GraphicsConfigTemplate.REQUIRED &&
-            gct.getDoubleBuffer() == GraphicsConfigTemplate.PREFERRED) {
+                gct.getDoubleBuffer() == GraphicsConfigTemplate.PREFERRED) {
             capsToDisable.add(DisabledCaps.DOUBLE_BUFFER);
         }
 
@@ -8356,9 +8566,9 @@
         // Pick an arbitrary graphics device.
         GraphicsDevice device = gc[0].getDevice();
         AbstractGraphicsScreen screen = (device != null) ? AWTGraphicsScreen.createScreenDevice(device, AbstractGraphicsDevice.DEFAULT_UNIT) :
-            AWTGraphicsScreen.createDefault();
+                AWTGraphicsScreen.createDefault();
 
-     // Create a Frame and dummy GLCanvas to perform eager pixel format selection
+        // Create a Frame and dummy GLCanvas to perform eager pixel format selection
 
         // Note that we loop in similar fashion to the NativePipeline's
         // native code in the situation where we need to disable certain
@@ -8366,24 +8576,35 @@
         boolean tryAgain = true;
         CapabilitiesCapturer capturer = null;
         AWTGraphicsConfiguration awtConfig = null;
-        while (tryAgain) {
+
+
+        // while statement switched off due to JVM 9 crash
+
+        //while (tryAgain)
+        {
             Frame f = new Frame(device.getDefaultConfiguration());
             f.setUndecorated(true);
             f.setLayout(new BorderLayout());
             capturer = new CapabilitiesCapturer();
+
             try {
                 awtConfig = createAwtGraphicsConfiguration(caps, capturer, screen);
                 QueryCanvas canvas = new QueryCanvas(awtConfig, capturer);
                 f.add(canvas, BorderLayout.CENTER);
                 f.setSize(MIN_FRAME_SIZE, MIN_FRAME_SIZE);
                 f.setVisible(true);
+
+                // Potential JVM 9 CRASH occurs here on MacOS
                 canvas.doQuery();
+
                 if (DEBUG_CONFIG) {
                     System.err.println("Waiting for CapabilitiesCapturer");
                 }
+
+
                 // Try to wait for result without blocking EDT
                 if (!EventQueue.isDispatchThread()) {
-                    synchronized(capturer) {
+                    synchronized (capturer) {
                         if (!capturer.done()) {
                             try {
                                 capturer.wait(WAIT_TIME);
@@ -8394,27 +8615,32 @@
                 }
                 disposeOnEDT(f);
                 tryAgain = false;
+
             } catch (GLException e) {
                 // Failure to select a pixel format; try switching off one
                 // of the only-preferred capabilities
+
                 if (capsToDisable.size() == 0) {
                     tryAgain = false;
+
                 } else {
+
                     switch (capsToDisable.remove(0)) {
-                    case STEREO:
-                        caps.setStereo(false);
-                        break;
-                    case AA:
-                        caps.setSampleBuffers(false);
-                        break;
-                    case DOUBLE_BUFFER:
-                        caps.setDoubleBuffered(false);
-                        break;
+                        case STEREO:
+                            caps.setStereo(false);
+                            break;
+                        case AA:
+                            caps.setSampleBuffers(false);
+                            break;
+                        case DOUBLE_BUFFER:
+                            caps.setDoubleBuffered(false);
+                            break;
                     }
                     awtConfig = null;
                 }
             }
         }
+
         int chosenIndex = capturer.getChosenIndex();
         GLCapabilities chosenCaps = null;
         if (chosenIndex < 0) {
@@ -8432,11 +8658,11 @@
             chosenCaps = capturer.getCapabilities();
         }
 
+        // JVM 9 CRASH found above this line
+
         // FIXME chosenIndex isn't used anymore, used -1 instead of finding it.
         JoglGraphicsConfiguration config = new JoglGraphicsConfiguration(chosenCaps, chosenIndex, device);
 
-
-
         // FIXME: because of the fact that JoglGraphicsConfiguration
         // doesn't override hashCode() or equals(), we will basically be
         // creating a new one each time getBestConfiguration() is
@@ -8450,7 +8676,7 @@
 
         synchronized (Canvas3D.graphicsConfigTable) {
             Canvas3D.graphicsConfigTable.put(config, gcInf0);
-          }
+        }
 
         return config;
     }
@@ -8458,7 +8684,7 @@
     // Determine whether specified graphics config is supported by pipeline
     @Override
     boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D gct,
-            GraphicsConfiguration gc) {
+                                      GraphicsConfiguration gc) {
         if (VERBOSE) System.err.println("JoglPipeline.isGraphicsConfigSupported()");
 
         // FIXME: it looks like this method is implemented incorrectly
@@ -8522,8 +8748,6 @@
                 caps.getAccumBlueBits() > 0);
     }
 
-    private boolean checkedForGetScreenMethod = false;
-    private Method getScreenMethod = null;
     @Override
     int getScreen(final GraphicsDevice graphicsDevice) {
         if (VERBOSE) System.err.println("JoglPipeline.getScreen()");
@@ -8536,7 +8760,7 @@
                 @Override
                 public Object run() {
                     try {
-                        getScreenMethod = graphicsDevice.getClass().getDeclaredMethod("getScreen", new Class[] {});
+                        getScreenMethod = graphicsDevice.getClass().getDeclaredMethod("getScreen", new Class[]{});
                         getScreenMethod.setAccessible(true);
                     } catch (Exception e) {
                     }
@@ -8557,14 +8781,125 @@
         return 0;
     }
 
-    //----------------------------------------------------------------------
-    // Helper classes and methods to support query context functionality
-    // and pixel format selection
+    private void disposeOnEDT(final Frame f) {
+        Runnable r = new Runnable() {
+            @Override
+            public void run() {
+                f.setVisible(false);
+                f.dispose();
+            }
+        };
+        if (!EventQueue.isDispatchThread()) {
+            EventQueue.invokeLater(r);
+        } else {
+            r.run();
+        }
+    }
+
+    // Method to construct a new DrawingSurfaceObject
+    @Override
+    DrawingSurfaceObject createDrawingSurfaceObject(Canvas3D cv) {
+        if (VERBOSE) System.err.println("JoglPipeline.createDrawingSurfaceObject()");
+        return new JoglDrawingSurfaceObject(cv);
+    }
+
+    // Method to free the drawing surface object
+    @Override
+    void freeDrawingSurface(Canvas3D cv, DrawingSurfaceObject drawingSurfaceObject) {
+        if (VERBOSE) System.err.println("JoglPipeline.freeDrawingSurface()");
+        // This method is a no-op
+    }
+
+    // Method to free the native drawing surface object
+    @Override
+    void freeDrawingSurfaceNative(Object o) {
+        if (VERBOSE) System.err.println("JoglPipeline.freeDrawingSurfaceNative()");
+        // This method is a no-op
+    }
+
+    // Helper used everywhere
+    GLContext context(Context ctx) {
+        if (ctx == null)
+            return null;
+        return ((JoglContext) ctx).getGLContext();
+    }
+
+    // Helper used everywhere
+    GLDrawable drawable(Drawable drawable) {
+        if (drawable == null)
+            return null;
+        return ((JoglDrawable) drawable).getGLDrawable();
+    }
+
+    GLCapabilities caps(Canvas3D ctx) {
+        if (ctx.drawable != null) {
+            // latest state for on- and offscreen drawables
+            return (GLCapabilities) drawable(ctx.drawable).getChosenGLCapabilities();
+        } else {
+            // state at the time of 'getBestConfiguration'
+            return ((JoglGraphicsConfiguration) ctx.graphicsConfiguration).getGLCapabilities();
+        }
+    }
+
+    private enum DisabledCaps {
+        STEREO,
+        AA,
+        DOUBLE_BUFFER,
+    }
 
     interface ExtendedCapabilitiesChooser extends GLCapabilitiesChooser {
         public void init(GLContext context);
     }
 
+    // Used in conjunction with IndexCapabilitiesChooser in pixel format
+    // selection -- see getBestConfiguration
+    static class CapabilitiesCapturer extends DefaultGLCapabilitiesChooser implements ExtendedCapabilitiesChooser {
+        private boolean done;
+        private GLCapabilities capabilities;
+        private int chosenIndex = -1;
+
+        public boolean done() {
+            return done;
+        }
+
+        public GLCapabilities getCapabilities() {
+            return capabilities;
+        }
+
+        public int getChosenIndex() {
+            return chosenIndex;
+        }
+
+        public int chooseCapabilities(GLCapabilities desired,
+                                      GLCapabilities[] available,
+                                      int windowSystemRecommendedChoice) {
+            int res = super.chooseCapabilities(desired, Arrays.asList(available), windowSystemRecommendedChoice);
+            capabilities = available[res];
+            chosenIndex = res;
+            markDone();
+            return res;
+        }
+
+        @Override
+        public void init(GLContext context) {
+            // Avoid hanging things up for several seconds
+            kick();
+        }
+
+        private void markDone() {
+            synchronized (this) {
+                done = true;
+                notifyAll();
+            }
+        }
+
+        private void kick() {
+            synchronized (this) {
+                notifyAll();
+            }
+        }
+    }
+
     // Canvas subclass to help with various query operations such as the
     // "query context" mechanism and pixel format selection.
     // Must defeat and simplify the single-threading behavior of JOGL's
@@ -8581,7 +8916,7 @@
         private JAWTWindow nativeWindow = null;
 
         private QueryCanvas(AWTGraphicsConfiguration awtConfig,
-        		            ExtendedCapabilitiesChooser chooser) {
+                            ExtendedCapabilitiesChooser chooser) {
             // The platform-specific GLDrawableFactory will only provide a
             // non-null GraphicsConfiguration on platforms where this is
             // necessary (currently only X11, as Windows allows the pixel
@@ -8601,14 +8936,13 @@
         public void addNotify() {
             super.addNotify();
 
-    		nativeWindow = (JAWTWindow)NativeWindowFactory.getNativeWindow(this, awtConfig);
-			nativeWindow.lockSurface();
-		    try {
-	    		glDrawable = GLDrawableFactory.getFactory(profile).createGLDrawable(nativeWindow);
-		    }
-		    finally {
-		    	nativeWindow.unlockSurface();
-		    }
+            nativeWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(this, awtConfig);
+            nativeWindow.lockSurface();
+            try {
+                glDrawable = GLDrawableFactory.getFactory(profile).createGLDrawable(nativeWindow);
+            } finally {
+                nativeWindow.unlockSurface();
+            }
 
             glDrawable.setRealized(true);
         }
@@ -8628,76 +8962,26 @@
                     context.release();
                 }
             }
-            context.destroy();
-            alreadyRan = true;
-
-            glDrawable.setRealized(false);
-            nativeWindow.destroy();
-        }
-    }
-
-    private static AWTGraphicsConfiguration createAwtGraphicsConfiguration(GLCapabilities capabilities,
-            CapabilitiesChooser chooser,
-            AbstractGraphicsScreen screen) {
-        GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class, GLCapabilities.class);
-        AWTGraphicsConfiguration awtGraphicsConfiguration = (AWTGraphicsConfiguration) factory.chooseGraphicsConfiguration(capabilities, capabilities,
-        chooser, screen, VisualIDHolder.VID_UNDEFINED);
-        return awtGraphicsConfiguration;
-    }
 
-    // Used in conjunction with IndexCapabilitiesChooser in pixel format
-    // selection -- see getBestConfiguration
-    static class CapabilitiesCapturer extends DefaultGLCapabilitiesChooser implements ExtendedCapabilitiesChooser {
-        private boolean done;
-        private GLCapabilities capabilities;
-        private int chosenIndex = -1;
-
-        public boolean done() {
-            return done;
-        }
+            // Potential JVM 9 CRASH occurs here on MacOS
+            // Other .destroy() methods have been removed
+            // TODO: correct .destroy() and use
+            //
+            // context.destroy();
 
-        public GLCapabilities getCapabilities() {
-            return capabilities;
-        }
-
-        public int getChosenIndex() {
-            return chosenIndex;
-        }
+            alreadyRan = true;
 
-        public int chooseCapabilities(GLCapabilities desired,
-                GLCapabilities[] available,
-                int windowSystemRecommendedChoice) {
-            int res = super.chooseCapabilities(desired, Arrays.asList(available), windowSystemRecommendedChoice);
-            capabilities = available[res];
-            chosenIndex = res;
-            markDone();
-            return res;
-        }
+            glDrawable.setRealized(false);
 
-        @Override
-        public void init(GLContext context) {
-            // Avoid hanging things up for several seconds
-            kick();
-        }
+            //nativeWindow.destroy();
 
-        private void markDone() {
-            synchronized (this) {
-                done = true;
-                notifyAll();
-            }
-        }
-
-        private void kick() {
-            synchronized (this) {
-                notifyAll();
-            }
         }
     }
 
     // Used to support the query context mechanism -- needs to be more
     // than just a GLCapabilitiesChooser
     private final class ContextQuerier extends DefaultGLCapabilitiesChooser
-                                              implements ExtendedCapabilitiesChooser {
+            implements ExtendedCapabilitiesChooser {
         private Canvas3D canvas;
         private boolean done;
 
@@ -8728,244 +9012,4 @@
             }
         }
     }
-
-    private void disposeOnEDT(final Frame f) {
-        Runnable r = new Runnable() {
-            @Override
-            public void run() {
-                f.setVisible(false);
-                f.dispose();
-            }
-        };
-        if (!EventQueue.isDispatchThread()) {
-            EventQueue.invokeLater(r);
-        } else {
-            r.run();
-        }
-    }
-
-
-    // ---------------------------------------------------------------------
-
-    //
-    // DrawingSurfaceObject methods
-    //
-
-    // Method to construct a new DrawingSurfaceObject
-    @Override
-    DrawingSurfaceObject createDrawingSurfaceObject(Canvas3D cv) {
-        if (VERBOSE) System.err.println("JoglPipeline.createDrawingSurfaceObject()");
-        return new JoglDrawingSurfaceObject(cv);
-    }
-
-    // Method to free the drawing surface object
-    @Override
-    void freeDrawingSurface(Canvas3D cv, DrawingSurfaceObject drawingSurfaceObject) {
-        if (VERBOSE) System.err.println("JoglPipeline.freeDrawingSurface()");
-        // This method is a no-op
-    }
-
-    // Method to free the native drawing surface object
-    @Override
-    void freeDrawingSurfaceNative(Object o) {
-        if (VERBOSE) System.err.println("JoglPipeline.freeDrawingSurfaceNative()");
-        // This method is a no-op
-    }
-
-    //----------------------------------------------------------------------
-    // Context-related routines
-    //
-
-    // Helper used everywhere
-    GLContext context(Context ctx) {
-        if (ctx == null)
-            return null;
-        return ((JoglContext) ctx).getGLContext();
-    }
-
-    // Helper used everywhere
-    GLDrawable drawable(Drawable drawable) {
-        if (drawable == null)
-            return null;
-        return ((JoglDrawable) drawable).getGLDrawable();
-    }
-
-    GLCapabilities caps(Canvas3D ctx) {
-    	if (ctx.drawable != null) {
-    		// latest state for on- and offscreen drawables
-    		return (GLCapabilities)drawable(ctx.drawable).getChosenGLCapabilities();
-    	}
-    	else {
-    		// state at the time of 'getBestConfiguration'
-        return ((JoglGraphicsConfiguration) ctx.graphicsConfiguration).getGLCapabilities();
-    }
-    }
-
-    //----------------------------------------------------------------------
-    // General helper routines
-    //
-
-    private static ThreadLocal<FloatBuffer> nioVertexTemp = new ThreadLocal<FloatBuffer>();
-    private static ThreadLocal<DoubleBuffer> nioVertexDoubleTemp = new ThreadLocal<DoubleBuffer>();
-    private static ThreadLocal<FloatBuffer> nioColorTemp = new ThreadLocal<FloatBuffer>();
-    private static ThreadLocal<ByteBuffer> nioColorByteTemp = new ThreadLocal<ByteBuffer>();
-    private static ThreadLocal<FloatBuffer> nioNormalTemp = new ThreadLocal<FloatBuffer>();
-    private static ThreadLocal<FloatBuffer[]> nioTexCoordSetTemp = new ThreadLocal<FloatBuffer[]>();
-    private static ThreadLocal<FloatBuffer[]> nioVertexAttrSetTemp = new ThreadLocal<FloatBuffer[]>();
-
-    private static FloatBuffer getVertexArrayBuffer(float[] vertexArray) {
-        return getVertexArrayBuffer(vertexArray, true);
-    }
-
-    private static FloatBuffer getVertexArrayBuffer(float[] vertexArray, boolean copyData) {
-        return getNIOBuffer(vertexArray, nioVertexTemp, copyData);
-    }
-
-    private static DoubleBuffer getVertexArrayBuffer(double[] vertexArray) {
-        return getVertexArrayBuffer(vertexArray, true);
-    }
-
-    private static DoubleBuffer getVertexArrayBuffer(double[] vertexArray, boolean copyData) {
-        return getNIOBuffer(vertexArray, nioVertexDoubleTemp, true);
-    }
-
-    private static FloatBuffer getColorArrayBuffer(float[] colorArray) {
-        return getColorArrayBuffer(colorArray, true);
-    }
-
-    private static FloatBuffer getColorArrayBuffer(float[] colorArray, boolean copyData) {
-        return getNIOBuffer(colorArray, nioColorTemp, true);
-    }
-
-    private static ByteBuffer getColorArrayBuffer(byte[] colorArray) {
-        return getColorArrayBuffer(colorArray, true);
-    }
-
-    private static ByteBuffer getColorArrayBuffer(byte[] colorArray, boolean copyData) {
-        return getNIOBuffer(colorArray, nioColorByteTemp, true);
-    }
-
-    private static FloatBuffer getNormalArrayBuffer(float[] normalArray) {
-        return getNormalArrayBuffer(normalArray, true);
-    }
-
-    private static FloatBuffer getNormalArrayBuffer(float[] normalArray, boolean copyData) {
-        return getNIOBuffer(normalArray, nioNormalTemp, true);
-    }
-
-    private static FloatBuffer[] getTexCoordSetBuffer(Object[] texCoordSet) {
-        return getNIOBuffer(texCoordSet, nioTexCoordSetTemp);
-    }
-
-    private static FloatBuffer[] getVertexAttrSetBuffer(Object[] vertexAttrSet) {
-        return getNIOBuffer(vertexAttrSet, nioVertexAttrSetTemp);
-    }
-
-    private static FloatBuffer getNIOBuffer(float[] array, ThreadLocal<FloatBuffer> threadLocal, boolean copyData) {
-        if (array == null) {
-            return null;
-        }
-        FloatBuffer buf = threadLocal.get();
-        if (buf == null) {
-			buf = Buffers.newDirectFloatBuffer(array.length);
-            threadLocal.set(buf);
-        } else {
-            buf.rewind();
-            if (buf.remaining() < array.length) {
-                int newSize = Math.max(2 * buf.remaining(), array.length);
-				buf = Buffers.newDirectFloatBuffer(newSize);
-                threadLocal.set(buf);
-            }
-        }
-        if (copyData) {
-            buf.put(array);
-            buf.rewind();
-        }
-        return buf;
-    }
-
-    private static DoubleBuffer getNIOBuffer(double[] array, ThreadLocal<DoubleBuffer> threadLocal, boolean copyData) {
-        if (array == null) {
-            return null;
-        }
-        DoubleBuffer buf = threadLocal.get();
-        if (buf == null) {
-			buf = Buffers.newDirectDoubleBuffer(array.length);
-            threadLocal.set(buf);
-        } else {
-            buf.rewind();
-            if (buf.remaining() < array.length) {
-                int newSize = Math.max(2 * buf.remaining(), array.length);
-				buf = Buffers.newDirectDoubleBuffer(newSize);
-                threadLocal.set(buf);
-            }
-        }
-        if (copyData) {
-            buf.put(array);
-            buf.rewind();
-        }
-        return buf;
-    }
-
-    private static ByteBuffer getNIOBuffer(byte[] array, ThreadLocal<ByteBuffer> threadLocal, boolean copyData) {
-        if (array == null) {
-            return null;
-        }
-        ByteBuffer buf = threadLocal.get();
-        if (buf == null) {
-			buf = Buffers.newDirectByteBuffer(array.length);
-            threadLocal.set(buf);
-        } else {
-            buf.rewind();
-            if (buf.remaining() < array.length) {
-                int newSize = Math.max(2 * buf.remaining(), array.length);
-				buf = Buffers.newDirectByteBuffer(newSize);
-                threadLocal.set(buf);
-            }
-        }
-        if (copyData) {
-            buf.put(array);
-            buf.rewind();
-        }
-        return buf;
-    }
-
-    private static FloatBuffer[] getNIOBuffer(Object[] array, ThreadLocal<FloatBuffer[]> threadLocal) {
-        if (array == null) {
-            return null;
-        }
-        FloatBuffer[] bufs = threadLocal.get();
-
-        // First resize array of FloatBuffers
-        if (bufs == null) {
-            bufs = new FloatBuffer[array.length];
-            threadLocal.set(bufs);
-        } else if (bufs.length < array.length) {
-            FloatBuffer[] newBufs = new FloatBuffer[array.length];
-            System.arraycopy(bufs, 0, newBufs, 0, bufs.length);
-            bufs = newBufs;
-            threadLocal.set(bufs);
-        }
-
-        // Now go down array of arrays, converting each into a direct FloatBuffer
-        for (int i = 0; i < array.length; i++) {
-            float[] cur = (float[]) array[i];
-            FloatBuffer buf = bufs[i];
-            if (buf == null) {
-				buf = Buffers.newDirectFloatBuffer(cur.length);
-                bufs[i] = buf;
-            } else {
-                buf.rewind();
-                if (buf.remaining() < cur.length) {
-                    int newSize = Math.max(2 * buf.remaining(), cur.length);
-					buf = Buffers.newDirectFloatBuffer(newSize);
-                    bufs[i] = buf;
-                }
-            }
-            buf.put(cur);
-            buf.rewind();
-        }
-
-        return bufs;
-    }
 }
