Normand Briere
2019-08-16 83d0c2fa0bd2e96448f776144e1a89cdb1bb6998
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,11 @@
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;
116
+ boolean transformMode;
117
+
77118 boolean reverseUP = false;
78119 static boolean frozen = false;
79120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -136,7 +177,7 @@
136177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
137178 boolean anisotropy = true;
138179 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140181
141182 boolean macromode = false;
142183
....@@ -150,6 +191,19 @@
150191 }
151192
152193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
153207
154208 void SetAsGLRenderer(boolean b)
155209 {
....@@ -169,7 +223,8 @@
169223
170224 SetCamera(cam);
171225
172
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
173228
174229 object = o;
175230
....@@ -1447,6 +1502,8 @@
14471502 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481503 }
14491504
1505
+ float[] colorV = new float[4];
1506
+
14501507 void SetColor(Object3D obj, Vertex p0)
14511508 {
14521509 CameraPane display = this;
....@@ -1514,8 +1571,6 @@
15141571 {
15151572 return;
15161573 }
1517
-
1518
- float[] colorV = new float[3];
15191574
15201575 if (false) // marked)
15211576 {
....@@ -2405,6 +2460,21 @@
24052460 return currentGL;
24062461 }
24072462
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
24082478 /**/
24092479 class CacheTexture
24102480 {
....@@ -2413,18 +2483,20 @@
24132483
24142484 int resolution;
24152485
2416
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24172487 {
2418
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
24192490 resolution = res;
24202491 }
24212492 }
24222493 /**/
24232494
24242495 // TEXTURE static Texture texture;
2425
- static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2426
- static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2427
- static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
24282500
24292501 int pigmentdepth = 0;
24302502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
....@@ -2432,10 +2504,10 @@
24322504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24332505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24342506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2435
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24362508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24372509
2438
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24392511 {
24402512 TextureData texturedata = null;
24412513
....@@ -2445,7 +2517,7 @@
24452517 com.sun.opengl.util.texture.TextureIO.newTextureData(
24462518 getClass().getClassLoader().getResourceAsStream(name),
24472519 true,
2448
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24492521 } catch (java.io.IOException e)
24502522 {
24512523 throw new javax.media.opengl.GLException(e);
....@@ -2454,16 +2526,16 @@
24542526 if (bump)
24552527 texturedata = ConvertBump(texturedata, false);
24562528
2457
- com.sun.opengl.util.texture.Texture texture =
2458
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24592531
2460
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2461
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24622534
2463
- return texture;
2535
+ return texturedata;
24642536 }
24652537
2466
- com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
24672539 {
24682540 TextureData texturedata = null;
24692541
....@@ -2471,7 +2543,7 @@
24712543 {
24722544 texturedata =
24732545 com.sun.opengl.util.texture.TextureIO.newTextureData(
2474
- name,
2546
+ bim,
24752547 true);
24762548 } catch (Exception e)
24772549 {
....@@ -2480,14 +2552,8 @@
24802552
24812553 if (bump)
24822554 texturedata = ConvertBump(texturedata, false);
2483
-
2484
- com.sun.opengl.util.texture.Texture texture =
2485
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2486
-
2487
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2488
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2489
-
2490
- return texture;
2555
+
2556
+ return texturedata;
24912557 }
24922558
24932559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -7975,8 +8041,8 @@
79758041 pigment = null;
79768042 }
79778043
7978
- ReleaseTexture(bump, true);
7979
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
79808046 }
79818047
79828048 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -8005,7 +8071,7 @@
80058071 pigment = null;
80068072 }
80078073
8008
- ReleaseTexture(pigment, false);
8074
+ ReleaseTexture(tex, false);
80098075 }
80108076
80118077 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -8034,10 +8100,10 @@
80348100 bump = null;
80358101 }
80368102
8037
- ReleaseTexture(bump, true);
8103
+ ReleaseTexture(tex, true);
80388104 }
80398105
8040
- void ReleaseTexture(String tex, boolean bump)
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
80418107 {
80428108 if (// DrawMode() != 0 || /*tex == null ||*/
80438109 ambientOcclusion ) // || !textureon)
....@@ -8048,7 +8114,7 @@
80488114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80498115
80508116 if (tex != null)
8051
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80528118
80538119 // //assert( texture != null );
80548120 // if (texture == null)
....@@ -8198,13 +8264,13 @@
81988264
81998265 if (tex == null)
82008266 {
8201
- BindTexture(null, null,false,resolution);
8267
+ BindTexture(null,false,resolution);
82028268 return;
82038269 }
82048270
82058271 String pigment = Object3D.GetPigment(tex);
82068272
8207
- usedtextures.add(pigment);
8273
+ usedtextures.add(tex);
82088274
82098275 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108276 {
....@@ -8218,7 +8284,7 @@
82188284 }
82198285
82208286 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8221
- BindTexture(tex.pigmenttexture, pigment, false, resolution);
8287
+ BindTexture(tex, false, resolution);
82228288 }
82238289
82248290 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8231,13 +8297,13 @@
82318297
82328298 if (tex == null)
82338299 {
8234
- BindTexture(null, null,true,resolution);
8300
+ BindTexture(null,true,resolution);
82358301 return;
82368302 }
82378303
82388304 String bump = Object3D.GetBump(tex);
82398305
8240
- usedtextures.add(bump);
8306
+ usedtextures.add(tex);
82418307
82428308 //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82438309 {
....@@ -8251,7 +8317,7 @@
82518317 }
82528318
82538319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8254
- BindTexture(tex.bumptexture, bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
82558321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82568322 }
82578323
....@@ -8275,13 +8341,19 @@
82758341 return fileExists;
82768342 }
82778343
8278
- CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82798345 {
82808346 CacheTexture texturecache = null;
82818347
82828348 if (tex != null)
82838349 {
8284
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8352
+
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
82858357
82868358 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82878359
....@@ -8291,29 +8363,46 @@
82918363 // else
82928364 // if (!texname.startsWith("/"))
82938365 // texname = "/Users/nbriere/Textures/" + texname;
8294
- if (!FileExists(tex))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
82958367 {
82968368 texname = fallbackTextureName;
82978369 }
82988370
82998371 if (CACHETEXTURE)
83008372 {
8301
- if (bim == null)
8302
- texturecache = textures.get(texname); // TEXTURE CACHE
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
83038375 else
8304
- texturecache = bimtextures.get(bim); // TEXTURE CACHE
8376
+ texturecache = bimtextures.get(texdata);
83058377 }
83068378
8307
- if (texturecache == null || texturecache.resolution < resolution)
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
83088380 {
83098381 TextureData texturedata = null;
83108382
8311
- if (bim == null)
8383
+ if (texdata != null && textureon)
83128384 {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
83138386
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
83148403 }
83158404 else
8316
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
83178406 {
83188407 assert(!bump);
83198408 // if (bump)
....@@ -8324,19 +8413,23 @@
83248413 // }
83258414 // else
83268415 // {
8327
- texturecache = textures.get(tex);
8416
+ // texturecache = textures.get(texname); // suspicious
83288417 if (texturecache == null)
83298418 {
83308419 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
83318420 }
8421
+ else
8422
+ new Exception().printStackTrace();
83328423 // }
83338424 } else
8334
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
83358426 {
83368427 assert(bump);
8337
- texturecache = textures.get(tex);
8428
+ // texturecache = textures.get(texname); // suspicious
83388429 if (texturecache == null)
83398430 texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
83408433 } else
83418434 {
83428435 //if (tex.equals("IMMORTAL"))
....@@ -8344,11 +8437,22 @@
83448437 // texture = GetResourceTexture("default.png");
83458438 //} else
83468439 //{
8347
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
83488441 {
8349
- texturecache = textures.get(tex);
8442
+ // texturecache = textures.get(texname); // suspicious
83508443 if (texturecache == null)
83518444 texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
83528456 } else
83538457 {
83548458 if (textureon)
....@@ -8407,14 +8511,15 @@
84078511 if (texturedata == null)
84088512 throw new Exception();
84098513
8410
- texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8514
+ texturecache = new CacheTexture(texturedata,resolution);
84118515 //texture = GetTexture(tex, bump);
84128516 }
8517
+ }
84138518 }
84148519 //}
84158520 }
84168521
8417
- if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
84188523 {
84198524 //return false;
84208525
....@@ -8436,52 +8541,17 @@
84368541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
84378542 if (!cachefile.exists())
84388543 {
8439
- // cache to disk
8440
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8441
- //buffers[0].
8442
-
8443
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8444
- int[] pixels = new int[bytebuf.capacity()/3];
8445
-
8446
- // squared size heuristic...
8447
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
84488545 {
8449
- for (int i=pixels.length; --i>=0;)
8450
- {
8451
- int i3 = i*3;
8452
- pixels[i] = 0xFF;
8453
- pixels[i] <<= 8;
8454
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8455
- pixels[i] <<= 8;
8456
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8457
- pixels[i] <<= 8;
8458
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8459
- }
8460
-
8461
- /*
8462
- int r=0,g=0,b=0,a=0;
8463
- for (int i=0; i<width; i++)
8464
- for (int j=0; j<height; j++)
8465
- {
8466
- int index = j*width+i;
8467
- int p = pixels[index];
8468
- a = ((p>>24) & 0xFF);
8469
- r = ((p>>16) & 0xFF);
8470
- g = ((p>>8) & 0xFF);
8471
- b = (p & 0xFF);
8472
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8473
- }
8474
- /**/
8475
- int width = (int)Math.sqrt(pixels.length); // squared
8476
- int height = width;
8477
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8478
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
84798548 ImageWriter writer = null;
84808549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84818550 if (iter.hasNext()) {
84828551 writer = (ImageWriter)iter.next();
84838552 }
8484
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
84858555 try
84868556 {
84878557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8498,18 +8568,20 @@
84988568 }
84998569 }
85008570 }
8501
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
85028574 //System.out.println("Texture = " + tex);
8503
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
85048576 {
8505
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
85068578 thetex.texture.disable();
85078579 thetex.texture.dispose();
8508
- textures.remove(texname);
8580
+ textures.remove(tex);
85098581 }
85108582
85118583 //texture.texturedata = texturedata;
8512
- textures.put(texname, texturecache);
8584
+ textures.put(tex, texturecache);
85138585
85148586 // newtex = true;
85158587 }
....@@ -8528,9 +8600,43 @@
85288600 return texturecache;
85298601 }
85308602
8531
- com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8603
+ static void EmbedTextures(cTexture tex)
85328604 {
8533
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
8638
+ {
8639
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85348640
85358641 if (bump)
85368642 {
....@@ -8546,14 +8652,14 @@
85468652 return texture!=null?texture.texture:null;
85478653 }
85488654
8549
- public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85508656 {
8551
- CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
8657
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85528658
85538659 return texture!=null?texture.texturedata:null;
85548660 }
85558661
8556
- boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85578663 {
85588664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85598665 {
....@@ -8562,7 +8668,7 @@
85628668
85638669 //boolean newtex = false;
85648670
8565
- com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
8671
+ com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85668672
85678673 if (texture == null)
85688674 return false;
....@@ -8595,6 +8701,72 @@
85958701 return true; // Warning: not used.
85968702 }
85978703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
85988770 ShadowBuffer shadowPBuf;
85998771 AntialiasBuffer antialiasPBuf;
86008772 int MAXSTACK;
....@@ -8611,10 +8783,12 @@
86118783
86128784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86138785 MAXSTACK = temp[0];
8614
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86158788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86168789 MAXSTACK = temp[0];
8617
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86188792
86198793 // Use debug pipeline
86208794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8622,7 +8796,8 @@
86228796 gl = drawable.getGL(); //
86238797
86248798 GL gl3 = getGL();
8625
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86268801
86278802
86288803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8787,7 +8962,7 @@
87878962
87888963 if (cubemap == null)
87898964 {
8790
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
87918966 }
87928967
87938968 //cubemap.enable();
....@@ -9063,6 +9238,8 @@
90639238
90649239 void LoadEnvy(int which)
90659240 {
9241
+ assert(false);
9242
+
90669243 String name;
90679244 String ext;
90689245
....@@ -9074,37 +9251,58 @@
90749251 cubemap = null;
90759252 return;
90769253 case 1:
9077
- name = "cubemaps/box_";
9078
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
90799256 reverseUP = false;
90809257 break;
90819258 case 2:
9082
- name = "cubemaps/uffizi_";
9083
- ext = "png";
9084
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
90859263 case 3:
9086
- name = "cubemaps/CloudyHills_";
9087
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
90889266 reverseUP = false;
90899267 break;
90909268 case 4:
9091
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
90929270 ext = "png";
90939271 reverseUP = false;
90949272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
90959298 default:
9096
- name = "cubemaps/rgb_";
9097
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
90989302 break;
90999303 }
9100
-
9101
- try
9102
- {
9103
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9104
- } catch (IOException e)
9105
- {
9106
- throw new RuntimeException(e);
9107
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
91089306 }
91099307
91109308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9136,8 +9334,12 @@
91369334 static double[] model = new double[16];
91379335 double[] camera2light = new double[16];
91389336 double[] light2camera = new double[16];
9139
- int newenvy = -1;
9140
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
91419343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
91429344 //float[] light0 = { 0,0,0 };
91439345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9555,7 +9757,7 @@
95559757
95569758 if (renderCamera != lightCamera)
95579759 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9558
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95599761
95609762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95619763
....@@ -9571,7 +9773,7 @@
95719773
95729774 if (renderCamera != lightCamera)
95739775 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9574
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95759777
95769778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95779779
....@@ -9617,10 +9819,12 @@
96179819 rati = 1 / rati;
96189820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96199821 }
9620
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
96219825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96229826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9623
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
96249828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96259829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96269830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10657,7 +10861,7 @@
1065710861
1065810862 if (wait)
1065910863 {
10660
- Sleep(500);
10864
+ Sleep(200); // blocks everything
1066110865
1066210866 wait = false;
1066310867 }
....@@ -10772,7 +10976,7 @@
1077210976 // if (parentcam != renderCamera) // not a light
1077310977 if (cam != lightCamera)
1077410978 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10775
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10979
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1077610980
1077710981 for (int j = 0; j < 4; j++)
1077810982 {
....@@ -10787,7 +10991,7 @@
1078710991 // if (parentcam != renderCamera) // not a light
1078810992 if (cam != lightCamera)
1078910993 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10790
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10994
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1079110995
1079210996 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1079310997
....@@ -10873,13 +11077,43 @@
1087311077 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1087411078 }
1087511079
10876
- if (newenvy > -1)
11080
+// if (newenvy > -1)
11081
+// {
11082
+// LoadEnvy(newenvy);
11083
+// }
11084
+//
11085
+// newenvy = -1;
11086
+
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1087711088 {
10878
- LoadEnvy(newenvy);
11089
+ if (cubemaprgb == null)
11090
+ {
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11092
+ }
11093
+
11094
+ cubemap = cubemaprgb;
1087911095 }
10880
-
10881
- newenvy = -1;
10882
-
11096
+ else
11097
+ {
11098
+ if (object.skyboxname != null)
11099
+ {
11100
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11101
+ {
11102
+ if (cubemap != null && cubemap != cubemaprgb)
11103
+ cubemap.dispose();
11104
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11105
+ loadedskyboxname = object.skyboxname;
11106
+ }
11107
+ }
11108
+ else
11109
+ {
11110
+ cubemapcustom = null;
11111
+ loadedskyboxname = null;
11112
+ }
11113
+
11114
+ cubemap = cubemapcustom;
11115
+ }
11116
+
1088311117 ratio = ((double) getWidth()) / getHeight();
1088411118 //System.out.println("ratio = " + ratio);
1088511119
....@@ -10895,7 +11129,7 @@
1089511129
1089611130 if (!IsFrozen() && !ambientOcclusion)
1089711131 {
10898
- DrawSkyBox(gl);
11132
+ DrawSkyBox(gl, (float)ratio);
1089911133 }
1090011134
1090111135 //if (selection_view == -1)
....@@ -11049,7 +11283,7 @@
1104911283
1105011284 try
1105111285 {
11052
- BindTexture(null, NOISE_TEXTURE, false, 2);
11286
+ BindTexture(NOISE_TEXTURE, false, 2);
1105311287 }
1105411288 catch (Exception e)
1105511289 {
....@@ -11181,7 +11415,7 @@
1118111415
1118211416 // if (cam != lightCamera)
1118311417 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11184
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11418
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1118511419 }
1118611420
1118711421 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11340,7 +11574,7 @@
1134011574 }
1134111575 }
1134211576
11343
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11577
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1134411578 {
1134511579 //gl.glDepthFunc(GL.GL_LEQUAL);
1134611580 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11348,24 +11582,21 @@
1134811582
1134911583 boolean texon = textureon;
1135011584
11351
- if (RENDERPROGRAM > 0)
11352
- {
11353
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11354
- textureon = false;
11355
- }
11585
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11586
+ textureon = false;
11587
+
1135611588 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1135711589 //System.out.println("ALLO");
1135811590 gl.glColorMask(false, false, false, false);
1135911591 DrawObject(gl);
11360
- if (RENDERPROGRAM > 0)
11361
- {
11362
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11363
- textureon = texon;
11364
- }
11592
+
11593
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11594
+ textureon = texon;
11595
+
1136511596 gl.glColorMask(true, true, true, true);
1136611597
1136711598 gl.glDepthFunc(GL.GL_EQUAL);
11368
- //gl.glDepthMask(false);
11599
+ gl.glDepthMask(false);
1136911600 }
1137011601
1137111602 if (false) // DrawMode() == SHADOW)
....@@ -11705,20 +11936,32 @@
1170511936 ReleaseTextures(DEFAULT_TEXTURES);
1170611937
1170711938 if (CLEANCACHE)
11708
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11939
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1170911940 {
11710
- String tex = e.nextElement();
11941
+ cTexture tex = e.nextElement();
1171111942
1171211943 // System.out.println("Texture --------- " + tex);
1171311944
11714
- if (tex.equals("WHITE_NOISE"))
11945
+ if (tex.equals("WHITE_NOISE:"))
1171511946 continue;
1171611947
1171711948 if (!usedtextures.contains(tex))
1171811949 {
11950
+ CacheTexture gettex = texturepigment.get(tex);
1171911951 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11720
- textures.get(tex).texture.dispose();
11721
- textures.remove(tex);
11952
+ if (gettex != null)
11953
+ {
11954
+ gettex.texture.dispose();
11955
+ texturepigment.remove(tex);
11956
+ }
11957
+
11958
+ gettex = texturebump.get(tex);
11959
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11960
+ if (gettex != null)
11961
+ {
11962
+ gettex.texture.dispose();
11963
+ texturebump.remove(tex);
11964
+ }
1172211965 }
1172311966 }
1172411967 }
....@@ -12246,8 +12489,76 @@
1224612489
1224712490 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1224812491
12249
- String program =
12492
+ String programmin =
12493
+ // Min shader
1225012494 "!!ARBfp1.0\n" +
12495
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12496
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12497
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12498
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12499
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12500
+ "PARAM light2cam0 = program.env[10];" +
12501
+ "PARAM light2cam1 = program.env[11];" +
12502
+ "PARAM light2cam2 = program.env[12];" +
12503
+ "TEMP temp;" +
12504
+ "TEMP light;" +
12505
+ "TEMP ndotl;" +
12506
+ "TEMP normal;" +
12507
+ "TEMP depth;" +
12508
+ "TEMP eye;" +
12509
+ "TEMP pos;" +
12510
+
12511
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12512
+ Normalize("normal") +
12513
+ "MOV light, state.light[0].position;" +
12514
+ "DP3 ndotl.x, light, normal;" +
12515
+
12516
+ // shadow
12517
+ "MOV pos, fragment.texcoord[1];" +
12518
+ "MOV temp, pos;" +
12519
+ ShadowTextureFetch("depth", "temp", "1") +
12520
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12521
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12522
+
12523
+ // No shadow when out of frustum
12524
+ //"SGE temp.y, depth.z, zero123.y;" +
12525
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12526
+
12527
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12528
+
12529
+ // Backlit
12530
+ "MOV pos.w, zero123.y;" +
12531
+ "DP4 eye.x, pos, light2cam0;" +
12532
+ "DP4 eye.y, pos, light2cam1;" +
12533
+ "DP4 eye.z, pos, light2cam2;" +
12534
+ Normalize("eye") +
12535
+
12536
+ "DP3 ndotl.y, -eye, normal;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12538
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12539
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12540
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12541
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12542
+
12543
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12544
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12545
+
12546
+ // Pigment
12547
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12548
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12549
+ "MUL temp, temp, ndotl.x;" +
12550
+
12551
+ "MUL temp, temp, zero123.z;" +
12552
+
12553
+ //"MUL temp, temp, ndotl.y;" +
12554
+
12555
+ "MOV temp.w, zero123.y;" + // reset alpha
12556
+ "MOV result.color, temp;" +
12557
+ "END";
12558
+
12559
+ String programmax =
12560
+ "!!ARBfp1.0\n" +
12561
+
1225112562 //"OPTION ARB_fragment_program_shadow;" +
1225212563 "PARAM light2cam0 = program.env[10];" +
1225312564 "PARAM light2cam1 = program.env[11];" +
....@@ -12362,8 +12673,7 @@
1236212673 "TEMP shininess;" +
1236312674 "\n" +
1236412675 "MOV texSamp, one;" +
12365
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12366
-
12676
+
1236712677 "MOV mapgrid.x, one2048th.x;" +
1236812678 "MOV temp, fragment.texcoord[1];" +
1236912679 /*
....@@ -12384,20 +12694,20 @@
1238412694 "MUL temp, floor, mapgrid.x;" +
1238512695 //"TEX depth0, temp, texture[1], 2D;" +
1238612696 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12387
- TextureFetch("depth0", "temp", "1") +
12697
+ ShadowTextureFetch("depth0", "temp", "1") +
1238812698 "") +
1238912699 "ADD temp.x, temp.x, mapgrid.x;" +
1239012700 //"TEX depth1, temp, texture[1], 2D;" +
1239112701 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12392
- TextureFetch("depth1", "temp", "1") +
12702
+ ShadowTextureFetch("depth1", "temp", "1") +
1239312703 "") +
1239412704 "ADD temp.y, temp.y, mapgrid.x;" +
1239512705 //"TEX depth2, temp, texture[1], 2D;" +
12396
- TextureFetch("depth2", "temp", "1") +
12706
+ ShadowTextureFetch("depth2", "temp", "1") +
1239712707 "SUB temp.x, temp.x, mapgrid.x;" +
1239812708 //"TEX depth3, temp, texture[1], 2D;" +
1239912709 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12400
- TextureFetch("depth3", "temp", "1") +
12710
+ ShadowTextureFetch("depth3", "temp", "1") +
1240112711 "") +
1240212712 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1240312713 //"MOV params, material;" +
....@@ -12768,10 +13078,10 @@
1276813078 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1276913079 "") +
1277013080
12771
- // display shadow only (bump == 0)
13081
+ // display shadow only (fakedepth == 0)
1277213082 "SUB temp.x, half.x, shadow.x;" +
1277313083 "MOV temp.y, -params5.z;" + // params6.x;" +
12774
- "SLT temp.z, temp.y, -one2048th.x;" +
13084
+ "SLT temp.z, temp.y, -c256i.x;" +
1277513085 "SUB temp.y, one.x, temp.z;" +
1277613086 "MUL temp.x, temp.x, temp.y;" +
1277713087 "KIL temp.x;" +
....@@ -13102,8 +13412,19 @@
1310213412 //once = true;
1310313413 }
1310413414
13105
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13106
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13415
+ String program = programmax;
13416
+
13417
+ if (Globals.MINSHADER)
13418
+ {
13419
+ program = programmin;
13420
+ }
13421
+
13422
+ if (Globals.DEBUG)
13423
+ {
13424
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13425
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13426
+ }
13427
+
1310713428 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1310813429
1310913430 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13150,7 +13471,8 @@
1315013471 "\n" +
1315113472 "END\n";
1315213473
13153
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13474
+ if (Globals.DEBUG)
13475
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1315413476 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1315513477
1315613478 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13195,25 +13517,26 @@
1319513517 return out;
1319613518 }
1319713519
13198
- String TextureFetch(String dest, String src, String unit)
13520
+ // Also does frustum culling
13521
+ String ShadowTextureFetch(String dest, String src, String unit)
1319913522 {
1320013523 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1320113524 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1320213525 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13526
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13527
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1320313528 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13204
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13205
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13206
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13207
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13529
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13530
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1320813531 //"SWZ buffer, temp, w,w,w,w;";
13209
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13532
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1321013533 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1321113534 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1321213535 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13213
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13536
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321413537
13215
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13216
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13538
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13539
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1321713540 }
1321813541
1321913542 String Shadow(String depth, String shadow)
....@@ -13260,7 +13583,7 @@
1326013583 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1326113584 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326213585
13263
- // No shadow when out of frustrum
13586
+ // No shadow when out of frustum
1326413587 "SGE temp.x, " + depth + ".z, one.z;" +
1326513588 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1326613589 "";
....@@ -14058,14 +14381,15 @@
1405814381 drag = false;
1405914382 //System.out.println("Mouse DOWN");
1406014383 editObj = false;
14061
- ClickInfo info = new ClickInfo();
14062
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14063
- info.pane = this;
14064
- info.camera = renderCamera;
14065
- info.x = x;
14066
- info.y = y;
14067
- info.modifiers = modifiersex;
14068
- editObj = object.doEditClick(info, 0);
14384
+ //ClickInfo info = new ClickInfo();
14385
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14386
+ object.clickInfo.pane = this;
14387
+ object.clickInfo.camera = renderCamera;
14388
+ object.clickInfo.x = x;
14389
+ object.clickInfo.y = y;
14390
+ object.clickInfo.modifiers = modifiersex;
14391
+ editObj = object.doEditClick(//info,
14392
+ 0);
1406914393 if (!editObj)
1407014394 {
1407114395 hasMarquee = true;
....@@ -14347,11 +14671,17 @@
1434714671 void GoDown(int mod)
1434814672 {
1434914673 MODIFIERS |= COMMAND;
14674
+ boolean isVR = (mouseMode&VR)!=0;
1435014675 /**/
1435114676 if((mod&SHIFT) == SHIFT)
14352
- manipCamera.RotatePosition(0, -speed);
14677
+ {
14678
+ if (isVR)
14679
+ manipCamera.RotateInterest(0, -speed);
14680
+ else
14681
+ manipCamera.RotatePosition(0, -speed);
14682
+ }
1435314683 else
14354
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14684
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1435514685 /**/
1435614686 if ((mod & SHIFT) == SHIFT)
1435714687 {
....@@ -14361,6 +14691,8 @@
1436114691 mouseMode |= BACKFORTH;
1436214692 }
1436314693
14694
+ targetLookAt.set(manipCamera.lookAt);
14695
+
1436414696 //prevX = X = anchorX;
1436514697 prevY = Y = anchorY - (int) (renderCamera.Distance());
1436614698 }
....@@ -14369,10 +14701,17 @@
1436914701 {
1437014702 MODIFIERS |= COMMAND;
1437114703 /**/
14704
+ boolean isVR = (mouseMode&VR)!=0;
14705
+
1437214706 if((mod&SHIFT) == SHIFT)
14373
- manipCamera.RotatePosition(0, speed);
14707
+ {
14708
+ if (isVR)
14709
+ manipCamera.RotateInterest(0, speed);
14710
+ else
14711
+ manipCamera.RotatePosition(0, speed);
14712
+ }
1437414713 else
14375
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14714
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1437614715 /**/
1437714716 if ((mod & SHIFT) == SHIFT)
1437814717 {
....@@ -14382,6 +14721,8 @@
1438214721 mouseMode |= BACKFORTH;
1438314722 }
1438414723
14724
+ targetLookAt.set(manipCamera.lookAt);
14725
+
1438514726 //prevX = X = anchorX;
1438614727 prevY = Y = anchorY + (int) (renderCamera.Distance());
1438714728 }
....@@ -14391,9 +14732,14 @@
1439114732 MODIFIERS |= COMMAND;
1439214733 /**/
1439314734 if((mod&SHIFT) == SHIFT)
14394
- manipCamera.Translate(speed*delta, 0, getWidth());
14735
+ manipCamera.Translate(speed*delta, 0, getWidth());
1439514736 else
14396
- manipCamera.RotatePosition(speed, 0);
14737
+ {
14738
+ if ((mouseMode&VR)!=0)
14739
+ manipCamera.RotateInterest(-speed, 0);
14740
+ else
14741
+ manipCamera.RotatePosition(speed, 0);
14742
+ }
1439714743 /**/
1439814744 if ((mod & SHIFT) == SHIFT)
1439914745 {
....@@ -14403,6 +14749,8 @@
1440314749 mouseMode |= ROTATE;
1440414750 } // TRANSLATE;
1440514751
14752
+ targetLookAt.set(manipCamera.lookAt);
14753
+
1440614754 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1440714755 prevY = Y = anchorY;
1440814756 }
....@@ -14412,9 +14760,15 @@
1441214760 MODIFIERS |= COMMAND;
1441314761 /**/
1441414762 if((mod&SHIFT) == SHIFT)
14415
- manipCamera.Translate(-speed*delta, 0, getWidth());
14763
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1441614764 else
14417
- manipCamera.RotatePosition(-speed, 0);
14765
+ {
14766
+ if ((mouseMode&VR)!=0)
14767
+ manipCamera.RotateInterest(speed, 0);
14768
+ else
14769
+ manipCamera.RotatePosition(-speed, 0);
14770
+ }
14771
+
1441814772 /**/
1441914773 if ((mod & SHIFT) == SHIFT)
1442014774 {
....@@ -14424,6 +14778,8 @@
1442414778 mouseMode |= ROTATE;
1442514779 } // TRANSLATE;
1442614780
14781
+ targetLookAt.set(manipCamera.lookAt);
14782
+
1442714783 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1442814784 prevY = Y = anchorY;
1442914785 }
....@@ -14465,15 +14821,16 @@
1446514821 if (editObj)
1446614822 {
1446714823 drag = true;
14468
- ClickInfo info = new ClickInfo();
14469
- info.bounds.setBounds(0, 0,
14824
+ //ClickInfo info = new ClickInfo();
14825
+ object.clickInfo.bounds.setBounds(0, 0,
1447014826 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14471
- info.pane = this;
14472
- info.camera = renderCamera;
14473
- info.x = x;
14474
- info.y = y;
14475
- object.GetWindow().copy
14476
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14827
+ object.clickInfo.pane = this;
14828
+ object.clickInfo.camera = renderCamera;
14829
+ object.clickInfo.x = x;
14830
+ object.clickInfo.y = y;
14831
+ object //.GetWindow().copy
14832
+ .doEditDrag(//info,
14833
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1447714834 } else
1447814835 {
1447914836 if (x < startX)
....@@ -14622,24 +14979,27 @@
1462214979 }
1462314980 }
1462414981
14982
+// ClickInfo clickInfo = new ClickInfo();
14983
+
1462514984 public void mouseMoved(MouseEvent e)
1462614985 {
1462714986 //System.out.println("mouseMoved: " + e);
1462814987 if (isRenderer)
1462914988 return;
1463014989
14631
- ClickInfo ci = new ClickInfo();
14632
- ci.x = e.getX();
14633
- ci.y = e.getY();
14634
- ci.modifiers = e.getModifiersEx();
14635
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14636
- ci.pane = this;
14637
- ci.camera = renderCamera;
14990
+ // Mouse cursor feedback
14991
+ object.clickInfo.x = e.getX();
14992
+ object.clickInfo.y = e.getY();
14993
+ object.clickInfo.modifiers = e.getModifiersEx();
14994
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14995
+ object.clickInfo.pane = this;
14996
+ object.clickInfo.camera = renderCamera;
1463814997 if (!isRenderer)
1463914998 {
1464014999 //ObjEditor editWindow = object.editWindow;
1464115000 //Object3D copy = editWindow.copy;
14642
- if (object.doEditClick(ci, 0))
15001
+ if (object.doEditClick(//clickInfo,
15002
+ 0))
1464315003 {
1464415004 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1464515005 } else
....@@ -14911,7 +15271,8 @@
1491115271 // break;
1491215272 case 'T':
1491315273 CACHETEXTURE ^= true;
14914
- textures.clear();
15274
+ texturepigment.clear();
15275
+ texturebump.clear();
1491515276 // repaint();
1491615277 break;
1491715278 case 'Y':
....@@ -15088,20 +15449,24 @@
1508815449 OCCLUSION_CULLING ^= true;
1508915450 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1509015451 break;
15091
- case '0': envyoff ^= true; repaint(); break;
15452
+ //case '0': envyoff ^= true; repaint(); break;
1509215453 case '1':
1509315454 case '2':
1509415455 case '3':
1509515456 case '4':
1509615457 case '5':
15097
- newenvy = Character.getNumericValue(key);
15098
- repaint();
15099
- break;
1510015458 case '6':
1510115459 case '7':
1510215460 case '8':
1510315461 case '9':
15104
- BGcolor = (key - '6')/3.f;
15462
+ if (true) // envyoff)
15463
+ {
15464
+ BGcolor = (key - '1')/8.f;
15465
+ }
15466
+ else
15467
+ {
15468
+ //newenvy = Character.getNumericValue(key);
15469
+ }
1510515470 repaint();
1510615471 break;
1510715472 case '!':
....@@ -15664,8 +16029,6 @@
1566416029
1566516030 int width = getBounds().width;
1566616031 int height = getBounds().height;
15667
- ClickInfo info = new ClickInfo();
15668
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1566916032 //Image img = CreateImage(width, height);
1567016033 //System.out.println("width = " + width + "; height = " + height + "\n");
1567116034
....@@ -15742,31 +16105,37 @@
1574216105 }
1574316106 if (object != null && !hasMarquee)
1574416107 {
16108
+ if (object.clickInfo == null)
16109
+ object.clickInfo = new ClickInfo();
16110
+ ClickInfo info = object.clickInfo;
16111
+ //ClickInfo info = new ClickInfo();
16112
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16113
+
1574516114 if (isRenderer)
1574616115 {
15747
- info.flags++;
16116
+ object.clickInfo.flags++;
1574816117 double frameAspect = (double) width / (double) height;
1574916118 if (frameAspect > renderCamera.aspect)
1575016119 {
1575116120 int desired = (int) ((double) height * renderCamera.aspect);
15752
- info.bounds.width -= width - desired;
15753
- info.bounds.x += (width - desired) / 2;
16121
+ object.clickInfo.bounds.width -= width - desired;
16122
+ object.clickInfo.bounds.x += (width - desired) / 2;
1575416123 } else
1575516124 {
1575616125 int desired = (int) ((double) width / renderCamera.aspect);
15757
- info.bounds.height -= height - desired;
15758
- info.bounds.y += (height - desired) / 2;
16126
+ object.clickInfo.bounds.height -= height - desired;
16127
+ object.clickInfo.bounds.y += (height - desired) / 2;
1575916128 }
1576016129 }
1576116130
15762
- info.g = gr;
15763
- info.camera = renderCamera;
16131
+ object.clickInfo.g = gr;
16132
+ object.clickInfo.camera = renderCamera;
1576416133 /*
1576516134 // Memory intensive (brep.verticescopy)
1576616135 if (!(object instanceof Composite))
1576716136 object.draw(info, 0, false); // SLOW :
1576816137 */
15769
- if (!isRenderer)
16138
+ if (!isRenderer) // && drag)
1577016139 {
1577116140 Grafreed.Assert(object != null);
1577216141 Grafreed.Assert(object.selection != null);
....@@ -15774,9 +16143,9 @@
1577416143 {
1577516144 int hitSomething = object.selection.get(0).hitSomething;
1577616145
15777
- info.DX = 0;
15778
- info.DY = 0;
15779
- info.W = 1;
16146
+ object.clickInfo.DX = 0;
16147
+ object.clickInfo.DY = 0;
16148
+ object.clickInfo.W = 1;
1578016149 if (hitSomething == Object3D.hitCenter)
1578116150 {
1578216151 info.DX = X;
....@@ -15788,13 +16157,14 @@
1578816157 info.DY -= info.bounds.height/2;
1578916158 }
1579016159
15791
- object.drawEditHandles(info, 0);
16160
+ object.drawEditHandles(//info,
16161
+ 0);
1579216162
1579316163 if (drag && (X != 0 || Y != 0))
1579416164 {
1579516165 switch (hitSomething)
1579616166 {
15797
- case Object3D.hitCenter: gr.setColor(Color.pink);
16167
+ case Object3D.hitCenter: gr.setColor(Color.white);
1579816168 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1579916169 break;
1580016170 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -15820,7 +16190,7 @@
1582016190 if (hasMarquee)
1582116191 {
1582216192 gr.setXORMode(Color.white);
15823
- gr.setColor(Color.red);
16193
+ gr.setColor(Color.white);
1582416194 if (!firstime)
1582516195 {
1582616196 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16287,6 +16657,8 @@
1628716657 private /*static*/ boolean firstime;
1628816658 private /*static*/ cVector newView = new cVector();
1628916659 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16660
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16661
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1629016662 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1629116663 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1629216664 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16299,29 +16671,67 @@
1629916671 {
1630016672 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1630116673
16674
+ int usedsuf = 0;
16675
+
1630216676 for (int i = 0; i < suffixes.length; i++)
1630316677 {
16304
- String resourceName = basename + suffixes[i] + "." + suffix;
16305
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16306
- mipmapped,
16307
- FileUtil.getFileSuffix(resourceName));
16308
- if (data == null)
16678
+ String[] suffixe = suffixes;
16679
+ String[] fallback = suffixes2;
16680
+ String[] fallfallback = suffixes3;
16681
+
16682
+ for (int c=usedsuf; --c>=0;)
1630916683 {
16310
- throw new IOException("Unable to load texture " + resourceName);
16684
+// String[] temp = suffixe;
16685
+// suffixe = fallback;
16686
+// fallback = fallfallback;
16687
+// fallfallback = temp;
1631116688 }
16689
+
16690
+ String resourceName = basename + suffixe[i] + "." + suffix;
16691
+ TextureData data;
16692
+
16693
+ try
16694
+ {
16695
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16696
+ mipmapped,
16697
+ FileUtil.getFileSuffix(resourceName));
16698
+ }
16699
+ catch (Exception e)
16700
+ {
16701
+ try
16702
+ {
16703
+ resourceName = basename + fallback[i] + "." + suffix;
16704
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16705
+ mipmapped,
16706
+ FileUtil.getFileSuffix(resourceName));
16707
+ }
16708
+ catch (Exception e2)
16709
+ {
16710
+ resourceName = basename + fallfallback[i] + "." + suffix;
16711
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16712
+ mipmapped,
16713
+ FileUtil.getFileSuffix(resourceName));
16714
+ }
16715
+ }
16716
+
1631216717 //System.out.println("Target = " + targets[i]);
1631316718 cubemap.updateImage(data, targets[i]);
1631416719 }
1631516720
1631616721 return cubemap;
1631716722 }
16723
+
1631816724 int bigsphere = -1;
1631916725
1632016726 float BGcolor = 0.5f;
1632116727
16322
- private void DrawSkyBox(GL gl)
16728
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16729
+
16730
+ private void DrawSkyBox(GL gl, float ratio)
1632316731 {
16324
- if (envyoff || cubemap == null)
16732
+ if (//envyoff ||
16733
+ WIREFRAME ||
16734
+ cubemap == null)
1632516735 {
1632616736 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1632716737 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16336,7 +16746,17 @@
1633616746 // Compensates for ExaminerViewer's modification of modelview matrix
1633716747 gl.glMatrixMode(GL.GL_MODELVIEW);
1633816748 gl.glLoadIdentity();
16749
+ gl.glScalef(1,ratio,1);
1633916750
16751
+// colorV[0] = 2;
16752
+// colorV[1] = 2;
16753
+// colorV[2] = 2;
16754
+// colorV[3] = 1;
16755
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16756
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16757
+//
16758
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16759
+
1634016760 //gl.glActiveTexture(GL.GL_TEXTURE1);
1634116761 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1634216762
....@@ -16368,6 +16788,7 @@
1636816788 {
1636916789 gl.glScalef(1.0f, -1.0f, 1.0f);
1637016790 }
16791
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1637116792 gl.glMultMatrixd(viewrot_1, 0);
1637216793 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1637316794 //viewer.updateInverseRotation(gl);
....@@ -16408,7 +16829,8 @@
1640816829 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1640916830
1641016831 cubemap.disable();
16411
- ////cubemap.unbind();
16832
+ //cubemap.dispose();
16833
+
1641216834 if (CULLFACE)
1641316835 {
1641416836 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16626,7 +17048,7 @@
1662617048 //new Exception().printStackTrace();
1662717049 System.out.println("select buffer init");
1662817050 // Use debug pipeline
16629
- drawable.setGL(new DebugGL(drawable.getGL()));
17051
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1663017052
1663117053 GL gl = drawable.getGL();
1663217054
....@@ -16944,6 +17366,7 @@
1694417366
1694517367 public void init(GLAutoDrawable drawable)
1694617368 {
17369
+ if (Globals.DEBUG)
1694717370 System.out.println("shadow buffer init");
1694817371
1694917372 GL gl = drawable.getGL();
....@@ -17172,10 +17595,14 @@
1717217595 gl.glFlush();
1717317596
1717417597 /**/
17175
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17598
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1717617599
17177
- float[] pixels = occlusionsizebuffer.array();
17600
+ float[] depths = occlusiondepthbuffer.array();
1717817601
17602
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17603
+
17604
+ int[] pixels = selectsizebuffer.array();
17605
+
1717917606 double r = 0, g = 0, b = 0;
1718017607
1718117608 double count = 0;
....@@ -17186,7 +17613,7 @@
1718617613
1718717614 double FACTOR = 1;
1718817615
17189
- for (int i = 0; i < pixels.length; i++)
17616
+ for (int i = 0; i < depths.length; i++)
1719017617 {
1719117618 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1719217619 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17269,7 +17696,7 @@
1726917696
1727017697 double scale = ray.z; // 1; // cos
1727117698
17272
- float depth = pixels[newindex];
17699
+ float depth = depths[newindex];
1727317700
1727417701 /*
1727517702 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17466,11 +17893,14 @@
1746617893 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1746717894 static IntBuffer bigAAbuffer;
1746817895 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17469
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17896
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1747017897 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1747117898 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1747217899 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17473
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17900
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17901
+
17902
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17903
+
1747417904 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1747517905 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1747617906 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();