.. | .. |
---|
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; |
---|
.. | .. |
---|
169 | 206 | |
---|
170 | 207 | SetCamera(cam); |
---|
171 | 208 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 209 | + // Warning: not used. |
---|
| 210 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 211 | |
---|
174 | 212 | object = o; |
---|
175 | 213 | |
---|
.. | .. |
---|
2405 | 2443 | return currentGL; |
---|
2406 | 2444 | } |
---|
2407 | 2445 | |
---|
2408 | | - private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2446 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
2409 | 2447 | { |
---|
2410 | | - // cache to disk |
---|
2411 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
2412 | | - //buffers[0]. |
---|
2413 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
2414 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
2415 | | - int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared |
---|
2416 | | - int height = width; |
---|
2417 | | - for (int i=pixels.length; --i>=0;) |
---|
2418 | | - { |
---|
2419 | | - int i3 = i*3; |
---|
2420 | | - pixels[i] = 0xFF; |
---|
2421 | | - pixels[i] <<= 8; |
---|
2422 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
2423 | | - pixels[i] <<= 8; |
---|
2424 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
2425 | | - pixels[i] <<= 8; |
---|
2426 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
2427 | | - } |
---|
2428 | | - /* |
---|
2429 | | - int r=0,g=0,b=0,a=0; |
---|
2430 | | - for (int i=0; i<width; i++) |
---|
2431 | | - for (int j=0; j<height; j++) |
---|
2432 | | - { |
---|
2433 | | - int index = j*width+i; |
---|
2434 | | - int p = pixels[index]; |
---|
2435 | | - a = ((p>>24) & 0xFF); |
---|
2436 | | - r = ((p>>16) & 0xFF); |
---|
2437 | | - g = ((p>>8) & 0xFF); |
---|
2438 | | - b = (p & 0xFF); |
---|
2439 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
2440 | | - } |
---|
2441 | | - /**/ |
---|
2442 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
2443 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
2444 | | - return rendImage; |
---|
| 2448 | + Grafreed.Assert(texturedata != null); |
---|
| 2449 | + |
---|
| 2450 | + int width = texturedata.getWidth(); |
---|
| 2451 | + int height = texturedata.getHeight(); |
---|
| 2452 | + |
---|
| 2453 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2454 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2455 | + |
---|
| 2456 | + byte[] bytes = bytebuf.array(); |
---|
| 2457 | + |
---|
| 2458 | + return CreateBim(bytes, width, height); |
---|
2445 | 2459 | } |
---|
2446 | 2460 | |
---|
2447 | 2461 | /**/ |
---|
.. | .. |
---|
2452 | 2466 | |
---|
2453 | 2467 | int resolution; |
---|
2454 | 2468 | |
---|
2455 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2469 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2456 | 2470 | { |
---|
2457 | | - texture = tex; |
---|
| 2471 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2472 | + texturedata = texdata; |
---|
2458 | 2473 | resolution = res; |
---|
2459 | 2474 | } |
---|
2460 | 2475 | } |
---|
2461 | 2476 | /**/ |
---|
2462 | 2477 | |
---|
2463 | 2478 | // TEXTURE static Texture texture; |
---|
2464 | | - static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>(); |
---|
2465 | | - static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>(); |
---|
2466 | | - static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>(); |
---|
| 2479 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2480 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2481 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2482 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
2467 | 2483 | |
---|
2468 | 2484 | int pigmentdepth = 0; |
---|
2469 | 2485 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
.. | .. |
---|
2471 | 2487 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2472 | 2488 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2473 | 2489 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2474 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2490 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2475 | 2491 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2476 | 2492 | |
---|
2477 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2493 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2478 | 2494 | { |
---|
2479 | 2495 | TextureData texturedata = null; |
---|
2480 | 2496 | |
---|
.. | .. |
---|
2493 | 2509 | if (bump) |
---|
2494 | 2510 | texturedata = ConvertBump(texturedata, false); |
---|
2495 | 2511 | |
---|
2496 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2497 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2512 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2513 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2498 | 2514 | |
---|
2499 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2500 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2515 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2516 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2501 | 2517 | |
---|
2502 | | - return texture; |
---|
| 2518 | + return texturedata; |
---|
2503 | 2519 | } |
---|
2504 | 2520 | |
---|
2505 | | - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2521 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
2506 | 2522 | { |
---|
2507 | 2523 | TextureData texturedata = null; |
---|
2508 | 2524 | |
---|
.. | .. |
---|
2510 | 2526 | { |
---|
2511 | 2527 | texturedata = |
---|
2512 | 2528 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2513 | | - name, |
---|
| 2529 | + bim, |
---|
2514 | 2530 | true); |
---|
2515 | 2531 | } catch (Exception e) |
---|
2516 | 2532 | { |
---|
.. | .. |
---|
2519 | 2535 | |
---|
2520 | 2536 | if (bump) |
---|
2521 | 2537 | texturedata = ConvertBump(texturedata, false); |
---|
2522 | | - |
---|
2523 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2524 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2525 | | - |
---|
2526 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2527 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2528 | | - |
---|
2529 | | - return texture; |
---|
| 2538 | + |
---|
| 2539 | + return texturedata; |
---|
2530 | 2540 | } |
---|
2531 | 2541 | |
---|
2532 | 2542 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
8014 | 8024 | pigment = null; |
---|
8015 | 8025 | } |
---|
8016 | 8026 | |
---|
8017 | | - ReleaseTexture(bump, true); |
---|
8018 | | - ReleaseTexture(pigment, false); |
---|
| 8027 | + ReleaseTexture(tex, true); |
---|
| 8028 | + ReleaseTexture(tex, false); |
---|
8019 | 8029 | } |
---|
8020 | 8030 | |
---|
8021 | 8031 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8044 | 8054 | pigment = null; |
---|
8045 | 8055 | } |
---|
8046 | 8056 | |
---|
8047 | | - ReleaseTexture(pigment, false); |
---|
| 8057 | + ReleaseTexture(tex, false); |
---|
8048 | 8058 | } |
---|
8049 | 8059 | |
---|
8050 | 8060 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8073 | 8083 | bump = null; |
---|
8074 | 8084 | } |
---|
8075 | 8085 | |
---|
8076 | | - ReleaseTexture(bump, true); |
---|
| 8086 | + ReleaseTexture(tex, true); |
---|
8077 | 8087 | } |
---|
8078 | 8088 | |
---|
8079 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8089 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8080 | 8090 | { |
---|
8081 | 8091 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8082 | 8092 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8087 | 8097 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8088 | 8098 | |
---|
8089 | 8099 | if (tex != null) |
---|
8090 | | - texture = textures.get(tex); |
---|
| 8100 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8091 | 8101 | |
---|
8092 | 8102 | // //assert( texture != null ); |
---|
8093 | 8103 | // if (texture == null) |
---|
.. | .. |
---|
8237 | 8247 | |
---|
8238 | 8248 | if (tex == null) |
---|
8239 | 8249 | { |
---|
8240 | | - BindTexture(null, null,false,resolution); |
---|
| 8250 | + BindTexture(null,false,resolution); |
---|
8241 | 8251 | return; |
---|
8242 | 8252 | } |
---|
8243 | 8253 | |
---|
8244 | 8254 | String pigment = Object3D.GetPigment(tex); |
---|
8245 | 8255 | |
---|
8246 | | - usedtextures.add(pigment); |
---|
| 8256 | + usedtextures.add(tex); |
---|
8247 | 8257 | |
---|
8248 | 8258 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8249 | 8259 | { |
---|
.. | .. |
---|
8257 | 8267 | } |
---|
8258 | 8268 | |
---|
8259 | 8269 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8260 | | - BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
| 8270 | + BindTexture(tex, false, resolution); |
---|
8261 | 8271 | } |
---|
8262 | 8272 | |
---|
8263 | 8273 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8270 | 8280 | |
---|
8271 | 8281 | if (tex == null) |
---|
8272 | 8282 | { |
---|
8273 | | - BindTexture(null, null,true,resolution); |
---|
| 8283 | + BindTexture(null,true,resolution); |
---|
8274 | 8284 | return; |
---|
8275 | 8285 | } |
---|
8276 | 8286 | |
---|
8277 | 8287 | String bump = Object3D.GetBump(tex); |
---|
8278 | 8288 | |
---|
8279 | | - usedtextures.add(bump); |
---|
| 8289 | + usedtextures.add(tex); |
---|
8280 | 8290 | |
---|
8281 | 8291 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8282 | 8292 | { |
---|
.. | .. |
---|
8290 | 8300 | } |
---|
8291 | 8301 | |
---|
8292 | 8302 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8293 | | - BindTexture(tex.bumptexture, bump, true, resolution); |
---|
| 8303 | + BindTexture(tex, true, resolution); |
---|
8294 | 8304 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8295 | 8305 | } |
---|
8296 | 8306 | |
---|
.. | .. |
---|
8314 | 8324 | return fileExists; |
---|
8315 | 8325 | } |
---|
8316 | 8326 | |
---|
8317 | | - CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception |
---|
| 8327 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8318 | 8328 | { |
---|
8319 | 8329 | CacheTexture texturecache = null; |
---|
8320 | 8330 | |
---|
8321 | 8331 | if (tex != null) |
---|
8322 | 8332 | { |
---|
8323 | | - String texname = tex; |
---|
| 8333 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8334 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8335 | + |
---|
| 8336 | + if (texname.equals("") && texdata == null) |
---|
| 8337 | + { |
---|
| 8338 | + return null; |
---|
| 8339 | + } |
---|
8324 | 8340 | |
---|
8325 | 8341 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8326 | 8342 | |
---|
.. | .. |
---|
8330 | 8346 | // else |
---|
8331 | 8347 | // if (!texname.startsWith("/")) |
---|
8332 | 8348 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8333 | | - if (!FileExists(tex)) |
---|
| 8349 | + if (!FileExists(texname)) |
---|
8334 | 8350 | { |
---|
8335 | 8351 | texname = fallbackTextureName; |
---|
8336 | 8352 | } |
---|
8337 | 8353 | |
---|
8338 | 8354 | if (CACHETEXTURE) |
---|
8339 | 8355 | { |
---|
8340 | | - if (bim == null) |
---|
8341 | | - texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8356 | + if (texdata == null) |
---|
| 8357 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8342 | 8358 | else |
---|
8343 | | - texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8359 | + texturecache = bimtextures.get(texdata); |
---|
8344 | 8360 | } |
---|
8345 | 8361 | |
---|
8346 | | - if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8362 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
8347 | 8363 | { |
---|
8348 | 8364 | TextureData texturedata = null; |
---|
8349 | 8365 | |
---|
8350 | | - if (bim != null) |
---|
| 8366 | + if (texdata != null && textureon) |
---|
8351 | 8367 | { |
---|
| 8368 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8369 | + |
---|
| 8370 | + try |
---|
| 8371 | + { |
---|
| 8372 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8373 | + } |
---|
| 8374 | + catch (Exception e) |
---|
| 8375 | + { |
---|
| 8376 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8377 | + } |
---|
| 8378 | + |
---|
8352 | 8379 | texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8380 | + bimtextures.put(texdata, texturecache); |
---|
| 8381 | + |
---|
| 8382 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8383 | + |
---|
| 8384 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8385 | + //bim2 = bim; |
---|
8353 | 8386 | } |
---|
8354 | 8387 | else |
---|
8355 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8388 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8356 | 8389 | { |
---|
8357 | 8390 | assert(!bump); |
---|
8358 | 8391 | // if (bump) |
---|
.. | .. |
---|
8363 | 8396 | // } |
---|
8364 | 8397 | // else |
---|
8365 | 8398 | // { |
---|
8366 | | - texturecache = textures.get(tex); |
---|
| 8399 | + // texturecache = textures.get(texname); // suspicious |
---|
8367 | 8400 | if (texturecache == null) |
---|
8368 | 8401 | { |
---|
8369 | 8402 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
.. | .. |
---|
8372 | 8405 | new Exception().printStackTrace(); |
---|
8373 | 8406 | // } |
---|
8374 | 8407 | } else |
---|
8375 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8408 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8376 | 8409 | { |
---|
8377 | 8410 | assert(bump); |
---|
8378 | | - texturecache = textures.get(tex); |
---|
| 8411 | + // texturecache = textures.get(texname); // suspicious |
---|
8379 | 8412 | if (texturecache == null) |
---|
8380 | 8413 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8381 | 8414 | else |
---|
.. | .. |
---|
8387 | 8420 | // texture = GetResourceTexture("default.png"); |
---|
8388 | 8421 | //} else |
---|
8389 | 8422 | //{ |
---|
8390 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8423 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8391 | 8424 | { |
---|
8392 | | - texturecache = textures.get(tex); |
---|
| 8425 | + // texturecache = textures.get(texname); // suspicious |
---|
8393 | 8426 | if (texturecache == null) |
---|
8394 | 8427 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
8395 | 8428 | else |
---|
.. | .. |
---|
8452 | 8485 | if (texturedata == null) |
---|
8453 | 8486 | throw new Exception(); |
---|
8454 | 8487 | |
---|
8455 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8488 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8456 | 8489 | //texture = GetTexture(tex, bump); |
---|
8457 | 8490 | } |
---|
8458 | 8491 | } |
---|
8459 | 8492 | //} |
---|
8460 | 8493 | } |
---|
8461 | 8494 | |
---|
8462 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8495 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8463 | 8496 | { |
---|
8464 | 8497 | //return false; |
---|
8465 | | - assert(bim == null); |
---|
8466 | 8498 | |
---|
8467 | 8499 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8468 | 8500 | if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
.. | .. |
---|
8509 | 8541 | } |
---|
8510 | 8542 | } |
---|
8511 | 8543 | } |
---|
8512 | | - |
---|
| 8544 | + |
---|
| 8545 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8546 | + |
---|
8513 | 8547 | //System.out.println("Texture = " + tex); |
---|
8514 | | - if (textures.containsKey(texname)) |
---|
| 8548 | + if (textures.containsKey(tex)) |
---|
8515 | 8549 | { |
---|
8516 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8550 | + CacheTexture thetex = textures.get(tex); |
---|
8517 | 8551 | thetex.texture.disable(); |
---|
8518 | 8552 | thetex.texture.dispose(); |
---|
8519 | | - textures.remove(texname); |
---|
| 8553 | + textures.remove(tex); |
---|
8520 | 8554 | } |
---|
8521 | 8555 | |
---|
8522 | 8556 | //texture.texturedata = texturedata; |
---|
8523 | | - textures.put(texname, texturecache); |
---|
| 8557 | + textures.put(tex, texturecache); |
---|
8524 | 8558 | |
---|
8525 | 8559 | // newtex = true; |
---|
8526 | 8560 | } |
---|
.. | .. |
---|
8541 | 8575 | |
---|
8542 | 8576 | static void EmbedTextures(cTexture tex) |
---|
8543 | 8577 | { |
---|
| 8578 | + if (tex.pigmentdata == null) |
---|
| 8579 | + { |
---|
| 8580 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8581 | + |
---|
| 8582 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8583 | + |
---|
| 8584 | + if (texturecache != null) |
---|
| 8585 | + { |
---|
| 8586 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8587 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8588 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8589 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8590 | + ; |
---|
| 8591 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8592 | + } |
---|
| 8593 | + } |
---|
8544 | 8594 | |
---|
| 8595 | + if (tex.bumpdata == null) |
---|
| 8596 | + { |
---|
| 8597 | + //String texname = Object3D.GetBump(tex); |
---|
| 8598 | + |
---|
| 8599 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8600 | + |
---|
| 8601 | + if (texturecache != null) |
---|
| 8602 | + { |
---|
| 8603 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8604 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8605 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8606 | + } |
---|
| 8607 | + } |
---|
8545 | 8608 | } |
---|
8546 | 8609 | |
---|
8547 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8610 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8548 | 8611 | { |
---|
8549 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8612 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8550 | 8613 | |
---|
8551 | 8614 | if (bump) |
---|
8552 | 8615 | { |
---|
.. | .. |
---|
8562 | 8625 | return texture!=null?texture.texture:null; |
---|
8563 | 8626 | } |
---|
8564 | 8627 | |
---|
8565 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8628 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8566 | 8629 | { |
---|
8567 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8630 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8568 | 8631 | |
---|
8569 | 8632 | return texture!=null?texture.texturedata:null; |
---|
8570 | 8633 | } |
---|
8571 | 8634 | |
---|
8572 | | - boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8635 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8573 | 8636 | { |
---|
8574 | 8637 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8575 | 8638 | { |
---|
.. | .. |
---|
8578 | 8641 | |
---|
8579 | 8642 | //boolean newtex = false; |
---|
8580 | 8643 | |
---|
8581 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8644 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8582 | 8645 | |
---|
8583 | 8646 | if (texture == null) |
---|
8584 | 8647 | return false; |
---|
.. | .. |
---|
8611 | 8674 | return true; // Warning: not used. |
---|
8612 | 8675 | } |
---|
8613 | 8676 | |
---|
| 8677 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8678 | + { |
---|
| 8679 | + try |
---|
| 8680 | + { |
---|
| 8681 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8682 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8683 | + ImageWriter writer = writers.next(); |
---|
| 8684 | + |
---|
| 8685 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8686 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8687 | + param.setCompressionQuality(quality); |
---|
| 8688 | + |
---|
| 8689 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8690 | + writer.setOutput(ios); |
---|
| 8691 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8692 | + |
---|
| 8693 | + byte[] data = baos.toByteArray(); |
---|
| 8694 | + writer.dispose(); |
---|
| 8695 | + return data; |
---|
| 8696 | + } |
---|
| 8697 | + catch (Exception e) |
---|
| 8698 | + { |
---|
| 8699 | + e.printStackTrace(); |
---|
| 8700 | + return null; |
---|
| 8701 | + } |
---|
| 8702 | + } |
---|
| 8703 | + |
---|
| 8704 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8705 | + { |
---|
| 8706 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8707 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8708 | + ImageReader reader = writers.next(); |
---|
| 8709 | + |
---|
| 8710 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8711 | + |
---|
| 8712 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8713 | + param.setDestination(bim); |
---|
| 8714 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8715 | + |
---|
| 8716 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8717 | + reader.setInput(ios); |
---|
| 8718 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8719 | + reader.dispose(); |
---|
| 8720 | + |
---|
| 8721 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8722 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8723 | +// byte[] bytes = data.getData(); |
---|
| 8724 | +// |
---|
| 8725 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8726 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8727 | +// { |
---|
| 8728 | +// int i3 = i*3; |
---|
| 8729 | +// pixels[i] = 0xFF; |
---|
| 8730 | +// pixels[i] <<= 8; |
---|
| 8731 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8732 | +// pixels[i] <<= 8; |
---|
| 8733 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8734 | +// pixels[i] <<= 8; |
---|
| 8735 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8736 | +// } |
---|
| 8737 | +// |
---|
| 8738 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8739 | + |
---|
| 8740 | + return bim; |
---|
| 8741 | + } |
---|
| 8742 | + |
---|
8614 | 8743 | ShadowBuffer shadowPBuf; |
---|
8615 | 8744 | AntialiasBuffer antialiasPBuf; |
---|
8616 | 8745 | int MAXSTACK; |
---|
.. | .. |
---|
9571 | 9700 | |
---|
9572 | 9701 | if (renderCamera != lightCamera) |
---|
9573 | 9702 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9574 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9703 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9575 | 9704 | |
---|
9576 | 9705 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9577 | 9706 | |
---|
.. | .. |
---|
9587 | 9716 | |
---|
9588 | 9717 | if (renderCamera != lightCamera) |
---|
9589 | 9718 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9590 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9719 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9591 | 9720 | |
---|
9592 | 9721 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9593 | 9722 | |
---|
.. | .. |
---|
10788 | 10917 | // if (parentcam != renderCamera) // not a light |
---|
10789 | 10918 | if (cam != lightCamera) |
---|
10790 | 10919 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10791 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10920 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10792 | 10921 | |
---|
10793 | 10922 | for (int j = 0; j < 4; j++) |
---|
10794 | 10923 | { |
---|
.. | .. |
---|
10803 | 10932 | // if (parentcam != renderCamera) // not a light |
---|
10804 | 10933 | if (cam != lightCamera) |
---|
10805 | 10934 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10806 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10935 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10807 | 10936 | |
---|
10808 | 10937 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10809 | 10938 | |
---|
.. | .. |
---|
11065 | 11194 | |
---|
11066 | 11195 | try |
---|
11067 | 11196 | { |
---|
11068 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11197 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11069 | 11198 | } |
---|
11070 | 11199 | catch (Exception e) |
---|
11071 | 11200 | { |
---|
.. | .. |
---|
11356 | 11485 | } |
---|
11357 | 11486 | } |
---|
11358 | 11487 | |
---|
11359 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11488 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11360 | 11489 | { |
---|
11361 | 11490 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11362 | 11491 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11364 | 11493 | |
---|
11365 | 11494 | boolean texon = textureon; |
---|
11366 | 11495 | |
---|
11367 | | - if (RENDERPROGRAM > 0) |
---|
11368 | | - { |
---|
11369 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11370 | | - textureon = false; |
---|
11371 | | - } |
---|
| 11496 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11497 | + textureon = false; |
---|
| 11498 | + |
---|
11372 | 11499 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11373 | 11500 | //System.out.println("ALLO"); |
---|
11374 | 11501 | gl.glColorMask(false, false, false, false); |
---|
11375 | 11502 | DrawObject(gl); |
---|
11376 | | - if (RENDERPROGRAM > 0) |
---|
11377 | | - { |
---|
11378 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11379 | | - textureon = texon; |
---|
11380 | | - } |
---|
| 11503 | + |
---|
| 11504 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11505 | + textureon = texon; |
---|
| 11506 | + |
---|
11381 | 11507 | gl.glColorMask(true, true, true, true); |
---|
11382 | 11508 | |
---|
11383 | 11509 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11384 | | - //gl.glDepthMask(false); |
---|
| 11510 | + gl.glDepthMask(false); |
---|
11385 | 11511 | } |
---|
11386 | 11512 | |
---|
11387 | 11513 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11721 | 11847 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11722 | 11848 | |
---|
11723 | 11849 | if (CLEANCACHE) |
---|
11724 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11850 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11725 | 11851 | { |
---|
11726 | | - String tex = e.nextElement(); |
---|
| 11852 | + cTexture tex = e.nextElement(); |
---|
11727 | 11853 | |
---|
11728 | 11854 | // System.out.println("Texture --------- " + tex); |
---|
11729 | 11855 | |
---|
11730 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11856 | + if (tex.equals("WHITE_NOISE:")) |
---|
11731 | 11857 | continue; |
---|
11732 | 11858 | |
---|
11733 | 11859 | if (!usedtextures.contains(tex)) |
---|
11734 | 11860 | { |
---|
| 11861 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11735 | 11862 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11736 | | - textures.get(tex).texture.dispose(); |
---|
11737 | | - textures.remove(tex); |
---|
| 11863 | + if (gettex != null) |
---|
| 11864 | + { |
---|
| 11865 | + gettex.texture.dispose(); |
---|
| 11866 | + texturepigment.remove(tex); |
---|
| 11867 | + } |
---|
| 11868 | + |
---|
| 11869 | + gettex = texturebump.get(tex); |
---|
| 11870 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11871 | + if (gettex != null) |
---|
| 11872 | + { |
---|
| 11873 | + gettex.texture.dispose(); |
---|
| 11874 | + texturebump.remove(tex); |
---|
| 11875 | + } |
---|
11738 | 11876 | } |
---|
11739 | 11877 | } |
---|
11740 | 11878 | } |
---|
.. | .. |
---|
12263 | 12401 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12264 | 12402 | |
---|
12265 | 12403 | String program = |
---|
| 12404 | + // Min shader |
---|
12266 | 12405 | "!!ARBfp1.0\n" + |
---|
| 12406 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12407 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12408 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12409 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12410 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12411 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12412 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12413 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12414 | + "TEMP temp;" + |
---|
| 12415 | + "TEMP light;" + |
---|
| 12416 | + "TEMP ndotl;" + |
---|
| 12417 | + "TEMP normal;" + |
---|
| 12418 | + "TEMP depth;" + |
---|
| 12419 | + "TEMP eye;" + |
---|
| 12420 | + "TEMP pos;" + |
---|
| 12421 | + |
---|
| 12422 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12423 | + Normalize("normal") + |
---|
| 12424 | + "MOV light, state.light[0].position;" + |
---|
| 12425 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12426 | + |
---|
| 12427 | + // shadow |
---|
| 12428 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12429 | + "MOV temp, pos;" + |
---|
| 12430 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12431 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12432 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12433 | + |
---|
| 12434 | + // No shadow when out of frustum |
---|
| 12435 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12436 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12437 | + |
---|
| 12438 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12439 | + |
---|
| 12440 | + // Backlit |
---|
| 12441 | + "MOV pos.w, zero123.y;" + |
---|
| 12442 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12443 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12444 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12445 | + Normalize("eye") + |
---|
| 12446 | + |
---|
| 12447 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12448 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12449 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12450 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12451 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12452 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12453 | + |
---|
| 12454 | + "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12455 | + |
---|
| 12456 | + // Pigment |
---|
| 12457 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12458 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12459 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12460 | + |
---|
| 12461 | + "MUL temp, temp, zero123.z;" + |
---|
| 12462 | + |
---|
| 12463 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12464 | + |
---|
| 12465 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12466 | + "MOV result.color, temp;" + |
---|
| 12467 | + "END"; |
---|
| 12468 | + |
---|
| 12469 | + String program2 = |
---|
| 12470 | + "!!ARBfp1.0\n" + |
---|
| 12471 | + |
---|
12267 | 12472 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12268 | 12473 | "PARAM light2cam0 = program.env[10];" + |
---|
12269 | 12474 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12378 | 12583 | "TEMP shininess;" + |
---|
12379 | 12584 | "\n" + |
---|
12380 | 12585 | "MOV texSamp, one;" + |
---|
12381 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12382 | | - |
---|
| 12586 | + |
---|
12383 | 12587 | "MOV mapgrid.x, one2048th.x;" + |
---|
12384 | 12588 | "MOV temp, fragment.texcoord[1];" + |
---|
12385 | 12589 | /* |
---|
.. | .. |
---|
12400 | 12604 | "MUL temp, floor, mapgrid.x;" + |
---|
12401 | 12605 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12402 | 12606 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12403 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12607 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12404 | 12608 | "") + |
---|
12405 | 12609 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12406 | 12610 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12407 | 12611 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12408 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12612 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12409 | 12613 | "") + |
---|
12410 | 12614 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12411 | 12615 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12412 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12616 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12413 | 12617 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12414 | 12618 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12415 | 12619 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12416 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12620 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12417 | 12621 | "") + |
---|
12418 | 12622 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12419 | 12623 | //"MOV params, material;" + |
---|
.. | .. |
---|
12784 | 12988 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12785 | 12989 | "") + |
---|
12786 | 12990 | |
---|
12787 | | - // display shadow only (bump == 0) |
---|
| 12991 | + // display shadow only (fakedepth == 0) |
---|
12788 | 12992 | "SUB temp.x, half.x, shadow.x;" + |
---|
12789 | 12993 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12790 | 12994 | "SLT temp.z, temp.y, -one2048th.x;" + |
---|
.. | .. |
---|
13211 | 13415 | return out; |
---|
13212 | 13416 | } |
---|
13213 | 13417 | |
---|
13214 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13418 | + // Also does frustum culling |
---|
| 13419 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13215 | 13420 | { |
---|
13216 | 13421 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13217 | 13422 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13218 | 13423 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13424 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13425 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13219 | 13426 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13220 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13221 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13222 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13223 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13427 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13428 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13224 | 13429 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13225 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13430 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13226 | 13431 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13227 | 13432 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13228 | 13433 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13229 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13434 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13230 | 13435 | |
---|
13231 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13232 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13436 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13437 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13233 | 13438 | } |
---|
13234 | 13439 | |
---|
13235 | 13440 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13276 | 13481 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13277 | 13482 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13278 | 13483 | |
---|
13279 | | - // No shadow when out of frustrum |
---|
| 13484 | + // No shadow when out of frustum |
---|
13280 | 13485 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13281 | 13486 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13282 | 13487 | ""; |
---|
.. | .. |
---|
14074 | 14279 | drag = false; |
---|
14075 | 14280 | //System.out.println("Mouse DOWN"); |
---|
14076 | 14281 | editObj = false; |
---|
14077 | | - ClickInfo info = new ClickInfo(); |
---|
14078 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14079 | | - info.pane = this; |
---|
14080 | | - info.camera = renderCamera; |
---|
14081 | | - info.x = x; |
---|
14082 | | - info.y = y; |
---|
14083 | | - info.modifiers = modifiersex; |
---|
14084 | | - editObj = object.doEditClick(info, 0); |
---|
| 14282 | + //ClickInfo info = new ClickInfo(); |
---|
| 14283 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14284 | + object.clickInfo.pane = this; |
---|
| 14285 | + object.clickInfo.camera = renderCamera; |
---|
| 14286 | + object.clickInfo.x = x; |
---|
| 14287 | + object.clickInfo.y = y; |
---|
| 14288 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14289 | + editObj = object.doEditClick(//info, |
---|
| 14290 | + 0); |
---|
14085 | 14291 | if (!editObj) |
---|
14086 | 14292 | { |
---|
14087 | 14293 | hasMarquee = true; |
---|
.. | .. |
---|
14481 | 14687 | if (editObj) |
---|
14482 | 14688 | { |
---|
14483 | 14689 | drag = true; |
---|
14484 | | - ClickInfo info = new ClickInfo(); |
---|
14485 | | - info.bounds.setBounds(0, 0, |
---|
| 14690 | + //ClickInfo info = new ClickInfo(); |
---|
| 14691 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14486 | 14692 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14487 | | - info.pane = this; |
---|
14488 | | - info.camera = renderCamera; |
---|
14489 | | - info.x = x; |
---|
14490 | | - info.y = y; |
---|
14491 | | - object.GetWindow().copy |
---|
14492 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14693 | + object.clickInfo.pane = this; |
---|
| 14694 | + object.clickInfo.camera = renderCamera; |
---|
| 14695 | + object.clickInfo.x = x; |
---|
| 14696 | + object.clickInfo.y = y; |
---|
| 14697 | + object //.GetWindow().copy |
---|
| 14698 | + .doEditDrag(//info, |
---|
| 14699 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14493 | 14700 | } else |
---|
14494 | 14701 | { |
---|
14495 | 14702 | if (x < startX) |
---|
.. | .. |
---|
14638 | 14845 | } |
---|
14639 | 14846 | } |
---|
14640 | 14847 | |
---|
| 14848 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14849 | + |
---|
14641 | 14850 | public void mouseMoved(MouseEvent e) |
---|
14642 | 14851 | { |
---|
14643 | 14852 | //System.out.println("mouseMoved: " + e); |
---|
14644 | 14853 | if (isRenderer) |
---|
14645 | 14854 | return; |
---|
14646 | 14855 | |
---|
14647 | | - ClickInfo ci = new ClickInfo(); |
---|
14648 | | - ci.x = e.getX(); |
---|
14649 | | - ci.y = e.getY(); |
---|
14650 | | - ci.modifiers = e.getModifiersEx(); |
---|
14651 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14652 | | - ci.pane = this; |
---|
14653 | | - ci.camera = renderCamera; |
---|
| 14856 | + // Mouse cursor feedback |
---|
| 14857 | + object.clickInfo.x = e.getX(); |
---|
| 14858 | + object.clickInfo.y = e.getY(); |
---|
| 14859 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14860 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14861 | + object.clickInfo.pane = this; |
---|
| 14862 | + object.clickInfo.camera = renderCamera; |
---|
14654 | 14863 | if (!isRenderer) |
---|
14655 | 14864 | { |
---|
14656 | 14865 | //ObjEditor editWindow = object.editWindow; |
---|
14657 | 14866 | //Object3D copy = editWindow.copy; |
---|
14658 | | - if (object.doEditClick(ci, 0)) |
---|
| 14867 | + if (object.doEditClick(//clickInfo, |
---|
| 14868 | + 0)) |
---|
14659 | 14869 | { |
---|
14660 | 14870 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14661 | 14871 | } else |
---|
.. | .. |
---|
14927 | 15137 | // break; |
---|
14928 | 15138 | case 'T': |
---|
14929 | 15139 | CACHETEXTURE ^= true; |
---|
14930 | | - textures.clear(); |
---|
| 15140 | + texturepigment.clear(); |
---|
| 15141 | + texturebump.clear(); |
---|
14931 | 15142 | // repaint(); |
---|
14932 | 15143 | break; |
---|
14933 | 15144 | case 'Y': |
---|
.. | .. |
---|
15680 | 15891 | |
---|
15681 | 15892 | int width = getBounds().width; |
---|
15682 | 15893 | int height = getBounds().height; |
---|
15683 | | - ClickInfo info = new ClickInfo(); |
---|
15684 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15685 | 15894 | //Image img = CreateImage(width, height); |
---|
15686 | 15895 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15687 | 15896 | |
---|
.. | .. |
---|
15758 | 15967 | } |
---|
15759 | 15968 | if (object != null && !hasMarquee) |
---|
15760 | 15969 | { |
---|
| 15970 | + if (object.clickInfo == null) |
---|
| 15971 | + object.clickInfo = new ClickInfo(); |
---|
| 15972 | + ClickInfo info = object.clickInfo; |
---|
| 15973 | + //ClickInfo info = new ClickInfo(); |
---|
| 15974 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 15975 | + |
---|
15761 | 15976 | if (isRenderer) |
---|
15762 | 15977 | { |
---|
15763 | | - info.flags++; |
---|
| 15978 | + object.clickInfo.flags++; |
---|
15764 | 15979 | double frameAspect = (double) width / (double) height; |
---|
15765 | 15980 | if (frameAspect > renderCamera.aspect) |
---|
15766 | 15981 | { |
---|
15767 | 15982 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15768 | | - info.bounds.width -= width - desired; |
---|
15769 | | - info.bounds.x += (width - desired) / 2; |
---|
| 15983 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 15984 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15770 | 15985 | } else |
---|
15771 | 15986 | { |
---|
15772 | 15987 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15773 | | - info.bounds.height -= height - desired; |
---|
15774 | | - info.bounds.y += (height - desired) / 2; |
---|
| 15988 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 15989 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15775 | 15990 | } |
---|
15776 | 15991 | } |
---|
15777 | 15992 | |
---|
15778 | | - info.g = gr; |
---|
15779 | | - info.camera = renderCamera; |
---|
| 15993 | + object.clickInfo.g = gr; |
---|
| 15994 | + object.clickInfo.camera = renderCamera; |
---|
15780 | 15995 | /* |
---|
15781 | 15996 | // Memory intensive (brep.verticescopy) |
---|
15782 | 15997 | if (!(object instanceof Composite)) |
---|
15783 | 15998 | object.draw(info, 0, false); // SLOW : |
---|
15784 | 15999 | */ |
---|
15785 | | - if (!isRenderer) |
---|
| 16000 | + if (!isRenderer) // && drag) |
---|
15786 | 16001 | { |
---|
15787 | 16002 | Grafreed.Assert(object != null); |
---|
15788 | 16003 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15790 | 16005 | { |
---|
15791 | 16006 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15792 | 16007 | |
---|
15793 | | - info.DX = 0; |
---|
15794 | | - info.DY = 0; |
---|
15795 | | - info.W = 1; |
---|
| 16008 | + object.clickInfo.DX = 0; |
---|
| 16009 | + object.clickInfo.DY = 0; |
---|
| 16010 | + object.clickInfo.W = 1; |
---|
15796 | 16011 | if (hitSomething == Object3D.hitCenter) |
---|
15797 | 16012 | { |
---|
15798 | 16013 | info.DX = X; |
---|
.. | .. |
---|
15804 | 16019 | info.DY -= info.bounds.height/2; |
---|
15805 | 16020 | } |
---|
15806 | 16021 | |
---|
15807 | | - object.drawEditHandles(info, 0); |
---|
| 16022 | + object.drawEditHandles(//info, |
---|
| 16023 | + 0); |
---|
15808 | 16024 | |
---|
15809 | 16025 | if (drag && (X != 0 || Y != 0)) |
---|
15810 | 16026 | { |
---|
.. | .. |
---|
15817 | 16033 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15818 | 16034 | break; |
---|
15819 | 16035 | case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
15820 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16036 | + gr.drawLine(X, Y, 0, 0); |
---|
15821 | 16037 | break; |
---|
15822 | 16038 | } |
---|
15823 | 16039 | |
---|