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 = true; // 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,43 +2458,19 @@
24052458 return currentGL;
24062459 }
24072460
2408
- private BufferedImage CreateBim(TextureData texturedata)
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
24092462 {
2410
- // cache to disk
2411
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
2412
- //buffers[0].
2413
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
2414
- int[] pixels = new int[bytebuf.capacity()/3];
2415
- int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared
2416
- int height = width;
2417
- for (int i=pixels.length; --i>=0;)
2418
- {
2419
- int i3 = i*3;
2420
- pixels[i] = 0xFF;
2421
- pixels[i] <<= 8;
2422
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
2423
- pixels[i] <<= 8;
2424
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
2425
- pixels[i] <<= 8;
2426
- pixels[i] |= bytebuf.get(i3) & 0xFF;
2427
- }
2428
- /*
2429
- int r=0,g=0,b=0,a=0;
2430
- for (int i=0; i<width; i++)
2431
- for (int j=0; j<height; j++)
2432
- {
2433
- int index = j*width+i;
2434
- int p = pixels[index];
2435
- a = ((p>>24) & 0xFF);
2436
- r = ((p>>16) & 0xFF);
2437
- g = ((p>>8) & 0xFF);
2438
- b = (p & 0xFF);
2439
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
2440
- }
2441
- /**/
2442
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
2443
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
2444
- return rendImage;
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);
24452474 }
24462475
24472476 /**/
....@@ -2452,18 +2481,20 @@
24522481
24532482 int resolution;
24542483
2455
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24562485 {
2457
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
24582488 resolution = res;
24592489 }
24602490 }
24612491 /**/
24622492
24632493 // TEXTURE static Texture texture;
2464
- static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2465
- static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2466
- static public java.util.HashSet<String> usedtextures = new java.util.HashSet<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>();
24672498
24682499 int pigmentdepth = 0;
24692500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
....@@ -2471,10 +2502,10 @@
24712502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24722503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24732504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2474
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24752506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24762507
2477
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24782509 {
24792510 TextureData texturedata = null;
24802511
....@@ -2493,16 +2524,16 @@
24932524 if (bump)
24942525 texturedata = ConvertBump(texturedata, false);
24952526
2496
- com.sun.opengl.util.texture.Texture texture =
2497
- 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);
24982529
2499
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2500
- 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);
25012532
2502
- return texture;
2533
+ return texturedata;
25032534 }
25042535
2505
- com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
25062537 {
25072538 TextureData texturedata = null;
25082539
....@@ -2510,7 +2541,7 @@
25102541 {
25112542 texturedata =
25122543 com.sun.opengl.util.texture.TextureIO.newTextureData(
2513
- name,
2544
+ bim,
25142545 true);
25152546 } catch (Exception e)
25162547 {
....@@ -2519,14 +2550,8 @@
25192550
25202551 if (bump)
25212552 texturedata = ConvertBump(texturedata, false);
2522
-
2523
- com.sun.opengl.util.texture.Texture texture =
2524
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2525
-
2526
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2527
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2528
-
2529
- return texture;
2553
+
2554
+ return texturedata;
25302555 }
25312556
25322557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -8014,8 +8039,8 @@
80148039 pigment = null;
80158040 }
80168041
8017
- ReleaseTexture(bump, true);
8018
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
80198044 }
80208045
80218046 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8044,7 +8069,7 @@
80448069 pigment = null;
80458070 }
80468071
8047
- ReleaseTexture(pigment, false);
8072
+ ReleaseTexture(tex, false);
80488073 }
80498074
80508075 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8073,10 +8098,10 @@
80738098 bump = null;
80748099 }
80758100
8076
- ReleaseTexture(bump, true);
8101
+ ReleaseTexture(tex, true);
80778102 }
80788103
8079
- void ReleaseTexture(String tex, boolean bump)
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
80808105 {
80818106 if (// DrawMode() != 0 || /*tex == null ||*/
80828107 ambientOcclusion ) // || !textureon)
....@@ -8087,7 +8112,7 @@
80878112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80888113
80898114 if (tex != null)
8090
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80918116
80928117 // //assert( texture != null );
80938118 // if (texture == null)
....@@ -8237,13 +8262,13 @@
82378262
82388263 if (tex == null)
82398264 {
8240
- BindTexture(null, null,false,resolution);
8265
+ BindTexture(null,false,resolution);
82418266 return;
82428267 }
82438268
82448269 String pigment = Object3D.GetPigment(tex);
82458270
8246
- usedtextures.add(pigment);
8271
+ usedtextures.add(tex);
82478272
82488273 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82498274 {
....@@ -8257,7 +8282,7 @@
82578282 }
82588283
82598284 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8260
- BindTexture(tex.pigmenttexture, pigment, false, resolution);
8285
+ BindTexture(tex, false, resolution);
82618286 }
82628287
82638288 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8270,13 +8295,13 @@
82708295
82718296 if (tex == null)
82728297 {
8273
- BindTexture(null, null,true,resolution);
8298
+ BindTexture(null,true,resolution);
82748299 return;
82758300 }
82768301
82778302 String bump = Object3D.GetBump(tex);
82788303
8279
- usedtextures.add(bump);
8304
+ usedtextures.add(tex);
82808305
82818306 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82828307 {
....@@ -8290,7 +8315,7 @@
82908315 }
82918316
82928317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8293
- BindTexture(tex.bumptexture, bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
82948319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82958320 }
82968321
....@@ -8314,13 +8339,19 @@
83148339 return fileExists;
83158340 }
83168341
8317
- CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
83188343 {
83198344 CacheTexture texturecache = null;
83208345
83218346 if (tex != null)
83228347 {
8323
- 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
+ }
83248355
83258356 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
83268357
....@@ -8330,29 +8361,46 @@
83308361 // else
83318362 // if (!texname.startsWith("/"))
83328363 // texname = "/Users/nbriere/Textures/" + texname;
8333
- if (!FileExists(tex))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
83348365 {
83358366 texname = fallbackTextureName;
83368367 }
83378368
83388369 if (CACHETEXTURE)
83398370 {
8340
- if (bim == null)
8341
- texturecache = textures.get(texname); // TEXTURE CACHE
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
83428373 else
8343
- texturecache = bimtextures.get(bim); // TEXTURE CACHE
8374
+ texturecache = bimtextures.get(texdata);
83448375 }
83458376
8346
- if (texturecache == null || texturecache.resolution < resolution)
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
83478378 {
83488379 TextureData texturedata = null;
83498380
8350
- if (bim != null)
8381
+ if (texdata != null && textureon)
83518382 {
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
+
83528394 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;
83538401 }
83548402 else
8355
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83568404 {
83578405 assert(!bump);
83588406 // if (bump)
....@@ -8363,7 +8411,7 @@
83638411 // }
83648412 // else
83658413 // {
8366
- texturecache = textures.get(tex);
8414
+ // texturecache = textures.get(texname); // suspicious
83678415 if (texturecache == null)
83688416 {
83698417 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
....@@ -8372,10 +8420,10 @@
83728420 new Exception().printStackTrace();
83738421 // }
83748422 } else
8375
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
83768424 {
83778425 assert(bump);
8378
- texturecache = textures.get(tex);
8426
+ // texturecache = textures.get(texname); // suspicious
83798427 if (texturecache == null)
83808428 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83818429 else
....@@ -8387,11 +8435,20 @@
83878435 // texture = GetResourceTexture("default.png");
83888436 //} else
83898437 //{
8390
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
83918439 {
8392
- texturecache = textures.get(tex);
8440
+ // texturecache = textures.get(texname); // suspicious
83938441 if (texturecache == null)
83948442 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);
83958452 else
83968453 new Exception().printStackTrace();
83978454 } else
....@@ -8452,17 +8509,17 @@
84528509 if (texturedata == null)
84538510 throw new Exception();
84548511
8455
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8512
+ texturecache = new CacheTexture(texturedata,resolution);
84568513 //texture = GetTexture(tex, bump);
84578514 }
8515
+ }
84588516 }
84598517 //}
84608518 }
84618519
8462
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84638521 {
84648522 //return false;
8465
- assert(bim == null);
84668523
84678524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
84688525 if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
....@@ -8509,18 +8566,20 @@
85098566 }
85108567 }
85118568 }
8512
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
85138572 //System.out.println("Texture = " + tex);
8514
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
85158574 {
8516
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
85178576 thetex.texture.disable();
85188577 thetex.texture.dispose();
8519
- textures.remove(texname);
8578
+ textures.remove(tex);
85208579 }
85218580
85228581 //texture.texturedata = texturedata;
8523
- textures.put(texname, texturecache);
8582
+ textures.put(tex, texturecache);
85248583
85258584 // newtex = true;
85268585 }
....@@ -8541,12 +8600,41 @@
85418600
85428601 static void EmbedTextures(cTexture tex)
85438602 {
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
+ }
85448619
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
+ }
85458633 }
85468634
8547
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
85488636 {
8549
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8637
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85508638
85518639 if (bump)
85528640 {
....@@ -8562,14 +8650,14 @@
85628650 return texture!=null?texture.texture:null;
85638651 }
85648652
8565
- public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, 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
85668654 {
8567
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8655
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85688656
85698657 return texture!=null?texture.texturedata:null;
85708658 }
85718659
8572
- boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85738661 {
85748662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85758663 {
....@@ -8578,7 +8666,7 @@
85788666
85798667 //boolean newtex = false;
85808668
8581
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8669
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85828670
85838671 if (texture == null)
85848672 return false;
....@@ -8611,6 +8699,72 @@
86118699 return true; // Warning: not used.
86128700 }
86138701
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
+
86148768 ShadowBuffer shadowPBuf;
86158769 AntialiasBuffer antialiasPBuf;
86168770 int MAXSTACK;
....@@ -8627,10 +8781,12 @@
86278781
86288782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86298783 MAXSTACK = temp[0];
8630
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86318786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86328787 MAXSTACK = temp[0];
8633
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86348790
86358791 // Use debug pipeline
86368792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8638,7 +8794,8 @@
86388794 gl = drawable.getGL(); //
86398795
86408796 GL gl3 = getGL();
8641
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86428799
86438800
86448801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8803,7 +8960,7 @@
88038960
88048961 if (cubemap == null)
88058962 {
8806
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
88078964 }
88088965
88098966 //cubemap.enable();
....@@ -9079,6 +9236,8 @@
90799236
90809237 void LoadEnvy(int which)
90819238 {
9239
+ assert(false);
9240
+
90829241 String name;
90839242 String ext;
90849243
....@@ -9090,37 +9249,58 @@
90909249 cubemap = null;
90919250 return;
90929251 case 1:
9093
- name = "cubemaps/box_";
9094
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
90959254 reverseUP = false;
90969255 break;
90979256 case 2:
9098
- name = "cubemaps/uffizi_";
9099
- ext = "png";
9100
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
91019261 case 3:
9102
- name = "cubemaps/CloudyHills_";
9103
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
91049264 reverseUP = false;
91059265 break;
91069266 case 4:
9107
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
91089268 ext = "png";
91099269 reverseUP = false;
91109270 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;
91119296 default:
9112
- name = "cubemaps/rgb_";
9113
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
91149300 break;
91159301 }
9116
-
9117
- try
9118
- {
9119
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9120
- } catch (IOException e)
9121
- {
9122
- throw new RuntimeException(e);
9123
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
91249304 }
91259305
91269306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9152,8 +9332,12 @@
91529332 static double[] model = new double[16];
91539333 double[] camera2light = new double[16];
91549334 double[] light2camera = new double[16];
9155
- int newenvy = -1;
9156
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
91579341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91589342 //float[] light0 = { 0,0,0 };
91599343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9571,7 +9755,7 @@
95719755
95729756 if (renderCamera != lightCamera)
95739757 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95759759
95769760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95779761
....@@ -9587,7 +9771,7 @@
95879771
95889772 if (renderCamera != lightCamera)
95899773 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9590
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95919775
95929776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95939777
....@@ -9633,10 +9817,12 @@
96339817 rati = 1 / rati;
96349818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96359819 }
9636
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
96379823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96389824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9639
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
96409826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96419827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96429828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10673,7 +10859,7 @@
1067310859
1067410860 if (wait)
1067510861 {
10676
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1067710863
1067810864 wait = false;
1067910865 }
....@@ -10788,7 +10974,7 @@
1078810974 // if (parentcam != renderCamera) // not a light
1078910975 if (cam != lightCamera)
1079010976 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10791
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1079210978
1079310979 for (int j = 0; j < 4; j++)
1079410980 {
....@@ -10803,7 +10989,7 @@
1080310989 // if (parentcam != renderCamera) // not a light
1080410990 if (cam != lightCamera)
1080510991 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10806
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1080710993
1080810994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1080910995
....@@ -10889,13 +11075,41 @@
1088911075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1089011076 }
1089111077
10892
- 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"))
1089311086 {
10894
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1089511093 }
10896
-
10897
- newenvy = -1;
10898
-
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
+
1089911113 ratio = ((double) getWidth()) / getHeight();
1090011114 //System.out.println("ratio = " + ratio);
1090111115
....@@ -10911,7 +11125,7 @@
1091111125
1091211126 if (!IsFrozen() && !ambientOcclusion)
1091311127 {
10914
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1091511129 }
1091611130
1091711131 //if (selection_view == -1)
....@@ -11065,7 +11279,7 @@
1106511279
1106611280 try
1106711281 {
11068
- BindTexture(null, NOISE_TEXTURE, false, 2);
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
1106911283 }
1107011284 catch (Exception e)
1107111285 {
....@@ -11197,7 +11411,7 @@
1119711411
1119811412 // if (cam != lightCamera)
1119911413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11200
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1120111415 }
1120211416
1120311417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11356,7 +11570,7 @@
1135611570 }
1135711571 }
1135811572
11359
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1136011574 {
1136111575 //gl.glDepthFunc(GL.GL_LEQUAL);
1136211576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11364,24 +11578,21 @@
1136411578
1136511579 boolean texon = textureon;
1136611580
11367
- if (RENDERPROGRAM > 0)
11368
- {
11369
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11370
- textureon = false;
11371
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1137211584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1137311585 //System.out.println("ALLO");
1137411586 gl.glColorMask(false, false, false, false);
1137511587 DrawObject(gl);
11376
- if (RENDERPROGRAM > 0)
11377
- {
11378
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11379
- textureon = texon;
11380
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1138111592 gl.glColorMask(true, true, true, true);
1138211593
1138311594 gl.glDepthFunc(GL.GL_EQUAL);
11384
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1138511596 }
1138611597
1138711598 if (false) // DrawMode() == SHADOW)
....@@ -11721,20 +11932,32 @@
1172111932 ReleaseTextures(DEFAULT_TEXTURES);
1172211933
1172311934 if (CLEANCACHE)
11724
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1172511936 {
11726
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1172711938
1172811939 // System.out.println("Texture --------- " + tex);
1172911940
11730
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1173111942 continue;
1173211943
1173311944 if (!usedtextures.contains(tex))
1173411945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1173511947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11736
- textures.get(tex).texture.dispose();
11737
- 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
+ }
1173811961 }
1173911962 }
1174011963 }
....@@ -12262,8 +12485,76 @@
1226212485
1226312486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1226412487
12265
- String program =
12488
+ String programmin =
12489
+ // Min shader
1226612490 "!!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
+
1226712558 //"OPTION ARB_fragment_program_shadow;" +
1226812559 "PARAM light2cam0 = program.env[10];" +
1226912560 "PARAM light2cam1 = program.env[11];" +
....@@ -12378,8 +12669,7 @@
1237812669 "TEMP shininess;" +
1237912670 "\n" +
1238012671 "MOV texSamp, one;" +
12381
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12382
-
12672
+
1238312673 "MOV mapgrid.x, one2048th.x;" +
1238412674 "MOV temp, fragment.texcoord[1];" +
1238512675 /*
....@@ -12400,20 +12690,20 @@
1240012690 "MUL temp, floor, mapgrid.x;" +
1240112691 //"TEX depth0, temp, texture[1], 2D;" +
1240212692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12403
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1240412694 "") +
1240512695 "ADD temp.x, temp.x, mapgrid.x;" +
1240612696 //"TEX depth1, temp, texture[1], 2D;" +
1240712697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12408
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1240912699 "") +
1241012700 "ADD temp.y, temp.y, mapgrid.x;" +
1241112701 //"TEX depth2, temp, texture[1], 2D;" +
12412
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1241312703 "SUB temp.x, temp.x, mapgrid.x;" +
1241412704 //"TEX depth3, temp, texture[1], 2D;" +
1241512705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12416
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1241712707 "") +
1241812708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1241912709 //"MOV params, material;" +
....@@ -12784,10 +13074,10 @@
1278413074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1278513075 "") +
1278613076
12787
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1278813078 "SUB temp.x, half.x, shadow.x;" +
1278913079 "MOV temp.y, -params5.z;" + // params6.x;" +
12790
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1279113081 "SUB temp.y, one.x, temp.z;" +
1279213082 "MUL temp.x, temp.x, temp.y;" +
1279313083 "KIL temp.x;" +
....@@ -13118,6 +13408,13 @@
1311813408 //once = true;
1311913409 }
1312013410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1312113418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1312213419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1312313420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13211,25 +13508,26 @@
1321113508 return out;
1321213509 }
1321313510
13214
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1321513513 {
1321613514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1321713515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1321813516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1321913519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13220
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13221
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13222
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13223
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1322413522 //"SWZ buffer, temp, w,w,w,w;";
13225
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1322613524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1322713525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1322813526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13229
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1323013528
13231
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13232
- //"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;";
1323313531 }
1323413532
1323513533 String Shadow(String depth, String shadow)
....@@ -13276,7 +13574,7 @@
1327613574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1327713575 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1327813576
13279
- // No shadow when out of frustrum
13577
+ // No shadow when out of frustum
1328013578 "SGE temp.x, " + depth + ".z, one.z;" +
1328113579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1328213580 "";
....@@ -14074,14 +14372,15 @@
1407414372 drag = false;
1407514373 //System.out.println("Mouse DOWN");
1407614374 editObj = false;
14077
- ClickInfo info = new ClickInfo();
14078
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14079
- info.pane = this;
14080
- info.camera = renderCamera;
14081
- info.x = x;
14082
- info.y = y;
14083
- info.modifiers = modifiersex;
14084
- 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);
1408514384 if (!editObj)
1408614385 {
1408714386 hasMarquee = true;
....@@ -14365,9 +14664,9 @@
1436514664 MODIFIERS |= COMMAND;
1436614665 /**/
1436714666 if((mod&SHIFT) == SHIFT)
14368
- manipCamera.RotatePosition(0, -speed);
14369
- else
1437014667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1437114670 /**/
1437214671 if ((mod & SHIFT) == SHIFT)
1437314672 {
....@@ -14386,9 +14685,9 @@
1438614685 MODIFIERS |= COMMAND;
1438714686 /**/
1438814687 if((mod&SHIFT) == SHIFT)
14389
- manipCamera.RotatePosition(0, speed);
14390
- else
1439114688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1439214691 /**/
1439314692 if ((mod & SHIFT) == SHIFT)
1439414693 {
....@@ -14481,15 +14780,16 @@
1448114780 if (editObj)
1448214781 {
1448314782 drag = true;
14484
- ClickInfo info = new ClickInfo();
14485
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1448614785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14487
- info.pane = this;
14488
- info.camera = renderCamera;
14489
- info.x = x;
14490
- info.y = y;
14491
- object.GetWindow().copy
14492
- .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);
1449314793 } else
1449414794 {
1449514795 if (x < startX)
....@@ -14638,24 +14938,27 @@
1463814938 }
1463914939 }
1464014940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1464114943 public void mouseMoved(MouseEvent e)
1464214944 {
1464314945 //System.out.println("mouseMoved: " + e);
1464414946 if (isRenderer)
1464514947 return;
1464614948
14647
- ClickInfo ci = new ClickInfo();
14648
- ci.x = e.getX();
14649
- ci.y = e.getY();
14650
- ci.modifiers = e.getModifiersEx();
14651
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14652
- ci.pane = this;
14653
- 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;
1465414956 if (!isRenderer)
1465514957 {
1465614958 //ObjEditor editWindow = object.editWindow;
1465714959 //Object3D copy = editWindow.copy;
14658
- if (object.doEditClick(ci, 0))
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1465914962 {
1466014963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1466114964 } else
....@@ -14927,7 +15230,8 @@
1492715230 // break;
1492815231 case 'T':
1492915232 CACHETEXTURE ^= true;
14930
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1493115235 // repaint();
1493215236 break;
1493315237 case 'Y':
....@@ -15104,20 +15408,24 @@
1510415408 OCCLUSION_CULLING ^= true;
1510515409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1510615410 break;
15107
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1510815412 case '1':
1510915413 case '2':
1511015414 case '3':
1511115415 case '4':
1511215416 case '5':
15113
- newenvy = Character.getNumericValue(key);
15114
- repaint();
15115
- break;
1511615417 case '6':
1511715418 case '7':
1511815419 case '8':
1511915420 case '9':
15120
- 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
+ }
1512115429 repaint();
1512215430 break;
1512315431 case '!':
....@@ -15680,8 +15988,6 @@
1568015988
1568115989 int width = getBounds().width;
1568215990 int height = getBounds().height;
15683
- ClickInfo info = new ClickInfo();
15684
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1568515991 //Image img = CreateImage(width, height);
1568615992 //System.out.println("width = " + width + "; height = " + height + "\n");
1568715993
....@@ -15758,31 +16064,37 @@
1575816064 }
1575916065 if (object != null && !hasMarquee)
1576016066 {
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
+
1576116073 if (isRenderer)
1576216074 {
15763
- info.flags++;
16075
+ object.clickInfo.flags++;
1576416076 double frameAspect = (double) width / (double) height;
1576516077 if (frameAspect > renderCamera.aspect)
1576616078 {
1576716079 int desired = (int) ((double) height * renderCamera.aspect);
15768
- info.bounds.width -= width - desired;
15769
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1577016082 } else
1577116083 {
1577216084 int desired = (int) ((double) width / renderCamera.aspect);
15773
- info.bounds.height -= height - desired;
15774
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1577516087 }
1577616088 }
1577716089
15778
- info.g = gr;
15779
- info.camera = renderCamera;
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1578016092 /*
1578116093 // Memory intensive (brep.verticescopy)
1578216094 if (!(object instanceof Composite))
1578316095 object.draw(info, 0, false); // SLOW :
1578416096 */
15785
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1578616098 {
1578716099 Grafreed.Assert(object != null);
1578816100 Grafreed.Assert(object.selection != null);
....@@ -15790,9 +16102,9 @@
1579016102 {
1579116103 int hitSomething = object.selection.get(0).hitSomething;
1579216104
15793
- info.DX = 0;
15794
- info.DY = 0;
15795
- info.W = 1;
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
1579616108 if (hitSomething == Object3D.hitCenter)
1579716109 {
1579816110 info.DX = X;
....@@ -15804,7 +16116,8 @@
1580416116 info.DY -= info.bounds.height/2;
1580516117 }
1580616118
15807
- object.drawEditHandles(info, 0);
16119
+ object.drawEditHandles(//info,
16120
+ 0);
1580816121
1580916122 if (drag && (X != 0 || Y != 0))
1581016123 {
....@@ -16303,6 +16616,8 @@
1630316616 private /*static*/ boolean firstime;
1630416617 private /*static*/ cVector newView = new cVector();
1630516618 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"};
1630616621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1630716622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1630816623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16315,29 +16630,67 @@
1631516630 {
1631616631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1631716632
16633
+ int usedsuf = 0;
16634
+
1631816635 for (int i = 0; i < suffixes.length; i++)
1631916636 {
16320
- String resourceName = basename + suffixes[i] + "." + suffix;
16321
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16322
- mipmapped,
16323
- FileUtil.getFileSuffix(resourceName));
16324
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1632516642 {
16326
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1632716647 }
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
+
1632816676 //System.out.println("Target = " + targets[i]);
1632916677 cubemap.updateImage(data, targets[i]);
1633016678 }
1633116679
1633216680 return cubemap;
1633316681 }
16682
+
1633416683 int bigsphere = -1;
1633516684
1633616685 float BGcolor = 0.5f;
1633716686
16338
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1633916690 {
16340
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1634116694 {
1634216695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1634316696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16352,7 +16705,17 @@
1635216705 // Compensates for ExaminerViewer's modification of modelview matrix
1635316706 gl.glMatrixMode(GL.GL_MODELVIEW);
1635416707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1635516709
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
+
1635616719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1635716720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1635816721
....@@ -16384,6 +16747,7 @@
1638416747 {
1638516748 gl.glScalef(1.0f, -1.0f, 1.0f);
1638616749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1638716751 gl.glMultMatrixd(viewrot_1, 0);
1638816752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1638916753 //viewer.updateInverseRotation(gl);
....@@ -16642,7 +17006,7 @@
1664217006 //new Exception().printStackTrace();
1664317007 System.out.println("select buffer init");
1664417008 // Use debug pipeline
16645
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1664617010
1664717011 GL gl = drawable.getGL();
1664817012
....@@ -17188,10 +17552,14 @@
1718817552 gl.glFlush();
1718917553
1719017554 /**/
17191
- 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);
1719217556
17193
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1719417558
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
+
1719517563 double r = 0, g = 0, b = 0;
1719617564
1719717565 double count = 0;
....@@ -17202,7 +17570,7 @@
1720217570
1720317571 double FACTOR = 1;
1720417572
17205
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1720617574 {
1720717575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1720817576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17285,7 +17653,7 @@
1728517653
1728617654 double scale = ray.z; // 1; // cos
1728717655
17288
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1728917657
1729017658 /*
1729117659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17482,11 +17850,14 @@
1748217850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1748317851 static IntBuffer bigAAbuffer;
1748417852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17485
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1748617854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1748717855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1748817856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17489
- 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
+
1749017861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1749117862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1749217863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();