Normand Briere
2019-08-12 b1d79b74514041a059b454a9f6fc3970773c0cb8
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,6 +2455,21 @@
24052455 return currentGL;
24062456 }
24072457
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
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);
2471
+ }
2472
+
24082473 /**/
24092474 class CacheTexture
24102475 {
....@@ -2413,18 +2478,20 @@
24132478
24142479 int resolution;
24152480
2416
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24172482 {
2418
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
24192485 resolution = res;
24202486 }
24212487 }
24222488 /**/
24232489
24242490 // TEXTURE static Texture texture;
2425
- static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2426
- static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2427
- 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>();
24282495
24292496 int pigmentdepth = 0;
24302497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
....@@ -2432,10 +2499,10 @@
24322499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24332500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24342501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2435
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24362503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24372504
2438
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24392506 {
24402507 TextureData texturedata = null;
24412508
....@@ -2454,16 +2521,16 @@
24542521 if (bump)
24552522 texturedata = ConvertBump(texturedata, false);
24562523
2457
- com.sun.opengl.util.texture.Texture texture =
2458
- 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);
24592526
2460
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2461
- 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);
24622529
2463
- return texture;
2530
+ return texturedata;
24642531 }
24652532
2466
- com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
24672534 {
24682535 TextureData texturedata = null;
24692536
....@@ -2471,7 +2538,7 @@
24712538 {
24722539 texturedata =
24732540 com.sun.opengl.util.texture.TextureIO.newTextureData(
2474
- name,
2541
+ bim,
24752542 true);
24762543 } catch (Exception e)
24772544 {
....@@ -2480,14 +2547,8 @@
24802547
24812548 if (bump)
24822549 texturedata = ConvertBump(texturedata, false);
2483
-
2484
- com.sun.opengl.util.texture.Texture texture =
2485
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2486
-
2487
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2488
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2489
-
2490
- return texture;
2550
+
2551
+ return texturedata;
24912552 }
24922553
24932554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -7975,8 +8036,8 @@
79758036 pigment = null;
79768037 }
79778038
7978
- ReleaseTexture(bump, true);
7979
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79808041 }
79818042
79828043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8005,7 +8066,7 @@
80058066 pigment = null;
80068067 }
80078068
8008
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
80098070 }
80108071
80118072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8034,10 +8095,10 @@
80348095 bump = null;
80358096 }
80368097
8037
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
80388099 }
80398100
8040
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
80418102 {
80428103 if (// DrawMode() != 0 || /*tex == null ||*/
80438104 ambientOcclusion ) // || !textureon)
....@@ -8048,7 +8109,7 @@
80488109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80498110
80508111 if (tex != null)
8051
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80528113
80538114 // //assert( texture != null );
80548115 // if (texture == null)
....@@ -8198,13 +8259,13 @@
81988259
81998260 if (tex == null)
82008261 {
8201
- BindTexture(null, null,false,resolution);
8262
+ BindTexture(null,false,resolution);
82028263 return;
82038264 }
82048265
82058266 String pigment = Object3D.GetPigment(tex);
82068267
8207
- usedtextures.add(pigment);
8268
+ usedtextures.add(tex);
82088269
82098270 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108271 {
....@@ -8218,7 +8279,7 @@
82188279 }
82198280
82208281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8221
- BindTexture(tex.pigmenttexture, pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
82228283 }
82238284
82248285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8231,13 +8292,13 @@
82318292
82328293 if (tex == null)
82338294 {
8234
- BindTexture(null, null,true,resolution);
8295
+ BindTexture(null,true,resolution);
82358296 return;
82368297 }
82378298
82388299 String bump = Object3D.GetBump(tex);
82398300
8240
- usedtextures.add(bump);
8301
+ usedtextures.add(tex);
82418302
82428303 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82438304 {
....@@ -8251,7 +8312,7 @@
82518312 }
82528313
82538314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8254
- BindTexture(tex.bumptexture, bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
82558316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82568317 }
82578318
....@@ -8275,13 +8336,19 @@
82758336 return fileExists;
82768337 }
82778338
8278
- 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
82798340 {
82808341 CacheTexture texturecache = null;
82818342
82828343 if (tex != null)
82838344 {
8284
- 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
+ }
82858352
82868353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82878354
....@@ -8291,29 +8358,46 @@
82918358 // else
82928359 // if (!texname.startsWith("/"))
82938360 // texname = "/Users/nbriere/Textures/" + texname;
8294
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
82958362 {
82968363 texname = fallbackTextureName;
82978364 }
82988365
82998366 if (CACHETEXTURE)
83008367 {
8301
- if (bim == null)
8302
- texturecache = textures.get(texname); // TEXTURE CACHE
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
83038370 else
8304
- texturecache = bimtextures.get(bim); // TEXTURE CACHE
8371
+ texturecache = bimtextures.get(texdata);
83058372 }
83068373
8307
- if (texturecache == null || texturecache.resolution < resolution)
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
83088375 {
83098376 TextureData texturedata = null;
83108377
8311
- if (bim == null)
8378
+ if (texdata != null && textureon)
83128379 {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
83138381
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
+
8391
+ 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;
83148398 }
83158399 else
8316
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83178401 {
83188402 assert(!bump);
83198403 // if (bump)
....@@ -8324,19 +8408,23 @@
83248408 // }
83258409 // else
83268410 // {
8327
- texturecache = textures.get(tex);
8411
+ // texturecache = textures.get(texname); // suspicious
83288412 if (texturecache == null)
83298413 {
83308414 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83318415 }
8416
+ else
8417
+ new Exception().printStackTrace();
83328418 // }
83338419 } else
8334
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
83358421 {
83368422 assert(bump);
8337
- texturecache = textures.get(tex);
8423
+ // texturecache = textures.get(texname); // suspicious
83388424 if (texturecache == null)
83398425 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
83408428 } else
83418429 {
83428430 //if (tex.equals("IMMORTAL"))
....@@ -8344,11 +8432,22 @@
83448432 // texture = GetResourceTexture("default.png");
83458433 //} else
83468434 //{
8347
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
83488436 {
8349
- texturecache = textures.get(tex);
8437
+ // texturecache = textures.get(texname); // suspicious
83508438 if (texturecache == null)
83518439 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);
8449
+ else
8450
+ new Exception().printStackTrace();
83528451 } else
83538452 {
83548453 if (textureon)
....@@ -8407,14 +8506,15 @@
84078506 if (texturedata == null)
84088507 throw new Exception();
84098508
8410
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
84118510 //texture = GetTexture(tex, bump);
84128511 }
8512
+ }
84138513 }
84148514 //}
84158515 }
84168516
8417
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84188518 {
84198519 //return false;
84208520
....@@ -8436,52 +8536,17 @@
84368536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
84378537 if (!cachefile.exists())
84388538 {
8439
- // cache to disk
8440
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8441
- //buffers[0].
8442
-
8443
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8444
- int[] pixels = new int[bytebuf.capacity()/3];
8445
-
8446
- // squared size heuristic...
8447
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
84488540 {
8449
- for (int i=pixels.length; --i>=0;)
8450
- {
8451
- int i3 = i*3;
8452
- pixels[i] = 0xFF;
8453
- pixels[i] <<= 8;
8454
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8455
- pixels[i] <<= 8;
8456
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8457
- pixels[i] <<= 8;
8458
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8459
- }
8460
-
8461
- /*
8462
- int r=0,g=0,b=0,a=0;
8463
- for (int i=0; i<width; i++)
8464
- for (int j=0; j<height; j++)
8465
- {
8466
- int index = j*width+i;
8467
- int p = pixels[index];
8468
- a = ((p>>24) & 0xFF);
8469
- r = ((p>>16) & 0xFF);
8470
- g = ((p>>8) & 0xFF);
8471
- b = (p & 0xFF);
8472
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8473
- }
8474
- /**/
8475
- int width = (int)Math.sqrt(pixels.length); // squared
8476
- int height = width;
8477
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8478
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
84798543 ImageWriter writer = null;
84808544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84818545 if (iter.hasNext()) {
84828546 writer = (ImageWriter)iter.next();
84838547 }
8484
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
84858550 try
84868551 {
84878552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8498,18 +8563,20 @@
84988563 }
84998564 }
85008565 }
8501
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
85028569 //System.out.println("Texture = " + tex);
8503
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
85048571 {
8505
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
85068573 thetex.texture.disable();
85078574 thetex.texture.dispose();
8508
- textures.remove(texname);
8575
+ textures.remove(tex);
85098576 }
85108577
85118578 //texture.texturedata = texturedata;
8512
- textures.put(texname, texturecache);
8579
+ textures.put(tex, texturecache);
85138580
85148581 // newtex = true;
85158582 }
....@@ -8528,9 +8595,43 @@
85288595 return texturecache;
85298596 }
85308597
8531
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8598
+ static void EmbedTextures(cTexture tex)
85328599 {
8533
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
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
+ }
8616
+
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
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
8633
+ {
8634
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85348635
85358636 if (bump)
85368637 {
....@@ -8546,14 +8647,14 @@
85468647 return texture!=null?texture.texture:null;
85478648 }
85488649
8549
- 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
85508651 {
8551
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8652
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85528653
85538654 return texture!=null?texture.texturedata:null;
85548655 }
85558656
8556
- 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
85578658 {
85588659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85598660 {
....@@ -8562,7 +8663,7 @@
85628663
85638664 //boolean newtex = false;
85648665
8565
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8666
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85668667
85678668 if (texture == null)
85688669 return false;
....@@ -8595,6 +8696,72 @@
85958696 return true; // Warning: not used.
85968697 }
85978698
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
+
85988765 ShadowBuffer shadowPBuf;
85998766 AntialiasBuffer antialiasPBuf;
86008767 int MAXSTACK;
....@@ -8787,7 +8954,7 @@
87878954
87888955 if (cubemap == null)
87898956 {
8790
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
87918958 }
87928959
87938960 //cubemap.enable();
....@@ -9074,37 +9241,58 @@
90749241 cubemap = null;
90759242 return;
90769243 case 1:
9077
- name = "cubemaps/box_";
9078
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
90799246 reverseUP = false;
90809247 break;
90819248 case 2:
9082
- name = "cubemaps/uffizi_";
9083
- ext = "png";
9084
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
90859253 case 3:
9086
- name = "cubemaps/CloudyHills_";
9087
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
90889256 reverseUP = false;
90899257 break;
90909258 case 4:
9091
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
90929260 ext = "png";
90939261 reverseUP = false;
90949262 break;
9263
+ case 5:
9264
+ name = "cubemaps/skycube/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 6:
9269
+ name = "cubemaps/SaintLazarusChurch3/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 7:
9274
+ name = "cubemaps/Sodermalmsallen/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 8:
9279
+ name = "cubemaps/Sodermalmsallen2/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 9:
9284
+ name = "cubemaps/UnionSquare/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
90959288 default:
9096
- name = "cubemaps/rgb_";
9097
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
90989292 break;
90999293 }
9100
-
9101
- try
9102
- {
9103
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9104
- } catch (IOException e)
9105
- {
9106
- throw new RuntimeException(e);
9107
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
91089296 }
91099297
91109298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9136,8 +9324,12 @@
91369324 static double[] model = new double[16];
91379325 double[] camera2light = new double[16];
91389326 double[] light2camera = new double[16];
9139
- int newenvy = -1;
9140
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
91419333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91429334 //float[] light0 = { 0,0,0 };
91439335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9555,7 +9747,7 @@
95559747
95569748 if (renderCamera != lightCamera)
95579749 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9558
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95599751
95609752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95619753
....@@ -9571,7 +9763,7 @@
95719763
95729764 if (renderCamera != lightCamera)
95739765 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95759767
95769768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95779769
....@@ -9617,10 +9809,12 @@
96179809 rati = 1 / rati;
96189810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96199811 }
9620
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
96219815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96229816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9623
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
96249818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96259819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96269820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10657,7 +10851,7 @@
1065710851
1065810852 if (wait)
1065910853 {
10660
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1066110855
1066210856 wait = false;
1066310857 }
....@@ -10772,7 +10966,7 @@
1077210966 // if (parentcam != renderCamera) // not a light
1077310967 if (cam != lightCamera)
1077410968 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10775
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1077610970
1077710971 for (int j = 0; j < 4; j++)
1077810972 {
....@@ -10787,7 +10981,7 @@
1078710981 // if (parentcam != renderCamera) // not a light
1078810982 if (cam != lightCamera)
1078910983 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10790
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1079110985
1079210986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1079310987
....@@ -10873,13 +11067,27 @@
1087311067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1087411068 }
1087511069
10876
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1087711078 {
10878
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1087911084 }
10880
-
10881
- newenvy = -1;
10882
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1088311091 ratio = ((double) getWidth()) / getHeight();
1088411092 //System.out.println("ratio = " + ratio);
1088511093
....@@ -10895,7 +11103,7 @@
1089511103
1089611104 if (!IsFrozen() && !ambientOcclusion)
1089711105 {
10898
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1089911107 }
1090011108
1090111109 //if (selection_view == -1)
....@@ -11049,7 +11257,7 @@
1104911257
1105011258 try
1105111259 {
11052
- BindTexture(null, NOISE_TEXTURE, false, 2);
11260
+ BindTexture(NOISE_TEXTURE, false, 2);
1105311261 }
1105411262 catch (Exception e)
1105511263 {
....@@ -11181,7 +11389,7 @@
1118111389
1118211390 // if (cam != lightCamera)
1118311391 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11184
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1118511393 }
1118611394
1118711395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11340,7 +11548,7 @@
1134011548 }
1134111549 }
1134211550
11343
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1134411552 {
1134511553 //gl.glDepthFunc(GL.GL_LEQUAL);
1134611554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11348,24 +11556,21 @@
1134811556
1134911557 boolean texon = textureon;
1135011558
11351
- if (RENDERPROGRAM > 0)
11352
- {
11353
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11354
- textureon = false;
11355
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1135611562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1135711563 //System.out.println("ALLO");
1135811564 gl.glColorMask(false, false, false, false);
1135911565 DrawObject(gl);
11360
- if (RENDERPROGRAM > 0)
11361
- {
11362
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11363
- textureon = texon;
11364
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1136511570 gl.glColorMask(true, true, true, true);
1136611571
1136711572 gl.glDepthFunc(GL.GL_EQUAL);
11368
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1136911574 }
1137011575
1137111576 if (false) // DrawMode() == SHADOW)
....@@ -11705,20 +11910,32 @@
1170511910 ReleaseTextures(DEFAULT_TEXTURES);
1170611911
1170711912 if (CLEANCACHE)
11708
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1170911914 {
11710
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1171111916
1171211917 // System.out.println("Texture --------- " + tex);
1171311918
11714
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1171511920 continue;
1171611921
1171711922 if (!usedtextures.contains(tex))
1171811923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1171911925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11720
- textures.get(tex).texture.dispose();
11721
- textures.remove(tex);
11926
+ if (gettex != null)
11927
+ {
11928
+ gettex.texture.dispose();
11929
+ texturepigment.remove(tex);
11930
+ }
11931
+
11932
+ gettex = texturebump.get(tex);
11933
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11934
+ if (gettex != null)
11935
+ {
11936
+ gettex.texture.dispose();
11937
+ texturebump.remove(tex);
11938
+ }
1172211939 }
1172311940 }
1172411941 }
....@@ -12246,8 +12463,76 @@
1224612463
1224712464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1224812465
12249
- String program =
12466
+ String programmin =
12467
+ // Min shader
1225012468 "!!ARBfp1.0\n" +
12469
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12470
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12471
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12472
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12473
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12474
+ "PARAM light2cam0 = program.env[10];" +
12475
+ "PARAM light2cam1 = program.env[11];" +
12476
+ "PARAM light2cam2 = program.env[12];" +
12477
+ "TEMP temp;" +
12478
+ "TEMP light;" +
12479
+ "TEMP ndotl;" +
12480
+ "TEMP normal;" +
12481
+ "TEMP depth;" +
12482
+ "TEMP eye;" +
12483
+ "TEMP pos;" +
12484
+
12485
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12486
+ Normalize("normal") +
12487
+ "MOV light, state.light[0].position;" +
12488
+ "DP3 ndotl.x, light, normal;" +
12489
+
12490
+ // shadow
12491
+ "MOV pos, fragment.texcoord[1];" +
12492
+ "MOV temp, pos;" +
12493
+ ShadowTextureFetch("depth", "temp", "1") +
12494
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12495
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12496
+
12497
+ // No shadow when out of frustum
12498
+ //"SGE temp.y, depth.z, zero123.y;" +
12499
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12500
+
12501
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12502
+
12503
+ // Backlit
12504
+ "MOV pos.w, zero123.y;" +
12505
+ "DP4 eye.x, pos, light2cam0;" +
12506
+ "DP4 eye.y, pos, light2cam1;" +
12507
+ "DP4 eye.z, pos, light2cam2;" +
12508
+ Normalize("eye") +
12509
+
12510
+ "DP3 ndotl.y, -eye, normal;" +
12511
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12512
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12513
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12514
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12515
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12516
+
12517
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12518
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12519
+
12520
+ // Pigment
12521
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12522
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12523
+ "MUL temp, temp, ndotl.x;" +
12524
+
12525
+ "MUL temp, temp, zero123.z;" +
12526
+
12527
+ //"MUL temp, temp, ndotl.y;" +
12528
+
12529
+ "MOV temp.w, zero123.y;" + // reset alpha
12530
+ "MOV result.color, temp;" +
12531
+ "END";
12532
+
12533
+ String programmax =
12534
+ "!!ARBfp1.0\n" +
12535
+
1225112536 //"OPTION ARB_fragment_program_shadow;" +
1225212537 "PARAM light2cam0 = program.env[10];" +
1225312538 "PARAM light2cam1 = program.env[11];" +
....@@ -12362,8 +12647,7 @@
1236212647 "TEMP shininess;" +
1236312648 "\n" +
1236412649 "MOV texSamp, one;" +
12365
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12366
-
12650
+
1236712651 "MOV mapgrid.x, one2048th.x;" +
1236812652 "MOV temp, fragment.texcoord[1];" +
1236912653 /*
....@@ -12384,20 +12668,20 @@
1238412668 "MUL temp, floor, mapgrid.x;" +
1238512669 //"TEX depth0, temp, texture[1], 2D;" +
1238612670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12387
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1238812672 "") +
1238912673 "ADD temp.x, temp.x, mapgrid.x;" +
1239012674 //"TEX depth1, temp, texture[1], 2D;" +
1239112675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12392
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1239312677 "") +
1239412678 "ADD temp.y, temp.y, mapgrid.x;" +
1239512679 //"TEX depth2, temp, texture[1], 2D;" +
12396
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1239712681 "SUB temp.x, temp.x, mapgrid.x;" +
1239812682 //"TEX depth3, temp, texture[1], 2D;" +
1239912683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12400
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1240112685 "") +
1240212686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1240312687 //"MOV params, material;" +
....@@ -12768,10 +13052,10 @@
1276813052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1276913053 "") +
1277013054
12771
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1277213056 "SUB temp.x, half.x, shadow.x;" +
1277313057 "MOV temp.y, -params5.z;" + // params6.x;" +
12774
- "SLT temp.z, temp.y, -one2048th.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1277513059 "SUB temp.y, one.x, temp.z;" +
1277613060 "MUL temp.x, temp.x, temp.y;" +
1277713061 "KIL temp.x;" +
....@@ -13102,6 +13386,13 @@
1310213386 //once = true;
1310313387 }
1310413388
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
1310513396 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1310613397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1310713398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13195,25 +13486,26 @@
1319513486 return out;
1319613487 }
1319713488
13198
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1319913491 {
1320013492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1320113493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1320213494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1320313497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13204
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13205
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13206
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13207
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1320813500 //"SWZ buffer, temp, w,w,w,w;";
13209
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1321013502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1321113503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1321213504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13213
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321413506
13215
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13216
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13507
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13508
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321713509 }
1321813510
1321913511 String Shadow(String depth, String shadow)
....@@ -13260,7 +13552,7 @@
1326013552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1326113553 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326213554
13263
- // No shadow when out of frustrum
13555
+ // No shadow when out of frustum
1326413556 "SGE temp.x, " + depth + ".z, one.z;" +
1326513557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326613558 "";
....@@ -14058,14 +14350,15 @@
1405814350 drag = false;
1405914351 //System.out.println("Mouse DOWN");
1406014352 editObj = false;
14061
- ClickInfo info = new ClickInfo();
14062
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14063
- info.pane = this;
14064
- info.camera = renderCamera;
14065
- info.x = x;
14066
- info.y = y;
14067
- info.modifiers = modifiersex;
14068
- editObj = object.doEditClick(info, 0);
14353
+ //ClickInfo info = new ClickInfo();
14354
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14355
+ object.clickInfo.pane = this;
14356
+ object.clickInfo.camera = renderCamera;
14357
+ object.clickInfo.x = x;
14358
+ object.clickInfo.y = y;
14359
+ object.clickInfo.modifiers = modifiersex;
14360
+ editObj = object.doEditClick(//info,
14361
+ 0);
1406914362 if (!editObj)
1407014363 {
1407114364 hasMarquee = true;
....@@ -14349,9 +14642,9 @@
1434914642 MODIFIERS |= COMMAND;
1435014643 /**/
1435114644 if((mod&SHIFT) == SHIFT)
14352
- manipCamera.RotatePosition(0, -speed);
14353
- else
1435414645 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14646
+ else
14647
+ manipCamera.RotatePosition(0, -speed);
1435514648 /**/
1435614649 if ((mod & SHIFT) == SHIFT)
1435714650 {
....@@ -14370,9 +14663,9 @@
1437014663 MODIFIERS |= COMMAND;
1437114664 /**/
1437214665 if((mod&SHIFT) == SHIFT)
14373
- manipCamera.RotatePosition(0, speed);
14374
- else
1437514666 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14667
+ else
14668
+ manipCamera.RotatePosition(0, speed);
1437614669 /**/
1437714670 if ((mod & SHIFT) == SHIFT)
1437814671 {
....@@ -14465,15 +14758,16 @@
1446514758 if (editObj)
1446614759 {
1446714760 drag = true;
14468
- ClickInfo info = new ClickInfo();
14469
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1447014763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14471
- info.pane = this;
14472
- info.camera = renderCamera;
14473
- info.x = x;
14474
- info.y = y;
14475
- object.GetWindow().copy
14476
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14764
+ object.clickInfo.pane = this;
14765
+ object.clickInfo.camera = renderCamera;
14766
+ object.clickInfo.x = x;
14767
+ object.clickInfo.y = y;
14768
+ object //.GetWindow().copy
14769
+ .doEditDrag(//info,
14770
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1447714771 } else
1447814772 {
1447914773 if (x < startX)
....@@ -14622,24 +14916,27 @@
1462214916 }
1462314917 }
1462414918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1462514921 public void mouseMoved(MouseEvent e)
1462614922 {
1462714923 //System.out.println("mouseMoved: " + e);
1462814924 if (isRenderer)
1462914925 return;
1463014926
14631
- ClickInfo ci = new ClickInfo();
14632
- ci.x = e.getX();
14633
- ci.y = e.getY();
14634
- ci.modifiers = e.getModifiersEx();
14635
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14636
- ci.pane = this;
14637
- ci.camera = renderCamera;
14927
+ // Mouse cursor feedback
14928
+ object.clickInfo.x = e.getX();
14929
+ object.clickInfo.y = e.getY();
14930
+ object.clickInfo.modifiers = e.getModifiersEx();
14931
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14932
+ object.clickInfo.pane = this;
14933
+ object.clickInfo.camera = renderCamera;
1463814934 if (!isRenderer)
1463914935 {
1464014936 //ObjEditor editWindow = object.editWindow;
1464114937 //Object3D copy = editWindow.copy;
14642
- if (object.doEditClick(ci, 0))
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1464314940 {
1464414941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1464514942 } else
....@@ -14911,7 +15208,8 @@
1491115208 // break;
1491215209 case 'T':
1491315210 CACHETEXTURE ^= true;
14914
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1491515213 // repaint();
1491615214 break;
1491715215 case 'Y':
....@@ -15088,20 +15386,24 @@
1508815386 OCCLUSION_CULLING ^= true;
1508915387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1509015388 break;
15091
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1509215390 case '1':
1509315391 case '2':
1509415392 case '3':
1509515393 case '4':
1509615394 case '5':
15097
- newenvy = Character.getNumericValue(key);
15098
- repaint();
15099
- break;
1510015395 case '6':
1510115396 case '7':
1510215397 case '8':
1510315398 case '9':
15104
- BGcolor = (key - '6')/3.f;
15399
+ if (true) // envyoff)
15400
+ {
15401
+ BGcolor = (key - '1')/8.f;
15402
+ }
15403
+ else
15404
+ {
15405
+ //newenvy = Character.getNumericValue(key);
15406
+ }
1510515407 repaint();
1510615408 break;
1510715409 case '!':
....@@ -15664,8 +15966,6 @@
1566415966
1566515967 int width = getBounds().width;
1566615968 int height = getBounds().height;
15667
- ClickInfo info = new ClickInfo();
15668
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1566915969 //Image img = CreateImage(width, height);
1567015970 //System.out.println("width = " + width + "; height = " + height + "\n");
1567115971
....@@ -15742,31 +16042,37 @@
1574216042 }
1574316043 if (object != null && !hasMarquee)
1574416044 {
16045
+ if (object.clickInfo == null)
16046
+ object.clickInfo = new ClickInfo();
16047
+ ClickInfo info = object.clickInfo;
16048
+ //ClickInfo info = new ClickInfo();
16049
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16050
+
1574516051 if (isRenderer)
1574616052 {
15747
- info.flags++;
16053
+ object.clickInfo.flags++;
1574816054 double frameAspect = (double) width / (double) height;
1574916055 if (frameAspect > renderCamera.aspect)
1575016056 {
1575116057 int desired = (int) ((double) height * renderCamera.aspect);
15752
- info.bounds.width -= width - desired;
15753
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1575416060 } else
1575516061 {
1575616062 int desired = (int) ((double) width / renderCamera.aspect);
15757
- info.bounds.height -= height - desired;
15758
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1575916065 }
1576016066 }
1576116067
15762
- info.g = gr;
15763
- info.camera = renderCamera;
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1576416070 /*
1576516071 // Memory intensive (brep.verticescopy)
1576616072 if (!(object instanceof Composite))
1576716073 object.draw(info, 0, false); // SLOW :
1576816074 */
15769
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1577016076 {
1577116077 Grafreed.Assert(object != null);
1577216078 Grafreed.Assert(object.selection != null);
....@@ -15774,9 +16080,9 @@
1577416080 {
1577516081 int hitSomething = object.selection.get(0).hitSomething;
1577616082
15777
- info.DX = 0;
15778
- info.DY = 0;
15779
- info.W = 1;
16083
+ object.clickInfo.DX = 0;
16084
+ object.clickInfo.DY = 0;
16085
+ object.clickInfo.W = 1;
1578016086 if (hitSomething == Object3D.hitCenter)
1578116087 {
1578216088 info.DX = X;
....@@ -15788,7 +16094,8 @@
1578816094 info.DY -= info.bounds.height/2;
1578916095 }
1579016096
15791
- object.drawEditHandles(info, 0);
16097
+ object.drawEditHandles(//info,
16098
+ 0);
1579216099
1579316100 if (drag && (X != 0 || Y != 0))
1579416101 {
....@@ -16287,6 +16594,8 @@
1628716594 private /*static*/ boolean firstime;
1628816595 private /*static*/ cVector newView = new cVector();
1628916596 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16597
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16598
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1629016599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1629116600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1629216601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16299,29 +16608,67 @@
1629916608 {
1630016609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1630116610
16611
+ int usedsuf = 0;
16612
+
1630216613 for (int i = 0; i < suffixes.length; i++)
1630316614 {
16304
- String resourceName = basename + suffixes[i] + "." + suffix;
16305
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16306
- mipmapped,
16307
- FileUtil.getFileSuffix(resourceName));
16308
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1630916620 {
16310
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1631116625 }
16626
+
16627
+ String resourceName = basename + suffixe[i] + "." + suffix;
16628
+ TextureData data;
16629
+
16630
+ try
16631
+ {
16632
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16633
+ mipmapped,
16634
+ FileUtil.getFileSuffix(resourceName));
16635
+ }
16636
+ catch (Exception e)
16637
+ {
16638
+ try
16639
+ {
16640
+ resourceName = basename + fallback[i] + "." + suffix;
16641
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16642
+ mipmapped,
16643
+ FileUtil.getFileSuffix(resourceName));
16644
+ }
16645
+ catch (Exception e2)
16646
+ {
16647
+ resourceName = basename + fallfallback[i] + "." + suffix;
16648
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16649
+ mipmapped,
16650
+ FileUtil.getFileSuffix(resourceName));
16651
+ }
16652
+ }
16653
+
1631216654 //System.out.println("Target = " + targets[i]);
1631316655 cubemap.updateImage(data, targets[i]);
1631416656 }
1631516657
1631616658 return cubemap;
1631716659 }
16660
+
1631816661 int bigsphere = -1;
1631916662
1632016663 float BGcolor = 0.5f;
1632116664
16322
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1632316668 {
16324
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1632516672 {
1632616673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1632716674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16336,7 +16683,17 @@
1633616683 // Compensates for ExaminerViewer's modification of modelview matrix
1633716684 gl.glMatrixMode(GL.GL_MODELVIEW);
1633816685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1633916687
16688
+// colorV[0] = 2;
16689
+// colorV[1] = 2;
16690
+// colorV[2] = 2;
16691
+// colorV[3] = 1;
16692
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16693
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16694
+//
16695
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16696
+
1634016697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1634116698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1634216699
....@@ -16368,6 +16725,7 @@
1636816725 {
1636916726 gl.glScalef(1.0f, -1.0f, 1.0f);
1637016727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1637116729 gl.glMultMatrixd(viewrot_1, 0);
1637216730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1637316731 //viewer.updateInverseRotation(gl);
....@@ -16626,7 +16984,7 @@
1662616984 //new Exception().printStackTrace();
1662716985 System.out.println("select buffer init");
1662816986 // Use debug pipeline
16629
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1663016988
1663116989 GL gl = drawable.getGL();
1663216990