From 5892f05411c3d4dce2d8a59e0966dc2e1843a971 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sat, 17 Aug 2019 08:33:35 -0400
Subject: [PATCH] Fix L&F nimbus too slow.

---
 CameraPane.java |  158 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 120 insertions(+), 38 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index df56b97..3c3d2d0 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -110,7 +110,11 @@
     //private Mat4f spotlightTransform = new Mat4f();
     //private Mat4f spotlightInverseTransform = new Mat4f();
     static GLContext glcontext = null;
-    /*static*/ com.sun.opengl.util.texture.Texture cubemap;
+    /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
+    /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
+    /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
+    boolean transformMode;
+    
     boolean reverseUP = false;
     static boolean frozen = false;
     boolean enablebackspace = false; // patch for back buffer refresh
@@ -164,7 +168,7 @@
 
     
     // OPTIONS
-    boolean Skinshader = true;
+    boolean Skinshader = false; // true;
     boolean cameraLight = false;
     boolean UVdebug = false;
     boolean Udebug = false;
@@ -173,7 +177,7 @@
     static boolean doublesided = false; // true; // reversed normals are awful for conformance
     boolean anisotropy = true;
     boolean softshadow = true; // slower but better false;
-    boolean opacityhalo = false;
+    boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
     
     boolean macromode = false;
     
@@ -188,15 +192,16 @@
     
     private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
 
-    public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
+    public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
     {
         try
         {
-            cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
+            return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
         } catch (IOException e)
         {
             System.out.println("NAME = " + name);
             e.printStackTrace(); // throw new RuntimeException(e);
+            return null;
         }
     }
     
@@ -2512,7 +2517,7 @@
                     com.sun.opengl.util.texture.TextureIO.newTextureData(
                     getClass().getClassLoader().getResourceAsStream(name),
                     true,
-                    com.sun.opengl.util.texture.TextureIO.PNG);
+                    GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
         } catch (java.io.IOException e)
         {
             throw new javax.media.opengl.GLException(e);
@@ -8778,10 +8783,12 @@
 
         gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
         MAXSTACK = temp[0];
-        System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
+        if (Globals.DEBUG)
+            System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
         gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
         MAXSTACK = temp[0];
-        System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
+        if (Globals.DEBUG)
+            System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
 
         // Use debug pipeline
         //drawable.setGL(new DebugGL(gl)); //
@@ -8789,7 +8796,8 @@
         gl = drawable.getGL(); //
 
         GL gl3 = getGL();
-        System.out.println("INIT GL IS: " + gl.getClass().getName());
+        if (Globals.DEBUG)
+            System.out.println("INIT GL IS: " + gl.getClass().getName());
 
 
         //float pos[] = { 100, 100, 100, 0 };
@@ -9230,6 +9238,8 @@
 
     void LoadEnvy(int which)
     {
+        assert(false);
+        
         String name;
         String ext;
 
@@ -10680,9 +10690,18 @@
     static boolean init = false;
     
     double[][] matrix = LA.newMatrix();
+    
+    // This is to refresh the UI of the material panel.
+    ObjEditor patchMaterial;
 
     public void display(GLAutoDrawable drawable)
     {
+        if (patchMaterial.patchMaterial)
+        {
+            patchMaterial.patchMaterial = false;
+            patchMaterial.objectPanel.setSelectedIndex(0);
+        }
+        
         if (Grafreed.savesound && Grafreed.hassound)
         {
             Grafreed.wav.save();
@@ -11074,18 +11093,34 @@
 //
 //        newenvy = -1;
         
-        if (object.skyboxname != null)
+        if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
         {
-            if (!object.skyboxname.equals(this.loadedskyboxname))
+            if (cubemaprgb == null)
             {
-                LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
-                loadedskyboxname = object.skyboxname;
+                cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
             }
+            
+            cubemap = cubemaprgb;
         }
         else
         {
-            cubemap = null;
-            loadedskyboxname = null;
+            if (object.skyboxname != null)
+            {
+                if (!object.skyboxname.equals(this.loadedskyboxname))
+                {
+                    if (cubemap != null && cubemap != cubemaprgb)
+                        cubemap.dispose();
+                    cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
+                    loadedskyboxname = object.skyboxname;
+                }
+            }
+            else
+            {
+                cubemapcustom = null;
+                loadedskyboxname = null;
+            }
+            
+            cubemap = cubemapcustom;
         }
         
         ratio = ((double) getWidth()) / getHeight();
@@ -13393,8 +13428,12 @@
             program = programmin;
         }
         
-        System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
-        System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
+        if (Globals.DEBUG)
+        {
+            System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
+            System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
+        }
+        
         loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
 
     //gl.glNewList(displayListID, GL.GL_COMPILE);
@@ -13441,7 +13480,8 @@
                 "\n" +
                 "END\n";
 
-        System.out.println("Program shadow #" + 0 + "; length = " + program.length());
+        if (Globals.DEBUG)
+            System.out.println("Program shadow #" + 0 + "; length = " + program.length());
         loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
 
     //gl.glNewList(displayListID, GL.GL_COMPILE);
@@ -14640,11 +14680,17 @@
     void GoDown(int mod)
     {
         MODIFIERS |= COMMAND;
+        boolean isVR = (mouseMode&VR)!=0;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
+        {
+            if (isVR)
+                manipCamera.RotateInterest(0, -speed);
+            else
+                manipCamera.RotatePosition(0, -speed);
+        }
         else
-        manipCamera.RotatePosition(0, -speed);
+            manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14654,6 +14700,8 @@
             mouseMode |= BACKFORTH;
         }
 
+        targetLookAt.set(manipCamera.lookAt);
+        
         //prevX = X = anchorX;
         prevY = Y = anchorY - (int) (renderCamera.Distance());
     }
@@ -14662,10 +14710,17 @@
     {
         MODIFIERS |= COMMAND;
         /**/
+        boolean isVR = (mouseMode&VR)!=0;
+        
         if((mod&SHIFT) == SHIFT)
-        manipCamera.BackForth(0, speed*delta, 0); // getWidth());
+        {
+            if (isVR)
+                manipCamera.RotateInterest(0, speed);
+            else
+                manipCamera.RotatePosition(0, speed);
+        }
         else
-        manipCamera.RotatePosition(0, speed);
+            manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14675,6 +14730,8 @@
             mouseMode |= BACKFORTH;
         }
 
+        targetLookAt.set(manipCamera.lookAt);
+        
         //prevX = X = anchorX;
         prevY = Y = anchorY + (int) (renderCamera.Distance());
     }
@@ -14684,9 +14741,14 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.Translate(speed*delta, 0, getWidth());
+            manipCamera.Translate(speed*delta, 0, getWidth());
         else
-        manipCamera.RotatePosition(speed, 0);
+        {
+            if ((mouseMode&VR)!=0)
+                manipCamera.RotateInterest(-speed, 0);
+            else
+                manipCamera.RotatePosition(speed, 0);
+        }
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14696,6 +14758,8 @@
             mouseMode |= ROTATE;
         } // TRANSLATE;
 
+        targetLookAt.set(manipCamera.lookAt);
+        
         prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
         prevY = Y = anchorY;
     }
@@ -14705,9 +14769,15 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.Translate(-speed*delta, 0, getWidth());
+            manipCamera.Translate(-speed*delta, 0, getWidth());
         else
-        manipCamera.RotatePosition(-speed, 0);
+        {
+            if ((mouseMode&VR)!=0)
+                manipCamera.RotateInterest(speed, 0);
+            else
+                manipCamera.RotatePosition(-speed, 0);
+        }
+        
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14717,6 +14787,8 @@
             mouseMode |= ROTATE;
         } // TRANSLATE;
 
+        targetLookAt.set(manipCamera.lookAt);
+        
         prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
         prevY = Y = anchorY;
     }
@@ -15219,8 +15291,8 @@
             case 'K':
                 KOMPACTTEXTURE ^= true;
                 //textures.clear();
-                break;
-            case 'P': // Texture Projection macros
+            //    break;
+            //case 'P': // Texture Projection macros
 //                SAVETEXTURE ^= true;
                 macromode = true;
                 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
@@ -15341,7 +15413,7 @@
                 targetLookAt.set(manipCamera.lookAt);
                 repaint();
                 break;
-            case 'p':
+            case 'P': // p':
        // c'est quoi ca au juste?         spherical ^= true;
                 Skinshader ^= true; programInitialized = false; 
                 repaint();
@@ -16101,7 +16173,7 @@
                     {
                         switch (hitSomething)
                         {
-                            case Object3D.hitCenter: gr.setColor(Color.pink);
+                            case Object3D.hitCenter: gr.setColor(Color.white);
                                 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
                                 break;
                             case Object3D.hitRotate: gr.setColor(Color.yellow);
@@ -16127,7 +16199,7 @@
         if (hasMarquee)
         {
             gr.setXORMode(Color.white);
-            gr.setColor(Color.red);
+            gr.setColor(Color.white);
             if (!firstime)
             {
                 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
@@ -16667,6 +16739,7 @@
     private void DrawSkyBox(GL gl, float ratio)
     {
         if (//envyoff ||
+            WIREFRAME ||
                 cubemap == null)
         {
             gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
@@ -16765,7 +16838,8 @@
         gl.glDisable(GL.GL_TEXTURE_GEN_R);
 
         cubemap.disable();
-        ////cubemap.unbind();
+        //cubemap.dispose();
+        
         if (CULLFACE)
         {
             gl.glEnable(gl.GL_CULL_FACE);
@@ -17301,6 +17375,7 @@
 
         public void init(GLAutoDrawable drawable)
         {
+        if (Globals.DEBUG)
             System.out.println("shadow buffer init");
 
             GL gl = drawable.getGL();
@@ -17529,10 +17604,14 @@
             gl.glFlush();
             
             /**/
-            gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
+            gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
 
-            float[] pixels = occlusionsizebuffer.array();
+            float[] depths = occlusiondepthbuffer.array();
 
+            gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
+
+            int[] pixels = selectsizebuffer.array();
+            
             double r = 0, g = 0, b = 0;
 
             double count = 0;
@@ -17543,7 +17622,7 @@
             
             double FACTOR = 1;
 
-            for (int i = 0; i < pixels.length; i++)
+            for (int i = 0; i < depths.length; i++)
             {
                 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
                 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
@@ -17626,7 +17705,7 @@
 
                 double scale = ray.z; // 1; // cos
 
-                float depth = pixels[newindex];
+                float depth = depths[newindex];
 
                 /*
                 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
@@ -17823,11 +17902,14 @@
     static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
     static IntBuffer bigAAbuffer;
     static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
-    static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
+    //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
     static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
     static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
     //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
-    static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
+    static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
+    
+    static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
+    
     static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
     static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
     static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();

--
Gitblit v1.6.2