.. | .. |
---|
45 | 45 | |
---|
46 | 46 | static int STEP = 1; |
---|
47 | 47 | |
---|
| 48 | + private static BufferedImage CreateBim(byte[] bytes, int width, int height) |
---|
| 49 | + { |
---|
| 50 | + int[] pixels = new int[bytes.length/3]; |
---|
| 51 | + for (int i=pixels.length; --i>=0;) |
---|
| 52 | + { |
---|
| 53 | + int i3 = i*3; |
---|
| 54 | + pixels[i] = 0xFF; |
---|
| 55 | + pixels[i] <<= 8; |
---|
| 56 | + pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 57 | + pixels[i] <<= 8; |
---|
| 58 | + pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 59 | + pixels[i] <<= 8; |
---|
| 60 | + pixels[i] |= bytes[i3] & 0xFF; |
---|
| 61 | + } |
---|
| 62 | + /* |
---|
| 63 | + int r=0,g=0,b=0,a=0; |
---|
| 64 | + for (int i=0; i<width; i++) |
---|
| 65 | + for (int j=0; j<height; j++) |
---|
| 66 | + { |
---|
| 67 | + int index = j*width+i; |
---|
| 68 | + int p = pixels[index]; |
---|
| 69 | + a = ((p>>24) & 0xFF); |
---|
| 70 | + r = ((p>>16) & 0xFF); |
---|
| 71 | + g = ((p>>8) & 0xFF); |
---|
| 72 | + b = (p & 0xFF); |
---|
| 73 | + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
| 74 | + } |
---|
| 75 | + /**/ |
---|
| 76 | + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
| 77 | + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 78 | + return rendImage; |
---|
| 79 | + } |
---|
| 80 | + |
---|
48 | 81 | /*static*/ private boolean CULLFACE = false; // true; |
---|
49 | 82 | /*static*/ boolean NEAREST = false; // true; |
---|
50 | 83 | /*static*/ boolean WIREFRAME = false; // true; |
---|
.. | .. |
---|
2405 | 2438 | return currentGL; |
---|
2406 | 2439 | } |
---|
2407 | 2440 | |
---|
| 2441 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2442 | + { |
---|
| 2443 | + Grafreed.Assert(texturedata != null); |
---|
| 2444 | + |
---|
| 2445 | + int width = texturedata.getWidth(); |
---|
| 2446 | + int height = texturedata.getHeight(); |
---|
| 2447 | + |
---|
| 2448 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2449 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2450 | + |
---|
| 2451 | + byte[] bytes = bytebuf.array(); |
---|
| 2452 | + |
---|
| 2453 | + return CreateBim(bytes, width, height); |
---|
| 2454 | + } |
---|
| 2455 | + |
---|
2408 | 2456 | /**/ |
---|
2409 | 2457 | class CacheTexture |
---|
2410 | 2458 | { |
---|
.. | .. |
---|
2413 | 2461 | |
---|
2414 | 2462 | int resolution; |
---|
2415 | 2463 | |
---|
2416 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2464 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2417 | 2465 | { |
---|
2418 | | - texture = tex; |
---|
| 2466 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2467 | + texturedata = texdata; |
---|
2419 | 2468 | resolution = res; |
---|
2420 | 2469 | } |
---|
2421 | 2470 | } |
---|
2422 | 2471 | /**/ |
---|
2423 | 2472 | |
---|
2424 | 2473 | // 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>(); |
---|
| 2474 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2475 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2476 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2477 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
2428 | 2478 | |
---|
2429 | 2479 | int pigmentdepth = 0; |
---|
2430 | 2480 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
.. | .. |
---|
2432 | 2482 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2433 | 2483 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2434 | 2484 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2435 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2485 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2436 | 2486 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2437 | 2487 | |
---|
2438 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2488 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2439 | 2489 | { |
---|
2440 | 2490 | TextureData texturedata = null; |
---|
2441 | 2491 | |
---|
.. | .. |
---|
2454 | 2504 | if (bump) |
---|
2455 | 2505 | texturedata = ConvertBump(texturedata, false); |
---|
2456 | 2506 | |
---|
2457 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2458 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2507 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2508 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2459 | 2509 | |
---|
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); |
---|
| 2510 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2511 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2462 | 2512 | |
---|
2463 | | - return texture; |
---|
| 2513 | + return texturedata; |
---|
2464 | 2514 | } |
---|
2465 | 2515 | |
---|
2466 | | - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2516 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
2467 | 2517 | { |
---|
2468 | 2518 | TextureData texturedata = null; |
---|
2469 | 2519 | |
---|
.. | .. |
---|
2471 | 2521 | { |
---|
2472 | 2522 | texturedata = |
---|
2473 | 2523 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2474 | | - name, |
---|
| 2524 | + bim, |
---|
2475 | 2525 | true); |
---|
2476 | 2526 | } catch (Exception e) |
---|
2477 | 2527 | { |
---|
.. | .. |
---|
2480 | 2530 | |
---|
2481 | 2531 | if (bump) |
---|
2482 | 2532 | 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; |
---|
| 2533 | + |
---|
| 2534 | + return texturedata; |
---|
2491 | 2535 | } |
---|
2492 | 2536 | |
---|
2493 | 2537 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
7975 | 8019 | pigment = null; |
---|
7976 | 8020 | } |
---|
7977 | 8021 | |
---|
7978 | | - ReleaseTexture(bump, true); |
---|
7979 | | - ReleaseTexture(pigment, false); |
---|
| 8022 | + ReleaseTexture(tex, true); |
---|
| 8023 | + ReleaseTexture(tex, false); |
---|
7980 | 8024 | } |
---|
7981 | 8025 | |
---|
7982 | 8026 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8005 | 8049 | pigment = null; |
---|
8006 | 8050 | } |
---|
8007 | 8051 | |
---|
8008 | | - ReleaseTexture(pigment, false); |
---|
| 8052 | + ReleaseTexture(tex, false); |
---|
8009 | 8053 | } |
---|
8010 | 8054 | |
---|
8011 | 8055 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8034 | 8078 | bump = null; |
---|
8035 | 8079 | } |
---|
8036 | 8080 | |
---|
8037 | | - ReleaseTexture(bump, true); |
---|
| 8081 | + ReleaseTexture(tex, true); |
---|
8038 | 8082 | } |
---|
8039 | 8083 | |
---|
8040 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8084 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8041 | 8085 | { |
---|
8042 | 8086 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8043 | 8087 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8048 | 8092 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8049 | 8093 | |
---|
8050 | 8094 | if (tex != null) |
---|
8051 | | - texture = textures.get(tex); |
---|
| 8095 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8052 | 8096 | |
---|
8053 | 8097 | // //assert( texture != null ); |
---|
8054 | 8098 | // if (texture == null) |
---|
.. | .. |
---|
8198 | 8242 | |
---|
8199 | 8243 | if (tex == null) |
---|
8200 | 8244 | { |
---|
8201 | | - BindTexture(null, null,false,resolution); |
---|
| 8245 | + BindTexture(null,false,resolution); |
---|
8202 | 8246 | return; |
---|
8203 | 8247 | } |
---|
8204 | 8248 | |
---|
8205 | 8249 | String pigment = Object3D.GetPigment(tex); |
---|
8206 | 8250 | |
---|
8207 | | - usedtextures.add(pigment); |
---|
| 8251 | + usedtextures.add(tex); |
---|
8208 | 8252 | |
---|
8209 | 8253 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8210 | 8254 | { |
---|
.. | .. |
---|
8218 | 8262 | } |
---|
8219 | 8263 | |
---|
8220 | 8264 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8221 | | - BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
| 8265 | + BindTexture(tex, false, resolution); |
---|
8222 | 8266 | } |
---|
8223 | 8267 | |
---|
8224 | 8268 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8231 | 8275 | |
---|
8232 | 8276 | if (tex == null) |
---|
8233 | 8277 | { |
---|
8234 | | - BindTexture(null, null,true,resolution); |
---|
| 8278 | + BindTexture(null,true,resolution); |
---|
8235 | 8279 | return; |
---|
8236 | 8280 | } |
---|
8237 | 8281 | |
---|
8238 | 8282 | String bump = Object3D.GetBump(tex); |
---|
8239 | 8283 | |
---|
8240 | | - usedtextures.add(bump); |
---|
| 8284 | + usedtextures.add(tex); |
---|
8241 | 8285 | |
---|
8242 | 8286 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8243 | 8287 | { |
---|
.. | .. |
---|
8251 | 8295 | } |
---|
8252 | 8296 | |
---|
8253 | 8297 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8254 | | - BindTexture(tex.bumptexture, bump, true, resolution); |
---|
| 8298 | + BindTexture(tex, true, resolution); |
---|
8255 | 8299 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8256 | 8300 | } |
---|
8257 | 8301 | |
---|
.. | .. |
---|
8275 | 8319 | return fileExists; |
---|
8276 | 8320 | } |
---|
8277 | 8321 | |
---|
8278 | | - CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception |
---|
| 8322 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8279 | 8323 | { |
---|
8280 | 8324 | CacheTexture texturecache = null; |
---|
8281 | 8325 | |
---|
8282 | 8326 | if (tex != null) |
---|
8283 | 8327 | { |
---|
8284 | | - String texname = tex; |
---|
| 8328 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8329 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8330 | + |
---|
| 8331 | + if (texname.equals("") && texdata == null) |
---|
| 8332 | + { |
---|
| 8333 | + return null; |
---|
| 8334 | + } |
---|
8285 | 8335 | |
---|
8286 | 8336 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8287 | 8337 | |
---|
.. | .. |
---|
8291 | 8341 | // else |
---|
8292 | 8342 | // if (!texname.startsWith("/")) |
---|
8293 | 8343 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8294 | | - if (!FileExists(tex)) |
---|
| 8344 | + if (!FileExists(texname)) |
---|
8295 | 8345 | { |
---|
8296 | 8346 | texname = fallbackTextureName; |
---|
8297 | 8347 | } |
---|
8298 | 8348 | |
---|
8299 | 8349 | if (CACHETEXTURE) |
---|
8300 | 8350 | { |
---|
8301 | | - if (bim == null) |
---|
8302 | | - texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8351 | + if (texdata == null) |
---|
| 8352 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8303 | 8353 | else |
---|
8304 | | - texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8354 | + texturecache = bimtextures.get(texdata); |
---|
8305 | 8355 | } |
---|
8306 | 8356 | |
---|
8307 | | - if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8357 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
8308 | 8358 | { |
---|
8309 | 8359 | TextureData texturedata = null; |
---|
8310 | 8360 | |
---|
8311 | | - if (bim == null) |
---|
| 8361 | + if (texdata != null) |
---|
8312 | 8362 | { |
---|
| 8363 | + BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
8313 | 8364 | |
---|
| 8365 | + CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8366 | + |
---|
| 8367 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8368 | + bimtextures.put(texdata, texturecache); |
---|
8314 | 8369 | } |
---|
8315 | 8370 | else |
---|
8316 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8371 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8317 | 8372 | { |
---|
8318 | 8373 | assert(!bump); |
---|
8319 | 8374 | // if (bump) |
---|
.. | .. |
---|
8324 | 8379 | // } |
---|
8325 | 8380 | // else |
---|
8326 | 8381 | // { |
---|
8327 | | - texturecache = textures.get(tex); |
---|
| 8382 | + // texturecache = textures.get(texname); // suspicious |
---|
8328 | 8383 | if (texturecache == null) |
---|
8329 | 8384 | { |
---|
8330 | 8385 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8331 | 8386 | } |
---|
| 8387 | + else |
---|
| 8388 | + new Exception().printStackTrace(); |
---|
8332 | 8389 | // } |
---|
8333 | 8390 | } else |
---|
8334 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8391 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8335 | 8392 | { |
---|
8336 | 8393 | assert(bump); |
---|
8337 | | - texturecache = textures.get(tex); |
---|
| 8394 | + // texturecache = textures.get(texname); // suspicious |
---|
8338 | 8395 | if (texturecache == null) |
---|
8339 | 8396 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8397 | + else |
---|
| 8398 | + new Exception().printStackTrace(); |
---|
8340 | 8399 | } else |
---|
8341 | 8400 | { |
---|
8342 | 8401 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8344 | 8403 | // texture = GetResourceTexture("default.png"); |
---|
8345 | 8404 | //} else |
---|
8346 | 8405 | //{ |
---|
8347 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8406 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8348 | 8407 | { |
---|
8349 | | - texturecache = textures.get(tex); |
---|
| 8408 | + // texturecache = textures.get(texname); // suspicious |
---|
8350 | 8409 | if (texturecache == null) |
---|
8351 | 8410 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8411 | + else |
---|
| 8412 | + new Exception().printStackTrace(); |
---|
8352 | 8413 | } else |
---|
8353 | 8414 | { |
---|
8354 | 8415 | if (textureon) |
---|
.. | .. |
---|
8407 | 8468 | if (texturedata == null) |
---|
8408 | 8469 | throw new Exception(); |
---|
8409 | 8470 | |
---|
8410 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8471 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8411 | 8472 | //texture = GetTexture(tex, bump); |
---|
8412 | 8473 | } |
---|
8413 | 8474 | } |
---|
8414 | 8475 | //} |
---|
8415 | 8476 | } |
---|
8416 | 8477 | |
---|
8417 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8478 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8418 | 8479 | { |
---|
8419 | 8480 | //return false; |
---|
8420 | 8481 | |
---|
.. | .. |
---|
8436 | 8497 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8437 | 8498 | if (!cachefile.exists()) |
---|
8438 | 8499 | { |
---|
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)) |
---|
| 8500 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8448 | 8501 | { |
---|
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); |
---|
| 8502 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8503 | + |
---|
8479 | 8504 | ImageWriter writer = null; |
---|
8480 | 8505 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8481 | 8506 | if (iter.hasNext()) { |
---|
8482 | 8507 | writer = (ImageWriter)iter.next(); |
---|
8483 | 8508 | } |
---|
8484 | | - float compressionQuality = 0.9f; |
---|
| 8509 | + |
---|
| 8510 | + float compressionQuality = 0.85f; |
---|
8485 | 8511 | try |
---|
8486 | 8512 | { |
---|
8487 | 8513 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8498 | 8524 | } |
---|
8499 | 8525 | } |
---|
8500 | 8526 | } |
---|
8501 | | - |
---|
| 8527 | + |
---|
| 8528 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8529 | + |
---|
8502 | 8530 | //System.out.println("Texture = " + tex); |
---|
8503 | | - if (textures.containsKey(texname)) |
---|
| 8531 | + if (textures.containsKey(tex)) |
---|
8504 | 8532 | { |
---|
8505 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8533 | + CacheTexture thetex = textures.get(tex); |
---|
8506 | 8534 | thetex.texture.disable(); |
---|
8507 | 8535 | thetex.texture.dispose(); |
---|
8508 | | - textures.remove(texname); |
---|
| 8536 | + textures.remove(tex); |
---|
8509 | 8537 | } |
---|
8510 | 8538 | |
---|
8511 | 8539 | //texture.texturedata = texturedata; |
---|
8512 | | - textures.put(texname, texturecache); |
---|
| 8540 | + textures.put(tex, texturecache); |
---|
8513 | 8541 | |
---|
8514 | 8542 | // newtex = true; |
---|
8515 | 8543 | } |
---|
.. | .. |
---|
8528 | 8556 | return texturecache; |
---|
8529 | 8557 | } |
---|
8530 | 8558 | |
---|
8531 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8559 | + static void EmbedTextures(cTexture tex) |
---|
8532 | 8560 | { |
---|
8533 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8561 | + if (tex.pigmentdata == null) |
---|
| 8562 | + { |
---|
| 8563 | + String texname = Object3D.GetPigment(tex); |
---|
| 8564 | + |
---|
| 8565 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8566 | + |
---|
| 8567 | + if (texturecache != null) |
---|
| 8568 | + { |
---|
| 8569 | + tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); |
---|
| 8570 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8571 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8572 | + } |
---|
| 8573 | + } |
---|
| 8574 | + |
---|
| 8575 | + if (tex.bumpdata == null) |
---|
| 8576 | + { |
---|
| 8577 | + String texname = Object3D.GetBump(tex); |
---|
| 8578 | + |
---|
| 8579 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8580 | + |
---|
| 8581 | + if (texturecache != null) |
---|
| 8582 | + { |
---|
| 8583 | + tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); |
---|
| 8584 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8585 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8586 | + } |
---|
| 8587 | + } |
---|
| 8588 | + } |
---|
| 8589 | + |
---|
| 8590 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
| 8591 | + { |
---|
| 8592 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8534 | 8593 | |
---|
8535 | 8594 | if (bump) |
---|
8536 | 8595 | { |
---|
.. | .. |
---|
8546 | 8605 | return texture!=null?texture.texture:null; |
---|
8547 | 8606 | } |
---|
8548 | 8607 | |
---|
8549 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8608 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8550 | 8609 | { |
---|
8551 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8610 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8552 | 8611 | |
---|
8553 | 8612 | return texture!=null?texture.texturedata:null; |
---|
8554 | 8613 | } |
---|
8555 | 8614 | |
---|
8556 | | - boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8615 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8557 | 8616 | { |
---|
8558 | 8617 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8559 | 8618 | { |
---|
.. | .. |
---|
8562 | 8621 | |
---|
8563 | 8622 | //boolean newtex = false; |
---|
8564 | 8623 | |
---|
8565 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8624 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8566 | 8625 | |
---|
8567 | 8626 | if (texture == null) |
---|
8568 | 8627 | return false; |
---|
.. | .. |
---|
11049 | 11108 | |
---|
11050 | 11109 | try |
---|
11051 | 11110 | { |
---|
11052 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11111 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11053 | 11112 | } |
---|
11054 | 11113 | catch (Exception e) |
---|
11055 | 11114 | { |
---|
.. | .. |
---|
11705 | 11764 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11706 | 11765 | |
---|
11707 | 11766 | if (CLEANCACHE) |
---|
11708 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11767 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11709 | 11768 | { |
---|
11710 | | - String tex = e.nextElement(); |
---|
| 11769 | + cTexture tex = e.nextElement(); |
---|
11711 | 11770 | |
---|
11712 | 11771 | // System.out.println("Texture --------- " + tex); |
---|
11713 | 11772 | |
---|
11714 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11773 | + if (tex.equals("WHITE_NOISE:")) |
---|
11715 | 11774 | continue; |
---|
11716 | 11775 | |
---|
11717 | 11776 | if (!usedtextures.contains(tex)) |
---|
11718 | 11777 | { |
---|
| 11778 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11719 | 11779 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11720 | | - textures.get(tex).texture.dispose(); |
---|
11721 | | - textures.remove(tex); |
---|
| 11780 | + if (gettex != null) |
---|
| 11781 | + { |
---|
| 11782 | + gettex.texture.dispose(); |
---|
| 11783 | + texturepigment.remove(tex); |
---|
| 11784 | + } |
---|
| 11785 | + |
---|
| 11786 | + gettex = texturebump.get(tex); |
---|
| 11787 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11788 | + if (gettex != null) |
---|
| 11789 | + { |
---|
| 11790 | + gettex.texture.dispose(); |
---|
| 11791 | + texturebump.remove(tex); |
---|
| 11792 | + } |
---|
11722 | 11793 | } |
---|
11723 | 11794 | } |
---|
11724 | 11795 | } |
---|
.. | .. |
---|
14911 | 14982 | // break; |
---|
14912 | 14983 | case 'T': |
---|
14913 | 14984 | CACHETEXTURE ^= true; |
---|
14914 | | - textures.clear(); |
---|
| 14985 | + texturepigment.clear(); |
---|
| 14986 | + texturebump.clear(); |
---|
14915 | 14987 | // repaint(); |
---|
14916 | 14988 | break; |
---|
14917 | 14989 | case 'Y': |
---|