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 = 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,28 +2478,31 @@
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/*com.sun.opengl.util.texture.Texture*/> textures
2426
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2427
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, 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>();
2495
+
24282496 int pigmentdepth = 0;
24292497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24302498 int bumpdepth = 0;
24312499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24322500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24332501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2434
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24352503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24362504
2437
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24382506 {
24392507 TextureData texturedata = null;
24402508
....@@ -2453,13 +2521,34 @@
24532521 if (bump)
24542522 texturedata = ConvertBump(texturedata, false);
24552523
2456
- com.sun.opengl.util.texture.Texture texture =
2457
- 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);
24582526
2459
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2460
- 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);
24612529
2462
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
24632552 }
24642553
24652554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3532,6 +3621,8 @@
35323621
35333622 System.out.println("LOADING TEXTURE : " + name);
35343623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
35353626 //
35363627 if (false) // compressbit > 0)
35373628 {
....@@ -7945,8 +8036,8 @@
79458036 pigment = null;
79468037 }
79478038
7948
- ReleaseTexture(bump, true);
7949
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
79508041 }
79518042
79528043 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7975,7 +8066,7 @@
79758066 pigment = null;
79768067 }
79778068
7978
- ReleaseTexture(pigment, false);
8069
+ ReleaseTexture(tex, false);
79798070 }
79808071
79818072 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8004,10 +8095,10 @@
80048095 bump = null;
80058096 }
80068097
8007
- ReleaseTexture(bump, true);
8098
+ ReleaseTexture(tex, true);
80088099 }
80098100
8010
- void ReleaseTexture(String tex, boolean bump)
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
80118102 {
80128103 if (// DrawMode() != 0 || /*tex == null ||*/
80138104 ambientOcclusion ) // || !textureon)
....@@ -8018,7 +8109,7 @@
80188109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80198110
80208111 if (tex != null)
8021
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80228113
80238114 // //assert( texture != null );
80248115 // if (texture == null)
....@@ -8112,47 +8203,50 @@
81128203
81138204 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81148205 {
8115
- if (// DrawMode() != 0 || /*tex == null ||*/
8116
- ambientOcclusion ) // || !textureon)
8117
- {
8118
- return; // false;
8119
- }
8120
-
8121
- if (tex == null)
8122
- {
8123
- BindTexture(null,false,resolution);
8124
- BindTexture(null,true,resolution);
8125
- return;
8126
- }
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
81278247
8128
- String pigment = Object3D.GetPigment(tex);
8129
- String bump = Object3D.GetBump(tex);
8130
-
8131
- usedtextures.put(pigment, pigment);
8132
- usedtextures.put(bump, bump);
8133
-
8134
- //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8135
- {
8136
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8137
- // System.out.println("; bump = " + bump);
8138
- }
8139
-
8140
- if (bump.equals(""))
8141
- {
8142
- bump = null;
8143
- }
8144
- if (pigment.equals(""))
8145
- {
8146
- pigment = null;
8147
- }
8148
-
8149
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8150
- BindTexture(pigment, false, resolution);
8151
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8152
- BindTexture(bump, true, resolution);
8153
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8154
-
8155
- return; // true;
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
81568250 }
81578251
81588252 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8171,7 +8265,7 @@
81718265
81728266 String pigment = Object3D.GetPigment(tex);
81738267
8174
- usedtextures.put(pigment, pigment);
8268
+ usedtextures.add(tex);
81758269
81768270 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81778271 {
....@@ -8185,7 +8279,7 @@
81858279 }
81868280
81878281 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8188
- BindTexture(pigment, false, resolution);
8282
+ BindTexture(tex, false, resolution);
81898283 }
81908284
81918285 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8204,7 +8298,7 @@
82048298
82058299 String bump = Object3D.GetBump(tex);
82068300
8207
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
82088302
82098303 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108304 {
....@@ -8218,7 +8312,7 @@
82188312 }
82198313
82208314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8221
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
82228316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82238317 }
82248318
....@@ -8242,13 +8336,19 @@
82428336 return fileExists;
82438337 }
82448338
8245
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82468340 {
8247
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ CacheTexture texturecache = null;
82488342
82498343 if (tex != null)
82508344 {
8251
- 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
+ }
82528352
82538353 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82548354
....@@ -8258,19 +8358,46 @@
82588358 // else
82598359 // if (!texname.startsWith("/"))
82608360 // texname = "/Users/nbriere/Textures/" + texname;
8261
- if (!FileExists(tex))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
82628362 {
82638363 texname = fallbackTextureName;
82648364 }
82658365
82668366 if (CACHETEXTURE)
8267
- texture = textures.get(texname); // TEXTURE CACHE
8268
-
8269
- TextureData texturedata = null;
8270
-
8271
- if (texture == null || texture.resolution < resolution)
82728367 {
8273
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
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;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82748401 {
82758402 assert(!bump);
82768403 // if (bump)
....@@ -8281,19 +8408,23 @@
82818408 // }
82828409 // else
82838410 // {
8284
- texture = textures.get(tex);
8285
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
82868413 {
8287
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82888415 }
8416
+ else
8417
+ new Exception().printStackTrace();
82898418 // }
82908419 } else
8291
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82928421 {
82938422 assert(bump);
8294
- texture = textures.get(tex);
8295
- if (texture == null)
8296
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
82978428 } else
82988429 {
82998430 //if (tex.equals("IMMORTAL"))
....@@ -8301,11 +8432,22 @@
83018432 // texture = GetResourceTexture("default.png");
83028433 //} else
83038434 //{
8304
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
83058436 {
8306
- texture = textures.get(tex);
8307
- if (texture == null)
8308
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ 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();
83098451 } else
83108452 {
83118453 if (textureon)
....@@ -8364,19 +8506,20 @@
83648506 if (texturedata == null)
83658507 throw new Exception();
83668508
8367
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ texturecache = new CacheTexture(texturedata,resolution);
83688510 //texture = GetTexture(tex, bump);
83698511 }
8512
+ }
83708513 }
83718514 //}
83728515 }
83738516
8374
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83758518 {
83768519 //return false;
83778520
83788521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8379
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83808523 {
83818524 // String ext = "_highres";
83828525 // if (REDUCETEXTURE)
....@@ -8393,52 +8536,17 @@
83938536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83948537 if (!cachefile.exists())
83958538 {
8396
- // cache to disk
8397
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8398
- //buffers[0].
8399
-
8400
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8401
- int[] pixels = new int[bytebuf.capacity()/3];
8402
-
8403
- // squared size heuristic...
8404
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
84058540 {
8406
- for (int i=pixels.length; --i>=0;)
8407
- {
8408
- int i3 = i*3;
8409
- pixels[i] = 0xFF;
8410
- pixels[i] <<= 8;
8411
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8412
- pixels[i] <<= 8;
8413
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8414
- pixels[i] <<= 8;
8415
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8416
- }
8417
-
8418
- /*
8419
- int r=0,g=0,b=0,a=0;
8420
- for (int i=0; i<width; i++)
8421
- for (int j=0; j<height; j++)
8422
- {
8423
- int index = j*width+i;
8424
- int p = pixels[index];
8425
- a = ((p>>24) & 0xFF);
8426
- r = ((p>>16) & 0xFF);
8427
- g = ((p>>8) & 0xFF);
8428
- b = (p & 0xFF);
8429
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8430
- }
8431
- /**/
8432
- int width = (int)Math.sqrt(pixels.length); // squared
8433
- int height = width;
8434
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8435
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
84368543 ImageWriter writer = null;
84378544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84388545 if (iter.hasNext()) {
84398546 writer = (ImageWriter)iter.next();
84408547 }
8441
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
84428550 try
84438551 {
84448552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8455,18 +8563,20 @@
84558563 }
84568564 }
84578565 }
8458
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
84598569 //System.out.println("Texture = " + tex);
8460
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
84618571 {
8462
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
84638573 thetex.texture.disable();
84648574 thetex.texture.dispose();
8465
- textures.remove(texname);
8575
+ textures.remove(tex);
84668576 }
84678577
8468
- texture.texturedata = texturedata;
8469
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
84708580
84718581 // newtex = true;
84728582 }
....@@ -8482,10 +8592,44 @@
84828592 }
84838593 }
84848594
8485
- return texture;
8595
+ return texturecache;
84868596 }
84878597
8488
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
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
84898633 {
84908634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84918635
....@@ -8503,14 +8647,14 @@
85038647 return texture!=null?texture.texture:null;
85048648 }
85058649
8506
- public com.sun.opengl.util.texture.TextureData GetTextureData(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
85078651 {
85088652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85098653
85108654 return texture!=null?texture.texturedata:null;
85118655 }
85128656
8513
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85148658 {
85158659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85168660 {
....@@ -8552,6 +8696,72 @@
85528696 return true; // Warning: not used.
85538697 }
85548698
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
+
85558765 ShadowBuffer shadowPBuf;
85568766 AntialiasBuffer antialiasPBuf;
85578767 int MAXSTACK;
....@@ -8744,7 +8954,7 @@
87448954
87458955 if (cubemap == null)
87468956 {
8747
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
87488958 }
87498959
87508960 //cubemap.enable();
....@@ -9031,37 +9241,58 @@
90319241 cubemap = null;
90329242 return;
90339243 case 1:
9034
- name = "cubemaps/box_";
9035
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
90369246 reverseUP = false;
90379247 break;
90389248 case 2:
9039
- name = "cubemaps/uffizi_";
9040
- ext = "png";
9041
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
90429253 case 3:
9043
- name = "cubemaps/CloudyHills_";
9044
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
90459256 reverseUP = false;
90469257 break;
90479258 case 4:
9048
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
90499260 ext = "png";
90509261 reverseUP = false;
90519262 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;
90529288 default:
9053
- name = "cubemaps/rgb_";
9054
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
90559292 break;
90569293 }
9057
-
9058
- try
9059
- {
9060
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9061
- } catch (IOException e)
9062
- {
9063
- throw new RuntimeException(e);
9064
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
90659296 }
90669297
90679298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9093,8 +9324,12 @@
90939324 static double[] model = new double[16];
90949325 double[] camera2light = new double[16];
90959326 double[] light2camera = new double[16];
9096
- int newenvy = -1;
9097
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
90989333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90999334 //float[] light0 = { 0,0,0 };
91009335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9512,7 +9747,7 @@
95129747
95139748 if (renderCamera != lightCamera)
95149749 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9515
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95169751
95179752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95189753
....@@ -9528,7 +9763,7 @@
95289763
95299764 if (renderCamera != lightCamera)
95309765 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9531
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95329767
95339768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95349769
....@@ -9574,10 +9809,12 @@
95749809 rati = 1 / rati;
95759810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95769811 }
9577
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
95789815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95799816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9580
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
95819818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95829819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95839820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10614,7 +10851,7 @@
1061410851
1061510852 if (wait)
1061610853 {
10617
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1061810855
1061910856 wait = false;
1062010857 }
....@@ -10729,7 +10966,7 @@
1072910966 // if (parentcam != renderCamera) // not a light
1073010967 if (cam != lightCamera)
1073110968 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10732
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1073310970
1073410971 for (int j = 0; j < 4; j++)
1073510972 {
....@@ -10744,7 +10981,7 @@
1074410981 // if (parentcam != renderCamera) // not a light
1074510982 if (cam != lightCamera)
1074610983 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10747
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074810985
1074910986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1075010987
....@@ -10830,13 +11067,27 @@
1083011067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1083111068 }
1083211069
10833
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1083411078 {
10835
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1083611084 }
10837
-
10838
- newenvy = -1;
10839
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1084011091 ratio = ((double) getWidth()) / getHeight();
1084111092 //System.out.println("ratio = " + ratio);
1084211093
....@@ -10852,7 +11103,7 @@
1085211103
1085311104 if (!IsFrozen() && !ambientOcclusion)
1085411105 {
10855
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1085611107 }
1085711108
1085811109 //if (selection_view == -1)
....@@ -11138,7 +11389,7 @@
1113811389
1113911390 // if (cam != lightCamera)
1114011391 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11141
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1114211393 }
1114311394
1114411395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11297,7 +11548,7 @@
1129711548 }
1129811549 }
1129911550
11300
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1130111552 {
1130211553 //gl.glDepthFunc(GL.GL_LEQUAL);
1130311554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11305,24 +11556,21 @@
1130511556
1130611557 boolean texon = textureon;
1130711558
11308
- if (RENDERPROGRAM > 0)
11309
- {
11310
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11311
- textureon = false;
11312
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
1131311562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1131411563 //System.out.println("ALLO");
1131511564 gl.glColorMask(false, false, false, false);
1131611565 DrawObject(gl);
11317
- if (RENDERPROGRAM > 0)
11318
- {
11319
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11320
- textureon = texon;
11321
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
1132211570 gl.glColorMask(true, true, true, true);
1132311571
1132411572 gl.glDepthFunc(GL.GL_EQUAL);
11325
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
1132611574 }
1132711575
1132811576 if (false) // DrawMode() == SHADOW)
....@@ -11662,20 +11910,32 @@
1166211910 ReleaseTextures(DEFAULT_TEXTURES);
1166311911
1166411912 if (CLEANCACHE)
11665
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1166611914 {
11667
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
1166811916
1166911917 // System.out.println("Texture --------- " + tex);
1167011918
11671
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
1167211920 continue;
1167311921
11674
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
1167511923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
1167611925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11677
- textures.get(tex).texture.dispose();
11678
- 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
+ }
1167911939 }
1168011940 }
1168111941 }
....@@ -12203,8 +12463,76 @@
1220312463
1220412464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1220512465
12206
- String program =
12466
+ String programmin =
12467
+ // Min shader
1220712468 "!!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
+
1220812536 //"OPTION ARB_fragment_program_shadow;" +
1220912537 "PARAM light2cam0 = program.env[10];" +
1221012538 "PARAM light2cam1 = program.env[11];" +
....@@ -12319,8 +12647,7 @@
1231912647 "TEMP shininess;" +
1232012648 "\n" +
1232112649 "MOV texSamp, one;" +
12322
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12323
-
12650
+
1232412651 "MOV mapgrid.x, one2048th.x;" +
1232512652 "MOV temp, fragment.texcoord[1];" +
1232612653 /*
....@@ -12341,20 +12668,20 @@
1234112668 "MUL temp, floor, mapgrid.x;" +
1234212669 //"TEX depth0, temp, texture[1], 2D;" +
1234312670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12344
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1234512672 "") +
1234612673 "ADD temp.x, temp.x, mapgrid.x;" +
1234712674 //"TEX depth1, temp, texture[1], 2D;" +
1234812675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12349
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1235012677 "") +
1235112678 "ADD temp.y, temp.y, mapgrid.x;" +
1235212679 //"TEX depth2, temp, texture[1], 2D;" +
12353
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1235412681 "SUB temp.x, temp.x, mapgrid.x;" +
1235512682 //"TEX depth3, temp, texture[1], 2D;" +
1235612683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12357
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1235812685 "") +
1235912686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1236012687 //"MOV params, material;" +
....@@ -12725,10 +13052,10 @@
1272513052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1272613053 "") +
1272713054
12728
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1272913056 "SUB temp.x, half.x, shadow.x;" +
1273013057 "MOV temp.y, -params5.z;" + // params6.x;" +
12731
- "SLT temp.z, temp.y, -one2048th.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1273213059 "SUB temp.y, one.x, temp.z;" +
1273313060 "MUL temp.x, temp.x, temp.y;" +
1273413061 "KIL temp.x;" +
....@@ -13059,6 +13386,13 @@
1305913386 //once = true;
1306013387 }
1306113388
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
1306213396 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1306313397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1306413398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13152,25 +13486,26 @@
1315213486 return out;
1315313487 }
1315413488
13155
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1315613491 {
1315713492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315813493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315913494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1316013497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13161
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13162
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13163
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13164
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1316513500 //"SWZ buffer, temp, w,w,w,w;";
13166
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316713502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316813503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316913504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13170
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317113506
13172
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13173
- //"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;";
1317413509 }
1317513510
1317613511 String Shadow(String depth, String shadow)
....@@ -13217,7 +13552,7 @@
1321713552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321813553 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321913554
13220
- // No shadow when out of frustrum
13555
+ // No shadow when out of frustum
1322113556 "SGE temp.x, " + depth + ".z, one.z;" +
1322213557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1322313558 "";
....@@ -14015,14 +14350,15 @@
1401514350 drag = false;
1401614351 //System.out.println("Mouse DOWN");
1401714352 editObj = false;
14018
- ClickInfo info = new ClickInfo();
14019
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14020
- info.pane = this;
14021
- info.camera = renderCamera;
14022
- info.x = x;
14023
- info.y = y;
14024
- info.modifiers = modifiersex;
14025
- 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);
1402614362 if (!editObj)
1402714363 {
1402814364 hasMarquee = true;
....@@ -14306,9 +14642,9 @@
1430614642 MODIFIERS |= COMMAND;
1430714643 /**/
1430814644 if((mod&SHIFT) == SHIFT)
14309
- manipCamera.RotatePosition(0, -speed);
14310
- else
1431114645 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14646
+ else
14647
+ manipCamera.RotatePosition(0, -speed);
1431214648 /**/
1431314649 if ((mod & SHIFT) == SHIFT)
1431414650 {
....@@ -14327,9 +14663,9 @@
1432714663 MODIFIERS |= COMMAND;
1432814664 /**/
1432914665 if((mod&SHIFT) == SHIFT)
14330
- manipCamera.RotatePosition(0, speed);
14331
- else
1433214666 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14667
+ else
14668
+ manipCamera.RotatePosition(0, speed);
1433314669 /**/
1433414670 if ((mod & SHIFT) == SHIFT)
1433514671 {
....@@ -14422,15 +14758,16 @@
1442214758 if (editObj)
1442314759 {
1442414760 drag = true;
14425
- ClickInfo info = new ClickInfo();
14426
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1442714763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14428
- info.pane = this;
14429
- info.camera = renderCamera;
14430
- info.x = x;
14431
- info.y = y;
14432
- object.GetWindow().copy
14433
- .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);
1443414771 } else
1443514772 {
1443614773 if (x < startX)
....@@ -14579,24 +14916,27 @@
1457914916 }
1458014917 }
1458114918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1458214921 public void mouseMoved(MouseEvent e)
1458314922 {
1458414923 //System.out.println("mouseMoved: " + e);
1458514924 if (isRenderer)
1458614925 return;
1458714926
14588
- ClickInfo ci = new ClickInfo();
14589
- ci.x = e.getX();
14590
- ci.y = e.getY();
14591
- ci.modifiers = e.getModifiersEx();
14592
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14593
- ci.pane = this;
14594
- 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;
1459514934 if (!isRenderer)
1459614935 {
1459714936 //ObjEditor editWindow = object.editWindow;
1459814937 //Object3D copy = editWindow.copy;
14599
- if (object.doEditClick(ci, 0))
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1460014940 {
1460114941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1460214942 } else
....@@ -14868,7 +15208,8 @@
1486815208 // break;
1486915209 case 'T':
1487015210 CACHETEXTURE ^= true;
14871
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1487215213 // repaint();
1487315214 break;
1487415215 case 'Y':
....@@ -15045,20 +15386,24 @@
1504515386 OCCLUSION_CULLING ^= true;
1504615387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504715388 break;
15048
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1504915390 case '1':
1505015391 case '2':
1505115392 case '3':
1505215393 case '4':
1505315394 case '5':
15054
- newenvy = Character.getNumericValue(key);
15055
- repaint();
15056
- break;
1505715395 case '6':
1505815396 case '7':
1505915397 case '8':
1506015398 case '9':
15061
- 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
+ }
1506215407 repaint();
1506315408 break;
1506415409 case '!':
....@@ -15621,8 +15966,6 @@
1562115966
1562215967 int width = getBounds().width;
1562315968 int height = getBounds().height;
15624
- ClickInfo info = new ClickInfo();
15625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562615969 //Image img = CreateImage(width, height);
1562715970 //System.out.println("width = " + width + "; height = " + height + "\n");
1562815971
....@@ -15699,31 +16042,37 @@
1569916042 }
1570016043 if (object != null && !hasMarquee)
1570116044 {
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
+
1570216051 if (isRenderer)
1570316052 {
15704
- info.flags++;
16053
+ object.clickInfo.flags++;
1570516054 double frameAspect = (double) width / (double) height;
1570616055 if (frameAspect > renderCamera.aspect)
1570716056 {
1570816057 int desired = (int) ((double) height * renderCamera.aspect);
15709
- info.bounds.width -= width - desired;
15710
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1571116060 } else
1571216061 {
1571316062 int desired = (int) ((double) width / renderCamera.aspect);
15714
- info.bounds.height -= height - desired;
15715
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571616065 }
1571716066 }
1571816067
15719
- info.g = gr;
15720
- info.camera = renderCamera;
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1572116070 /*
1572216071 // Memory intensive (brep.verticescopy)
1572316072 if (!(object instanceof Composite))
1572416073 object.draw(info, 0, false); // SLOW :
1572516074 */
15726
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1572716076 {
1572816077 Grafreed.Assert(object != null);
1572916078 Grafreed.Assert(object.selection != null);
....@@ -15731,9 +16080,9 @@
1573116080 {
1573216081 int hitSomething = object.selection.get(0).hitSomething;
1573316082
15734
- info.DX = 0;
15735
- info.DY = 0;
15736
- info.W = 1;
16083
+ object.clickInfo.DX = 0;
16084
+ object.clickInfo.DY = 0;
16085
+ object.clickInfo.W = 1;
1573716086 if (hitSomething == Object3D.hitCenter)
1573816087 {
1573916088 info.DX = X;
....@@ -15745,7 +16094,8 @@
1574516094 info.DY -= info.bounds.height/2;
1574616095 }
1574716096
15748
- object.drawEditHandles(info, 0);
16097
+ object.drawEditHandles(//info,
16098
+ 0);
1574916099
1575016100 if (drag && (X != 0 || Y != 0))
1575116101 {
....@@ -16244,6 +16594,8 @@
1624416594 private /*static*/ boolean firstime;
1624516595 private /*static*/ cVector newView = new cVector();
1624616596 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"};
1624716599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1624816600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624916601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16256,29 +16608,67 @@
1625616608 {
1625716609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1625816610
16611
+ int usedsuf = 0;
16612
+
1625916613 for (int i = 0; i < suffixes.length; i++)
1626016614 {
16261
- String resourceName = basename + suffixes[i] + "." + suffix;
16262
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16263
- mipmapped,
16264
- FileUtil.getFileSuffix(resourceName));
16265
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1626616620 {
16267
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1626816625 }
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
+
1626916654 //System.out.println("Target = " + targets[i]);
1627016655 cubemap.updateImage(data, targets[i]);
1627116656 }
1627216657
1627316658 return cubemap;
1627416659 }
16660
+
1627516661 int bigsphere = -1;
1627616662
1627716663 float BGcolor = 0.5f;
1627816664
16279
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1628016668 {
16281
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1628216672 {
1628316673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1628416674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16293,7 +16683,17 @@
1629316683 // Compensates for ExaminerViewer's modification of modelview matrix
1629416684 gl.glMatrixMode(GL.GL_MODELVIEW);
1629516685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1629616687
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
+
1629716697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1629816698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629916699
....@@ -16325,6 +16725,7 @@
1632516725 {
1632616726 gl.glScalef(1.0f, -1.0f, 1.0f);
1632716727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1632816729 gl.glMultMatrixd(viewrot_1, 0);
1632916730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1633016731 //viewer.updateInverseRotation(gl);
....@@ -16583,7 +16984,7 @@
1658316984 //new Exception().printStackTrace();
1658416985 System.out.println("select buffer init");
1658516986 // Use debug pipeline
16586
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1658716988
1658816989 GL gl = drawable.getGL();
1658916990