Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -93,7 +97,7 @@
9397 //boolean REDUCETEXTURE = true;
9498 boolean CACHETEXTURE = true;
9599 boolean CLEANCACHE = false; // true;
96
- boolean MIPMAP = true; // false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
97101 boolean COMPRESSTEXTURE = false;
98102 boolean KOMPACTTEXTURE = false; // true;
99103 boolean RESIZETEXTURE = false;
....@@ -106,7 +110,9 @@
106110 //private Mat4f spotlightTransform = new Mat4f();
107111 //private Mat4f spotlightInverseTransform = new Mat4f();
108112 static GLContext glcontext = null;
109
- /*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;
110116 boolean reverseUP = false;
111117 static boolean frozen = false;
112118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -169,7 +175,7 @@
169175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
170176 boolean anisotropy = true;
171177 boolean softshadow = true; // slower but better false;
172
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
173179
174180 boolean macromode = false;
175181
....@@ -183,6 +189,19 @@
183189 }
184190
185191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
186205
187206 void SetAsGLRenderer(boolean b)
188207 {
....@@ -202,7 +221,8 @@
202221
203222 SetCamera(cam);
204223
205
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
206226
207227 object = o;
208228
....@@ -1480,6 +1500,8 @@
14801500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14811501 }
14821502
1503
+ float[] colorV = new float[4];
1504
+
14831505 void SetColor(Object3D obj, Vertex p0)
14841506 {
14851507 CameraPane display = this;
....@@ -1547,8 +1569,6 @@
15471569 {
15481570 return;
15491571 }
1550
-
1551
- float[] colorV = new float[3];
15521572
15531573 if (false) // marked)
15541574 {
....@@ -8341,7 +8361,7 @@
83418361 // else
83428362 // if (!texname.startsWith("/"))
83438363 // texname = "/Users/nbriere/Textures/" + texname;
8344
- if (!FileExists(texname))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
83458365 {
83468366 texname = fallbackTextureName;
83478367 }
....@@ -8358,14 +8378,26 @@
83588378 {
83598379 TextureData texturedata = null;
83608380
8361
- if (texdata != null)
8381
+ if (texdata != null && textureon)
83628382 {
8363
- BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
83648384
8365
- CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
83668393
83678394 texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
83688395 bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
83698401 }
83708402 else
83718403 if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
....@@ -8408,6 +8440,15 @@
84088440 // texturecache = textures.get(texname); // suspicious
84098441 if (texturecache == null)
84108442 texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
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);
84118452 else
84128453 new Exception().printStackTrace();
84138454 } else
....@@ -8471,6 +8512,7 @@
84718512 texturecache = new CacheTexture(texturedata,resolution);
84728513 //texture = GetTexture(tex, bump);
84738514 }
8515
+ }
84748516 }
84758517 //}
84768518 }
....@@ -8560,29 +8602,32 @@
85608602 {
85618603 if (tex.pigmentdata == null)
85628604 {
8563
- String texname = Object3D.GetPigment(tex);
8605
+ //String texname = Object3D.GetPigment(tex);
85648606
85658607 CacheTexture texturecache = texturepigment.get(tex);
85668608
85678609 if (texturecache != null)
85688610 {
8569
- tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
85708611 tex.pw = texturecache.texturedata.getWidth();
85718612 tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
85728617 }
85738618 }
85748619
85758620 if (tex.bumpdata == null)
85768621 {
8577
- String texname = Object3D.GetBump(tex);
8622
+ //String texname = Object3D.GetBump(tex);
85788623
85798624 CacheTexture texturecache = texturebump.get(tex);
85808625
85818626 if (texturecache != null)
85828627 {
8583
- tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
85848628 tex.bw = texturecache.texturedata.getWidth();
85858629 tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
85868631 }
85878632 }
85888633 }
....@@ -8654,6 +8699,72 @@
86548699 return true; // Warning: not used.
86558700 }
86568701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
86578768 ShadowBuffer shadowPBuf;
86588769 AntialiasBuffer antialiasPBuf;
86598770 int MAXSTACK;
....@@ -8670,10 +8781,12 @@
86708781
86718782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86728783 MAXSTACK = temp[0];
8673
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86748786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86758787 MAXSTACK = temp[0];
8676
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86778790
86788791 // Use debug pipeline
86798792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8681,7 +8794,8 @@
86818794 gl = drawable.getGL(); //
86828795
86838796 GL gl3 = getGL();
8684
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86858799
86868800
86878801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8846,7 +8960,7 @@
88468960
88478961 if (cubemap == null)
88488962 {
8849
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
88508964 }
88518965
88528966 //cubemap.enable();
....@@ -9122,6 +9236,8 @@
91229236
91239237 void LoadEnvy(int which)
91249238 {
9239
+ assert(false);
9240
+
91259241 String name;
91269242 String ext;
91279243
....@@ -9133,37 +9249,58 @@
91339249 cubemap = null;
91349250 return;
91359251 case 1:
9136
- name = "cubemaps/box_";
9137
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
91389254 reverseUP = false;
91399255 break;
91409256 case 2:
9141
- name = "cubemaps/uffizi_";
9142
- ext = "png";
9143
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
91449261 case 3:
9145
- name = "cubemaps/CloudyHills_";
9146
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
91479264 reverseUP = false;
91489265 break;
91499266 case 4:
9150
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
91519268 ext = "png";
91529269 reverseUP = false;
91539270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
91549296 default:
9155
- name = "cubemaps/rgb_";
9156
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
91579300 break;
91589301 }
9159
-
9160
- try
9161
- {
9162
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9163
- } catch (IOException e)
9164
- {
9165
- throw new RuntimeException(e);
9166
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
91679304 }
91689305
91699306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9195,8 +9332,12 @@
91959332 static double[] model = new double[16];
91969333 double[] camera2light = new double[16];
91979334 double[] light2camera = new double[16];
9198
- int newenvy = -1;
9199
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
92009341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92019342 //float[] light0 = { 0,0,0 };
92029343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9614,7 +9755,7 @@
96149755
96159756 if (renderCamera != lightCamera)
96169757 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9617
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
96189759
96199760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
96209761
....@@ -9630,7 +9771,7 @@
96309771
96319772 if (renderCamera != lightCamera)
96329773 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9633
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
96349775
96359776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
96369777
....@@ -9676,10 +9817,12 @@
96769817 rati = 1 / rati;
96779818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96789819 }
9679
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
96809823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96819824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9682
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
96839826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96849827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96859828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10716,7 +10859,7 @@
1071610859
1071710860 if (wait)
1071810861 {
10719
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1072010863
1072110864 wait = false;
1072210865 }
....@@ -10831,7 +10974,7 @@
1083110974 // if (parentcam != renderCamera) // not a light
1083210975 if (cam != lightCamera)
1083310976 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10834
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1083510978
1083610979 for (int j = 0; j < 4; j++)
1083710980 {
....@@ -10846,7 +10989,7 @@
1084610989 // if (parentcam != renderCamera) // not a light
1084710990 if (cam != lightCamera)
1084810991 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10849
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1085010993
1085110994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1085210995
....@@ -10932,13 +11075,41 @@
1093211075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1093311076 }
1093411077
10935
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1093611086 {
10937
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1093811093 }
10939
-
10940
- newenvy = -1;
10941
-
11094
+ else
11095
+ {
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;
11111
+ }
11112
+
1094211113 ratio = ((double) getWidth()) / getHeight();
1094311114 //System.out.println("ratio = " + ratio);
1094411115
....@@ -10954,7 +11125,7 @@
1095411125
1095511126 if (!IsFrozen() && !ambientOcclusion)
1095611127 {
10957
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1095811129 }
1095911130
1096011131 //if (selection_view == -1)
....@@ -11240,7 +11411,7 @@
1124011411
1124111412 // if (cam != lightCamera)
1124211413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11243
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1124411415 }
1124511416
1124611417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11399,7 +11570,7 @@
1139911570 }
1140011571 }
1140111572
11402
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1140311574 {
1140411575 //gl.glDepthFunc(GL.GL_LEQUAL);
1140511576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11407,24 +11578,21 @@
1140711578
1140811579 boolean texon = textureon;
1140911580
11410
- if (RENDERPROGRAM > 0)
11411
- {
11412
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11413
- textureon = false;
11414
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1141511584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1141611585 //System.out.println("ALLO");
1141711586 gl.glColorMask(false, false, false, false);
1141811587 DrawObject(gl);
11419
- if (RENDERPROGRAM > 0)
11420
- {
11421
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11422
- textureon = texon;
11423
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1142411592 gl.glColorMask(true, true, true, true);
1142511593
1142611594 gl.glDepthFunc(GL.GL_EQUAL);
11427
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1142811596 }
1142911597
1143011598 if (false) // DrawMode() == SHADOW)
....@@ -12317,8 +12485,76 @@
1231712485
1231812486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1231912487
12320
- String program =
12488
+ String programmin =
12489
+ // Min shader
1232112490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1232212558 //"OPTION ARB_fragment_program_shadow;" +
1232312559 "PARAM light2cam0 = program.env[10];" +
1232412560 "PARAM light2cam1 = program.env[11];" +
....@@ -12433,8 +12669,7 @@
1243312669 "TEMP shininess;" +
1243412670 "\n" +
1243512671 "MOV texSamp, one;" +
12436
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12437
-
12672
+
1243812673 "MOV mapgrid.x, one2048th.x;" +
1243912674 "MOV temp, fragment.texcoord[1];" +
1244012675 /*
....@@ -12455,20 +12690,20 @@
1245512690 "MUL temp, floor, mapgrid.x;" +
1245612691 //"TEX depth0, temp, texture[1], 2D;" +
1245712692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12458
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1245912694 "") +
1246012695 "ADD temp.x, temp.x, mapgrid.x;" +
1246112696 //"TEX depth1, temp, texture[1], 2D;" +
1246212697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12463
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1246412699 "") +
1246512700 "ADD temp.y, temp.y, mapgrid.x;" +
1246612701 //"TEX depth2, temp, texture[1], 2D;" +
12467
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1246812703 "SUB temp.x, temp.x, mapgrid.x;" +
1246912704 //"TEX depth3, temp, texture[1], 2D;" +
1247012705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12471
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1247212707 "") +
1247312708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1247412709 //"MOV params, material;" +
....@@ -12839,10 +13074,10 @@
1283913074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284013075 "") +
1284113076
12842
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1284313078 "SUB temp.x, half.x, shadow.x;" +
1284413079 "MOV temp.y, -params5.z;" + // params6.x;" +
12845
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1284613081 "SUB temp.y, one.x, temp.z;" +
1284713082 "MUL temp.x, temp.x, temp.y;" +
1284813083 "KIL temp.x;" +
....@@ -13173,6 +13408,13 @@
1317313408 //once = true;
1317413409 }
1317513410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1317613418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1317713419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1317813420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13266,25 +13508,26 @@
1326613508 return out;
1326713509 }
1326813510
13269
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1327013513 {
1327113514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327213515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327313516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327413519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13275
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13276
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13277
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13278
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1327913522 //"SWZ buffer, temp, w,w,w,w;";
13280
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328113524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328213525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328313526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13284
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328513528
13286
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13287
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328813531 }
1328913532
1329013533 String Shadow(String depth, String shadow)
....@@ -13331,7 +13574,7 @@
1333113574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333213575 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333313576
13334
- // No shadow when out of frustrum
13577
+ // No shadow when out of frustum
1333513578 "SGE temp.x, " + depth + ".z, one.z;" +
1333613579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333713580 "";
....@@ -14129,14 +14372,15 @@
1412914372 drag = false;
1413014373 //System.out.println("Mouse DOWN");
1413114374 editObj = false;
14132
- ClickInfo info = new ClickInfo();
14133
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14134
- info.pane = this;
14135
- info.camera = renderCamera;
14136
- info.x = x;
14137
- info.y = y;
14138
- info.modifiers = modifiersex;
14139
- editObj = object.doEditClick(info, 0);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1414014384 if (!editObj)
1414114385 {
1414214386 hasMarquee = true;
....@@ -14420,9 +14664,9 @@
1442014664 MODIFIERS |= COMMAND;
1442114665 /**/
1442214666 if((mod&SHIFT) == SHIFT)
14423
- manipCamera.RotatePosition(0, -speed);
14424
- else
1442514667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1442614670 /**/
1442714671 if ((mod & SHIFT) == SHIFT)
1442814672 {
....@@ -14441,9 +14685,9 @@
1444114685 MODIFIERS |= COMMAND;
1444214686 /**/
1444314687 if((mod&SHIFT) == SHIFT)
14444
- manipCamera.RotatePosition(0, speed);
14445
- else
1444614688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1444714691 /**/
1444814692 if ((mod & SHIFT) == SHIFT)
1444914693 {
....@@ -14536,15 +14780,16 @@
1453614780 if (editObj)
1453714781 {
1453814782 drag = true;
14539
- ClickInfo info = new ClickInfo();
14540
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1454114785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14542
- info.pane = this;
14543
- info.camera = renderCamera;
14544
- info.x = x;
14545
- info.y = y;
14546
- object.GetWindow().copy
14547
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454814793 } else
1454914794 {
1455014795 if (x < startX)
....@@ -14693,24 +14938,27 @@
1469314938 }
1469414939 }
1469514940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1469614943 public void mouseMoved(MouseEvent e)
1469714944 {
1469814945 //System.out.println("mouseMoved: " + e);
1469914946 if (isRenderer)
1470014947 return;
1470114948
14702
- ClickInfo ci = new ClickInfo();
14703
- ci.x = e.getX();
14704
- ci.y = e.getY();
14705
- ci.modifiers = e.getModifiersEx();
14706
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14707
- ci.pane = this;
14708
- ci.camera = renderCamera;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1470914956 if (!isRenderer)
1471014957 {
1471114958 //ObjEditor editWindow = object.editWindow;
1471214959 //Object3D copy = editWindow.copy;
14713
- if (object.doEditClick(ci, 0))
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1471414962 {
1471514963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471614964 } else
....@@ -15160,20 +15408,24 @@
1516015408 OCCLUSION_CULLING ^= true;
1516115409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1516215410 break;
15163
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1516415412 case '1':
1516515413 case '2':
1516615414 case '3':
1516715415 case '4':
1516815416 case '5':
15169
- newenvy = Character.getNumericValue(key);
15170
- repaint();
15171
- break;
1517215417 case '6':
1517315418 case '7':
1517415419 case '8':
1517515420 case '9':
15176
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1517715429 repaint();
1517815430 break;
1517915431 case '!':
....@@ -15736,8 +15988,6 @@
1573615988
1573715989 int width = getBounds().width;
1573815990 int height = getBounds().height;
15739
- ClickInfo info = new ClickInfo();
15740
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574115991 //Image img = CreateImage(width, height);
1574215992 //System.out.println("width = " + width + "; height = " + height + "\n");
1574315993
....@@ -15814,31 +16064,37 @@
1581416064 }
1581516065 if (object != null && !hasMarquee)
1581616066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1581716073 if (isRenderer)
1581816074 {
15819
- info.flags++;
16075
+ object.clickInfo.flags++;
1582016076 double frameAspect = (double) width / (double) height;
1582116077 if (frameAspect > renderCamera.aspect)
1582216078 {
1582316079 int desired = (int) ((double) height * renderCamera.aspect);
15824
- info.bounds.width -= width - desired;
15825
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1582616082 } else
1582716083 {
1582816084 int desired = (int) ((double) width / renderCamera.aspect);
15829
- info.bounds.height -= height - desired;
15830
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583116087 }
1583216088 }
1583316089
15834
- info.g = gr;
15835
- info.camera = renderCamera;
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1583616092 /*
1583716093 // Memory intensive (brep.verticescopy)
1583816094 if (!(object instanceof Composite))
1583916095 object.draw(info, 0, false); // SLOW :
1584016096 */
15841
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1584216098 {
1584316099 Grafreed.Assert(object != null);
1584416100 Grafreed.Assert(object.selection != null);
....@@ -15846,9 +16102,9 @@
1584616102 {
1584716103 int hitSomething = object.selection.get(0).hitSomething;
1584816104
15849
- info.DX = 0;
15850
- info.DY = 0;
15851
- info.W = 1;
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
1585216108 if (hitSomething == Object3D.hitCenter)
1585316109 {
1585416110 info.DX = X;
....@@ -15860,7 +16116,8 @@
1586016116 info.DY -= info.bounds.height/2;
1586116117 }
1586216118
15863
- object.drawEditHandles(info, 0);
16119
+ object.drawEditHandles(//info,
16120
+ 0);
1586416121
1586516122 if (drag && (X != 0 || Y != 0))
1586616123 {
....@@ -16359,6 +16616,8 @@
1635916616 private /*static*/ boolean firstime;
1636016617 private /*static*/ cVector newView = new cVector();
1636116618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1636216621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1636316622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1636416623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16371,29 +16630,67 @@
1637116630 {
1637216631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1637316632
16633
+ int usedsuf = 0;
16634
+
1637416635 for (int i = 0; i < suffixes.length; i++)
1637516636 {
16376
- String resourceName = basename + suffixes[i] + "." + suffix;
16377
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16378
- mipmapped,
16379
- FileUtil.getFileSuffix(resourceName));
16380
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1638116642 {
16382
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1638316647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1638416676 //System.out.println("Target = " + targets[i]);
1638516677 cubemap.updateImage(data, targets[i]);
1638616678 }
1638716679
1638816680 return cubemap;
1638916681 }
16682
+
1639016683 int bigsphere = -1;
1639116684
1639216685 float BGcolor = 0.5f;
1639316686
16394
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1639516690 {
16396
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1639716694 {
1639816695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1639916696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16408,7 +16705,17 @@
1640816705 // Compensates for ExaminerViewer's modification of modelview matrix
1640916706 gl.glMatrixMode(GL.GL_MODELVIEW);
1641016707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1641116709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1641216719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1641316720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1641416721
....@@ -16440,6 +16747,7 @@
1644016747 {
1644116748 gl.glScalef(1.0f, -1.0f, 1.0f);
1644216749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1644316751 gl.glMultMatrixd(viewrot_1, 0);
1644416752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1644516753 //viewer.updateInverseRotation(gl);
....@@ -16698,7 +17006,7 @@
1669817006 //new Exception().printStackTrace();
1669917007 System.out.println("select buffer init");
1670017008 // Use debug pipeline
16701
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1670217010
1670317011 GL gl = drawable.getGL();
1670417012
....@@ -17244,10 +17552,14 @@
1724417552 gl.glFlush();
1724517553
1724617554 /**/
17247
- 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);
1724817556
17249
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1725017558
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
+
1725117563 double r = 0, g = 0, b = 0;
1725217564
1725317565 double count = 0;
....@@ -17258,7 +17570,7 @@
1725817570
1725917571 double FACTOR = 1;
1726017572
17261
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1726217574 {
1726317575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1726417576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17341,7 +17653,7 @@
1734117653
1734217654 double scale = ray.z; // 1; // cos
1734317655
17344
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1734517657
1734617658 /*
1734717659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17538,11 +17850,14 @@
1753817850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1753917851 static IntBuffer bigAAbuffer;
1754017852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17541
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1754217854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1754317855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1754417856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17545
- 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
+
1754617861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1754717862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1754817863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();