Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
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;
....@@ -73,7 +110,9 @@
73110 //private Mat4f spotlightTransform = new Mat4f();
74111 //private Mat4f spotlightInverseTransform = new Mat4f();
75112 static GLContext glcontext = null;
76
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
77116 boolean reverseUP = false;
78117 static boolean frozen = false;
79118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -136,7 +175,7 @@
136175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137176 boolean anisotropy = true;
138177 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140179
141180 boolean macromode = false;
142181
....@@ -150,6 +189,19 @@
150189 }
151190
152191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
153205
154206 void SetAsGLRenderer(boolean b)
155207 {
....@@ -169,7 +221,8 @@
169221
170222 SetCamera(cam);
171223
172
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
173226
174227 object = o;
175228
....@@ -1447,6 +1500,8 @@
14471500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481501 }
14491502
1503
+ float[] colorV = new float[4];
1504
+
14501505 void SetColor(Object3D obj, Vertex p0)
14511506 {
14521507 CameraPane display = this;
....@@ -1514,8 +1569,6 @@
15141569 {
15151570 return;
15161571 }
1517
-
1518
- float[] colorV = new float[3];
15191572
15201573 if (false) // marked)
15211574 {
....@@ -2405,6 +2458,21 @@
24052458 return currentGL;
24062459 }
24072460
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
24082476 /**/
24092477 class CacheTexture
24102478 {
....@@ -2413,28 +2481,31 @@
24132481
24142482 int resolution;
24152483
2416
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24172485 {
2418
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
24192488 resolution = res;
24202489 }
24212490 }
24222491 /**/
24232492
24242493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
24282499 int pigmentdepth = 0;
24292500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24302501 int bumpdepth = 0;
24312502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24322503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24332504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2434
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24352506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24362507
2437
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24382509 {
24392510 TextureData texturedata = null;
24402511
....@@ -2453,13 +2524,34 @@
24532524 if (bump)
24542525 texturedata = ConvertBump(texturedata, false);
24552526
2456
- com.sun.opengl.util.texture.Texture texture =
2457
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24582529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24612532
2462
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
24632555 }
24642556
24652557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3532,6 +3624,8 @@
35323624
35333625 System.out.println("LOADING TEXTURE : " + name);
35343626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
35353629 //
35363630 if (false) // compressbit > 0)
35373631 {
....@@ -7930,7 +8024,7 @@
79308024 String pigment = Object3D.GetPigment(tex);
79318025 String bump = Object3D.GetBump(tex);
79328026
7933
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79348028 {
79358029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79368030 // System.out.println("; bump = " + bump);
....@@ -7945,8 +8039,8 @@
79458039 pigment = null;
79468040 }
79478041
7948
- ReleaseTexture(bump, true);
7949
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
79508044 }
79518045
79528046 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7964,7 +8058,7 @@
79648058
79658059 String pigment = Object3D.GetPigment(tex);
79668060
7967
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79688062 {
79698063 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79708064 // System.out.println("; bump = " + bump);
....@@ -7975,7 +8069,7 @@
79758069 pigment = null;
79768070 }
79778071
7978
- ReleaseTexture(pigment, false);
8072
+ ReleaseTexture(tex, false);
79798073 }
79808074
79818075 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7993,7 +8087,7 @@
79938087
79948088 String bump = Object3D.GetBump(tex);
79958089
7996
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79978091 {
79988092 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79998093 // System.out.println("; bump = " + bump);
....@@ -8004,10 +8098,10 @@
80048098 bump = null;
80058099 }
80068100
8007
- ReleaseTexture(bump, true);
8101
+ ReleaseTexture(tex, true);
80088102 }
80098103
8010
- void ReleaseTexture(String tex, boolean bump)
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
80118105 {
80128106 if (// DrawMode() != 0 || /*tex == null ||*/
80138107 ambientOcclusion ) // || !textureon)
....@@ -8018,7 +8112,7 @@
80188112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80198113
80208114 if (tex != null)
8021
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80228116
80238117 // //assert( texture != null );
80248118 // if (texture == null)
....@@ -8112,47 +8206,50 @@
81128206
81138207 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81148208 {
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
- }
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
81278250
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;
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
81568253 }
81578254
81588255 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8171,9 +8268,9 @@
81718268
81728269 String pigment = Object3D.GetPigment(tex);
81738270
8174
- usedtextures.put(pigment, pigment);
8271
+ usedtextures.add(tex);
81758272
8176
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81778274 {
81788275 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81798276 // System.out.println("; bump = " + bump);
....@@ -8185,7 +8282,7 @@
81858282 }
81868283
81878284 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8188
- BindTexture(pigment, false, resolution);
8285
+ BindTexture(tex, false, resolution);
81898286 }
81908287
81918288 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8204,9 +8301,9 @@
82048301
82058302 String bump = Object3D.GetBump(tex);
82068303
8207
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
82088305
8209
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108307 {
82118308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82128309 // System.out.println("; bump = " + bump);
....@@ -8218,7 +8315,7 @@
82188315 }
82198316
82208317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8221
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
82228319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82238320 }
82248321
....@@ -8242,13 +8339,19 @@
82428339 return fileExists;
82438340 }
82448341
8245
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82468343 {
8247
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8344
+ CacheTexture texturecache = null;
82488345
82498346 if (tex != null)
82508347 {
8251
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8350
+
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
82528355
82538356 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82548357
....@@ -8258,19 +8361,46 @@
82588361 // else
82598362 // if (!texname.startsWith("/"))
82608363 // texname = "/Users/nbriere/Textures/" + texname;
8261
- if (!FileExists(tex))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
82628365 {
82638366 texname = fallbackTextureName;
82648367 }
82658368
82668369 if (CACHETEXTURE)
8267
- texture = textures.get(texname); // TEXTURE CACHE
8268
-
8269
- TextureData texturedata = null;
8270
-
8271
- if (texture == null || texture.resolution < resolution)
82728370 {
8273
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82748404 {
82758405 assert(!bump);
82768406 // if (bump)
....@@ -8281,19 +8411,23 @@
82818411 // }
82828412 // else
82838413 // {
8284
- texture = textures.get(tex);
8285
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
82868416 {
8287
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82888418 }
8419
+ else
8420
+ new Exception().printStackTrace();
82898421 // }
82908422 } else
8291
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82928424 {
82938425 assert(bump);
8294
- texture = textures.get(tex);
8295
- if (texture == null)
8296
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
82978431 } else
82988432 {
82998433 //if (tex.equals("IMMORTAL"))
....@@ -8301,11 +8435,22 @@
83018435 // texture = GetResourceTexture("default.png");
83028436 //} else
83038437 //{
8304
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
83058439 {
8306
- texture = textures.get(tex);
8307
- if (texture == null)
8308
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
83098454 } else
83108455 {
83118456 if (textureon)
....@@ -8364,19 +8509,20 @@
83648509 if (texturedata == null)
83658510 throw new Exception();
83668511
8367
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8512
+ texturecache = new CacheTexture(texturedata,resolution);
83688513 //texture = GetTexture(tex, bump);
83698514 }
8515
+ }
83708516 }
83718517 //}
83728518 }
83738519
8374
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83758521 {
83768522 //return false;
83778523
83788524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8379
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83808526 {
83818527 // String ext = "_highres";
83828528 // if (REDUCETEXTURE)
....@@ -8393,52 +8539,17 @@
83938539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83948540 if (!cachefile.exists())
83958541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
84058543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
84368546 ImageWriter writer = null;
84378547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84388548 if (iter.hasNext()) {
84398549 writer = (ImageWriter)iter.next();
84408550 }
8441
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
84428553 try
84438554 {
84448555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8455,18 +8566,20 @@
84558566 }
84568567 }
84578568 }
8458
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
84598572 //System.out.println("Texture = " + tex);
8460
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
84618574 {
8462
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
84638576 thetex.texture.disable();
84648577 thetex.texture.dispose();
8465
- textures.remove(texname);
8578
+ textures.remove(tex);
84668579 }
84678580
8468
- texture.texturedata = texturedata;
8469
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
84708583
84718584 // newtex = true;
84728585 }
....@@ -8482,10 +8595,44 @@
84828595 }
84838596 }
84848597
8485
- return texture;
8598
+ return texturecache;
84868599 }
84878600
8488
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84898636 {
84908637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84918638
....@@ -8503,26 +8650,26 @@
85038650 return texture!=null?texture.texture:null;
85048651 }
85058652
8506
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85078654 {
85088655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85098656
85108657 return texture!=null?texture.texturedata:null;
85118658 }
85128659
8513
- com.sun.opengl.util.texture.Texture BindTexture(String tex, boolean bump, int resolution) throws Exception
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85148661 {
85158662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85168663 {
85178664 return false;
85188665 }
85198666
8520
- boolean newtex = false;
8667
+ //boolean newtex = false;
85218668
85228669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85238670
85248671 if (texture == null)
8525
- return texture;
8672
+ return false;
85268673 /**/
85278674
85288675 if (textureon || tex.equals("DEFAULT_TEXTURE") || tex.equals("DEFAULT_TEXTURE_BUMP") || tex.equals("WHITE_NOISE")) // || tex.equals("IMMORTAL"))
....@@ -8549,9 +8696,75 @@
85498696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85508697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85518698
8552
- return newtex;
8699
+ return true; // Warning: not used.
85538700 }
85548701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
85558768 ShadowBuffer shadowPBuf;
85568769 AntialiasBuffer antialiasPBuf;
85578770 int MAXSTACK;
....@@ -8568,10 +8781,12 @@
85688781
85698782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85708783 MAXSTACK = temp[0];
8571
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85728786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85738787 MAXSTACK = temp[0];
8574
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85758790
85768791 // Use debug pipeline
85778792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8579,7 +8794,8 @@
85798794 gl = drawable.getGL(); //
85808795
85818796 GL gl3 = getGL();
8582
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85838799
85848800
85858801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8744,7 +8960,7 @@
87448960
87458961 if (cubemap == null)
87468962 {
8747
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
87488964 }
87498965
87508966 //cubemap.enable();
....@@ -9020,6 +9236,8 @@
90209236
90219237 void LoadEnvy(int which)
90229238 {
9239
+ assert(false);
9240
+
90239241 String name;
90249242 String ext;
90259243
....@@ -9031,37 +9249,58 @@
90319249 cubemap = null;
90329250 return;
90339251 case 1:
9034
- name = "cubemaps/box_";
9035
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
90369254 reverseUP = false;
90379255 break;
90389256 case 2:
9039
- name = "cubemaps/uffizi_";
9040
- ext = "png";
9041
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
90429261 case 3:
9043
- name = "cubemaps/CloudyHills_";
9044
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
90459264 reverseUP = false;
90469265 break;
90479266 case 4:
9048
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
90499268 ext = "png";
90509269 reverseUP = false;
90519270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
90529296 default:
9053
- name = "cubemaps/rgb_";
9054
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
90559300 break;
90569301 }
9057
-
9058
- try
9059
- {
9060
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9061
- } catch (IOException e)
9062
- {
9063
- throw new RuntimeException(e);
9064
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
90659304 }
90669305
90679306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9093,8 +9332,12 @@
90939332 static double[] model = new double[16];
90949333 double[] camera2light = new double[16];
90959334 double[] light2camera = new double[16];
9096
- int newenvy = -1;
9097
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
90989341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90999342 //float[] light0 = { 0,0,0 };
91009343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9512,7 +9755,7 @@
95129755
95139756 if (renderCamera != lightCamera)
95149757 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9515
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95169759
95179760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95189761
....@@ -9528,7 +9771,7 @@
95289771
95299772 if (renderCamera != lightCamera)
95309773 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9531
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95329775
95339776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95349777
....@@ -9574,10 +9817,12 @@
95749817 rati = 1 / rati;
95759818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95769819 }
9577
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
95789823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95799824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9580
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
95819826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95829827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
95839828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10614,7 +10859,7 @@
1061410859
1061510860 if (wait)
1061610861 {
10617
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1061810863
1061910864 wait = false;
1062010865 }
....@@ -10729,7 +10974,7 @@
1072910974 // if (parentcam != renderCamera) // not a light
1073010975 if (cam != lightCamera)
1073110976 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10732
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1073310978
1073410979 for (int j = 0; j < 4; j++)
1073510980 {
....@@ -10744,7 +10989,7 @@
1074410989 // if (parentcam != renderCamera) // not a light
1074510990 if (cam != lightCamera)
1074610991 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10747
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074810993
1074910994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1075010995
....@@ -10830,13 +11075,41 @@
1083011075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1083111076 }
1083211077
10833
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1083411086 {
10835
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1083611093 }
10837
-
10838
- newenvy = -1;
10839
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1084011113 ratio = ((double) getWidth()) / getHeight();
1084111114 //System.out.println("ratio = " + ratio);
1084211115
....@@ -10852,7 +11125,7 @@
1085211125
1085311126 if (!IsFrozen() && !ambientOcclusion)
1085411127 {
10855
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1085611129 }
1085711130
1085811131 //if (selection_view == -1)
....@@ -11138,7 +11411,7 @@
1113811411
1113911412 // if (cam != lightCamera)
1114011413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11141
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1114211415 }
1114311416
1114411417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11297,7 +11570,7 @@
1129711570 }
1129811571 }
1129911572
11300
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1130111574 {
1130211575 //gl.glDepthFunc(GL.GL_LEQUAL);
1130311576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11305,24 +11578,21 @@
1130511578
1130611579 boolean texon = textureon;
1130711580
11308
- if (RENDERPROGRAM > 0)
11309
- {
11310
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11311
- textureon = false;
11312
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1131311584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1131411585 //System.out.println("ALLO");
1131511586 gl.glColorMask(false, false, false, false);
1131611587 DrawObject(gl);
11317
- if (RENDERPROGRAM > 0)
11318
- {
11319
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11320
- textureon = texon;
11321
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1132211592 gl.glColorMask(true, true, true, true);
1132311593
1132411594 gl.glDepthFunc(GL.GL_EQUAL);
11325
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1132611596 }
1132711597
1132811598 if (false) // DrawMode() == SHADOW)
....@@ -11662,20 +11932,32 @@
1166211932 ReleaseTextures(DEFAULT_TEXTURES);
1166311933
1166411934 if (CLEANCACHE)
11665
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1166611936 {
11667
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1166811938
1166911939 // System.out.println("Texture --------- " + tex);
1167011940
11671
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1167211942 continue;
1167311943
11674
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1167511945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1167611947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11677
- textures.get(tex).texture.dispose();
11678
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1167911961 }
1168011962 }
1168111963 }
....@@ -12203,8 +12485,76 @@
1220312485
1220412486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1220512487
12206
- String program =
12488
+ String programmin =
12489
+ // Min shader
1220712490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1220812558 //"OPTION ARB_fragment_program_shadow;" +
1220912559 "PARAM light2cam0 = program.env[10];" +
1221012560 "PARAM light2cam1 = program.env[11];" +
....@@ -12319,8 +12669,7 @@
1231912669 "TEMP shininess;" +
1232012670 "\n" +
1232112671 "MOV texSamp, one;" +
12322
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12323
-
12672
+
1232412673 "MOV mapgrid.x, one2048th.x;" +
1232512674 "MOV temp, fragment.texcoord[1];" +
1232612675 /*
....@@ -12341,20 +12690,20 @@
1234112690 "MUL temp, floor, mapgrid.x;" +
1234212691 //"TEX depth0, temp, texture[1], 2D;" +
1234312692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12344
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1234512694 "") +
1234612695 "ADD temp.x, temp.x, mapgrid.x;" +
1234712696 //"TEX depth1, temp, texture[1], 2D;" +
1234812697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12349
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1235012699 "") +
1235112700 "ADD temp.y, temp.y, mapgrid.x;" +
1235212701 //"TEX depth2, temp, texture[1], 2D;" +
12353
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1235412703 "SUB temp.x, temp.x, mapgrid.x;" +
1235512704 //"TEX depth3, temp, texture[1], 2D;" +
1235612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12357
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1235812707 "") +
1235912708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1236012709 //"MOV params, material;" +
....@@ -12725,10 +13074,10 @@
1272513074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1272613075 "") +
1272713076
12728
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1272913078 "SUB temp.x, half.x, shadow.x;" +
1273013079 "MOV temp.y, -params5.z;" + // params6.x;" +
12731
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1273213081 "SUB temp.y, one.x, temp.z;" +
1273313082 "MUL temp.x, temp.x, temp.y;" +
1273413083 "KIL temp.x;" +
....@@ -13059,6 +13408,13 @@
1305913408 //once = true;
1306013409 }
1306113410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1306213418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1306313419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1306413420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13152,25 +13508,26 @@
1315213508 return out;
1315313509 }
1315413510
13155
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1315613513 {
1315713514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315813515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315913516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1316013519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1316513522 //"SWZ buffer, temp, w,w,w,w;";
13166
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316713524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316813525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316913526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13170
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317113528
13172
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13173
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317413531 }
1317513532
1317613533 String Shadow(String depth, String shadow)
....@@ -13217,7 +13574,7 @@
1321713574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321813575 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321913576
13220
- // No shadow when out of frustrum
13577
+ // No shadow when out of frustum
1322113578 "SGE temp.x, " + depth + ".z, one.z;" +
1322213579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1322313580 "";
....@@ -14015,14 +14372,15 @@
1401514372 drag = false;
1401614373 //System.out.println("Mouse DOWN");
1401714374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1402614384 if (!editObj)
1402714385 {
1402814386 hasMarquee = true;
....@@ -14306,9 +14664,9 @@
1430614664 MODIFIERS |= COMMAND;
1430714665 /**/
1430814666 if((mod&SHIFT) == SHIFT)
14309
- manipCamera.RotatePosition(0, -speed);
14310
- else
1431114667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1431214670 /**/
1431314671 if ((mod & SHIFT) == SHIFT)
1431414672 {
....@@ -14327,9 +14685,9 @@
1432714685 MODIFIERS |= COMMAND;
1432814686 /**/
1432914687 if((mod&SHIFT) == SHIFT)
14330
- manipCamera.RotatePosition(0, speed);
14331
- else
1433214688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1433314691 /**/
1433414692 if ((mod & SHIFT) == SHIFT)
1433514693 {
....@@ -14422,15 +14780,16 @@
1442214780 if (editObj)
1442314781 {
1442414782 drag = true;
14425
- ClickInfo info = new ClickInfo();
14426
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1442714785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1443414793 } else
1443514794 {
1443614795 if (x < startX)
....@@ -14579,24 +14938,27 @@
1457914938 }
1458014939 }
1458114940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1458214943 public void mouseMoved(MouseEvent e)
1458314944 {
1458414945 //System.out.println("mouseMoved: " + e);
1458514946 if (isRenderer)
1458614947 return;
1458714948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1459514956 if (!isRenderer)
1459614957 {
1459714958 //ObjEditor editWindow = object.editWindow;
1459814959 //Object3D copy = editWindow.copy;
14599
- if (object.doEditClick(ci, 0))
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1460014962 {
1460114963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1460214964 } else
....@@ -14868,7 +15230,8 @@
1486815230 // break;
1486915231 case 'T':
1487015232 CACHETEXTURE ^= true;
14871
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1487215235 // repaint();
1487315236 break;
1487415237 case 'Y':
....@@ -15045,20 +15408,24 @@
1504515408 OCCLUSION_CULLING ^= true;
1504615409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504715410 break;
15048
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1504915412 case '1':
1505015413 case '2':
1505115414 case '3':
1505215415 case '4':
1505315416 case '5':
15054
- newenvy = Character.getNumericValue(key);
15055
- repaint();
15056
- break;
1505715417 case '6':
1505815418 case '7':
1505915419 case '8':
1506015420 case '9':
15061
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1506215429 repaint();
1506315430 break;
1506415431 case '!':
....@@ -15621,8 +15988,6 @@
1562115988
1562215989 int width = getBounds().width;
1562315990 int height = getBounds().height;
15624
- ClickInfo info = new ClickInfo();
15625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562615991 //Image img = CreateImage(width, height);
1562715992 //System.out.println("width = " + width + "; height = " + height + "\n");
1562815993
....@@ -15699,31 +16064,37 @@
1569916064 }
1570016065 if (object != null && !hasMarquee)
1570116066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1570216073 if (isRenderer)
1570316074 {
15704
- info.flags++;
16075
+ object.clickInfo.flags++;
1570516076 double frameAspect = (double) width / (double) height;
1570616077 if (frameAspect > renderCamera.aspect)
1570716078 {
1570816079 int desired = (int) ((double) height * renderCamera.aspect);
15709
- info.bounds.width -= width - desired;
15710
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1571116082 } else
1571216083 {
1571316084 int desired = (int) ((double) width / renderCamera.aspect);
15714
- info.bounds.height -= height - desired;
15715
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571616087 }
1571716088 }
1571816089
15719
- info.g = gr;
15720
- info.camera = renderCamera;
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1572116092 /*
1572216093 // Memory intensive (brep.verticescopy)
1572316094 if (!(object instanceof Composite))
1572416095 object.draw(info, 0, false); // SLOW :
1572516096 */
15726
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1572716098 {
1572816099 Grafreed.Assert(object != null);
1572916100 Grafreed.Assert(object.selection != null);
....@@ -15731,9 +16102,9 @@
1573116102 {
1573216103 int hitSomething = object.selection.get(0).hitSomething;
1573316104
15734
- info.DX = 0;
15735
- info.DY = 0;
15736
- info.W = 1;
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
1573716108 if (hitSomething == Object3D.hitCenter)
1573816109 {
1573916110 info.DX = X;
....@@ -15745,7 +16116,8 @@
1574516116 info.DY -= info.bounds.height/2;
1574616117 }
1574716118
15748
- object.drawEditHandles(info, 0);
16119
+ object.drawEditHandles(//info,
16120
+ 0);
1574916121
1575016122 if (drag && (X != 0 || Y != 0))
1575116123 {
....@@ -16244,6 +16616,8 @@
1624416616 private /*static*/ boolean firstime;
1624516617 private /*static*/ cVector newView = new cVector();
1624616618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1624716621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1624816622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624916623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16256,29 +16630,67 @@
1625616630 {
1625716631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1625816632
16633
+ int usedsuf = 0;
16634
+
1625916635 for (int i = 0; i < suffixes.length; i++)
1626016636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1626616642 {
16267
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1626816647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1626916676 //System.out.println("Target = " + targets[i]);
1627016677 cubemap.updateImage(data, targets[i]);
1627116678 }
1627216679
1627316680 return cubemap;
1627416681 }
16682
+
1627516683 int bigsphere = -1;
1627616684
1627716685 float BGcolor = 0.5f;
1627816686
16279
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1628016690 {
16281
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1628216694 {
1628316695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1628416696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16293,7 +16705,17 @@
1629316705 // Compensates for ExaminerViewer's modification of modelview matrix
1629416706 gl.glMatrixMode(GL.GL_MODELVIEW);
1629516707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1629616709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1629716719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1629816720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629916721
....@@ -16325,6 +16747,7 @@
1632516747 {
1632616748 gl.glScalef(1.0f, -1.0f, 1.0f);
1632716749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1632816751 gl.glMultMatrixd(viewrot_1, 0);
1632916752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1633016753 //viewer.updateInverseRotation(gl);
....@@ -16583,7 +17006,7 @@
1658317006 //new Exception().printStackTrace();
1658417007 System.out.println("select buffer init");
1658517008 // Use debug pipeline
16586
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1658717010
1658817011 GL gl = drawable.getGL();
1658917012
....@@ -17129,10 +17552,14 @@
1712917552 gl.glFlush();
1713017553
1713117554 /**/
17132
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1713317556
17134
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1713517558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1713617563 double r = 0, g = 0, b = 0;
1713717564
1713817565 double count = 0;
....@@ -17143,7 +17570,7 @@
1714317570
1714417571 double FACTOR = 1;
1714517572
17146
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1714717574 {
1714817575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1714917576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17226,7 +17653,7 @@
1722617653
1722717654 double scale = ray.z; // 1; // cos
1722817655
17229
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1723017657
1723117658 /*
1723217659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17423,11 +17850,14 @@
1742317850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1742417851 static IntBuffer bigAAbuffer;
1742517852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17426
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1742717854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1742817855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1742917856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17430
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1743117861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1743217862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1743317863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();