Normand Briere
2019-08-06 b3ae4e889872ca0b9ca76f1d17b2f0b961226729
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))
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,13 @@
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();
83528442 } else
83538443 {
83548444 if (textureon)
....@@ -8407,14 +8497,14 @@
84078497 if (texturedata == null)
84088498 throw new Exception();
84098499
8410
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8500
+ texturecache = new CacheTexture(texturedata,resolution);
84118501 //texture = GetTexture(tex, bump);
84128502 }
84138503 }
84148504 //}
84158505 }
84168506
8417
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84188508 {
84198509 //return false;
84208510
....@@ -8436,52 +8526,17 @@
84368526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
84378527 if (!cachefile.exists())
84388528 {
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))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
84488530 {
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);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
84798533 ImageWriter writer = null;
84808534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84818535 if (iter.hasNext()) {
84828536 writer = (ImageWriter)iter.next();
84838537 }
8484
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
84858540 try
84868541 {
84878542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8498,18 +8553,20 @@
84988553 }
84998554 }
85008555 }
8501
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
85028559 //System.out.println("Texture = " + tex);
8503
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
85048561 {
8505
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
85068563 thetex.texture.disable();
85078564 thetex.texture.dispose();
8508
- textures.remove(texname);
8565
+ textures.remove(tex);
85098566 }
85108567
85118568 //texture.texturedata = texturedata;
8512
- textures.put(texname, texturecache);
8569
+ textures.put(tex, texturecache);
85138570
85148571 // newtex = true;
85158572 }
....@@ -8528,9 +8585,43 @@
85288585 return texturecache;
85298586 }
85308587
8531
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8588
+ static void EmbedTextures(cTexture tex)
85328589 {
8533
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8590
+ if (tex.pigmentdata == null)
8591
+ {
8592
+ //String texname = Object3D.GetPigment(tex);
8593
+
8594
+ CacheTexture texturecache = texturepigment.get(tex);
8595
+
8596
+ if (texturecache != null)
8597
+ {
8598
+ tex.pw = texturecache.texturedata.getWidth();
8599
+ tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
8604
+ }
8605
+ }
8606
+
8607
+ if (tex.bumpdata == null)
8608
+ {
8609
+ //String texname = Object3D.GetBump(tex);
8610
+
8611
+ CacheTexture texturecache = texturebump.get(tex);
8612
+
8613
+ if (texturecache != null)
8614
+ {
8615
+ tex.bw = texturecache.texturedata.getWidth();
8616
+ tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8618
+ }
8619
+ }
8620
+ }
8621
+
8622
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
8623
+ {
8624
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85348625
85358626 if (bump)
85368627 {
....@@ -8546,14 +8637,14 @@
85468637 return texture!=null?texture.texture:null;
85478638 }
85488639
8549
- public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8640
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85508641 {
8551
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8642
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85528643
85538644 return texture!=null?texture.texturedata:null;
85548645 }
85558646
8556
- boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85578648 {
85588649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85598650 {
....@@ -8562,7 +8653,7 @@
85628653
85638654 //boolean newtex = false;
85648655
8565
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8656
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85668657
85678658 if (texture == null)
85688659 return false;
....@@ -8595,6 +8686,72 @@
85958686 return true; // Warning: not used.
85968687 }
85978688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
85988755 ShadowBuffer shadowPBuf;
85998756 AntialiasBuffer antialiasPBuf;
86008757 int MAXSTACK;
....@@ -8787,7 +8944,7 @@
87878944
87888945 if (cubemap == null)
87898946 {
8790
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
87918948 }
87928949
87938950 //cubemap.enable();
....@@ -9074,37 +9231,58 @@
90749231 cubemap = null;
90759232 return;
90769233 case 1:
9077
- name = "cubemaps/box_";
9078
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
90799236 reverseUP = false;
90809237 break;
90819238 case 2:
9082
- name = "cubemaps/uffizi_";
9083
- ext = "png";
9084
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
90859243 case 3:
9086
- name = "cubemaps/CloudyHills_";
9087
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
90889246 reverseUP = false;
90899247 break;
90909248 case 4:
9091
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
90929250 ext = "png";
90939251 reverseUP = false;
90949252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
90959278 default:
9096
- name = "cubemaps/rgb_";
9097
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
90989282 break;
90999283 }
9100
-
9101
- try
9102
- {
9103
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9104
- } catch (IOException e)
9105
- {
9106
- throw new RuntimeException(e);
9107
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
91089286 }
91099287
91109288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9136,8 +9314,12 @@
91369314 static double[] model = new double[16];
91379315 double[] camera2light = new double[16];
91389316 double[] light2camera = new double[16];
9139
- int newenvy = -1;
9140
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
91419323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91429324 //float[] light0 = { 0,0,0 };
91439325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9555,7 +9737,7 @@
95559737
95569738 if (renderCamera != lightCamera)
95579739 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9558
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95599741
95609742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95619743
....@@ -9571,7 +9753,7 @@
95719753
95729754 if (renderCamera != lightCamera)
95739755 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95759757
95769758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95779759
....@@ -9617,10 +9799,12 @@
96179799 rati = 1 / rati;
96189800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96199801 }
9620
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
96219805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96229806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9623
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
96249808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96259809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96269810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10772,7 +10956,7 @@
1077210956 // if (parentcam != renderCamera) // not a light
1077310957 if (cam != lightCamera)
1077410958 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10775
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1077610960
1077710961 for (int j = 0; j < 4; j++)
1077810962 {
....@@ -10787,7 +10971,7 @@
1078710971 // if (parentcam != renderCamera) // not a light
1078810972 if (cam != lightCamera)
1078910973 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10790
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1079110975
1079210976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1079310977
....@@ -10873,13 +11057,27 @@
1087311057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1087411058 }
1087511059
10876
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1087711068 {
10878
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1087911074 }
10880
-
10881
- newenvy = -1;
10882
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1088311081 ratio = ((double) getWidth()) / getHeight();
1088411082 //System.out.println("ratio = " + ratio);
1088511083
....@@ -10895,7 +11093,7 @@
1089511093
1089611094 if (!IsFrozen() && !ambientOcclusion)
1089711095 {
10898
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1089911097 }
1090011098
1090111099 //if (selection_view == -1)
....@@ -11049,7 +11247,7 @@
1104911247
1105011248 try
1105111249 {
11052
- BindTexture(null, NOISE_TEXTURE, false, 2);
11250
+ BindTexture(NOISE_TEXTURE, false, 2);
1105311251 }
1105411252 catch (Exception e)
1105511253 {
....@@ -11181,7 +11379,7 @@
1118111379
1118211380 // if (cam != lightCamera)
1118311381 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11184
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11382
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1118511383 }
1118611384
1118711385 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11340,7 +11538,7 @@
1134011538 }
1134111539 }
1134211540
11343
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1134411542 {
1134511543 //gl.glDepthFunc(GL.GL_LEQUAL);
1134611544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11348,24 +11546,21 @@
1134811546
1134911547 boolean texon = textureon;
1135011548
11351
- if (RENDERPROGRAM > 0)
11352
- {
11353
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11354
- textureon = false;
11355
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1135611552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1135711553 //System.out.println("ALLO");
1135811554 gl.glColorMask(false, false, false, false);
1135911555 DrawObject(gl);
11360
- if (RENDERPROGRAM > 0)
11361
- {
11362
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11363
- textureon = texon;
11364
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1136511560 gl.glColorMask(true, true, true, true);
1136611561
1136711562 gl.glDepthFunc(GL.GL_EQUAL);
11368
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1136911564 }
1137011565
1137111566 if (false) // DrawMode() == SHADOW)
....@@ -11705,20 +11900,32 @@
1170511900 ReleaseTextures(DEFAULT_TEXTURES);
1170611901
1170711902 if (CLEANCACHE)
11708
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11903
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1170911904 {
11710
- String tex = e.nextElement();
11905
+ cTexture tex = e.nextElement();
1171111906
1171211907 // System.out.println("Texture --------- " + tex);
1171311908
11714
- if (tex.equals("WHITE_NOISE"))
11909
+ if (tex.equals("WHITE_NOISE:"))
1171511910 continue;
1171611911
1171711912 if (!usedtextures.contains(tex))
1171811913 {
11914
+ CacheTexture gettex = texturepigment.get(tex);
1171911915 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11720
- textures.get(tex).texture.dispose();
11721
- textures.remove(tex);
11916
+ if (gettex != null)
11917
+ {
11918
+ gettex.texture.dispose();
11919
+ texturepigment.remove(tex);
11920
+ }
11921
+
11922
+ gettex = texturebump.get(tex);
11923
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11924
+ if (gettex != null)
11925
+ {
11926
+ gettex.texture.dispose();
11927
+ texturebump.remove(tex);
11928
+ }
1172211929 }
1172311930 }
1172411931 }
....@@ -12246,8 +12453,76 @@
1224612453
1224712454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1224812455
12249
- String program =
12456
+ String programmin =
12457
+ // Min shader
1225012458 "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
12523
+ String programmax =
12524
+ "!!ARBfp1.0\n" +
12525
+
1225112526 //"OPTION ARB_fragment_program_shadow;" +
1225212527 "PARAM light2cam0 = program.env[10];" +
1225312528 "PARAM light2cam1 = program.env[11];" +
....@@ -12362,8 +12637,7 @@
1236212637 "TEMP shininess;" +
1236312638 "\n" +
1236412639 "MOV texSamp, one;" +
12365
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12366
-
12640
+
1236712641 "MOV mapgrid.x, one2048th.x;" +
1236812642 "MOV temp, fragment.texcoord[1];" +
1236912643 /*
....@@ -12384,20 +12658,20 @@
1238412658 "MUL temp, floor, mapgrid.x;" +
1238512659 //"TEX depth0, temp, texture[1], 2D;" +
1238612660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12387
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1238812662 "") +
1238912663 "ADD temp.x, temp.x, mapgrid.x;" +
1239012664 //"TEX depth1, temp, texture[1], 2D;" +
1239112665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12392
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1239312667 "") +
1239412668 "ADD temp.y, temp.y, mapgrid.x;" +
1239512669 //"TEX depth2, temp, texture[1], 2D;" +
12396
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1239712671 "SUB temp.x, temp.x, mapgrid.x;" +
1239812672 //"TEX depth3, temp, texture[1], 2D;" +
1239912673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12400
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1240112675 "") +
1240212676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1240312677 //"MOV params, material;" +
....@@ -12768,10 +13042,10 @@
1276813042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1276913043 "") +
1277013044
12771
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1277213046 "SUB temp.x, half.x, shadow.x;" +
1277313047 "MOV temp.y, -params5.z;" + // params6.x;" +
12774
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1277513049 "SUB temp.y, one.x, temp.z;" +
1277613050 "MUL temp.x, temp.x, temp.y;" +
1277713051 "KIL temp.x;" +
....@@ -13102,6 +13376,13 @@
1310213376 //once = true;
1310313377 }
1310413378
13379
+ String program = programmax;
13380
+
13381
+ if (Globals.MINSHADER)
13382
+ {
13383
+ program = programmin;
13384
+ }
13385
+
1310513386 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1310613387 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1310713388 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13195,25 +13476,26 @@
1319513476 return out;
1319613477 }
1319713478
13198
- String TextureFetch(String dest, String src, String unit)
13479
+ // Also does frustum culling
13480
+ String ShadowTextureFetch(String dest, String src, String unit)
1319913481 {
1320013482 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1320113483 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1320213484 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13485
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13486
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1320313487 "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;" +
13488
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13489
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1320813490 //"SWZ buffer, temp, w,w,w,w;";
13209
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13491
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1321013492 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1321113493 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1321213494 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13213
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13495
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321413496
13215
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13216
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13497
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13498
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321713499 }
1321813500
1321913501 String Shadow(String depth, String shadow)
....@@ -13260,7 +13542,7 @@
1326013542 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1326113543 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326213544
13263
- // No shadow when out of frustrum
13545
+ // No shadow when out of frustum
1326413546 "SGE temp.x, " + depth + ".z, one.z;" +
1326513547 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326613548 "";
....@@ -14058,14 +14340,15 @@
1405814340 drag = false;
1405914341 //System.out.println("Mouse DOWN");
1406014342 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);
14343
+ //ClickInfo info = new ClickInfo();
14344
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14345
+ object.clickInfo.pane = this;
14346
+ object.clickInfo.camera = renderCamera;
14347
+ object.clickInfo.x = x;
14348
+ object.clickInfo.y = y;
14349
+ object.clickInfo.modifiers = modifiersex;
14350
+ editObj = object.doEditClick(//info,
14351
+ 0);
1406914352 if (!editObj)
1407014353 {
1407114354 hasMarquee = true;
....@@ -14349,9 +14632,9 @@
1434914632 MODIFIERS |= COMMAND;
1435014633 /**/
1435114634 if((mod&SHIFT) == SHIFT)
14352
- manipCamera.RotatePosition(0, -speed);
14353
- else
1435414635 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14636
+ else
14637
+ manipCamera.RotatePosition(0, -speed);
1435514638 /**/
1435614639 if ((mod & SHIFT) == SHIFT)
1435714640 {
....@@ -14370,9 +14653,9 @@
1437014653 MODIFIERS |= COMMAND;
1437114654 /**/
1437214655 if((mod&SHIFT) == SHIFT)
14373
- manipCamera.RotatePosition(0, speed);
14374
- else
1437514656 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14657
+ else
14658
+ manipCamera.RotatePosition(0, speed);
1437614659 /**/
1437714660 if ((mod & SHIFT) == SHIFT)
1437814661 {
....@@ -14465,15 +14748,16 @@
1446514748 if (editObj)
1446614749 {
1446714750 drag = true;
14468
- ClickInfo info = new ClickInfo();
14469
- info.bounds.setBounds(0, 0,
14751
+ //ClickInfo info = new ClickInfo();
14752
+ object.clickInfo.bounds.setBounds(0, 0,
1447014753 (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);
14754
+ object.clickInfo.pane = this;
14755
+ object.clickInfo.camera = renderCamera;
14756
+ object.clickInfo.x = x;
14757
+ object.clickInfo.y = y;
14758
+ object //.GetWindow().copy
14759
+ .doEditDrag(//info,
14760
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1447714761 } else
1447814762 {
1447914763 if (x < startX)
....@@ -14622,24 +14906,27 @@
1462214906 }
1462314907 }
1462414908
14909
+// ClickInfo clickInfo = new ClickInfo();
14910
+
1462514911 public void mouseMoved(MouseEvent e)
1462614912 {
1462714913 //System.out.println("mouseMoved: " + e);
1462814914 if (isRenderer)
1462914915 return;
1463014916
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;
14917
+ // Mouse cursor feedback
14918
+ object.clickInfo.x = e.getX();
14919
+ object.clickInfo.y = e.getY();
14920
+ object.clickInfo.modifiers = e.getModifiersEx();
14921
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14922
+ object.clickInfo.pane = this;
14923
+ object.clickInfo.camera = renderCamera;
1463814924 if (!isRenderer)
1463914925 {
1464014926 //ObjEditor editWindow = object.editWindow;
1464114927 //Object3D copy = editWindow.copy;
14642
- if (object.doEditClick(ci, 0))
14928
+ if (object.doEditClick(//clickInfo,
14929
+ 0))
1464314930 {
1464414931 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1464514932 } else
....@@ -14911,7 +15198,8 @@
1491115198 // break;
1491215199 case 'T':
1491315200 CACHETEXTURE ^= true;
14914
- textures.clear();
15201
+ texturepigment.clear();
15202
+ texturebump.clear();
1491515203 // repaint();
1491615204 break;
1491715205 case 'Y':
....@@ -15088,20 +15376,24 @@
1508815376 OCCLUSION_CULLING ^= true;
1508915377 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1509015378 break;
15091
- case '0': envyoff ^= true; repaint(); break;
15379
+ //case '0': envyoff ^= true; repaint(); break;
1509215380 case '1':
1509315381 case '2':
1509415382 case '3':
1509515383 case '4':
1509615384 case '5':
15097
- newenvy = Character.getNumericValue(key);
15098
- repaint();
15099
- break;
1510015385 case '6':
1510115386 case '7':
1510215387 case '8':
1510315388 case '9':
15104
- BGcolor = (key - '6')/3.f;
15389
+ if (true) // envyoff)
15390
+ {
15391
+ BGcolor = (key - '1')/8.f;
15392
+ }
15393
+ else
15394
+ {
15395
+ //newenvy = Character.getNumericValue(key);
15396
+ }
1510515397 repaint();
1510615398 break;
1510715399 case '!':
....@@ -15664,8 +15956,6 @@
1566415956
1566515957 int width = getBounds().width;
1566615958 int height = getBounds().height;
15667
- ClickInfo info = new ClickInfo();
15668
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1566915959 //Image img = CreateImage(width, height);
1567015960 //System.out.println("width = " + width + "; height = " + height + "\n");
1567115961
....@@ -15742,31 +16032,37 @@
1574216032 }
1574316033 if (object != null && !hasMarquee)
1574416034 {
16035
+ if (object.clickInfo == null)
16036
+ object.clickInfo = new ClickInfo();
16037
+ ClickInfo info = object.clickInfo;
16038
+ //ClickInfo info = new ClickInfo();
16039
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16040
+
1574516041 if (isRenderer)
1574616042 {
15747
- info.flags++;
16043
+ object.clickInfo.flags++;
1574816044 double frameAspect = (double) width / (double) height;
1574916045 if (frameAspect > renderCamera.aspect)
1575016046 {
1575116047 int desired = (int) ((double) height * renderCamera.aspect);
15752
- info.bounds.width -= width - desired;
15753
- info.bounds.x += (width - desired) / 2;
16048
+ object.clickInfo.bounds.width -= width - desired;
16049
+ object.clickInfo.bounds.x += (width - desired) / 2;
1575416050 } else
1575516051 {
1575616052 int desired = (int) ((double) width / renderCamera.aspect);
15757
- info.bounds.height -= height - desired;
15758
- info.bounds.y += (height - desired) / 2;
16053
+ object.clickInfo.bounds.height -= height - desired;
16054
+ object.clickInfo.bounds.y += (height - desired) / 2;
1575916055 }
1576016056 }
1576116057
15762
- info.g = gr;
15763
- info.camera = renderCamera;
16058
+ object.clickInfo.g = gr;
16059
+ object.clickInfo.camera = renderCamera;
1576416060 /*
1576516061 // Memory intensive (brep.verticescopy)
1576616062 if (!(object instanceof Composite))
1576716063 object.draw(info, 0, false); // SLOW :
1576816064 */
15769
- if (!isRenderer)
16065
+ if (!isRenderer) // && drag)
1577016066 {
1577116067 Grafreed.Assert(object != null);
1577216068 Grafreed.Assert(object.selection != null);
....@@ -15774,9 +16070,9 @@
1577416070 {
1577516071 int hitSomething = object.selection.get(0).hitSomething;
1577616072
15777
- info.DX = 0;
15778
- info.DY = 0;
15779
- info.W = 1;
16073
+ object.clickInfo.DX = 0;
16074
+ object.clickInfo.DY = 0;
16075
+ object.clickInfo.W = 1;
1578016076 if (hitSomething == Object3D.hitCenter)
1578116077 {
1578216078 info.DX = X;
....@@ -15788,7 +16084,8 @@
1578816084 info.DY -= info.bounds.height/2;
1578916085 }
1579016086
15791
- object.drawEditHandles(info, 0);
16087
+ object.drawEditHandles(//info,
16088
+ 0);
1579216089
1579316090 if (drag && (X != 0 || Y != 0))
1579416091 {
....@@ -16287,6 +16584,8 @@
1628716584 private /*static*/ boolean firstime;
1628816585 private /*static*/ cVector newView = new cVector();
1628916586 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16587
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16588
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1629016589 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1629116590 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1629216591 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16299,29 +16598,66 @@
1629916598 {
1630016599 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1630116600
16601
+ int usedsuf = 0;
16602
+
1630216603 for (int i = 0; i < suffixes.length; i++)
1630316604 {
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)
16605
+ String[] suffixe = suffixes;
16606
+ String[] fallback = suffixes2;
16607
+ String[] fallfallback = suffixes3;
16608
+
16609
+ for (int c=usedsuf; --c>=0;)
1630916610 {
16310
- throw new IOException("Unable to load texture " + resourceName);
16611
+// String[] temp = suffixe;
16612
+// suffixe = fallback;
16613
+// fallback = fallfallback;
16614
+// fallfallback = temp;
1631116615 }
16616
+
16617
+ String resourceName = basename + suffixe[i] + "." + suffix;
16618
+ TextureData data;
16619
+
16620
+ try
16621
+ {
16622
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16623
+ mipmapped,
16624
+ FileUtil.getFileSuffix(resourceName));
16625
+ }
16626
+ catch (Exception e)
16627
+ {
16628
+ try
16629
+ {
16630
+ resourceName = basename + fallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ catch (Exception e2)
16636
+ {
16637
+ resourceName = basename + fallfallback[i] + "." + suffix;
16638
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16639
+ mipmapped,
16640
+ FileUtil.getFileSuffix(resourceName));
16641
+ }
16642
+ }
16643
+
1631216644 //System.out.println("Target = " + targets[i]);
1631316645 cubemap.updateImage(data, targets[i]);
1631416646 }
1631516647
1631616648 return cubemap;
1631716649 }
16650
+
1631816651 int bigsphere = -1;
1631916652
1632016653 float BGcolor = 0.5f;
1632116654
16322
- private void DrawSkyBox(GL gl)
16655
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16656
+
16657
+ private void DrawSkyBox(GL gl, float ratio)
1632316658 {
16324
- if (envyoff || cubemap == null)
16659
+ if (//envyoff ||
16660
+ cubemap == null)
1632516661 {
1632616662 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1632716663 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16336,7 +16672,17 @@
1633616672 // Compensates for ExaminerViewer's modification of modelview matrix
1633716673 gl.glMatrixMode(GL.GL_MODELVIEW);
1633816674 gl.glLoadIdentity();
16675
+ gl.glScalef(1,ratio,1);
1633916676
16677
+// colorV[0] = 2;
16678
+// colorV[1] = 2;
16679
+// colorV[2] = 2;
16680
+// colorV[3] = 1;
16681
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16682
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16683
+//
16684
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16685
+
1634016686 //gl.glActiveTexture(GL.GL_TEXTURE1);
1634116687 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1634216688
....@@ -16368,6 +16714,7 @@
1636816714 {
1636916715 gl.glScalef(1.0f, -1.0f, 1.0f);
1637016716 }
16717
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1637116718 gl.glMultMatrixd(viewrot_1, 0);
1637216719 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1637316720 //viewer.updateInverseRotation(gl);
....@@ -16626,7 +16973,7 @@
1662616973 //new Exception().printStackTrace();
1662716974 System.out.println("select buffer init");
1662816975 // Use debug pipeline
16629
- drawable.setGL(new DebugGL(drawable.getGL()));
16976
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1663016977
1663116978 GL gl = drawable.getGL();
1663216979