Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -110,7 +110,9 @@
110110 //private Mat4f spotlightTransform = new Mat4f();
111111 //private Mat4f spotlightInverseTransform = new Mat4f();
112112 static GLContext glcontext = null;
113
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
114116 boolean reverseUP = false;
115117 static boolean frozen = false;
116118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -173,7 +175,7 @@
173175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174176 boolean anisotropy = true;
175177 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177179
178180 boolean macromode = false;
179181
....@@ -188,15 +190,16 @@
188190
189191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190192
191
- public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192194 {
193195 try
194196 {
195
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196198 } catch (IOException e)
197199 {
198200 System.out.println("NAME = " + name);
199201 e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
200203 }
201204 }
202205
....@@ -8358,7 +8361,7 @@
83588361 // else
83598362 // if (!texname.startsWith("/"))
83608363 // texname = "/Users/nbriere/Textures/" + texname;
8361
- if (!FileExists(texname))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
83628365 {
83638366 texname = fallbackTextureName;
83648367 }
....@@ -8441,6 +8444,15 @@
84418444 new Exception().printStackTrace();
84428445 } else
84438446 {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
8454
+ } else
8455
+ {
84448456 if (textureon)
84458457 {
84468458 String cachename = texname;
....@@ -8500,6 +8512,7 @@
85008512 texturecache = new CacheTexture(texturedata,resolution);
85018513 //texture = GetTexture(tex, bump);
85028514 }
8515
+ }
85038516 }
85048517 //}
85058518 }
....@@ -8768,10 +8781,12 @@
87688781
87698782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87708783 MAXSTACK = temp[0];
8771
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87728786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87738787 MAXSTACK = temp[0];
8774
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87758790
87768791 // Use debug pipeline
87778792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8779,7 +8794,8 @@
87798794 gl = drawable.getGL(); //
87808795
87818796 GL gl3 = getGL();
8782
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87838799
87848800
87858801 //float pos[] = { 100, 100, 100, 0 };
....@@ -9220,6 +9236,8 @@
92209236
92219237 void LoadEnvy(int which)
92229238 {
9239
+ assert(false);
9240
+
92239241 String name;
92249242 String ext;
92259243
....@@ -10841,7 +10859,7 @@
1084110859
1084210860 if (wait)
1084310861 {
10844
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1084510863
1084610864 wait = false;
1084710865 }
....@@ -11064,18 +11082,32 @@
1106411082 //
1106511083 // newenvy = -1;
1106611084
11067
- if (object.skyboxname != null)
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1106811086 {
11069
- if (!object.skyboxname.equals(this.loadedskyboxname))
11087
+ if (cubemaprgb == null)
1107011088 {
11071
- LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
- loadedskyboxname = object.skyboxname;
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
1107311090 }
11091
+
11092
+ cubemap = cubemaprgb;
1107411093 }
1107511094 else
1107611095 {
11077
- cubemap = null;
11078
- loadedskyboxname = null;
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
1107911111 }
1108011112
1108111113 ratio = ((double) getWidth()) / getHeight();
....@@ -14632,9 +14664,9 @@
1463214664 MODIFIERS |= COMMAND;
1463314665 /**/
1463414666 if((mod&SHIFT) == SHIFT)
14635
- manipCamera.RotatePosition(0, -speed);
14636
- else
1463714667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1463814670 /**/
1463914671 if ((mod & SHIFT) == SHIFT)
1464014672 {
....@@ -14653,9 +14685,9 @@
1465314685 MODIFIERS |= COMMAND;
1465414686 /**/
1465514687 if((mod&SHIFT) == SHIFT)
14656
- manipCamera.RotatePosition(0, speed);
14657
- else
1465814688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1465914691 /**/
1466014692 if ((mod & SHIFT) == SHIFT)
1466114693 {
....@@ -16657,6 +16689,7 @@
1665716689 private void DrawSkyBox(GL gl, float ratio)
1665816690 {
1665916691 if (//envyoff ||
16692
+ WIREFRAME ||
1666016693 cubemap == null)
1666116694 {
1666216695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
....@@ -17519,10 +17552,14 @@
1751917552 gl.glFlush();
1752017553
1752117554 /**/
17522
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1752317556
17524
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1752517558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1752617563 double r = 0, g = 0, b = 0;
1752717564
1752817565 double count = 0;
....@@ -17533,7 +17570,7 @@
1753317570
1753417571 double FACTOR = 1;
1753517572
17536
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1753717574 {
1753817575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1753917576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17616,7 +17653,7 @@
1761617653
1761717654 double scale = ray.z; // 1; // cos
1761817655
17619
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1762017657
1762117658 /*
1762217659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17813,11 +17850,14 @@
1781317850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1781417851 static IntBuffer bigAAbuffer;
1781517852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17816
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1781717854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1781817855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1781917856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17820
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1782117861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1782217862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1782317863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();