.. | .. |
---|
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 | |
---|
2408 | | - private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2441 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
2409 | 2442 | { |
---|
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; |
---|
| 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); |
---|
2445 | 2454 | } |
---|
2446 | 2455 | |
---|
2447 | 2456 | /**/ |
---|
.. | .. |
---|
2452 | 2461 | |
---|
2453 | 2462 | int resolution; |
---|
2454 | 2463 | |
---|
2455 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2464 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2456 | 2465 | { |
---|
2457 | | - texture = tex; |
---|
| 2466 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2467 | + texturedata = texdata; |
---|
2458 | 2468 | resolution = res; |
---|
2459 | 2469 | } |
---|
2460 | 2470 | } |
---|
2461 | 2471 | /**/ |
---|
2462 | 2472 | |
---|
2463 | 2473 | // 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>(); |
---|
| 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>(); |
---|
2467 | 2478 | |
---|
2468 | 2479 | int pigmentdepth = 0; |
---|
2469 | 2480 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
.. | .. |
---|
2471 | 2482 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2472 | 2483 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2473 | 2484 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2474 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2485 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2475 | 2486 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2476 | 2487 | |
---|
2477 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2488 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2478 | 2489 | { |
---|
2479 | 2490 | TextureData texturedata = null; |
---|
2480 | 2491 | |
---|
.. | .. |
---|
2493 | 2504 | if (bump) |
---|
2494 | 2505 | texturedata = ConvertBump(texturedata, false); |
---|
2495 | 2506 | |
---|
2496 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2497 | | - 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); |
---|
2498 | 2509 | |
---|
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); |
---|
| 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); |
---|
2501 | 2512 | |
---|
2502 | | - return texture; |
---|
| 2513 | + return texturedata; |
---|
2503 | 2514 | } |
---|
2504 | 2515 | |
---|
2505 | | - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2516 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
2506 | 2517 | { |
---|
2507 | 2518 | TextureData texturedata = null; |
---|
2508 | 2519 | |
---|
.. | .. |
---|
2510 | 2521 | { |
---|
2511 | 2522 | texturedata = |
---|
2512 | 2523 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2513 | | - name, |
---|
| 2524 | + bim, |
---|
2514 | 2525 | true); |
---|
2515 | 2526 | } catch (Exception e) |
---|
2516 | 2527 | { |
---|
.. | .. |
---|
2519 | 2530 | |
---|
2520 | 2531 | if (bump) |
---|
2521 | 2532 | 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; |
---|
| 2533 | + |
---|
| 2534 | + return texturedata; |
---|
2530 | 2535 | } |
---|
2531 | 2536 | |
---|
2532 | 2537 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
8014 | 8019 | pigment = null; |
---|
8015 | 8020 | } |
---|
8016 | 8021 | |
---|
8017 | | - ReleaseTexture(bump, true); |
---|
8018 | | - ReleaseTexture(pigment, false); |
---|
| 8022 | + ReleaseTexture(tex, true); |
---|
| 8023 | + ReleaseTexture(tex, false); |
---|
8019 | 8024 | } |
---|
8020 | 8025 | |
---|
8021 | 8026 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8044 | 8049 | pigment = null; |
---|
8045 | 8050 | } |
---|
8046 | 8051 | |
---|
8047 | | - ReleaseTexture(pigment, false); |
---|
| 8052 | + ReleaseTexture(tex, false); |
---|
8048 | 8053 | } |
---|
8049 | 8054 | |
---|
8050 | 8055 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8073 | 8078 | bump = null; |
---|
8074 | 8079 | } |
---|
8075 | 8080 | |
---|
8076 | | - ReleaseTexture(bump, true); |
---|
| 8081 | + ReleaseTexture(tex, true); |
---|
8077 | 8082 | } |
---|
8078 | 8083 | |
---|
8079 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8084 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8080 | 8085 | { |
---|
8081 | 8086 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8082 | 8087 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8087 | 8092 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8088 | 8093 | |
---|
8089 | 8094 | if (tex != null) |
---|
8090 | | - texture = textures.get(tex); |
---|
| 8095 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8091 | 8096 | |
---|
8092 | 8097 | // //assert( texture != null ); |
---|
8093 | 8098 | // if (texture == null) |
---|
.. | .. |
---|
8237 | 8242 | |
---|
8238 | 8243 | if (tex == null) |
---|
8239 | 8244 | { |
---|
8240 | | - BindTexture(null, null,false,resolution); |
---|
| 8245 | + BindTexture(null,false,resolution); |
---|
8241 | 8246 | return; |
---|
8242 | 8247 | } |
---|
8243 | 8248 | |
---|
8244 | 8249 | String pigment = Object3D.GetPigment(tex); |
---|
8245 | 8250 | |
---|
8246 | | - usedtextures.add(pigment); |
---|
| 8251 | + usedtextures.add(tex); |
---|
8247 | 8252 | |
---|
8248 | 8253 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8249 | 8254 | { |
---|
.. | .. |
---|
8257 | 8262 | } |
---|
8258 | 8263 | |
---|
8259 | 8264 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8260 | | - BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
| 8265 | + BindTexture(tex, false, resolution); |
---|
8261 | 8266 | } |
---|
8262 | 8267 | |
---|
8263 | 8268 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8270 | 8275 | |
---|
8271 | 8276 | if (tex == null) |
---|
8272 | 8277 | { |
---|
8273 | | - BindTexture(null, null,true,resolution); |
---|
| 8278 | + BindTexture(null,true,resolution); |
---|
8274 | 8279 | return; |
---|
8275 | 8280 | } |
---|
8276 | 8281 | |
---|
8277 | 8282 | String bump = Object3D.GetBump(tex); |
---|
8278 | 8283 | |
---|
8279 | | - usedtextures.add(bump); |
---|
| 8284 | + usedtextures.add(tex); |
---|
8280 | 8285 | |
---|
8281 | 8286 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8282 | 8287 | { |
---|
.. | .. |
---|
8290 | 8295 | } |
---|
8291 | 8296 | |
---|
8292 | 8297 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8293 | | - BindTexture(tex.bumptexture, bump, true, resolution); |
---|
| 8298 | + BindTexture(tex, true, resolution); |
---|
8294 | 8299 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8295 | 8300 | } |
---|
8296 | 8301 | |
---|
.. | .. |
---|
8314 | 8319 | return fileExists; |
---|
8315 | 8320 | } |
---|
8316 | 8321 | |
---|
8317 | | - 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 |
---|
8318 | 8323 | { |
---|
8319 | 8324 | CacheTexture texturecache = null; |
---|
8320 | 8325 | |
---|
8321 | 8326 | if (tex != null) |
---|
8322 | 8327 | { |
---|
8323 | | - 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 | + } |
---|
8324 | 8335 | |
---|
8325 | 8336 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8326 | 8337 | |
---|
.. | .. |
---|
8330 | 8341 | // else |
---|
8331 | 8342 | // if (!texname.startsWith("/")) |
---|
8332 | 8343 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8333 | | - if (!FileExists(tex)) |
---|
| 8344 | + if (!FileExists(texname)) |
---|
8334 | 8345 | { |
---|
8335 | 8346 | texname = fallbackTextureName; |
---|
8336 | 8347 | } |
---|
8337 | 8348 | |
---|
8338 | 8349 | if (CACHETEXTURE) |
---|
8339 | 8350 | { |
---|
8340 | | - if (bim == null) |
---|
8341 | | - texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8351 | + if (texdata == null) |
---|
| 8352 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8342 | 8353 | else |
---|
8343 | | - texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8354 | + texturecache = bimtextures.get(texdata); |
---|
8344 | 8355 | } |
---|
8345 | 8356 | |
---|
8346 | | - if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8357 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
8347 | 8358 | { |
---|
8348 | 8359 | TextureData texturedata = null; |
---|
8349 | 8360 | |
---|
8350 | | - if (bim != null) |
---|
| 8361 | + if (texdata != null) |
---|
8351 | 8362 | { |
---|
| 8363 | + BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8364 | + |
---|
| 8365 | + CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8366 | + |
---|
8352 | 8367 | texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8368 | + bimtextures.put(texdata, texturecache); |
---|
8353 | 8369 | } |
---|
8354 | 8370 | else |
---|
8355 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8371 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8356 | 8372 | { |
---|
8357 | 8373 | assert(!bump); |
---|
8358 | 8374 | // if (bump) |
---|
.. | .. |
---|
8363 | 8379 | // } |
---|
8364 | 8380 | // else |
---|
8365 | 8381 | // { |
---|
8366 | | - texturecache = textures.get(tex); |
---|
| 8382 | + // texturecache = textures.get(texname); // suspicious |
---|
8367 | 8383 | if (texturecache == null) |
---|
8368 | 8384 | { |
---|
8369 | 8385 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
.. | .. |
---|
8372 | 8388 | new Exception().printStackTrace(); |
---|
8373 | 8389 | // } |
---|
8374 | 8390 | } else |
---|
8375 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8391 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8376 | 8392 | { |
---|
8377 | 8393 | assert(bump); |
---|
8378 | | - texturecache = textures.get(tex); |
---|
| 8394 | + // texturecache = textures.get(texname); // suspicious |
---|
8379 | 8395 | if (texturecache == null) |
---|
8380 | 8396 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8381 | 8397 | else |
---|
.. | .. |
---|
8387 | 8403 | // texture = GetResourceTexture("default.png"); |
---|
8388 | 8404 | //} else |
---|
8389 | 8405 | //{ |
---|
8390 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8406 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8391 | 8407 | { |
---|
8392 | | - texturecache = textures.get(tex); |
---|
| 8408 | + // texturecache = textures.get(texname); // suspicious |
---|
8393 | 8409 | if (texturecache == null) |
---|
8394 | 8410 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
8395 | 8411 | else |
---|
.. | .. |
---|
8452 | 8468 | if (texturedata == null) |
---|
8453 | 8469 | throw new Exception(); |
---|
8454 | 8470 | |
---|
8455 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8471 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8456 | 8472 | //texture = GetTexture(tex, bump); |
---|
8457 | 8473 | } |
---|
8458 | 8474 | } |
---|
8459 | 8475 | //} |
---|
8460 | 8476 | } |
---|
8461 | 8477 | |
---|
8462 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8478 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8463 | 8479 | { |
---|
8464 | 8480 | //return false; |
---|
8465 | | - assert(bim == null); |
---|
8466 | 8481 | |
---|
8467 | 8482 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8468 | 8483 | if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
.. | .. |
---|
8509 | 8524 | } |
---|
8510 | 8525 | } |
---|
8511 | 8526 | } |
---|
8512 | | - |
---|
| 8527 | + |
---|
| 8528 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8529 | + |
---|
8513 | 8530 | //System.out.println("Texture = " + tex); |
---|
8514 | | - if (textures.containsKey(texname)) |
---|
| 8531 | + if (textures.containsKey(tex)) |
---|
8515 | 8532 | { |
---|
8516 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8533 | + CacheTexture thetex = textures.get(tex); |
---|
8517 | 8534 | thetex.texture.disable(); |
---|
8518 | 8535 | thetex.texture.dispose(); |
---|
8519 | | - textures.remove(texname); |
---|
| 8536 | + textures.remove(tex); |
---|
8520 | 8537 | } |
---|
8521 | 8538 | |
---|
8522 | 8539 | //texture.texturedata = texturedata; |
---|
8523 | | - textures.put(texname, texturecache); |
---|
| 8540 | + textures.put(tex, texturecache); |
---|
8524 | 8541 | |
---|
8525 | 8542 | // newtex = true; |
---|
8526 | 8543 | } |
---|
.. | .. |
---|
8541 | 8558 | |
---|
8542 | 8559 | static void EmbedTextures(cTexture tex) |
---|
8543 | 8560 | { |
---|
| 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 | + } |
---|
8544 | 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 | + } |
---|
8545 | 8588 | } |
---|
8546 | 8589 | |
---|
8547 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8590 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8548 | 8591 | { |
---|
8549 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8592 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8550 | 8593 | |
---|
8551 | 8594 | if (bump) |
---|
8552 | 8595 | { |
---|
.. | .. |
---|
8562 | 8605 | return texture!=null?texture.texture:null; |
---|
8563 | 8606 | } |
---|
8564 | 8607 | |
---|
8565 | | - 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 |
---|
8566 | 8609 | { |
---|
8567 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8610 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8568 | 8611 | |
---|
8569 | 8612 | return texture!=null?texture.texturedata:null; |
---|
8570 | 8613 | } |
---|
8571 | 8614 | |
---|
8572 | | - 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 |
---|
8573 | 8616 | { |
---|
8574 | 8617 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8575 | 8618 | { |
---|
.. | .. |
---|
8578 | 8621 | |
---|
8579 | 8622 | //boolean newtex = false; |
---|
8580 | 8623 | |
---|
8581 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8624 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8582 | 8625 | |
---|
8583 | 8626 | if (texture == null) |
---|
8584 | 8627 | return false; |
---|
.. | .. |
---|
11065 | 11108 | |
---|
11066 | 11109 | try |
---|
11067 | 11110 | { |
---|
11068 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11111 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11069 | 11112 | } |
---|
11070 | 11113 | catch (Exception e) |
---|
11071 | 11114 | { |
---|
.. | .. |
---|
11721 | 11764 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11722 | 11765 | |
---|
11723 | 11766 | if (CLEANCACHE) |
---|
11724 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11767 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11725 | 11768 | { |
---|
11726 | | - String tex = e.nextElement(); |
---|
| 11769 | + cTexture tex = e.nextElement(); |
---|
11727 | 11770 | |
---|
11728 | 11771 | // System.out.println("Texture --------- " + tex); |
---|
11729 | 11772 | |
---|
11730 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11773 | + if (tex.equals("WHITE_NOISE:")) |
---|
11731 | 11774 | continue; |
---|
11732 | 11775 | |
---|
11733 | 11776 | if (!usedtextures.contains(tex)) |
---|
11734 | 11777 | { |
---|
| 11778 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11735 | 11779 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11736 | | - textures.get(tex).texture.dispose(); |
---|
11737 | | - 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 | + } |
---|
11738 | 11793 | } |
---|
11739 | 11794 | } |
---|
11740 | 11795 | } |
---|
.. | .. |
---|
14927 | 14982 | // break; |
---|
14928 | 14983 | case 'T': |
---|
14929 | 14984 | CACHETEXTURE ^= true; |
---|
14930 | | - textures.clear(); |
---|
| 14985 | + texturepigment.clear(); |
---|
| 14986 | + texturebump.clear(); |
---|
14931 | 14987 | // repaint(); |
---|
14932 | 14988 | break; |
---|
14933 | 14989 | case 'Y': |
---|