Normand Briere
2019-08-15 33504fc9a180903aace77613264550754fba5706
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
....@@ -9316,10 +9336,9 @@
93169336 double[] light2camera = new double[16];
93179337
93189338 //int newenvy = -1;
9319
- boolean envyoff = true; // false;
9320
- String skyboxname = "";
9321
- String skyboxext;
9322
- String loadedskyboxname = "";
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
93239342
93249343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
93259344 //float[] light0 = { 0,0,0 };
....@@ -10842,7 +10861,7 @@
1084210861
1084310862 if (wait)
1084410863 {
10845
- Sleep(500);
10864
+ Sleep(200); // blocks everything
1084610865
1084710866 wait = false;
1084810867 }
....@@ -11065,10 +11084,34 @@
1106511084 //
1106611085 // newenvy = -1;
1106711086
11068
- if (!skyboxname.equals(this.loadedskyboxname))
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1106911088 {
11070
- LoadSkybox(skyboxname + "/", skyboxext, false);
11071
- loadedskyboxname = skyboxname;
11089
+ if (cubemaprgb == null)
11090
+ {
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false);
11092
+ }
11093
+
11094
+ cubemap = cubemaprgb;
11095
+ }
11096
+ else
11097
+ {
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;
1107211115 }
1107311116
1107411117 ratio = ((double) getWidth()) / getHeight();
....@@ -11372,7 +11415,7 @@
1137211415
1137311416 // if (cam != lightCamera)
1137411417 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11375
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11418
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1137611419 }
1137711420
1137811421 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12446,7 +12489,7 @@
1244612489
1244712490 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1244812491
12449
- String program0 =
12492
+ String programmin =
1245012493 // Min shader
1245112494 "!!ARBfp1.0\n" +
1245212495 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12513,7 +12556,7 @@
1251312556 "MOV result.color, temp;" +
1251412557 "END";
1251512558
12516
- String program =
12559
+ String programmax =
1251712560 "!!ARBfp1.0\n" +
1251812561
1251912562 //"OPTION ARB_fragment_program_shadow;" +
....@@ -13369,6 +13412,13 @@
1336913412 //once = true;
1337013413 }
1337113414
13415
+ String program = programmax;
13416
+
13417
+ if (Globals.MINSHADER)
13418
+ {
13419
+ program = programmin;
13420
+ }
13421
+
1337213422 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1337313423 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1337413424 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -14618,9 +14668,9 @@
1461814668 MODIFIERS |= COMMAND;
1461914669 /**/
1462014670 if((mod&SHIFT) == SHIFT)
14621
- manipCamera.RotatePosition(0, -speed);
14622
- else
1462314671 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14672
+ else
14673
+ manipCamera.RotatePosition(0, -speed);
1462414674 /**/
1462514675 if ((mod & SHIFT) == SHIFT)
1462614676 {
....@@ -14639,9 +14689,9 @@
1463914689 MODIFIERS |= COMMAND;
1464014690 /**/
1464114691 if((mod&SHIFT) == SHIFT)
14642
- manipCamera.RotatePosition(0, speed);
14643
- else
1464414692 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14693
+ else
14694
+ manipCamera.RotatePosition(0, speed);
1464514695 /**/
1464614696 if ((mod & SHIFT) == SHIFT)
1464714697 {
....@@ -15362,7 +15412,7 @@
1536215412 OCCLUSION_CULLING ^= true;
1536315413 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1536415414 break;
15365
- case '0': envyoff ^= true; repaint(); break;
15415
+ //case '0': envyoff ^= true; repaint(); break;
1536615416 case '1':
1536715417 case '2':
1536815418 case '3':
....@@ -15372,7 +15422,7 @@
1537215422 case '7':
1537315423 case '8':
1537415424 case '9':
15375
- if (envyoff)
15425
+ if (true) // envyoff)
1537615426 {
1537715427 BGcolor = (key - '1')/8.f;
1537815428 }
....@@ -16084,7 +16134,7 @@
1608416134 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1608516135 break;
1608616136 case Object3D.hitScale: gr.setColor(Color.cyan);
16087
- gr.drawLine(X, Y, 0, 0);
16137
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1608816138 break;
1608916139 }
1609016140
....@@ -16633,6 +16683,7 @@
1663316683
1663416684 return cubemap;
1663516685 }
16686
+
1663616687 int bigsphere = -1;
1663716688
1663816689 float BGcolor = 0.5f;
....@@ -16641,7 +16692,9 @@
1664116692
1664216693 private void DrawSkyBox(GL gl, float ratio)
1664316694 {
16644
- if (envyoff || cubemap == null)
16695
+ if (//envyoff ||
16696
+ WIREFRAME ||
16697
+ cubemap == null)
1664516698 {
1664616699 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1664716700 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16658,14 +16711,14 @@
1665816711 gl.glLoadIdentity();
1665916712 gl.glScalef(1,ratio,1);
1666016713
16661
- colorV[0] = 2;
16662
- colorV[1] = 2;
16663
- colorV[2] = 2;
16664
- colorV[3] = 1;
16665
- gl.glDisable(gl.GL_COLOR_MATERIAL);
16666
- gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16667
-
16668
- gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16714
+// colorV[0] = 2;
16715
+// colorV[1] = 2;
16716
+// colorV[2] = 2;
16717
+// colorV[3] = 1;
16718
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16719
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16720
+//
16721
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
1666916722
1667016723 //gl.glActiveTexture(GL.GL_TEXTURE1);
1667116724 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
....@@ -16679,7 +16732,7 @@
1667916732 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1668016733 // causes the normals to be sent down. Thanks to Ken Dyke.
1668116734 //gl.glEnable(GL.GL_LIGHTING);
16682
- gl.glEnable(GL.GL_LIGHTING);
16735
+ gl.glDisable(GL.GL_LIGHTING);
1668316736
1668416737 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1668516738 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16739,7 +16792,8 @@
1673916792 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1674016793
1674116794 cubemap.disable();
16742
- ////cubemap.unbind();
16795
+ //cubemap.dispose();
16796
+
1674316797 if (CULLFACE)
1674416798 {
1674516799 gl.glEnable(gl.GL_CULL_FACE);
....@@ -17503,10 +17557,14 @@
1750317557 gl.glFlush();
1750417558
1750517559 /**/
17506
- 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);
1750717561
17508
- float[] pixels = occlusionsizebuffer.array();
17562
+ float[] depths = occlusiondepthbuffer.array();
1750917563
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
+
1751017568 double r = 0, g = 0, b = 0;
1751117569
1751217570 double count = 0;
....@@ -17517,7 +17575,7 @@
1751717575
1751817576 double FACTOR = 1;
1751917577
17520
- for (int i = 0; i < pixels.length; i++)
17578
+ for (int i = 0; i < depths.length; i++)
1752117579 {
1752217580 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1752317581 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17600,7 +17658,7 @@
1760017658
1760117659 double scale = ray.z; // 1; // cos
1760217660
17603
- float depth = pixels[newindex];
17661
+ float depth = depths[newindex];
1760417662
1760517663 /*
1760617664 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17797,11 +17855,14 @@
1779717855 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1779817856 static IntBuffer bigAAbuffer;
1779917857 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17800
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17858
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1780117859 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1780217860 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1780317861 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17804
- 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
+
1780517866 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1780617867 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1780717868 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();