Normand Briere
2019-08-06 b3ae4e889872ca0b9ca76f1d17b2f0b961226729
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -44,6 +48,39 @@
4448 static boolean ABORTED = false;
4549
4650 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4784
4885 /*static*/ private boolean CULLFACE = false; // true;
4986 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +97,7 @@
6097 //boolean REDUCETEXTURE = true;
6198 boolean CACHETEXTURE = true;
6299 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = 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 {
....@@ -7930,7 +8021,7 @@
79308021 String pigment = Object3D.GetPigment(tex);
79318022 String bump = Object3D.GetBump(tex);
79328023
7933
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79348025 {
79358026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79368027 // System.out.println("; bump = " + bump);
....@@ -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
....@@ -7964,7 +8055,7 @@
79648055
79658056 String pigment = Object3D.GetPigment(tex);
79668057
7967
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79688059 {
79698060 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79708061 // System.out.println("; bump = " + bump);
....@@ -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
....@@ -7993,7 +8084,7 @@
79938084
79948085 String bump = Object3D.GetBump(tex);
79958086
7996
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79978088 {
79988089 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79998090 // System.out.println("; bump = " + bump);
....@@ -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,9 +8265,9 @@
81718265
81728266 String pigment = Object3D.GetPigment(tex);
81738267
8174
- usedtextures.put(pigment, pigment);
8268
+ usedtextures.add(tex);
81758269
8176
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81778271 {
81788272 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81798273 // System.out.println("; bump = " + bump);
....@@ -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,9 +8298,9 @@
82048298
82058299 String bump = Object3D.GetBump(tex);
82068300
8207
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
82088302
8209
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108304 {
82118305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82128306 // System.out.println("; bump = " + bump);
....@@ -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,26 +8637,26 @@
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
- com.sun.opengl.util.texture.Texture 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 {
85178651 return false;
85188652 }
85198653
8520
- boolean newtex = false;
8654
+ //boolean newtex = false;
85218655
85228656 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85238657
85248658 if (texture == null)
8525
- return texture;
8659
+ return false;
85268660 /**/
85278661
85288662 if (textureon || tex.equals("DEFAULT_TEXTURE") || tex.equals("DEFAULT_TEXTURE_BUMP") || tex.equals("WHITE_NOISE")) // || tex.equals("IMMORTAL"))
....@@ -8549,9 +8683,75 @@
85498683 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85508684 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85518685
8552
- return newtex;
8686
+ 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,12 @@
90939314 static double[] model = new double[16];
90949315 double[] camera2light = new double[16];
90959316 double[] light2camera = new double[16];
9096
- int newenvy = -1;
9097
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
90989323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90999324 //float[] light0 = { 0,0,0 };
91009325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9512,7 +9737,7 @@
95129737
95139738 if (renderCamera != lightCamera)
95149739 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9515
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95169741
95179742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95189743
....@@ -9528,7 +9753,7 @@
95289753
95299754 if (renderCamera != lightCamera)
95309755 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9531
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95329757
95339758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95349759
....@@ -9574,10 +9799,12 @@
95749799 rati = 1 / rati;
95759800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95769801 }
9577
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
95789805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95799806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9580
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
95819808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95829809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95839810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10729,7 +10956,7 @@
1072910956 // if (parentcam != renderCamera) // not a light
1073010957 if (cam != lightCamera)
1073110958 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10732
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1073310960
1073410961 for (int j = 0; j < 4; j++)
1073510962 {
....@@ -10744,7 +10971,7 @@
1074410971 // if (parentcam != renderCamera) // not a light
1074510972 if (cam != lightCamera)
1074610973 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10747
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074810975
1074910976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1075010977
....@@ -10830,13 +11057,27 @@
1083011057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1083111058 }
1083211059
10833
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1083411068 {
10835
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1083611074 }
10837
-
10838
- newenvy = -1;
10839
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1084011081 ratio = ((double) getWidth()) / getHeight();
1084111082 //System.out.println("ratio = " + ratio);
1084211083
....@@ -10852,7 +11093,7 @@
1085211093
1085311094 if (!IsFrozen() && !ambientOcclusion)
1085411095 {
10855
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1085611097 }
1085711098
1085811099 //if (selection_view == -1)
....@@ -11138,7 +11379,7 @@
1113811379
1113911380 // if (cam != lightCamera)
1114011381 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11141
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11382
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1114211383 }
1114311384
1114411385 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11297,7 +11538,7 @@
1129711538 }
1129811539 }
1129911540
11300
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1130111542 {
1130211543 //gl.glDepthFunc(GL.GL_LEQUAL);
1130311544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11305,24 +11546,21 @@
1130511546
1130611547 boolean texon = textureon;
1130711548
11308
- if (RENDERPROGRAM > 0)
11309
- {
11310
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11311
- textureon = false;
11312
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1131311552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1131411553 //System.out.println("ALLO");
1131511554 gl.glColorMask(false, false, false, false);
1131611555 DrawObject(gl);
11317
- if (RENDERPROGRAM > 0)
11318
- {
11319
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11320
- textureon = texon;
11321
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1132211560 gl.glColorMask(true, true, true, true);
1132311561
1132411562 gl.glDepthFunc(GL.GL_EQUAL);
11325
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1132611564 }
1132711565
1132811566 if (false) // DrawMode() == SHADOW)
....@@ -11662,20 +11900,32 @@
1166211900 ReleaseTextures(DEFAULT_TEXTURES);
1166311901
1166411902 if (CLEANCACHE)
11665
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11903
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1166611904 {
11667
- String tex = e.nextElement();
11905
+ cTexture tex = e.nextElement();
1166811906
1166911907 // System.out.println("Texture --------- " + tex);
1167011908
11671
- if (tex.equals("WHITE_NOISE"))
11909
+ if (tex.equals("WHITE_NOISE:"))
1167211910 continue;
1167311911
11674
- if (!usedtextures.containsKey(tex))
11912
+ if (!usedtextures.contains(tex))
1167511913 {
11914
+ CacheTexture gettex = texturepigment.get(tex);
1167611915 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11677
- textures.get(tex).texture.dispose();
11678
- textures.remove(tex);
11916
+ if (gettex != null)
11917
+ {
11918
+ gettex.texture.dispose();
11919
+ texturepigment.remove(tex);
11920
+ }
11921
+
11922
+ gettex = texturebump.get(tex);
11923
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11924
+ if (gettex != null)
11925
+ {
11926
+ gettex.texture.dispose();
11927
+ texturebump.remove(tex);
11928
+ }
1167911929 }
1168011930 }
1168111931 }
....@@ -12203,8 +12453,76 @@
1220312453
1220412454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1220512455
12206
- String program =
12456
+ String programmin =
12457
+ // Min shader
1220712458 "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
12523
+ String programmax =
12524
+ "!!ARBfp1.0\n" +
12525
+
1220812526 //"OPTION ARB_fragment_program_shadow;" +
1220912527 "PARAM light2cam0 = program.env[10];" +
1221012528 "PARAM light2cam1 = program.env[11];" +
....@@ -12319,8 +12637,7 @@
1231912637 "TEMP shininess;" +
1232012638 "\n" +
1232112639 "MOV texSamp, one;" +
12322
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12323
-
12640
+
1232412641 "MOV mapgrid.x, one2048th.x;" +
1232512642 "MOV temp, fragment.texcoord[1];" +
1232612643 /*
....@@ -12341,20 +12658,20 @@
1234112658 "MUL temp, floor, mapgrid.x;" +
1234212659 //"TEX depth0, temp, texture[1], 2D;" +
1234312660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12344
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1234512662 "") +
1234612663 "ADD temp.x, temp.x, mapgrid.x;" +
1234712664 //"TEX depth1, temp, texture[1], 2D;" +
1234812665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12349
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1235012667 "") +
1235112668 "ADD temp.y, temp.y, mapgrid.x;" +
1235212669 //"TEX depth2, temp, texture[1], 2D;" +
12353
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1235412671 "SUB temp.x, temp.x, mapgrid.x;" +
1235512672 //"TEX depth3, temp, texture[1], 2D;" +
1235612673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12357
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1235812675 "") +
1235912676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1236012677 //"MOV params, material;" +
....@@ -12725,10 +13042,10 @@
1272513042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1272613043 "") +
1272713044
12728
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1272913046 "SUB temp.x, half.x, shadow.x;" +
1273013047 "MOV temp.y, -params5.z;" + // params6.x;" +
12731
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1273213049 "SUB temp.y, one.x, temp.z;" +
1273313050 "MUL temp.x, temp.x, temp.y;" +
1273413051 "KIL temp.x;" +
....@@ -13059,6 +13376,13 @@
1305913376 //once = true;
1306013377 }
1306113378
13379
+ String program = programmax;
13380
+
13381
+ if (Globals.MINSHADER)
13382
+ {
13383
+ program = programmin;
13384
+ }
13385
+
1306213386 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1306313387 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1306413388 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13152,25 +13476,26 @@
1315213476 return out;
1315313477 }
1315413478
13155
- String TextureFetch(String dest, String src, String unit)
13479
+ // Also does frustum culling
13480
+ String ShadowTextureFetch(String dest, String src, String unit)
1315613481 {
1315713482 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315813483 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315913484 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13485
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13486
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1316013487 "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;" +
13488
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13489
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1316513490 //"SWZ buffer, temp, w,w,w,w;";
13166
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13491
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316713492 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316813493 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316913494 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13170
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13495
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317113496
13172
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13173
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13497
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13498
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317413499 }
1317513500
1317613501 String Shadow(String depth, String shadow)
....@@ -13217,7 +13542,7 @@
1321713542 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321813543 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321913544
13220
- // No shadow when out of frustrum
13545
+ // No shadow when out of frustum
1322113546 "SGE temp.x, " + depth + ".z, one.z;" +
1322213547 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1322313548 "";
....@@ -14015,14 +14340,15 @@
1401514340 drag = false;
1401614341 //System.out.println("Mouse DOWN");
1401714342 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);
14343
+ //ClickInfo info = new ClickInfo();
14344
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14345
+ object.clickInfo.pane = this;
14346
+ object.clickInfo.camera = renderCamera;
14347
+ object.clickInfo.x = x;
14348
+ object.clickInfo.y = y;
14349
+ object.clickInfo.modifiers = modifiersex;
14350
+ editObj = object.doEditClick(//info,
14351
+ 0);
1402614352 if (!editObj)
1402714353 {
1402814354 hasMarquee = true;
....@@ -14306,9 +14632,9 @@
1430614632 MODIFIERS |= COMMAND;
1430714633 /**/
1430814634 if((mod&SHIFT) == SHIFT)
14309
- manipCamera.RotatePosition(0, -speed);
14310
- else
1431114635 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14636
+ else
14637
+ manipCamera.RotatePosition(0, -speed);
1431214638 /**/
1431314639 if ((mod & SHIFT) == SHIFT)
1431414640 {
....@@ -14327,9 +14653,9 @@
1432714653 MODIFIERS |= COMMAND;
1432814654 /**/
1432914655 if((mod&SHIFT) == SHIFT)
14330
- manipCamera.RotatePosition(0, speed);
14331
- else
1433214656 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14657
+ else
14658
+ manipCamera.RotatePosition(0, speed);
1433314659 /**/
1433414660 if ((mod & SHIFT) == SHIFT)
1433514661 {
....@@ -14422,15 +14748,16 @@
1442214748 if (editObj)
1442314749 {
1442414750 drag = true;
14425
- ClickInfo info = new ClickInfo();
14426
- info.bounds.setBounds(0, 0,
14751
+ //ClickInfo info = new ClickInfo();
14752
+ object.clickInfo.bounds.setBounds(0, 0,
1442714753 (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);
14754
+ object.clickInfo.pane = this;
14755
+ object.clickInfo.camera = renderCamera;
14756
+ object.clickInfo.x = x;
14757
+ object.clickInfo.y = y;
14758
+ object //.GetWindow().copy
14759
+ .doEditDrag(//info,
14760
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1443414761 } else
1443514762 {
1443614763 if (x < startX)
....@@ -14579,24 +14906,27 @@
1457914906 }
1458014907 }
1458114908
14909
+// ClickInfo clickInfo = new ClickInfo();
14910
+
1458214911 public void mouseMoved(MouseEvent e)
1458314912 {
1458414913 //System.out.println("mouseMoved: " + e);
1458514914 if (isRenderer)
1458614915 return;
1458714916
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;
14917
+ // Mouse cursor feedback
14918
+ object.clickInfo.x = e.getX();
14919
+ object.clickInfo.y = e.getY();
14920
+ object.clickInfo.modifiers = e.getModifiersEx();
14921
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14922
+ object.clickInfo.pane = this;
14923
+ object.clickInfo.camera = renderCamera;
1459514924 if (!isRenderer)
1459614925 {
1459714926 //ObjEditor editWindow = object.editWindow;
1459814927 //Object3D copy = editWindow.copy;
14599
- if (object.doEditClick(ci, 0))
14928
+ if (object.doEditClick(//clickInfo,
14929
+ 0))
1460014930 {
1460114931 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1460214932 } else
....@@ -14868,7 +15198,8 @@
1486815198 // break;
1486915199 case 'T':
1487015200 CACHETEXTURE ^= true;
14871
- textures.clear();
15201
+ texturepigment.clear();
15202
+ texturebump.clear();
1487215203 // repaint();
1487315204 break;
1487415205 case 'Y':
....@@ -15045,20 +15376,24 @@
1504515376 OCCLUSION_CULLING ^= true;
1504615377 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504715378 break;
15048
- case '0': envyoff ^= true; repaint(); break;
15379
+ //case '0': envyoff ^= true; repaint(); break;
1504915380 case '1':
1505015381 case '2':
1505115382 case '3':
1505215383 case '4':
1505315384 case '5':
15054
- newenvy = Character.getNumericValue(key);
15055
- repaint();
15056
- break;
1505715385 case '6':
1505815386 case '7':
1505915387 case '8':
1506015388 case '9':
15061
- BGcolor = (key - '6')/3.f;
15389
+ if (true) // envyoff)
15390
+ {
15391
+ BGcolor = (key - '1')/8.f;
15392
+ }
15393
+ else
15394
+ {
15395
+ //newenvy = Character.getNumericValue(key);
15396
+ }
1506215397 repaint();
1506315398 break;
1506415399 case '!':
....@@ -15621,8 +15956,6 @@
1562115956
1562215957 int width = getBounds().width;
1562315958 int height = getBounds().height;
15624
- ClickInfo info = new ClickInfo();
15625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562615959 //Image img = CreateImage(width, height);
1562715960 //System.out.println("width = " + width + "; height = " + height + "\n");
1562815961
....@@ -15699,31 +16032,37 @@
1569916032 }
1570016033 if (object != null && !hasMarquee)
1570116034 {
16035
+ if (object.clickInfo == null)
16036
+ object.clickInfo = new ClickInfo();
16037
+ ClickInfo info = object.clickInfo;
16038
+ //ClickInfo info = new ClickInfo();
16039
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16040
+
1570216041 if (isRenderer)
1570316042 {
15704
- info.flags++;
16043
+ object.clickInfo.flags++;
1570516044 double frameAspect = (double) width / (double) height;
1570616045 if (frameAspect > renderCamera.aspect)
1570716046 {
1570816047 int desired = (int) ((double) height * renderCamera.aspect);
15709
- info.bounds.width -= width - desired;
15710
- info.bounds.x += (width - desired) / 2;
16048
+ object.clickInfo.bounds.width -= width - desired;
16049
+ object.clickInfo.bounds.x += (width - desired) / 2;
1571116050 } else
1571216051 {
1571316052 int desired = (int) ((double) width / renderCamera.aspect);
15714
- info.bounds.height -= height - desired;
15715
- info.bounds.y += (height - desired) / 2;
16053
+ object.clickInfo.bounds.height -= height - desired;
16054
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571616055 }
1571716056 }
1571816057
15719
- info.g = gr;
15720
- info.camera = renderCamera;
16058
+ object.clickInfo.g = gr;
16059
+ object.clickInfo.camera = renderCamera;
1572116060 /*
1572216061 // Memory intensive (brep.verticescopy)
1572316062 if (!(object instanceof Composite))
1572416063 object.draw(info, 0, false); // SLOW :
1572516064 */
15726
- if (!isRenderer)
16065
+ if (!isRenderer) // && drag)
1572716066 {
1572816067 Grafreed.Assert(object != null);
1572916068 Grafreed.Assert(object.selection != null);
....@@ -15731,9 +16070,9 @@
1573116070 {
1573216071 int hitSomething = object.selection.get(0).hitSomething;
1573316072
15734
- info.DX = 0;
15735
- info.DY = 0;
15736
- info.W = 1;
16073
+ object.clickInfo.DX = 0;
16074
+ object.clickInfo.DY = 0;
16075
+ object.clickInfo.W = 1;
1573716076 if (hitSomething == Object3D.hitCenter)
1573816077 {
1573916078 info.DX = X;
....@@ -15745,7 +16084,8 @@
1574516084 info.DY -= info.bounds.height/2;
1574616085 }
1574716086
15748
- object.drawEditHandles(info, 0);
16087
+ object.drawEditHandles(//info,
16088
+ 0);
1574916089
1575016090 if (drag && (X != 0 || Y != 0))
1575116091 {
....@@ -16244,6 +16584,8 @@
1624416584 private /*static*/ boolean firstime;
1624516585 private /*static*/ cVector newView = new cVector();
1624616586 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16587
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16588
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1624716589 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1624816590 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624916591 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16256,29 +16598,66 @@
1625616598 {
1625716599 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1625816600
16601
+ int usedsuf = 0;
16602
+
1625916603 for (int i = 0; i < suffixes.length; i++)
1626016604 {
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)
16605
+ String[] suffixe = suffixes;
16606
+ String[] fallback = suffixes2;
16607
+ String[] fallfallback = suffixes3;
16608
+
16609
+ for (int c=usedsuf; --c>=0;)
1626616610 {
16267
- throw new IOException("Unable to load texture " + resourceName);
16611
+// String[] temp = suffixe;
16612
+// suffixe = fallback;
16613
+// fallback = fallfallback;
16614
+// fallfallback = temp;
1626816615 }
16616
+
16617
+ String resourceName = basename + suffixe[i] + "." + suffix;
16618
+ TextureData data;
16619
+
16620
+ try
16621
+ {
16622
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16623
+ mipmapped,
16624
+ FileUtil.getFileSuffix(resourceName));
16625
+ }
16626
+ catch (Exception e)
16627
+ {
16628
+ try
16629
+ {
16630
+ resourceName = basename + fallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ catch (Exception e2)
16636
+ {
16637
+ resourceName = basename + fallfallback[i] + "." + suffix;
16638
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16639
+ mipmapped,
16640
+ FileUtil.getFileSuffix(resourceName));
16641
+ }
16642
+ }
16643
+
1626916644 //System.out.println("Target = " + targets[i]);
1627016645 cubemap.updateImage(data, targets[i]);
1627116646 }
1627216647
1627316648 return cubemap;
1627416649 }
16650
+
1627516651 int bigsphere = -1;
1627616652
1627716653 float BGcolor = 0.5f;
1627816654
16279
- private void DrawSkyBox(GL gl)
16655
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16656
+
16657
+ private void DrawSkyBox(GL gl, float ratio)
1628016658 {
16281
- if (envyoff || cubemap == null)
16659
+ if (//envyoff ||
16660
+ cubemap == null)
1628216661 {
1628316662 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1628416663 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16293,7 +16672,17 @@
1629316672 // Compensates for ExaminerViewer's modification of modelview matrix
1629416673 gl.glMatrixMode(GL.GL_MODELVIEW);
1629516674 gl.glLoadIdentity();
16675
+ gl.glScalef(1,ratio,1);
1629616676
16677
+// colorV[0] = 2;
16678
+// colorV[1] = 2;
16679
+// colorV[2] = 2;
16680
+// colorV[3] = 1;
16681
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16682
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16683
+//
16684
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16685
+
1629716686 //gl.glActiveTexture(GL.GL_TEXTURE1);
1629816687 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629916688
....@@ -16325,6 +16714,7 @@
1632516714 {
1632616715 gl.glScalef(1.0f, -1.0f, 1.0f);
1632716716 }
16717
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1632816718 gl.glMultMatrixd(viewrot_1, 0);
1632916719 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1633016720 //viewer.updateInverseRotation(gl);
....@@ -16583,7 +16973,7 @@
1658316973 //new Exception().printStackTrace();
1658416974 System.out.println("select buffer init");
1658516975 // Use debug pipeline
16586
- drawable.setGL(new DebugGL(drawable.getGL()));
16976
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1658716977
1658816978 GL gl = drawable.getGL();
1658916979