Normand Briere
2019-08-15 7f97054d681518416a4ee1c1548ad42cfb489a8f
CameraPane.java
....@@ -110,7 +110,11 @@
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;
116
+ boolean transformMode;
117
+
114118 boolean reverseUP = false;
115119 static boolean frozen = false;
116120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -173,7 +177,7 @@
173177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174178 boolean anisotropy = true;
175179 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177181
178182 boolean macromode = false;
179183
....@@ -188,15 +192,16 @@
188192
189193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190194
191
- public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192196 {
193197 try
194198 {
195
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196200 } catch (IOException e)
197201 {
198202 System.out.println("NAME = " + name);
199203 e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
200205 }
201206 }
202207
....@@ -2512,7 +2517,7 @@
25122517 com.sun.opengl.util.texture.TextureIO.newTextureData(
25132518 getClass().getClassLoader().getResourceAsStream(name),
25142519 true,
2515
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25162521 } catch (java.io.IOException e)
25172522 {
25182523 throw new javax.media.opengl.GLException(e);
....@@ -8358,7 +8363,7 @@
83588363 // else
83598364 // if (!texname.startsWith("/"))
83608365 // texname = "/Users/nbriere/Textures/" + texname;
8361
- if (!FileExists(texname))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
83628367 {
83638368 texname = fallbackTextureName;
83648369 }
....@@ -8441,6 +8446,15 @@
84418446 new Exception().printStackTrace();
84428447 } else
84438448 {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
8456
+ } else
8457
+ {
84448458 if (textureon)
84458459 {
84468460 String cachename = texname;
....@@ -8500,6 +8514,7 @@
85008514 texturecache = new CacheTexture(texturedata,resolution);
85018515 //texture = GetTexture(tex, bump);
85028516 }
8517
+ }
85038518 }
85048519 //}
85058520 }
....@@ -8768,10 +8783,12 @@
87688783
87698784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87708785 MAXSTACK = temp[0];
8771
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87728788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87738789 MAXSTACK = temp[0];
8774
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87758792
87768793 // Use debug pipeline
87778794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8779,7 +8796,8 @@
87798796 gl = drawable.getGL(); //
87808797
87818798 GL gl3 = getGL();
8782
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87838801
87848802
87858803 //float pos[] = { 100, 100, 100, 0 };
....@@ -9220,6 +9238,8 @@
92209238
92219239 void LoadEnvy(int which)
92229240 {
9241
+ assert(false);
9242
+
92239243 String name;
92249244 String ext;
92259245
....@@ -10841,7 +10861,7 @@
1084110861
1084210862 if (wait)
1084310863 {
10844
- Sleep(500);
10864
+ Sleep(200); // blocks everything
1084510865
1084610866 wait = false;
1084710867 }
....@@ -11064,18 +11084,34 @@
1106411084 //
1106511085 // newenvy = -1;
1106611086
11067
- if (object.skyboxname != null)
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1106811088 {
11069
- if (!object.skyboxname.equals(this.loadedskyboxname))
11089
+ if (cubemaprgb == null)
1107011090 {
11071
- LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
- loadedskyboxname = object.skyboxname;
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false);
1107311092 }
11093
+
11094
+ cubemap = cubemaprgb;
1107411095 }
1107511096 else
1107611097 {
11077
- cubemap = null;
11078
- loadedskyboxname = null;
11098
+ if (object.skyboxname != null)
11099
+ {
11100
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11101
+ {
11102
+ if (cubemap != null && cubemap != cubemaprgb)
11103
+ cubemap.dispose();
11104
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11105
+ loadedskyboxname = object.skyboxname;
11106
+ }
11107
+ }
11108
+ else
11109
+ {
11110
+ cubemapcustom = null;
11111
+ loadedskyboxname = null;
11112
+ }
11113
+
11114
+ cubemap = cubemapcustom;
1107911115 }
1108011116
1108111117 ratio = ((double) getWidth()) / getHeight();
....@@ -11379,7 +11415,7 @@
1137911415
1138011416 // if (cam != lightCamera)
1138111417 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11382
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11418
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1138311419 }
1138411420
1138511421 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -14632,9 +14668,9 @@
1463214668 MODIFIERS |= COMMAND;
1463314669 /**/
1463414670 if((mod&SHIFT) == SHIFT)
14635
- manipCamera.RotatePosition(0, -speed);
14636
- else
1463714671 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14672
+ else
14673
+ manipCamera.RotatePosition(0, -speed);
1463814674 /**/
1463914675 if ((mod & SHIFT) == SHIFT)
1464014676 {
....@@ -14653,9 +14689,9 @@
1465314689 MODIFIERS |= COMMAND;
1465414690 /**/
1465514691 if((mod&SHIFT) == SHIFT)
14656
- manipCamera.RotatePosition(0, speed);
14657
- else
1465814692 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14693
+ else
14694
+ manipCamera.RotatePosition(0, speed);
1465914695 /**/
1466014696 if ((mod & SHIFT) == SHIFT)
1466114697 {
....@@ -16657,6 +16693,7 @@
1665716693 private void DrawSkyBox(GL gl, float ratio)
1665816694 {
1665916695 if (//envyoff ||
16696
+ WIREFRAME ||
1666016697 cubemap == null)
1666116698 {
1666216699 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
....@@ -16755,7 +16792,8 @@
1675516792 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1675616793
1675716794 cubemap.disable();
16758
- ////cubemap.unbind();
16795
+ //cubemap.dispose();
16796
+
1675916797 if (CULLFACE)
1676016798 {
1676116799 gl.glEnable(gl.GL_CULL_FACE);
....@@ -17519,10 +17557,14 @@
1751917557 gl.glFlush();
1752017558
1752117559 /**/
17522
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17560
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1752317561
17524
- float[] pixels = occlusionsizebuffer.array();
17562
+ float[] depths = occlusiondepthbuffer.array();
1752517563
17564
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17565
+
17566
+ int[] pixels = selectsizebuffer.array();
17567
+
1752617568 double r = 0, g = 0, b = 0;
1752717569
1752817570 double count = 0;
....@@ -17533,7 +17575,7 @@
1753317575
1753417576 double FACTOR = 1;
1753517577
17536
- for (int i = 0; i < pixels.length; i++)
17578
+ for (int i = 0; i < depths.length; i++)
1753717579 {
1753817580 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1753917581 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17616,7 +17658,7 @@
1761617658
1761717659 double scale = ray.z; // 1; // cos
1761817660
17619
- float depth = pixels[newindex];
17661
+ float depth = depths[newindex];
1762017662
1762117663 /*
1762217664 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17813,11 +17855,14 @@
1781317855 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1781417856 static IntBuffer bigAAbuffer;
1781517857 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17816
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17858
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1781717859 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1781817860 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1781917861 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17820
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17862
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17863
+
17864
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17865
+
1782117866 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1782217867 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1782317868 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();