Normand Briere
2019-07-28 d7fd07756f4095cb87dc25d89fcffcbda092e2cf
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))
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,13 @@
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();
83098442 } else
83108443 {
83118444 if (textureon)
....@@ -8364,19 +8497,19 @@
83648497 if (texturedata == null)
83658498 throw new Exception();
83668499
8367
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8500
+ texturecache = new CacheTexture(texturedata,resolution);
83688501 //texture = GetTexture(tex, bump);
83698502 }
83708503 }
83718504 //}
83728505 }
83738506
8374
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83758508 {
83768509 //return false;
83778510
83788511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8379
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8512
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83808513 {
83818514 // String ext = "_highres";
83828515 // if (REDUCETEXTURE)
....@@ -8393,52 +8526,17 @@
83938526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83948527 if (!cachefile.exists())
83958528 {
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))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
84058530 {
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);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
84368533 ImageWriter writer = null;
84378534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84388535 if (iter.hasNext()) {
84398536 writer = (ImageWriter)iter.next();
84408537 }
8441
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
84428540 try
84438541 {
84448542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8455,18 +8553,20 @@
84558553 }
84568554 }
84578555 }
8458
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
84598559 //System.out.println("Texture = " + tex);
8460
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
84618561 {
8462
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
84638563 thetex.texture.disable();
84648564 thetex.texture.dispose();
8465
- textures.remove(texname);
8565
+ textures.remove(tex);
84668566 }
84678567
8468
- texture.texturedata = texturedata;
8469
- textures.put(texname, texture);
8568
+ //texture.texturedata = texturedata;
8569
+ textures.put(tex, texturecache);
84708570
84718571 // newtex = true;
84728572 }
....@@ -8482,10 +8582,44 @@
84828582 }
84838583 }
84848584
8485
- return texture;
8585
+ return texturecache;
84868586 }
84878587
8488
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8588
+ static void EmbedTextures(cTexture tex)
8589
+ {
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
84898623 {
84908624 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84918625
....@@ -8503,14 +8637,14 @@
85038637 return texture!=null?texture.texture:null;
85048638 }
85058639
8506
- public com.sun.opengl.util.texture.TextureData GetTextureData(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
85078641 {
85088642 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85098643
85108644 return texture!=null?texture.texturedata:null;
85118645 }
85128646
8513
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85148648 {
85158649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85168650 {
....@@ -8552,6 +8686,72 @@
85528686 return true; // Warning: not used.
85538687 }
85548688
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
+
85558755 ShadowBuffer shadowPBuf;
85568756 AntialiasBuffer antialiasPBuf;
85578757 int MAXSTACK;
....@@ -8744,7 +8944,7 @@
87448944
87458945 if (cubemap == null)
87468946 {
8747
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
87488948 }
87498949
87508950 //cubemap.enable();
....@@ -9031,37 +9231,58 @@
90319231 cubemap = null;
90329232 return;
90339233 case 1:
9034
- name = "cubemaps/box_";
9035
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
90369236 reverseUP = false;
90379237 break;
90389238 case 2:
9039
- name = "cubemaps/uffizi_";
9040
- ext = "png";
9041
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
90429243 case 3:
9043
- name = "cubemaps/CloudyHills_";
9044
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
90459246 reverseUP = false;
90469247 break;
90479248 case 4:
9048
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
90499250 ext = "png";
90509251 reverseUP = false;
90519252 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;
90529278 default:
9053
- name = "cubemaps/rgb_";
9054
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
90559282 break;
90569283 }
9057
-
9058
- try
9059
- {
9060
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9061
- } catch (IOException e)
9062
- {
9063
- throw new RuntimeException(e);
9064
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
90659286 }
90669287
90679288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9093,8 +9314,13 @@
90939314 static double[] model = new double[16];
90949315 double[] camera2light = new double[16];
90959316 double[] light2camera = new double[16];
9096
- int newenvy = -1;
9317
+
9318
+ //int newenvy = -1;
90979319 boolean envyoff = true; // false;
9320
+ String skyboxname = "";
9321
+ String skyboxext;
9322
+ String loadedskyboxname = "";
9323
+
90989324 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90999325 //float[] light0 = { 0,0,0 };
91009326 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9512,7 +9738,7 @@
95129738
95139739 if (renderCamera != lightCamera)
95149740 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9515
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9741
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95169742
95179743 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95189744
....@@ -9528,7 +9754,7 @@
95289754
95299755 if (renderCamera != lightCamera)
95309756 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9531
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9757
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95329758
95339759 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95349760
....@@ -9574,10 +9800,12 @@
95749800 rati = 1 / rati;
95759801 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95769802 }
9577
- assert (newenvy == -1);
9803
+
9804
+ //assert (newenvy == -1);
9805
+
95789806 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95799807 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9580
- DrawSkyBox(gl);
9808
+ DrawSkyBox(gl, (float)rati);
95819809 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95829810 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95839811 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10729,7 +10957,7 @@
1072910957 // if (parentcam != renderCamera) // not a light
1073010958 if (cam != lightCamera)
1073110959 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10732
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10960
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1073310961
1073410962 for (int j = 0; j < 4; j++)
1073510963 {
....@@ -10744,7 +10972,7 @@
1074410972 // if (parentcam != renderCamera) // not a light
1074510973 if (cam != lightCamera)
1074610974 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10747
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10975
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074810976
1074910977 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1075010978
....@@ -10830,13 +11058,19 @@
1083011058 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1083111059 }
1083211060
10833
- if (newenvy > -1)
11061
+// if (newenvy > -1)
11062
+// {
11063
+// LoadEnvy(newenvy);
11064
+// }
11065
+//
11066
+// newenvy = -1;
11067
+
11068
+ if (!skyboxname.equals(this.loadedskyboxname))
1083411069 {
10835
- LoadEnvy(newenvy);
11070
+ LoadSkybox(skyboxname + "/", skyboxext, false);
11071
+ loadedskyboxname = skyboxname;
1083611072 }
10837
-
10838
- newenvy = -1;
10839
-
11073
+
1084011074 ratio = ((double) getWidth()) / getHeight();
1084111075 //System.out.println("ratio = " + ratio);
1084211076
....@@ -10852,7 +11086,7 @@
1085211086
1085311087 if (!IsFrozen() && !ambientOcclusion)
1085411088 {
10855
- DrawSkyBox(gl);
11089
+ DrawSkyBox(gl, (float)ratio);
1085611090 }
1085711091
1085811092 //if (selection_view == -1)
....@@ -11297,7 +11531,7 @@
1129711531 }
1129811532 }
1129911533
11300
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11534
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1130111535 {
1130211536 //gl.glDepthFunc(GL.GL_LEQUAL);
1130311537 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11305,24 +11539,21 @@
1130511539
1130611540 boolean texon = textureon;
1130711541
11308
- if (RENDERPROGRAM > 0)
11309
- {
11310
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11311
- textureon = false;
11312
- }
11542
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11543
+ textureon = false;
11544
+
1131311545 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1131411546 //System.out.println("ALLO");
1131511547 gl.glColorMask(false, false, false, false);
1131611548 DrawObject(gl);
11317
- if (RENDERPROGRAM > 0)
11318
- {
11319
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11320
- textureon = texon;
11321
- }
11549
+
11550
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11551
+ textureon = texon;
11552
+
1132211553 gl.glColorMask(true, true, true, true);
1132311554
1132411555 gl.glDepthFunc(GL.GL_EQUAL);
11325
- //gl.glDepthMask(false);
11556
+ gl.glDepthMask(false);
1132611557 }
1132711558
1132811559 if (false) // DrawMode() == SHADOW)
....@@ -11662,20 +11893,32 @@
1166211893 ReleaseTextures(DEFAULT_TEXTURES);
1166311894
1166411895 if (CLEANCACHE)
11665
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11896
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1166611897 {
11667
- String tex = e.nextElement();
11898
+ cTexture tex = e.nextElement();
1166811899
1166911900 // System.out.println("Texture --------- " + tex);
1167011901
11671
- if (tex.equals("WHITE_NOISE"))
11902
+ if (tex.equals("WHITE_NOISE:"))
1167211903 continue;
1167311904
11674
- if (!usedtextures.containsKey(tex))
11905
+ if (!usedtextures.contains(tex))
1167511906 {
11907
+ CacheTexture gettex = texturepigment.get(tex);
1167611908 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11677
- textures.get(tex).texture.dispose();
11678
- textures.remove(tex);
11909
+ if (gettex != null)
11910
+ {
11911
+ gettex.texture.dispose();
11912
+ texturepigment.remove(tex);
11913
+ }
11914
+
11915
+ gettex = texturebump.get(tex);
11916
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11917
+ if (gettex != null)
11918
+ {
11919
+ gettex.texture.dispose();
11920
+ texturebump.remove(tex);
11921
+ }
1167911922 }
1168011923 }
1168111924 }
....@@ -12203,8 +12446,76 @@
1220312446
1220412447 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1220512448
12449
+ String program0 =
12450
+ // Min shader
12451
+ "!!ARBfp1.0\n" +
12452
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12453
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12454
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12455
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12456
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12457
+ "PARAM light2cam0 = program.env[10];" +
12458
+ "PARAM light2cam1 = program.env[11];" +
12459
+ "PARAM light2cam2 = program.env[12];" +
12460
+ "TEMP temp;" +
12461
+ "TEMP light;" +
12462
+ "TEMP ndotl;" +
12463
+ "TEMP normal;" +
12464
+ "TEMP depth;" +
12465
+ "TEMP eye;" +
12466
+ "TEMP pos;" +
12467
+
12468
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12469
+ Normalize("normal") +
12470
+ "MOV light, state.light[0].position;" +
12471
+ "DP3 ndotl.x, light, normal;" +
12472
+
12473
+ // shadow
12474
+ "MOV pos, fragment.texcoord[1];" +
12475
+ "MOV temp, pos;" +
12476
+ ShadowTextureFetch("depth", "temp", "1") +
12477
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12478
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12479
+
12480
+ // No shadow when out of frustum
12481
+ //"SGE temp.y, depth.z, zero123.y;" +
12482
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12483
+
12484
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12485
+
12486
+ // Backlit
12487
+ "MOV pos.w, zero123.y;" +
12488
+ "DP4 eye.x, pos, light2cam0;" +
12489
+ "DP4 eye.y, pos, light2cam1;" +
12490
+ "DP4 eye.z, pos, light2cam2;" +
12491
+ Normalize("eye") +
12492
+
12493
+ "DP3 ndotl.y, -eye, normal;" +
12494
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12495
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12496
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12497
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12498
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12499
+
12500
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12501
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12502
+
12503
+ // Pigment
12504
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12505
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12506
+ "MUL temp, temp, ndotl.x;" +
12507
+
12508
+ "MUL temp, temp, zero123.z;" +
12509
+
12510
+ //"MUL temp, temp, ndotl.y;" +
12511
+
12512
+ "MOV temp.w, zero123.y;" + // reset alpha
12513
+ "MOV result.color, temp;" +
12514
+ "END";
12515
+
1220612516 String program =
1220712517 "!!ARBfp1.0\n" +
12518
+
1220812519 //"OPTION ARB_fragment_program_shadow;" +
1220912520 "PARAM light2cam0 = program.env[10];" +
1221012521 "PARAM light2cam1 = program.env[11];" +
....@@ -12319,8 +12630,7 @@
1231912630 "TEMP shininess;" +
1232012631 "\n" +
1232112632 "MOV texSamp, one;" +
12322
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12323
-
12633
+
1232412634 "MOV mapgrid.x, one2048th.x;" +
1232512635 "MOV temp, fragment.texcoord[1];" +
1232612636 /*
....@@ -12341,20 +12651,20 @@
1234112651 "MUL temp, floor, mapgrid.x;" +
1234212652 //"TEX depth0, temp, texture[1], 2D;" +
1234312653 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12344
- TextureFetch("depth0", "temp", "1") +
12654
+ ShadowTextureFetch("depth0", "temp", "1") +
1234512655 "") +
1234612656 "ADD temp.x, temp.x, mapgrid.x;" +
1234712657 //"TEX depth1, temp, texture[1], 2D;" +
1234812658 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12349
- TextureFetch("depth1", "temp", "1") +
12659
+ ShadowTextureFetch("depth1", "temp", "1") +
1235012660 "") +
1235112661 "ADD temp.y, temp.y, mapgrid.x;" +
1235212662 //"TEX depth2, temp, texture[1], 2D;" +
12353
- TextureFetch("depth2", "temp", "1") +
12663
+ ShadowTextureFetch("depth2", "temp", "1") +
1235412664 "SUB temp.x, temp.x, mapgrid.x;" +
1235512665 //"TEX depth3, temp, texture[1], 2D;" +
1235612666 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12357
- TextureFetch("depth3", "temp", "1") +
12667
+ ShadowTextureFetch("depth3", "temp", "1") +
1235812668 "") +
1235912669 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1236012670 //"MOV params, material;" +
....@@ -12725,10 +13035,10 @@
1272513035 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1272613036 "") +
1272713037
12728
- // display shadow only (bump == 0)
13038
+ // display shadow only (fakedepth == 0)
1272913039 "SUB temp.x, half.x, shadow.x;" +
1273013040 "MOV temp.y, -params5.z;" + // params6.x;" +
12731
- "SLT temp.z, temp.y, -one2048th.x;" +
13041
+ "SLT temp.z, temp.y, -c256i.x;" +
1273213042 "SUB temp.y, one.x, temp.z;" +
1273313043 "MUL temp.x, temp.x, temp.y;" +
1273413044 "KIL temp.x;" +
....@@ -13152,25 +13462,26 @@
1315213462 return out;
1315313463 }
1315413464
13155
- String TextureFetch(String dest, String src, String unit)
13465
+ // Also does frustum culling
13466
+ String ShadowTextureFetch(String dest, String src, String unit)
1315613467 {
1315713468 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315813469 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315913470 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13471
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13472
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1316013473 "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;" +
13474
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13475
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1316513476 //"SWZ buffer, temp, w,w,w,w;";
13166
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13477
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316713478 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316813479 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316913480 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13170
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13481
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317113482
13172
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13173
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13483
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13484
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317413485 }
1317513486
1317613487 String Shadow(String depth, String shadow)
....@@ -13217,7 +13528,7 @@
1321713528 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321813529 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321913530
13220
- // No shadow when out of frustrum
13531
+ // No shadow when out of frustum
1322113532 "SGE temp.x, " + depth + ".z, one.z;" +
1322213533 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1322313534 "";
....@@ -14015,14 +14326,15 @@
1401514326 drag = false;
1401614327 //System.out.println("Mouse DOWN");
1401714328 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);
14329
+ //ClickInfo info = new ClickInfo();
14330
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14331
+ object.clickInfo.pane = this;
14332
+ object.clickInfo.camera = renderCamera;
14333
+ object.clickInfo.x = x;
14334
+ object.clickInfo.y = y;
14335
+ object.clickInfo.modifiers = modifiersex;
14336
+ editObj = object.doEditClick(//info,
14337
+ 0);
1402614338 if (!editObj)
1402714339 {
1402814340 hasMarquee = true;
....@@ -14422,15 +14734,16 @@
1442214734 if (editObj)
1442314735 {
1442414736 drag = true;
14425
- ClickInfo info = new ClickInfo();
14426
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1442714739 (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);
14740
+ object.clickInfo.pane = this;
14741
+ object.clickInfo.camera = renderCamera;
14742
+ object.clickInfo.x = x;
14743
+ object.clickInfo.y = y;
14744
+ object //.GetWindow().copy
14745
+ .doEditDrag(//info,
14746
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1443414747 } else
1443514748 {
1443614749 if (x < startX)
....@@ -14579,24 +14892,27 @@
1457914892 }
1458014893 }
1458114894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1458214897 public void mouseMoved(MouseEvent e)
1458314898 {
1458414899 //System.out.println("mouseMoved: " + e);
1458514900 if (isRenderer)
1458614901 return;
1458714902
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;
14903
+ // Mouse cursor feedback
14904
+ object.clickInfo.x = e.getX();
14905
+ object.clickInfo.y = e.getY();
14906
+ object.clickInfo.modifiers = e.getModifiersEx();
14907
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14908
+ object.clickInfo.pane = this;
14909
+ object.clickInfo.camera = renderCamera;
1459514910 if (!isRenderer)
1459614911 {
1459714912 //ObjEditor editWindow = object.editWindow;
1459814913 //Object3D copy = editWindow.copy;
14599
- if (object.doEditClick(ci, 0))
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1460014916 {
1460114917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1460214918 } else
....@@ -14868,7 +15184,8 @@
1486815184 // break;
1486915185 case 'T':
1487015186 CACHETEXTURE ^= true;
14871
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1487215189 // repaint();
1487315190 break;
1487415191 case 'Y':
....@@ -15051,14 +15368,18 @@
1505115368 case '3':
1505215369 case '4':
1505315370 case '5':
15054
- newenvy = Character.getNumericValue(key);
15055
- repaint();
15056
- break;
1505715371 case '6':
1505815372 case '7':
1505915373 case '8':
1506015374 case '9':
15061
- BGcolor = (key - '6')/3.f;
15375
+ if (envyoff)
15376
+ {
15377
+ BGcolor = (key - '1')/8.f;
15378
+ }
15379
+ else
15380
+ {
15381
+ //newenvy = Character.getNumericValue(key);
15382
+ }
1506215383 repaint();
1506315384 break;
1506415385 case '!':
....@@ -15621,8 +15942,6 @@
1562115942
1562215943 int width = getBounds().width;
1562315944 int height = getBounds().height;
15624
- ClickInfo info = new ClickInfo();
15625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562615945 //Image img = CreateImage(width, height);
1562715946 //System.out.println("width = " + width + "; height = " + height + "\n");
1562815947
....@@ -15699,31 +16018,37 @@
1569916018 }
1570016019 if (object != null && !hasMarquee)
1570116020 {
16021
+ if (object.clickInfo == null)
16022
+ object.clickInfo = new ClickInfo();
16023
+ ClickInfo info = object.clickInfo;
16024
+ //ClickInfo info = new ClickInfo();
16025
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16026
+
1570216027 if (isRenderer)
1570316028 {
15704
- info.flags++;
16029
+ object.clickInfo.flags++;
1570516030 double frameAspect = (double) width / (double) height;
1570616031 if (frameAspect > renderCamera.aspect)
1570716032 {
1570816033 int desired = (int) ((double) height * renderCamera.aspect);
15709
- info.bounds.width -= width - desired;
15710
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1571116036 } else
1571216037 {
1571316038 int desired = (int) ((double) width / renderCamera.aspect);
15714
- info.bounds.height -= height - desired;
15715
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571616041 }
1571716042 }
1571816043
15719
- info.g = gr;
15720
- info.camera = renderCamera;
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1572116046 /*
1572216047 // Memory intensive (brep.verticescopy)
1572316048 if (!(object instanceof Composite))
1572416049 object.draw(info, 0, false); // SLOW :
1572516050 */
15726
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1572716052 {
1572816053 Grafreed.Assert(object != null);
1572916054 Grafreed.Assert(object.selection != null);
....@@ -15731,9 +16056,9 @@
1573116056 {
1573216057 int hitSomething = object.selection.get(0).hitSomething;
1573316058
15734
- info.DX = 0;
15735
- info.DY = 0;
15736
- info.W = 1;
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
1573716062 if (hitSomething == Object3D.hitCenter)
1573816063 {
1573916064 info.DX = X;
....@@ -15745,7 +16070,8 @@
1574516070 info.DY -= info.bounds.height/2;
1574616071 }
1574716072
15748
- object.drawEditHandles(info, 0);
16073
+ object.drawEditHandles(//info,
16074
+ 0);
1574916075
1575016076 if (drag && (X != 0 || Y != 0))
1575116077 {
....@@ -15758,7 +16084,7 @@
1575816084 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1575916085 break;
1576016086 case Object3D.hitScale: gr.setColor(Color.cyan);
15761
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16087
+ gr.drawLine(X, Y, 0, 0);
1576216088 break;
1576316089 }
1576416090
....@@ -16276,7 +16602,9 @@
1627616602
1627716603 float BGcolor = 0.5f;
1627816604
16279
- private void DrawSkyBox(GL gl)
16605
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16606
+
16607
+ private void DrawSkyBox(GL gl, float ratio)
1628016608 {
1628116609 if (envyoff || cubemap == null)
1628216610 {
....@@ -16293,7 +16621,17 @@
1629316621 // Compensates for ExaminerViewer's modification of modelview matrix
1629416622 gl.glMatrixMode(GL.GL_MODELVIEW);
1629516623 gl.glLoadIdentity();
16624
+ gl.glScalef(1,ratio,1);
1629616625
16626
+ colorV[0] = 2;
16627
+ colorV[1] = 2;
16628
+ colorV[2] = 2;
16629
+ colorV[3] = 1;
16630
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16631
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16632
+
16633
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16634
+
1629716635 //gl.glActiveTexture(GL.GL_TEXTURE1);
1629816636 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629916637
....@@ -16306,7 +16644,7 @@
1630616644 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1630716645 // causes the normals to be sent down. Thanks to Ken Dyke.
1630816646 //gl.glEnable(GL.GL_LIGHTING);
16309
- gl.glDisable(GL.GL_LIGHTING);
16647
+ gl.glEnable(GL.GL_LIGHTING);
1631016648
1631116649 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1631216650 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16583,7 +16921,7 @@
1658316921 //new Exception().printStackTrace();
1658416922 System.out.println("select buffer init");
1658516923 // Use debug pipeline
16586
- drawable.setGL(new DebugGL(drawable.getGL()));
16924
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1658716925
1658816926 GL gl = drawable.getGL();
1658916927