From 29d5516687020263d3ae0454ce81879a3a450af0 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Thu, 01 Aug 2019 00:20:18 -0400
Subject: [PATCH] Min shader option.

---
 CameraPane.java |  108 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 80 insertions(+), 28 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index 8953dc4..219e567 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -9316,10 +9316,9 @@
     double[] light2camera = new double[16];
     
     //int newenvy = -1;
-    boolean envyoff = true; // false;
-    String skyboxname = "";
-    String skyboxext;
-    String loadedskyboxname = "";
+    //boolean envyoff = false;
+    
+    String loadedskyboxname;
     
     cVector light0 = new cVector(0, 0, 0); // 1,3,2);
     //float[] light0 = { 0,0,0 };
@@ -11065,10 +11064,18 @@
 //
 //        newenvy = -1;
         
-        if (!skyboxname.equals(this.loadedskyboxname))
+        if (object.skyboxname != null)
         {
-            LoadSkybox(skyboxname + "/", skyboxext, false);
-            loadedskyboxname = skyboxname;
+            if (!object.skyboxname.equals(this.loadedskyboxname))
+            {
+                LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
+                loadedskyboxname = object.skyboxname;
+            }
+        }
+        else
+        {
+            cubemap = null;
+            loadedskyboxname = null;
         }
         
         ratio = ((double) getWidth()) / getHeight();
@@ -12446,7 +12453,7 @@
 
         //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
 
-        String program0 =
+        String programmin =
                 // Min shader
                 "!!ARBfp1.0\n" +
                 "PARAM zero123      = { 0.0, 1.0, 2, 1.25 };" +
@@ -12513,7 +12520,7 @@
                 "MOV result.color, temp;" +
                 "END";
         
-        String program =
+        String programmax =
                 "!!ARBfp1.0\n" +
                 
                 //"OPTION ARB_fragment_program_shadow;" +
@@ -13369,6 +13376,13 @@
             //once = true;
         }
 
+        String program = programmax;
+        
+        if (Globals.MINSHADER)
+        {
+            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 " : ""));
         loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
@@ -15362,7 +15376,7 @@
                 OCCLUSION_CULLING ^= true;
                 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
                 break;
-            case '0': envyoff ^= true; repaint(); break;
+            //case '0': envyoff ^= true; repaint(); break;
             case '1':
             case '2':
             case '3':
@@ -15372,7 +15386,7 @@
             case '7':
             case '8':
             case '9':
-                if (envyoff)
+                if (true) // envyoff)
                 {
                     BGcolor = (key - '1')/8.f;
                 }
@@ -16084,7 +16098,7 @@
                                 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
                             break;
                             case Object3D.hitScale: gr.setColor(Color.cyan);
-                                gr.drawLine(X, Y, 0, 0);
+                                gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
                             break;
                         }
 
@@ -16570,6 +16584,8 @@
     private /*static*/ boolean firstime;
     private /*static*/ cVector newView = new cVector();
     private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
+    private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
+    private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
     private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
                                              GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
                                              GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
@@ -16582,22 +16598,56 @@
     {
         com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
 
+        int usedsuf = 0;
+        
         for (int i = 0; i < suffixes.length; i++)
         {
-            String resourceName = basename + suffixes[i] + "." + suffix;
-            TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
-                    mipmapped,
-                    FileUtil.getFileSuffix(resourceName));
-            if (data == null)
+            String[] suffixe = suffixes;
+            String[] fallback = suffixes2;
+            String[] fallfallback = suffixes3;
+            
+            for (int c=usedsuf; --c>=0;)
             {
-                throw new IOException("Unable to load texture " + resourceName);
+//                String[] temp = suffixe;
+//                suffixe = fallback;
+//                fallback = fallfallback;
+//                fallfallback = temp;
             }
+            
+            String resourceName = basename + suffixe[i] + "." + suffix;
+            TextureData data;
+            
+            try
+            {
+                data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                        mipmapped,
+                        FileUtil.getFileSuffix(resourceName));
+            }
+            catch (Exception e)
+            {
+                try
+                {
+                    resourceName = basename + fallback[i] + "." + suffix;
+                    data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                            mipmapped,
+                            FileUtil.getFileSuffix(resourceName));
+                }
+                catch (Exception e2)
+                {
+                    resourceName = basename + fallfallback[i] + "." + suffix;
+                    data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                            mipmapped,
+                            FileUtil.getFileSuffix(resourceName));
+                }
+            }
+            
             //System.out.println("Target = " + targets[i]);
             cubemap.updateImage(data, targets[i]);
         }
 
         return cubemap;
     }
+    
     int bigsphere = -1;
 
     float BGcolor = 0.5f;
@@ -16606,7 +16656,8 @@
     
     private void DrawSkyBox(GL gl, float ratio)
     {
-        if (envyoff || cubemap == null)
+        if (//envyoff ||
+                cubemap == null)
         {
             gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
             gl.glClear(gl.GL_COLOR_BUFFER_BIT);
@@ -16623,14 +16674,14 @@
         gl.glLoadIdentity();
         gl.glScalef(1,ratio,1);
 
-        colorV[0] = 2;
-        colorV[1] = 2;
-        colorV[2] = 2;
-        colorV[3] = 1;
-        gl.glDisable(gl.GL_COLOR_MATERIAL);
-        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
-        
-        gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
+//        colorV[0] = 2;
+//        colorV[1] = 2;
+//        colorV[2] = 2;
+//        colorV[3] = 1;
+//        gl.glDisable(gl.GL_COLOR_MATERIAL);
+//        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
+//        
+//        gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
         
         //gl.glActiveTexture(GL.GL_TEXTURE1);
         //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
@@ -16644,7 +16695,7 @@
         // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
         // causes the normals to be sent down. Thanks to Ken Dyke.
         //gl.glEnable(GL.GL_LIGHTING);
-        gl.glEnable(GL.GL_LIGHTING);
+        gl.glDisable(GL.GL_LIGHTING);
 
         gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
         gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
@@ -16663,6 +16714,7 @@
         {
             gl.glScalef(1.0f, -1.0f, 1.0f);
         }
+        gl.glScalef(-1.0f, 1.0f, 1.0f);
         gl.glMultMatrixd(viewrot_1, 0);
         gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance());  // 0.5f);
         //viewer.updateInverseRotation(gl);

--
Gitblit v1.6.2