.. | .. |
---|
18 | 18 | import javax.imageio.ImageIO; |
---|
19 | 19 | import javax.imageio.ImageWriteParam; |
---|
20 | 20 | import javax.imageio.ImageWriter; |
---|
| 21 | +import javax.imageio.ImageReadParam; |
---|
| 22 | +import javax.imageio.ImageReader; |
---|
21 | 23 | import javax.imageio.plugins.jpeg.JPEGImageWriteParam; |
---|
| 24 | +import javax.imageio.stream.ImageInputStream; |
---|
22 | 25 | import javax.imageio.stream.ImageOutputStream; |
---|
23 | 26 | import javax.imageio.ImageWriteParam; |
---|
24 | 27 | |
---|
.. | .. |
---|
30 | 33 | import java.nio.*; |
---|
31 | 34 | |
---|
32 | 35 | import gleem.linalg.Mat4f; |
---|
| 36 | +import javax.imageio.ImageTypeSpecifier; |
---|
33 | 37 | |
---|
34 | 38 | class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener |
---|
35 | 39 | { |
---|
.. | .. |
---|
44 | 48 | static boolean ABORTED = false; |
---|
45 | 49 | |
---|
46 | 50 | 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 | + } |
---|
47 | 84 | |
---|
48 | 85 | /*static*/ private boolean CULLFACE = false; // true; |
---|
49 | 86 | /*static*/ boolean NEAREST = false; // true; |
---|
.. | .. |
---|
60 | 97 | //boolean REDUCETEXTURE = true; |
---|
61 | 98 | boolean CACHETEXTURE = true; |
---|
62 | 99 | boolean CLEANCACHE = false; // true; |
---|
63 | | - boolean MIPMAP = true; // false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
64 | 101 | boolean COMPRESSTEXTURE = false; |
---|
65 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
66 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
2405 | 2442 | return currentGL; |
---|
2406 | 2443 | } |
---|
2407 | 2444 | |
---|
| 2445 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2446 | + { |
---|
| 2447 | + Grafreed.Assert(texturedata != null); |
---|
| 2448 | + |
---|
| 2449 | + int width = texturedata.getWidth(); |
---|
| 2450 | + int height = texturedata.getHeight(); |
---|
| 2451 | + |
---|
| 2452 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2453 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2454 | + |
---|
| 2455 | + byte[] bytes = bytebuf.array(); |
---|
| 2456 | + |
---|
| 2457 | + return CreateBim(bytes, width, height); |
---|
| 2458 | + } |
---|
| 2459 | + |
---|
2408 | 2460 | /**/ |
---|
2409 | 2461 | class CacheTexture |
---|
2410 | 2462 | { |
---|
.. | .. |
---|
2413 | 2465 | |
---|
2414 | 2466 | int resolution; |
---|
2415 | 2467 | |
---|
2416 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2468 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2417 | 2469 | { |
---|
2418 | | - texture = tex; |
---|
| 2470 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2471 | + texturedata = texdata; |
---|
2419 | 2472 | resolution = res; |
---|
2420 | 2473 | } |
---|
2421 | 2474 | } |
---|
2422 | 2475 | /**/ |
---|
2423 | 2476 | |
---|
2424 | 2477 | // 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>(); |
---|
| 2478 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2479 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2480 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2481 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
2428 | 2482 | |
---|
2429 | 2483 | int pigmentdepth = 0; |
---|
2430 | 2484 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
.. | .. |
---|
2432 | 2486 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2433 | 2487 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2434 | 2488 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2435 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2489 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2436 | 2490 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2437 | 2491 | |
---|
2438 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2492 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2439 | 2493 | { |
---|
2440 | 2494 | TextureData texturedata = null; |
---|
2441 | 2495 | |
---|
.. | .. |
---|
2454 | 2508 | if (bump) |
---|
2455 | 2509 | texturedata = ConvertBump(texturedata, false); |
---|
2456 | 2510 | |
---|
2457 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2458 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2511 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2512 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2459 | 2513 | |
---|
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); |
---|
| 2514 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2515 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2462 | 2516 | |
---|
2463 | | - return texture; |
---|
| 2517 | + return texturedata; |
---|
2464 | 2518 | } |
---|
2465 | 2519 | |
---|
2466 | | - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2520 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
2467 | 2521 | { |
---|
2468 | 2522 | TextureData texturedata = null; |
---|
2469 | 2523 | |
---|
.. | .. |
---|
2471 | 2525 | { |
---|
2472 | 2526 | texturedata = |
---|
2473 | 2527 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2474 | | - name, |
---|
| 2528 | + bim, |
---|
2475 | 2529 | true); |
---|
2476 | 2530 | } catch (Exception e) |
---|
2477 | 2531 | { |
---|
.. | .. |
---|
2480 | 2534 | |
---|
2481 | 2535 | if (bump) |
---|
2482 | 2536 | 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; |
---|
| 2537 | + |
---|
| 2538 | + return texturedata; |
---|
2491 | 2539 | } |
---|
2492 | 2540 | |
---|
2493 | 2541 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
7975 | 8023 | pigment = null; |
---|
7976 | 8024 | } |
---|
7977 | 8025 | |
---|
7978 | | - ReleaseTexture(bump, true); |
---|
7979 | | - ReleaseTexture(pigment, false); |
---|
| 8026 | + ReleaseTexture(tex, true); |
---|
| 8027 | + ReleaseTexture(tex, false); |
---|
7980 | 8028 | } |
---|
7981 | 8029 | |
---|
7982 | 8030 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8005 | 8053 | pigment = null; |
---|
8006 | 8054 | } |
---|
8007 | 8055 | |
---|
8008 | | - ReleaseTexture(pigment, false); |
---|
| 8056 | + ReleaseTexture(tex, false); |
---|
8009 | 8057 | } |
---|
8010 | 8058 | |
---|
8011 | 8059 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8034 | 8082 | bump = null; |
---|
8035 | 8083 | } |
---|
8036 | 8084 | |
---|
8037 | | - ReleaseTexture(bump, true); |
---|
| 8085 | + ReleaseTexture(tex, true); |
---|
8038 | 8086 | } |
---|
8039 | 8087 | |
---|
8040 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8088 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8041 | 8089 | { |
---|
8042 | 8090 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8043 | 8091 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8048 | 8096 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8049 | 8097 | |
---|
8050 | 8098 | if (tex != null) |
---|
8051 | | - texture = textures.get(tex); |
---|
| 8099 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8052 | 8100 | |
---|
8053 | 8101 | // //assert( texture != null ); |
---|
8054 | 8102 | // if (texture == null) |
---|
.. | .. |
---|
8198 | 8246 | |
---|
8199 | 8247 | if (tex == null) |
---|
8200 | 8248 | { |
---|
8201 | | - BindTexture(null, null,false,resolution); |
---|
| 8249 | + BindTexture(null,false,resolution); |
---|
8202 | 8250 | return; |
---|
8203 | 8251 | } |
---|
8204 | 8252 | |
---|
8205 | 8253 | String pigment = Object3D.GetPigment(tex); |
---|
8206 | 8254 | |
---|
8207 | | - usedtextures.add(pigment); |
---|
| 8255 | + usedtextures.add(tex); |
---|
8208 | 8256 | |
---|
8209 | 8257 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8210 | 8258 | { |
---|
.. | .. |
---|
8218 | 8266 | } |
---|
8219 | 8267 | |
---|
8220 | 8268 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8221 | | - BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
| 8269 | + BindTexture(tex, false, resolution); |
---|
8222 | 8270 | } |
---|
8223 | 8271 | |
---|
8224 | 8272 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8231 | 8279 | |
---|
8232 | 8280 | if (tex == null) |
---|
8233 | 8281 | { |
---|
8234 | | - BindTexture(null, null,true,resolution); |
---|
| 8282 | + BindTexture(null,true,resolution); |
---|
8235 | 8283 | return; |
---|
8236 | 8284 | } |
---|
8237 | 8285 | |
---|
8238 | 8286 | String bump = Object3D.GetBump(tex); |
---|
8239 | 8287 | |
---|
8240 | | - usedtextures.add(bump); |
---|
| 8288 | + usedtextures.add(tex); |
---|
8241 | 8289 | |
---|
8242 | 8290 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8243 | 8291 | { |
---|
.. | .. |
---|
8251 | 8299 | } |
---|
8252 | 8300 | |
---|
8253 | 8301 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8254 | | - BindTexture(tex.bumptexture, bump, true, resolution); |
---|
| 8302 | + BindTexture(tex, true, resolution); |
---|
8255 | 8303 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8256 | 8304 | } |
---|
8257 | 8305 | |
---|
.. | .. |
---|
8275 | 8323 | return fileExists; |
---|
8276 | 8324 | } |
---|
8277 | 8325 | |
---|
8278 | | - CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception |
---|
| 8326 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8279 | 8327 | { |
---|
8280 | 8328 | CacheTexture texturecache = null; |
---|
8281 | 8329 | |
---|
8282 | 8330 | if (tex != null) |
---|
8283 | 8331 | { |
---|
8284 | | - String texname = tex; |
---|
| 8332 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8333 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8334 | + |
---|
| 8335 | + if (texname.equals("") && texdata == null) |
---|
| 8336 | + { |
---|
| 8337 | + return null; |
---|
| 8338 | + } |
---|
8285 | 8339 | |
---|
8286 | 8340 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8287 | 8341 | |
---|
.. | .. |
---|
8291 | 8345 | // else |
---|
8292 | 8346 | // if (!texname.startsWith("/")) |
---|
8293 | 8347 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8294 | | - if (!FileExists(tex)) |
---|
| 8348 | + if (!FileExists(texname)) |
---|
8295 | 8349 | { |
---|
8296 | 8350 | texname = fallbackTextureName; |
---|
8297 | 8351 | } |
---|
8298 | 8352 | |
---|
8299 | 8353 | if (CACHETEXTURE) |
---|
8300 | 8354 | { |
---|
8301 | | - if (bim == null) |
---|
8302 | | - texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8355 | + if (texdata == null) |
---|
| 8356 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8303 | 8357 | else |
---|
8304 | | - texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8358 | + texturecache = bimtextures.get(texdata); |
---|
8305 | 8359 | } |
---|
8306 | 8360 | |
---|
8307 | | - if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8361 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
8308 | 8362 | { |
---|
8309 | 8363 | TextureData texturedata = null; |
---|
8310 | 8364 | |
---|
8311 | | - if (bim == null) |
---|
| 8365 | + if (texdata != null && textureon) |
---|
8312 | 8366 | { |
---|
| 8367 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
8313 | 8368 | |
---|
| 8369 | + try |
---|
| 8370 | + { |
---|
| 8371 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8372 | + } |
---|
| 8373 | + catch (Exception e) |
---|
| 8374 | + { |
---|
| 8375 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8376 | + } |
---|
| 8377 | + |
---|
| 8378 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8379 | + bimtextures.put(texdata, texturecache); |
---|
| 8380 | + |
---|
| 8381 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8382 | + |
---|
| 8383 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8384 | + //bim2 = bim; |
---|
8314 | 8385 | } |
---|
8315 | 8386 | else |
---|
8316 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8387 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8317 | 8388 | { |
---|
8318 | 8389 | assert(!bump); |
---|
8319 | 8390 | // if (bump) |
---|
.. | .. |
---|
8324 | 8395 | // } |
---|
8325 | 8396 | // else |
---|
8326 | 8397 | // { |
---|
8327 | | - texturecache = textures.get(tex); |
---|
| 8398 | + // texturecache = textures.get(texname); // suspicious |
---|
8328 | 8399 | if (texturecache == null) |
---|
8329 | 8400 | { |
---|
8330 | 8401 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8331 | 8402 | } |
---|
| 8403 | + else |
---|
| 8404 | + new Exception().printStackTrace(); |
---|
8332 | 8405 | // } |
---|
8333 | 8406 | } else |
---|
8334 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8407 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8335 | 8408 | { |
---|
8336 | 8409 | assert(bump); |
---|
8337 | | - texturecache = textures.get(tex); |
---|
| 8410 | + // texturecache = textures.get(texname); // suspicious |
---|
8338 | 8411 | if (texturecache == null) |
---|
8339 | 8412 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8413 | + else |
---|
| 8414 | + new Exception().printStackTrace(); |
---|
8340 | 8415 | } else |
---|
8341 | 8416 | { |
---|
8342 | 8417 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8344 | 8419 | // texture = GetResourceTexture("default.png"); |
---|
8345 | 8420 | //} else |
---|
8346 | 8421 | //{ |
---|
8347 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8422 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8348 | 8423 | { |
---|
8349 | | - texturecache = textures.get(tex); |
---|
| 8424 | + // texturecache = textures.get(texname); // suspicious |
---|
8350 | 8425 | if (texturecache == null) |
---|
8351 | 8426 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8427 | + else |
---|
| 8428 | + new Exception().printStackTrace(); |
---|
8352 | 8429 | } else |
---|
8353 | 8430 | { |
---|
8354 | 8431 | if (textureon) |
---|
.. | .. |
---|
8407 | 8484 | if (texturedata == null) |
---|
8408 | 8485 | throw new Exception(); |
---|
8409 | 8486 | |
---|
8410 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8487 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8411 | 8488 | //texture = GetTexture(tex, bump); |
---|
8412 | 8489 | } |
---|
8413 | 8490 | } |
---|
8414 | 8491 | //} |
---|
8415 | 8492 | } |
---|
8416 | 8493 | |
---|
8417 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8494 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8418 | 8495 | { |
---|
8419 | 8496 | //return false; |
---|
8420 | 8497 | |
---|
.. | .. |
---|
8436 | 8513 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8437 | 8514 | if (!cachefile.exists()) |
---|
8438 | 8515 | { |
---|
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)) |
---|
| 8516 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8448 | 8517 | { |
---|
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); |
---|
| 8518 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8519 | + |
---|
8479 | 8520 | ImageWriter writer = null; |
---|
8480 | 8521 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8481 | 8522 | if (iter.hasNext()) { |
---|
8482 | 8523 | writer = (ImageWriter)iter.next(); |
---|
8483 | 8524 | } |
---|
8484 | | - float compressionQuality = 0.9f; |
---|
| 8525 | + |
---|
| 8526 | + float compressionQuality = 0.85f; |
---|
8485 | 8527 | try |
---|
8486 | 8528 | { |
---|
8487 | 8529 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8498 | 8540 | } |
---|
8499 | 8541 | } |
---|
8500 | 8542 | } |
---|
8501 | | - |
---|
| 8543 | + |
---|
| 8544 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8545 | + |
---|
8502 | 8546 | //System.out.println("Texture = " + tex); |
---|
8503 | | - if (textures.containsKey(texname)) |
---|
| 8547 | + if (textures.containsKey(tex)) |
---|
8504 | 8548 | { |
---|
8505 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8549 | + CacheTexture thetex = textures.get(tex); |
---|
8506 | 8550 | thetex.texture.disable(); |
---|
8507 | 8551 | thetex.texture.dispose(); |
---|
8508 | | - textures.remove(texname); |
---|
| 8552 | + textures.remove(tex); |
---|
8509 | 8553 | } |
---|
8510 | 8554 | |
---|
8511 | 8555 | //texture.texturedata = texturedata; |
---|
8512 | | - textures.put(texname, texturecache); |
---|
| 8556 | + textures.put(tex, texturecache); |
---|
8513 | 8557 | |
---|
8514 | 8558 | // newtex = true; |
---|
8515 | 8559 | } |
---|
.. | .. |
---|
8528 | 8572 | return texturecache; |
---|
8529 | 8573 | } |
---|
8530 | 8574 | |
---|
8531 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8575 | + static void EmbedTextures(cTexture tex) |
---|
8532 | 8576 | { |
---|
8533 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8577 | + if (tex.pigmentdata == null) |
---|
| 8578 | + { |
---|
| 8579 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8580 | + |
---|
| 8581 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8582 | + |
---|
| 8583 | + if (texturecache != null) |
---|
| 8584 | + { |
---|
| 8585 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8586 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8587 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8588 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8589 | + ; |
---|
| 8590 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8591 | + } |
---|
| 8592 | + } |
---|
| 8593 | + |
---|
| 8594 | + if (tex.bumpdata == null) |
---|
| 8595 | + { |
---|
| 8596 | + //String texname = Object3D.GetBump(tex); |
---|
| 8597 | + |
---|
| 8598 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8599 | + |
---|
| 8600 | + if (texturecache != null) |
---|
| 8601 | + { |
---|
| 8602 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8603 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8604 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8605 | + } |
---|
| 8606 | + } |
---|
| 8607 | + } |
---|
| 8608 | + |
---|
| 8609 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
| 8610 | + { |
---|
| 8611 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8534 | 8612 | |
---|
8535 | 8613 | if (bump) |
---|
8536 | 8614 | { |
---|
.. | .. |
---|
8546 | 8624 | return texture!=null?texture.texture:null; |
---|
8547 | 8625 | } |
---|
8548 | 8626 | |
---|
8549 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8627 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8550 | 8628 | { |
---|
8551 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8629 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8552 | 8630 | |
---|
8553 | 8631 | return texture!=null?texture.texturedata:null; |
---|
8554 | 8632 | } |
---|
8555 | 8633 | |
---|
8556 | | - boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8634 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8557 | 8635 | { |
---|
8558 | 8636 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8559 | 8637 | { |
---|
.. | .. |
---|
8562 | 8640 | |
---|
8563 | 8641 | //boolean newtex = false; |
---|
8564 | 8642 | |
---|
8565 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8643 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8566 | 8644 | |
---|
8567 | 8645 | if (texture == null) |
---|
8568 | 8646 | return false; |
---|
.. | .. |
---|
8595 | 8673 | return true; // Warning: not used. |
---|
8596 | 8674 | } |
---|
8597 | 8675 | |
---|
| 8676 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8677 | + { |
---|
| 8678 | + try |
---|
| 8679 | + { |
---|
| 8680 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8681 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8682 | + ImageWriter writer = writers.next(); |
---|
| 8683 | + |
---|
| 8684 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8685 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8686 | + param.setCompressionQuality(quality); |
---|
| 8687 | + |
---|
| 8688 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8689 | + writer.setOutput(ios); |
---|
| 8690 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8691 | + |
---|
| 8692 | + byte[] data = baos.toByteArray(); |
---|
| 8693 | + writer.dispose(); |
---|
| 8694 | + return data; |
---|
| 8695 | + } |
---|
| 8696 | + catch (Exception e) |
---|
| 8697 | + { |
---|
| 8698 | + e.printStackTrace(); |
---|
| 8699 | + return null; |
---|
| 8700 | + } |
---|
| 8701 | + } |
---|
| 8702 | + |
---|
| 8703 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8704 | + { |
---|
| 8705 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8706 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8707 | + ImageReader reader = writers.next(); |
---|
| 8708 | + |
---|
| 8709 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8710 | + |
---|
| 8711 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8712 | + param.setDestination(bim); |
---|
| 8713 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8714 | + |
---|
| 8715 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8716 | + reader.setInput(ios); |
---|
| 8717 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8718 | + reader.dispose(); |
---|
| 8719 | + |
---|
| 8720 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8721 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8722 | +// byte[] bytes = data.getData(); |
---|
| 8723 | +// |
---|
| 8724 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8725 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8726 | +// { |
---|
| 8727 | +// int i3 = i*3; |
---|
| 8728 | +// pixels[i] = 0xFF; |
---|
| 8729 | +// pixels[i] <<= 8; |
---|
| 8730 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8731 | +// pixels[i] <<= 8; |
---|
| 8732 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8733 | +// pixels[i] <<= 8; |
---|
| 8734 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8735 | +// } |
---|
| 8736 | +// |
---|
| 8737 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8738 | + |
---|
| 8739 | + return bim; |
---|
| 8740 | + } |
---|
| 8741 | + |
---|
8598 | 8742 | ShadowBuffer shadowPBuf; |
---|
8599 | 8743 | AntialiasBuffer antialiasPBuf; |
---|
8600 | 8744 | int MAXSTACK; |
---|
.. | .. |
---|
9555 | 9699 | |
---|
9556 | 9700 | if (renderCamera != lightCamera) |
---|
9557 | 9701 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9558 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9702 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9559 | 9703 | |
---|
9560 | 9704 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9561 | 9705 | |
---|
.. | .. |
---|
9571 | 9715 | |
---|
9572 | 9716 | if (renderCamera != lightCamera) |
---|
9573 | 9717 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9574 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9718 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9575 | 9719 | |
---|
9576 | 9720 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9577 | 9721 | |
---|
.. | .. |
---|
10772 | 10916 | // if (parentcam != renderCamera) // not a light |
---|
10773 | 10917 | if (cam != lightCamera) |
---|
10774 | 10918 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10775 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10919 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10776 | 10920 | |
---|
10777 | 10921 | for (int j = 0; j < 4; j++) |
---|
10778 | 10922 | { |
---|
.. | .. |
---|
10787 | 10931 | // if (parentcam != renderCamera) // not a light |
---|
10788 | 10932 | if (cam != lightCamera) |
---|
10789 | 10933 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10790 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10934 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10791 | 10935 | |
---|
10792 | 10936 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10793 | 10937 | |
---|
.. | .. |
---|
11049 | 11193 | |
---|
11050 | 11194 | try |
---|
11051 | 11195 | { |
---|
11052 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11196 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11053 | 11197 | } |
---|
11054 | 11198 | catch (Exception e) |
---|
11055 | 11199 | { |
---|
.. | .. |
---|
11340 | 11484 | } |
---|
11341 | 11485 | } |
---|
11342 | 11486 | |
---|
11343 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11487 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11344 | 11488 | { |
---|
11345 | 11489 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11346 | 11490 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11348 | 11492 | |
---|
11349 | 11493 | boolean texon = textureon; |
---|
11350 | 11494 | |
---|
11351 | | - if (RENDERPROGRAM > 0) |
---|
11352 | | - { |
---|
11353 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11354 | | - textureon = false; |
---|
11355 | | - } |
---|
| 11495 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11496 | + textureon = false; |
---|
| 11497 | + |
---|
11356 | 11498 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11357 | 11499 | //System.out.println("ALLO"); |
---|
11358 | 11500 | gl.glColorMask(false, false, false, false); |
---|
11359 | 11501 | DrawObject(gl); |
---|
11360 | | - if (RENDERPROGRAM > 0) |
---|
11361 | | - { |
---|
11362 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11363 | | - textureon = texon; |
---|
11364 | | - } |
---|
| 11502 | + |
---|
| 11503 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11504 | + textureon = texon; |
---|
| 11505 | + |
---|
11365 | 11506 | gl.glColorMask(true, true, true, true); |
---|
11366 | 11507 | |
---|
11367 | 11508 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11368 | | - //gl.glDepthMask(false); |
---|
| 11509 | + gl.glDepthMask(false); |
---|
11369 | 11510 | } |
---|
11370 | 11511 | |
---|
11371 | 11512 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11705 | 11846 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11706 | 11847 | |
---|
11707 | 11848 | if (CLEANCACHE) |
---|
11708 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11849 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11709 | 11850 | { |
---|
11710 | | - String tex = e.nextElement(); |
---|
| 11851 | + cTexture tex = e.nextElement(); |
---|
11711 | 11852 | |
---|
11712 | 11853 | // System.out.println("Texture --------- " + tex); |
---|
11713 | 11854 | |
---|
11714 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11855 | + if (tex.equals("WHITE_NOISE:")) |
---|
11715 | 11856 | continue; |
---|
11716 | 11857 | |
---|
11717 | 11858 | if (!usedtextures.contains(tex)) |
---|
11718 | 11859 | { |
---|
| 11860 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11719 | 11861 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11720 | | - textures.get(tex).texture.dispose(); |
---|
11721 | | - textures.remove(tex); |
---|
| 11862 | + if (gettex != null) |
---|
| 11863 | + { |
---|
| 11864 | + gettex.texture.dispose(); |
---|
| 11865 | + texturepigment.remove(tex); |
---|
| 11866 | + } |
---|
| 11867 | + |
---|
| 11868 | + gettex = texturebump.get(tex); |
---|
| 11869 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11870 | + if (gettex != null) |
---|
| 11871 | + { |
---|
| 11872 | + gettex.texture.dispose(); |
---|
| 11873 | + texturebump.remove(tex); |
---|
| 11874 | + } |
---|
11722 | 11875 | } |
---|
11723 | 11876 | } |
---|
11724 | 11877 | } |
---|
.. | .. |
---|
12247 | 12400 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12248 | 12401 | |
---|
12249 | 12402 | String program = |
---|
| 12403 | + // Min shader |
---|
12250 | 12404 | "!!ARBfp1.0\n" + |
---|
| 12405 | + "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" + |
---|
| 12406 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12407 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12408 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12409 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12410 | + "TEMP temp;" + |
---|
| 12411 | + "TEMP light;" + |
---|
| 12412 | + "TEMP ndotl;" + |
---|
| 12413 | + "TEMP normal;" + |
---|
| 12414 | + "TEMP depth;" + |
---|
| 12415 | + |
---|
| 12416 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12417 | + |
---|
| 12418 | + "MOV light, state.light[0].position;" + |
---|
| 12419 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12420 | + |
---|
| 12421 | + // shadow |
---|
| 12422 | + "MOV temp, fragment.texcoord[1];" + |
---|
| 12423 | + TextureFetch("depth", "temp", "1") + |
---|
| 12424 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12425 | + "SLT temp.x, fragment.texcoord[1].z, depth.z;" + |
---|
| 12426 | + |
---|
| 12427 | + |
---|
| 12428 | + // No shadow when out of frustum |
---|
| 12429 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12430 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12431 | + |
---|
| 12432 | + "MUL ndotl.x, ndotl.x, temp.x;" + |
---|
| 12433 | + "MAX ndotl.x, ndotl.x, pow2.y;" + |
---|
| 12434 | + |
---|
| 12435 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12436 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12437 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12438 | + |
---|
| 12439 | + "MUL temp, temp, zero123.z;" + |
---|
| 12440 | + |
---|
| 12441 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12442 | + |
---|
| 12443 | + "MOV result.color, temp;" + |
---|
| 12444 | + "END"; |
---|
| 12445 | + |
---|
| 12446 | + String program2 = |
---|
| 12447 | + "!!ARBfp1.0\n" + |
---|
| 12448 | + |
---|
12251 | 12449 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12252 | 12450 | "PARAM light2cam0 = program.env[10];" + |
---|
12253 | 12451 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12362 | 12560 | "TEMP shininess;" + |
---|
12363 | 12561 | "\n" + |
---|
12364 | 12562 | "MOV texSamp, one;" + |
---|
12365 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12366 | | - |
---|
| 12563 | + |
---|
12367 | 12564 | "MOV mapgrid.x, one2048th.x;" + |
---|
12368 | 12565 | "MOV temp, fragment.texcoord[1];" + |
---|
12369 | 12566 | /* |
---|
.. | .. |
---|
12768 | 12965 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12769 | 12966 | "") + |
---|
12770 | 12967 | |
---|
12771 | | - // display shadow only (bump == 0) |
---|
| 12968 | + // display shadow only (fakedepth == 0) |
---|
12772 | 12969 | "SUB temp.x, half.x, shadow.x;" + |
---|
12773 | 12970 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12774 | 12971 | "SLT temp.z, temp.y, -one2048th.x;" + |
---|
.. | .. |
---|
13200 | 13397 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13201 | 13398 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13202 | 13399 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13400 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13401 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13203 | 13402 | "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;" + |
---|
| 13403 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13404 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13208 | 13405 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13209 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13406 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13210 | 13407 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13211 | 13408 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13212 | 13409 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13213 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13410 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13214 | 13411 | |
---|
13215 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13216 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13412 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13413 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13217 | 13414 | } |
---|
13218 | 13415 | |
---|
13219 | 13416 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13260 | 13457 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13261 | 13458 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13262 | 13459 | |
---|
13263 | | - // No shadow when out of frustrum |
---|
| 13460 | + // No shadow when out of frustum |
---|
13264 | 13461 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13265 | 13462 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13266 | 13463 | ""; |
---|
.. | .. |
---|
14058 | 14255 | drag = false; |
---|
14059 | 14256 | //System.out.println("Mouse DOWN"); |
---|
14060 | 14257 | 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); |
---|
| 14258 | + //ClickInfo info = new ClickInfo(); |
---|
| 14259 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14260 | + object.clickInfo.pane = this; |
---|
| 14261 | + object.clickInfo.camera = renderCamera; |
---|
| 14262 | + object.clickInfo.x = x; |
---|
| 14263 | + object.clickInfo.y = y; |
---|
| 14264 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14265 | + editObj = object.doEditClick(//info, |
---|
| 14266 | + 0); |
---|
14069 | 14267 | if (!editObj) |
---|
14070 | 14268 | { |
---|
14071 | 14269 | hasMarquee = true; |
---|
.. | .. |
---|
14465 | 14663 | if (editObj) |
---|
14466 | 14664 | { |
---|
14467 | 14665 | drag = true; |
---|
14468 | | - ClickInfo info = new ClickInfo(); |
---|
14469 | | - info.bounds.setBounds(0, 0, |
---|
| 14666 | + //ClickInfo info = new ClickInfo(); |
---|
| 14667 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14470 | 14668 | (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); |
---|
| 14669 | + object.clickInfo.pane = this; |
---|
| 14670 | + object.clickInfo.camera = renderCamera; |
---|
| 14671 | + object.clickInfo.x = x; |
---|
| 14672 | + object.clickInfo.y = y; |
---|
| 14673 | + object //.GetWindow().copy |
---|
| 14674 | + .doEditDrag(//info, |
---|
| 14675 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14477 | 14676 | } else |
---|
14478 | 14677 | { |
---|
14479 | 14678 | if (x < startX) |
---|
.. | .. |
---|
14622 | 14821 | } |
---|
14623 | 14822 | } |
---|
14624 | 14823 | |
---|
| 14824 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14825 | + |
---|
14625 | 14826 | public void mouseMoved(MouseEvent e) |
---|
14626 | 14827 | { |
---|
14627 | 14828 | //System.out.println("mouseMoved: " + e); |
---|
14628 | 14829 | if (isRenderer) |
---|
14629 | 14830 | return; |
---|
14630 | 14831 | |
---|
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; |
---|
| 14832 | + // Mouse cursor feedback |
---|
| 14833 | + object.clickInfo.x = e.getX(); |
---|
| 14834 | + object.clickInfo.y = e.getY(); |
---|
| 14835 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14836 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14837 | + object.clickInfo.pane = this; |
---|
| 14838 | + object.clickInfo.camera = renderCamera; |
---|
14638 | 14839 | if (!isRenderer) |
---|
14639 | 14840 | { |
---|
14640 | 14841 | //ObjEditor editWindow = object.editWindow; |
---|
14641 | 14842 | //Object3D copy = editWindow.copy; |
---|
14642 | | - if (object.doEditClick(ci, 0)) |
---|
| 14843 | + if (object.doEditClick(//clickInfo, |
---|
| 14844 | + 0)) |
---|
14643 | 14845 | { |
---|
14644 | 14846 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14645 | 14847 | } else |
---|
.. | .. |
---|
14911 | 15113 | // break; |
---|
14912 | 15114 | case 'T': |
---|
14913 | 15115 | CACHETEXTURE ^= true; |
---|
14914 | | - textures.clear(); |
---|
| 15116 | + texturepigment.clear(); |
---|
| 15117 | + texturebump.clear(); |
---|
14915 | 15118 | // repaint(); |
---|
14916 | 15119 | break; |
---|
14917 | 15120 | case 'Y': |
---|
.. | .. |
---|
15664 | 15867 | |
---|
15665 | 15868 | int width = getBounds().width; |
---|
15666 | 15869 | int height = getBounds().height; |
---|
15667 | | - ClickInfo info = new ClickInfo(); |
---|
15668 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15669 | 15870 | //Image img = CreateImage(width, height); |
---|
15670 | 15871 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15671 | 15872 | |
---|
.. | .. |
---|
15742 | 15943 | } |
---|
15743 | 15944 | if (object != null && !hasMarquee) |
---|
15744 | 15945 | { |
---|
| 15946 | + if (object.clickInfo == null) |
---|
| 15947 | + object.clickInfo = new ClickInfo(); |
---|
| 15948 | + ClickInfo info = object.clickInfo; |
---|
| 15949 | + //ClickInfo info = new ClickInfo(); |
---|
| 15950 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 15951 | + |
---|
15745 | 15952 | if (isRenderer) |
---|
15746 | 15953 | { |
---|
15747 | | - info.flags++; |
---|
| 15954 | + object.clickInfo.flags++; |
---|
15748 | 15955 | double frameAspect = (double) width / (double) height; |
---|
15749 | 15956 | if (frameAspect > renderCamera.aspect) |
---|
15750 | 15957 | { |
---|
15751 | 15958 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15752 | | - info.bounds.width -= width - desired; |
---|
15753 | | - info.bounds.x += (width - desired) / 2; |
---|
| 15959 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 15960 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15754 | 15961 | } else |
---|
15755 | 15962 | { |
---|
15756 | 15963 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15757 | | - info.bounds.height -= height - desired; |
---|
15758 | | - info.bounds.y += (height - desired) / 2; |
---|
| 15964 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 15965 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15759 | 15966 | } |
---|
15760 | 15967 | } |
---|
15761 | 15968 | |
---|
15762 | | - info.g = gr; |
---|
15763 | | - info.camera = renderCamera; |
---|
| 15969 | + object.clickInfo.g = gr; |
---|
| 15970 | + object.clickInfo.camera = renderCamera; |
---|
15764 | 15971 | /* |
---|
15765 | 15972 | // Memory intensive (brep.verticescopy) |
---|
15766 | 15973 | if (!(object instanceof Composite)) |
---|
15767 | 15974 | object.draw(info, 0, false); // SLOW : |
---|
15768 | 15975 | */ |
---|
15769 | | - if (!isRenderer) |
---|
| 15976 | + if (!isRenderer) // && drag) |
---|
15770 | 15977 | { |
---|
15771 | 15978 | Grafreed.Assert(object != null); |
---|
15772 | 15979 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15774 | 15981 | { |
---|
15775 | 15982 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15776 | 15983 | |
---|
15777 | | - info.DX = 0; |
---|
15778 | | - info.DY = 0; |
---|
15779 | | - info.W = 1; |
---|
| 15984 | + object.clickInfo.DX = 0; |
---|
| 15985 | + object.clickInfo.DY = 0; |
---|
| 15986 | + object.clickInfo.W = 1; |
---|
15780 | 15987 | if (hitSomething == Object3D.hitCenter) |
---|
15781 | 15988 | { |
---|
15782 | 15989 | info.DX = X; |
---|
.. | .. |
---|
15788 | 15995 | info.DY -= info.bounds.height/2; |
---|
15789 | 15996 | } |
---|
15790 | 15997 | |
---|
15791 | | - object.drawEditHandles(info, 0); |
---|
| 15998 | + object.drawEditHandles(//info, |
---|
| 15999 | + 0); |
---|
15792 | 16000 | |
---|
15793 | 16001 | if (drag && (X != 0 || Y != 0)) |
---|
15794 | 16002 | { |
---|
.. | .. |
---|
15801 | 16009 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15802 | 16010 | break; |
---|
15803 | 16011 | case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15804 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16012 | + gr.drawLine(X, Y, 0, 0); |
---|
15805 | 16013 | break; |
---|
15806 | 16014 | } |
---|
15807 | 16015 | |
---|