Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
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 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = true; // false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
64101 boolean COMPRESSTEXTURE = false;
65102 boolean KOMPACTTEXTURE = false; // true;
66103 boolean RESIZETEXTURE = false;
....@@ -150,6 +187,18 @@
150187 }
151188
152189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
153202
154203 void SetAsGLRenderer(boolean b)
155204 {
....@@ -169,7 +218,8 @@
169218
170219 SetCamera(cam);
171220
172
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
173223
174224 object = o;
175225
....@@ -1447,6 +1497,8 @@
14471497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481498 }
14491499
1500
+ float[] colorV = new float[4];
1501
+
14501502 void SetColor(Object3D obj, Vertex p0)
14511503 {
14521504 CameraPane display = this;
....@@ -1514,8 +1566,6 @@
15141566 {
15151567 return;
15161568 }
1517
-
1518
- float[] colorV = new float[3];
15191569
15201570 if (false) // marked)
15211571 {
....@@ -2405,43 +2455,19 @@
24052455 return currentGL;
24062456 }
24072457
2408
- private BufferedImage CreateBim(TextureData texturedata)
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
24092459 {
2410
- // cache to disk
2411
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
2412
- //buffers[0].
2413
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
2414
- int[] pixels = new int[bytebuf.capacity()/3];
2415
- int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared
2416
- int height = width;
2417
- for (int i=pixels.length; --i>=0;)
2418
- {
2419
- int i3 = i*3;
2420
- pixels[i] = 0xFF;
2421
- pixels[i] <<= 8;
2422
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
2423
- pixels[i] <<= 8;
2424
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
2425
- pixels[i] <<= 8;
2426
- pixels[i] |= bytebuf.get(i3) & 0xFF;
2427
- }
2428
- /*
2429
- int r=0,g=0,b=0,a=0;
2430
- for (int i=0; i<width; i++)
2431
- for (int j=0; j<height; j++)
2432
- {
2433
- int index = j*width+i;
2434
- int p = pixels[index];
2435
- a = ((p>>24) & 0xFF);
2436
- r = ((p>>16) & 0xFF);
2437
- g = ((p>>8) & 0xFF);
2438
- b = (p & 0xFF);
2439
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
2440
- }
2441
- /**/
2442
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
2443
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
2444
- return rendImage;
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
24452471 }
24462472
24472473 /**/
....@@ -2452,18 +2478,20 @@
24522478
24532479 int resolution;
24542480
2455
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24562482 {
2457
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
24582485 resolution = res;
24592486 }
24602487 }
24612488 /**/
24622489
24632490 // TEXTURE static Texture texture;
2464
- static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2465
- static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2466
- static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
24672495
24682496 int pigmentdepth = 0;
24692497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
....@@ -2471,10 +2499,10 @@
24712499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24722500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24732501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2474
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24752503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24762504
2477
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24782506 {
24792507 TextureData texturedata = null;
24802508
....@@ -2493,16 +2521,16 @@
24932521 if (bump)
24942522 texturedata = ConvertBump(texturedata, false);
24952523
2496
- com.sun.opengl.util.texture.Texture texture =
2497
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24982526
2499
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2500
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
25012529
2502
- return texture;
2530
+ return texturedata;
25032531 }
25042532
2505
- com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
25062534 {
25072535 TextureData texturedata = null;
25082536
....@@ -2510,7 +2538,7 @@
25102538 {
25112539 texturedata =
25122540 com.sun.opengl.util.texture.TextureIO.newTextureData(
2513
- name,
2541
+ bim,
25142542 true);
25152543 } catch (Exception e)
25162544 {
....@@ -2519,14 +2547,8 @@
25192547
25202548 if (bump)
25212549 texturedata = ConvertBump(texturedata, false);
2522
-
2523
- com.sun.opengl.util.texture.Texture texture =
2524
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2525
-
2526
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2527
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2528
-
2529
- return texture;
2550
+
2551
+ return texturedata;
25302552 }
25312553
25322554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -8014,8 +8036,8 @@
80148036 pigment = null;
80158037 }
80168038
8017
- ReleaseTexture(bump, true);
8018
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
80198041 }
80208042
80218043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8044,7 +8066,7 @@
80448066 pigment = null;
80458067 }
80468068
8047
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
80488070 }
80498071
80508072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8073,10 +8095,10 @@
80738095 bump = null;
80748096 }
80758097
8076
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
80778099 }
80788100
8079
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
80808102 {
80818103 if (// DrawMode() != 0 || /*tex == null ||*/
80828104 ambientOcclusion ) // || !textureon)
....@@ -8087,7 +8109,7 @@
80878109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80888110
80898111 if (tex != null)
8090
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80918113
80928114 // //assert( texture != null );
80938115 // if (texture == null)
....@@ -8237,13 +8259,13 @@
82378259
82388260 if (tex == null)
82398261 {
8240
- BindTexture(null, null,false,resolution);
8262
+ BindTexture(null,false,resolution);
82418263 return;
82428264 }
82438265
82448266 String pigment = Object3D.GetPigment(tex);
82458267
8246
- usedtextures.add(pigment);
8268
+ usedtextures.add(tex);
82478269
82488270 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82498271 {
....@@ -8257,7 +8279,7 @@
82578279 }
82588280
82598281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8260
- BindTexture(tex.pigmenttexture, pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
82618283 }
82628284
82638285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8270,13 +8292,13 @@
82708292
82718293 if (tex == null)
82728294 {
8273
- BindTexture(null, null,true,resolution);
8295
+ BindTexture(null,true,resolution);
82748296 return;
82758297 }
82768298
82778299 String bump = Object3D.GetBump(tex);
82788300
8279
- usedtextures.add(bump);
8301
+ usedtextures.add(tex);
82808302
82818303 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82828304 {
....@@ -8290,7 +8312,7 @@
82908312 }
82918313
82928314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8293
- BindTexture(tex.bumptexture, bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
82948316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82958317 }
82968318
....@@ -8314,13 +8336,19 @@
83148336 return fileExists;
83158337 }
83168338
8317
- CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
83188340 {
83198341 CacheTexture texturecache = null;
83208342
83218343 if (tex != null)
83228344 {
8323
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8347
+
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
83248352
83258353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
83268354
....@@ -8330,29 +8358,46 @@
83308358 // else
83318359 // if (!texname.startsWith("/"))
83328360 // texname = "/Users/nbriere/Textures/" + texname;
8333
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
83348362 {
83358363 texname = fallbackTextureName;
83368364 }
83378365
83388366 if (CACHETEXTURE)
83398367 {
8340
- if (bim == null)
8341
- texturecache = textures.get(texname); // TEXTURE CACHE
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
83428370 else
8343
- texturecache = bimtextures.get(bim); // TEXTURE CACHE
8371
+ texturecache = bimtextures.get(texdata);
83448372 }
83458373
8346
- if (texturecache == null || texturecache.resolution < resolution)
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
83478375 {
83488376 TextureData texturedata = null;
83498377
8350
- if (bim != null)
8378
+ if (texdata != null && textureon)
83518379 {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
83528391 texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
83538398 }
83548399 else
8355
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83568401 {
83578402 assert(!bump);
83588403 // if (bump)
....@@ -8363,7 +8408,7 @@
83638408 // }
83648409 // else
83658410 // {
8366
- texturecache = textures.get(tex);
8411
+ // texturecache = textures.get(texname); // suspicious
83678412 if (texturecache == null)
83688413 {
83698414 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
....@@ -8372,10 +8417,10 @@
83728417 new Exception().printStackTrace();
83738418 // }
83748419 } else
8375
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
83768421 {
83778422 assert(bump);
8378
- texturecache = textures.get(tex);
8423
+ // texturecache = textures.get(texname); // suspicious
83798424 if (texturecache == null)
83808425 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83818426 else
....@@ -8387,11 +8432,20 @@
83878432 // texture = GetResourceTexture("default.png");
83888433 //} else
83898434 //{
8390
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
83918436 {
8392
- texturecache = textures.get(tex);
8437
+ // texturecache = textures.get(texname); // suspicious
83938438 if (texturecache == null)
83948439 texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
83958449 else
83968450 new Exception().printStackTrace();
83978451 } else
....@@ -8452,17 +8506,17 @@
84528506 if (texturedata == null)
84538507 throw new Exception();
84548508
8455
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
84568510 //texture = GetTexture(tex, bump);
84578511 }
8512
+ }
84588513 }
84598514 //}
84608515 }
84618516
8462
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84638518 {
84648519 //return false;
8465
- assert(bim == null);
84668520
84678521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
84688522 if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
....@@ -8509,18 +8563,20 @@
85098563 }
85108564 }
85118565 }
8512
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
85138569 //System.out.println("Texture = " + tex);
8514
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
85158571 {
8516
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
85178573 thetex.texture.disable();
85188574 thetex.texture.dispose();
8519
- textures.remove(texname);
8575
+ textures.remove(tex);
85208576 }
85218577
85228578 //texture.texturedata = texturedata;
8523
- textures.put(texname, texturecache);
8579
+ textures.put(tex, texturecache);
85248580
85258581 // newtex = true;
85268582 }
....@@ -8541,12 +8597,41 @@
85418597
85428598 static void EmbedTextures(cTexture tex)
85438599 {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
85448616
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
85458630 }
85468631
8547
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
85488633 {
8549
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8634
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85508635
85518636 if (bump)
85528637 {
....@@ -8562,14 +8647,14 @@
85628647 return texture!=null?texture.texture:null;
85638648 }
85648649
8565
- public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85668651 {
8567
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8652
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85688653
85698654 return texture!=null?texture.texturedata:null;
85708655 }
85718656
8572
- boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85738658 {
85748659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85758660 {
....@@ -8578,7 +8663,7 @@
85788663
85798664 //boolean newtex = false;
85808665
8581
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8666
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85828667
85838668 if (texture == null)
85848669 return false;
....@@ -8611,6 +8696,72 @@
86118696 return true; // Warning: not used.
86128697 }
86138698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
86148765 ShadowBuffer shadowPBuf;
86158766 AntialiasBuffer antialiasPBuf;
86168767 int MAXSTACK;
....@@ -8627,10 +8778,12 @@
86278778
86288779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86298780 MAXSTACK = temp[0];
8630
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86318783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86328784 MAXSTACK = temp[0];
8633
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86348787
86358788 // Use debug pipeline
86368789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8638,7 +8791,8 @@
86388791 gl = drawable.getGL(); //
86398792
86408793 GL gl3 = getGL();
8641
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86428796
86438797
86448798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8803,7 +8957,7 @@
88038957
88048958 if (cubemap == null)
88058959 {
8806
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
88078961 }
88088962
88098963 //cubemap.enable();
....@@ -9090,37 +9244,58 @@
90909244 cubemap = null;
90919245 return;
90929246 case 1:
9093
- name = "cubemaps/box_";
9094
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
90959249 reverseUP = false;
90969250 break;
90979251 case 2:
9098
- name = "cubemaps/uffizi_";
9099
- ext = "png";
9100
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
91019256 case 3:
9102
- name = "cubemaps/CloudyHills_";
9103
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
91049259 reverseUP = false;
91059260 break;
91069261 case 4:
9107
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
91089263 ext = "png";
91099264 reverseUP = false;
91109265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
91119291 default:
9112
- name = "cubemaps/rgb_";
9113
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
91149295 break;
91159296 }
9116
-
9117
- try
9118
- {
9119
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9120
- } catch (IOException e)
9121
- {
9122
- throw new RuntimeException(e);
9123
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
91249299 }
91259300
91269301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9152,8 +9327,12 @@
91529327 static double[] model = new double[16];
91539328 double[] camera2light = new double[16];
91549329 double[] light2camera = new double[16];
9155
- int newenvy = -1;
9156
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
91579336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91589337 //float[] light0 = { 0,0,0 };
91599338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9571,7 +9750,7 @@
95719750
95729751 if (renderCamera != lightCamera)
95739752 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95759754
95769755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95779756
....@@ -9587,7 +9766,7 @@
95879766
95889767 if (renderCamera != lightCamera)
95899768 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9590
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95919770
95929771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95939772
....@@ -9633,10 +9812,12 @@
96339812 rati = 1 / rati;
96349813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96359814 }
9636
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
96379818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96389819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9639
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
96409821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96419822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96429823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10673,7 +10854,7 @@
1067310854
1067410855 if (wait)
1067510856 {
10676
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1067710858
1067810859 wait = false;
1067910860 }
....@@ -10788,7 +10969,7 @@
1078810969 // if (parentcam != renderCamera) // not a light
1078910970 if (cam != lightCamera)
1079010971 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10791
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1079210973
1079310974 for (int j = 0; j < 4; j++)
1079410975 {
....@@ -10803,7 +10984,7 @@
1080310984 // if (parentcam != renderCamera) // not a light
1080410985 if (cam != lightCamera)
1080510986 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10806
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1080710988
1080810989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1080910990
....@@ -10889,13 +11070,27 @@
1088911070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1089011071 }
1089111072
10892
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1089311081 {
10894
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1089511087 }
10896
-
10897
- newenvy = -1;
10898
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1089911094 ratio = ((double) getWidth()) / getHeight();
1090011095 //System.out.println("ratio = " + ratio);
1090111096
....@@ -10911,7 +11106,7 @@
1091111106
1091211107 if (!IsFrozen() && !ambientOcclusion)
1091311108 {
10914
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1091511110 }
1091611111
1091711112 //if (selection_view == -1)
....@@ -11065,7 +11260,7 @@
1106511260
1106611261 try
1106711262 {
11068
- BindTexture(null, NOISE_TEXTURE, false, 2);
11263
+ BindTexture(NOISE_TEXTURE, false, 2);
1106911264 }
1107011265 catch (Exception e)
1107111266 {
....@@ -11197,7 +11392,7 @@
1119711392
1119811393 // if (cam != lightCamera)
1119911394 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11200
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1120111396 }
1120211397
1120311398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11356,7 +11551,7 @@
1135611551 }
1135711552 }
1135811553
11359
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1136011555 {
1136111556 //gl.glDepthFunc(GL.GL_LEQUAL);
1136211557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11364,24 +11559,21 @@
1136411559
1136511560 boolean texon = textureon;
1136611561
11367
- if (RENDERPROGRAM > 0)
11368
- {
11369
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11370
- textureon = false;
11371
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1137211565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1137311566 //System.out.println("ALLO");
1137411567 gl.glColorMask(false, false, false, false);
1137511568 DrawObject(gl);
11376
- if (RENDERPROGRAM > 0)
11377
- {
11378
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11379
- textureon = texon;
11380
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1138111573 gl.glColorMask(true, true, true, true);
1138211574
1138311575 gl.glDepthFunc(GL.GL_EQUAL);
11384
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1138511577 }
1138611578
1138711579 if (false) // DrawMode() == SHADOW)
....@@ -11721,20 +11913,32 @@
1172111913 ReleaseTextures(DEFAULT_TEXTURES);
1172211914
1172311915 if (CLEANCACHE)
11724
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1172511917 {
11726
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1172711919
1172811920 // System.out.println("Texture --------- " + tex);
1172911921
11730
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1173111923 continue;
1173211924
1173311925 if (!usedtextures.contains(tex))
1173411926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1173511928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11736
- textures.get(tex).texture.dispose();
11737
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
1173811942 }
1173911943 }
1174011944 }
....@@ -12262,8 +12466,76 @@
1226212466
1226312467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1226412468
12265
- String program =
12469
+ String programmin =
12470
+ // Min shader
1226612471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1226712539 //"OPTION ARB_fragment_program_shadow;" +
1226812540 "PARAM light2cam0 = program.env[10];" +
1226912541 "PARAM light2cam1 = program.env[11];" +
....@@ -12378,8 +12650,7 @@
1237812650 "TEMP shininess;" +
1237912651 "\n" +
1238012652 "MOV texSamp, one;" +
12381
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12382
-
12653
+
1238312654 "MOV mapgrid.x, one2048th.x;" +
1238412655 "MOV temp, fragment.texcoord[1];" +
1238512656 /*
....@@ -12400,20 +12671,20 @@
1240012671 "MUL temp, floor, mapgrid.x;" +
1240112672 //"TEX depth0, temp, texture[1], 2D;" +
1240212673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12403
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1240412675 "") +
1240512676 "ADD temp.x, temp.x, mapgrid.x;" +
1240612677 //"TEX depth1, temp, texture[1], 2D;" +
1240712678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12408
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1240912680 "") +
1241012681 "ADD temp.y, temp.y, mapgrid.x;" +
1241112682 //"TEX depth2, temp, texture[1], 2D;" +
12412
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1241312684 "SUB temp.x, temp.x, mapgrid.x;" +
1241412685 //"TEX depth3, temp, texture[1], 2D;" +
1241512686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12416
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1241712688 "") +
1241812689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1241912690 //"MOV params, material;" +
....@@ -12784,10 +13055,10 @@
1278413055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1278513056 "") +
1278613057
12787
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1278813059 "SUB temp.x, half.x, shadow.x;" +
1278913060 "MOV temp.y, -params5.z;" + // params6.x;" +
12790
- "SLT temp.z, temp.y, -one2048th.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1279113062 "SUB temp.y, one.x, temp.z;" +
1279213063 "MUL temp.x, temp.x, temp.y;" +
1279313064 "KIL temp.x;" +
....@@ -13118,6 +13389,13 @@
1311813389 //once = true;
1311913390 }
1312013391
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
1312113399 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1312213400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1312313401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13211,25 +13489,26 @@
1321113489 return out;
1321213490 }
1321313491
13214
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1321513494 {
1321613495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1321713496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1321813497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1321913500 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13220
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13221
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13222
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13223
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1322413503 //"SWZ buffer, temp, w,w,w,w;";
13225
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1322613505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1322713506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1322813507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13229
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323013509
13231
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13232
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323313512 }
1323413513
1323513514 String Shadow(String depth, String shadow)
....@@ -13276,7 +13555,7 @@
1327613555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1327713556 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1327813557
13279
- // No shadow when out of frustrum
13558
+ // No shadow when out of frustum
1328013559 "SGE temp.x, " + depth + ".z, one.z;" +
1328113560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1328213561 "";
....@@ -14074,14 +14353,15 @@
1407414353 drag = false;
1407514354 //System.out.println("Mouse DOWN");
1407614355 editObj = false;
14077
- ClickInfo info = new ClickInfo();
14078
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14079
- info.pane = this;
14080
- info.camera = renderCamera;
14081
- info.x = x;
14082
- info.y = y;
14083
- info.modifiers = modifiersex;
14084
- editObj = object.doEditClick(info, 0);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1408514365 if (!editObj)
1408614366 {
1408714367 hasMarquee = true;
....@@ -14365,9 +14645,9 @@
1436514645 MODIFIERS |= COMMAND;
1436614646 /**/
1436714647 if((mod&SHIFT) == SHIFT)
14368
- manipCamera.RotatePosition(0, -speed);
14369
- else
1437014648 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14649
+ else
14650
+ manipCamera.RotatePosition(0, -speed);
1437114651 /**/
1437214652 if ((mod & SHIFT) == SHIFT)
1437314653 {
....@@ -14386,9 +14666,9 @@
1438614666 MODIFIERS |= COMMAND;
1438714667 /**/
1438814668 if((mod&SHIFT) == SHIFT)
14389
- manipCamera.RotatePosition(0, speed);
14390
- else
1439114669 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14670
+ else
14671
+ manipCamera.RotatePosition(0, speed);
1439214672 /**/
1439314673 if ((mod & SHIFT) == SHIFT)
1439414674 {
....@@ -14481,15 +14761,16 @@
1448114761 if (editObj)
1448214762 {
1448314763 drag = true;
14484
- ClickInfo info = new ClickInfo();
14485
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1448614766 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14487
- info.pane = this;
14488
- info.camera = renderCamera;
14489
- info.x = x;
14490
- info.y = y;
14491
- object.GetWindow().copy
14492
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1449314774 } else
1449414775 {
1449514776 if (x < startX)
....@@ -14638,24 +14919,27 @@
1463814919 }
1463914920 }
1464014921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1464114924 public void mouseMoved(MouseEvent e)
1464214925 {
1464314926 //System.out.println("mouseMoved: " + e);
1464414927 if (isRenderer)
1464514928 return;
1464614929
14647
- ClickInfo ci = new ClickInfo();
14648
- ci.x = e.getX();
14649
- ci.y = e.getY();
14650
- ci.modifiers = e.getModifiersEx();
14651
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14652
- ci.pane = this;
14653
- ci.camera = renderCamera;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1465414937 if (!isRenderer)
1465514938 {
1465614939 //ObjEditor editWindow = object.editWindow;
1465714940 //Object3D copy = editWindow.copy;
14658
- if (object.doEditClick(ci, 0))
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1465914943 {
1466014944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1466114945 } else
....@@ -14927,7 +15211,8 @@
1492715211 // break;
1492815212 case 'T':
1492915213 CACHETEXTURE ^= true;
14930
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1493115216 // repaint();
1493215217 break;
1493315218 case 'Y':
....@@ -15104,20 +15389,24 @@
1510415389 OCCLUSION_CULLING ^= true;
1510515390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1510615391 break;
15107
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1510815393 case '1':
1510915394 case '2':
1511015395 case '3':
1511115396 case '4':
1511215397 case '5':
15113
- newenvy = Character.getNumericValue(key);
15114
- repaint();
15115
- break;
1511615398 case '6':
1511715399 case '7':
1511815400 case '8':
1511915401 case '9':
15120
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1512115410 repaint();
1512215411 break;
1512315412 case '!':
....@@ -15680,8 +15969,6 @@
1568015969
1568115970 int width = getBounds().width;
1568215971 int height = getBounds().height;
15683
- ClickInfo info = new ClickInfo();
15684
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1568515972 //Image img = CreateImage(width, height);
1568615973 //System.out.println("width = " + width + "; height = " + height + "\n");
1568715974
....@@ -15758,31 +16045,37 @@
1575816045 }
1575916046 if (object != null && !hasMarquee)
1576016047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1576116054 if (isRenderer)
1576216055 {
15763
- info.flags++;
16056
+ object.clickInfo.flags++;
1576416057 double frameAspect = (double) width / (double) height;
1576516058 if (frameAspect > renderCamera.aspect)
1576616059 {
1576716060 int desired = (int) ((double) height * renderCamera.aspect);
15768
- info.bounds.width -= width - desired;
15769
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1577016063 } else
1577116064 {
1577216065 int desired = (int) ((double) width / renderCamera.aspect);
15773
- info.bounds.height -= height - desired;
15774
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1577516068 }
1577616069 }
1577716070
15778
- info.g = gr;
15779
- info.camera = renderCamera;
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1578016073 /*
1578116074 // Memory intensive (brep.verticescopy)
1578216075 if (!(object instanceof Composite))
1578316076 object.draw(info, 0, false); // SLOW :
1578416077 */
15785
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1578616079 {
1578716080 Grafreed.Assert(object != null);
1578816081 Grafreed.Assert(object.selection != null);
....@@ -15790,9 +16083,9 @@
1579016083 {
1579116084 int hitSomething = object.selection.get(0).hitSomething;
1579216085
15793
- info.DX = 0;
15794
- info.DY = 0;
15795
- info.W = 1;
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
1579616089 if (hitSomething == Object3D.hitCenter)
1579716090 {
1579816091 info.DX = X;
....@@ -15804,7 +16097,8 @@
1580416097 info.DY -= info.bounds.height/2;
1580516098 }
1580616099
15807
- object.drawEditHandles(info, 0);
16100
+ object.drawEditHandles(//info,
16101
+ 0);
1580816102
1580916103 if (drag && (X != 0 || Y != 0))
1581016104 {
....@@ -16303,6 +16597,8 @@
1630316597 private /*static*/ boolean firstime;
1630416598 private /*static*/ cVector newView = new cVector();
1630516599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1630616602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1630716603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1630816604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16315,29 +16611,67 @@
1631516611 {
1631616612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1631716613
16614
+ int usedsuf = 0;
16615
+
1631816616 for (int i = 0; i < suffixes.length; i++)
1631916617 {
16320
- String resourceName = basename + suffixes[i] + "." + suffix;
16321
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16322
- mipmapped,
16323
- FileUtil.getFileSuffix(resourceName));
16324
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1632516623 {
16326
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1632716628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1632816657 //System.out.println("Target = " + targets[i]);
1632916658 cubemap.updateImage(data, targets[i]);
1633016659 }
1633116660
1633216661 return cubemap;
1633316662 }
16663
+
1633416664 int bigsphere = -1;
1633516665
1633616666 float BGcolor = 0.5f;
1633716667
16338
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1633916671 {
16340
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1634116675 {
1634216676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1634316677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16352,7 +16686,17 @@
1635216686 // Compensates for ExaminerViewer's modification of modelview matrix
1635316687 gl.glMatrixMode(GL.GL_MODELVIEW);
1635416688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1635516690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1635616700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1635716701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1635816702
....@@ -16384,6 +16728,7 @@
1638416728 {
1638516729 gl.glScalef(1.0f, -1.0f, 1.0f);
1638616730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1638716732 gl.glMultMatrixd(viewrot_1, 0);
1638816733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1638916734 //viewer.updateInverseRotation(gl);
....@@ -16642,7 +16987,7 @@
1664216987 //new Exception().printStackTrace();
1664316988 System.out.println("select buffer init");
1664416989 // Use debug pipeline
16645
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1664616991
1664716992 GL gl = drawable.getGL();
1664816993