.. | .. |
---|
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; |
---|
.. | .. |
---|
60 | 93 | //boolean REDUCETEXTURE = true; |
---|
61 | 94 | boolean CACHETEXTURE = true; |
---|
62 | 95 | boolean CLEANCACHE = false; // true; |
---|
63 | | - boolean MIPMAP = false; // true; |
---|
| 96 | + boolean MIPMAP = true; // false; // true; |
---|
64 | 97 | boolean COMPRESSTEXTURE = false; |
---|
65 | 98 | boolean KOMPACTTEXTURE = false; // true; |
---|
66 | 99 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
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/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2426 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2427 | | - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, 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>(); |
---|
| 2478 | + |
---|
2428 | 2479 | int pigmentdepth = 0; |
---|
2429 | 2480 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2430 | 2481 | int bumpdepth = 0; |
---|
2431 | 2482 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2432 | 2483 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2433 | 2484 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2434 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2485 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2435 | 2486 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2436 | 2487 | |
---|
2437 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2488 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2438 | 2489 | { |
---|
2439 | 2490 | TextureData texturedata = null; |
---|
2440 | 2491 | |
---|
.. | .. |
---|
2453 | 2504 | if (bump) |
---|
2454 | 2505 | texturedata = ConvertBump(texturedata, false); |
---|
2455 | 2506 | |
---|
2456 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2457 | | - 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); |
---|
2458 | 2509 | |
---|
2459 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2460 | | - 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); |
---|
2461 | 2512 | |
---|
2462 | | - return texture; |
---|
| 2513 | + return texturedata; |
---|
| 2514 | + } |
---|
| 2515 | + |
---|
| 2516 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
| 2517 | + { |
---|
| 2518 | + TextureData texturedata = null; |
---|
| 2519 | + |
---|
| 2520 | + try |
---|
| 2521 | + { |
---|
| 2522 | + texturedata = |
---|
| 2523 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2524 | + bim, |
---|
| 2525 | + true); |
---|
| 2526 | + } catch (Exception e) |
---|
| 2527 | + { |
---|
| 2528 | + throw new javax.media.opengl.GLException(e); |
---|
| 2529 | + } |
---|
| 2530 | + |
---|
| 2531 | + if (bump) |
---|
| 2532 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2533 | + |
---|
| 2534 | + return texturedata; |
---|
2463 | 2535 | } |
---|
2464 | 2536 | |
---|
2465 | 2537 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
3532 | 3604 | |
---|
3533 | 3605 | System.out.println("LOADING TEXTURE : " + name); |
---|
3534 | 3606 | |
---|
| 3607 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3608 | + |
---|
3535 | 3609 | // |
---|
3536 | 3610 | if (false) // compressbit > 0) |
---|
3537 | 3611 | { |
---|
.. | .. |
---|
7945 | 8019 | pigment = null; |
---|
7946 | 8020 | } |
---|
7947 | 8021 | |
---|
7948 | | - ReleaseTexture(bump, true); |
---|
7949 | | - ReleaseTexture(pigment, false); |
---|
| 8022 | + ReleaseTexture(tex, true); |
---|
| 8023 | + ReleaseTexture(tex, false); |
---|
7950 | 8024 | } |
---|
7951 | 8025 | |
---|
7952 | 8026 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
7975 | 8049 | pigment = null; |
---|
7976 | 8050 | } |
---|
7977 | 8051 | |
---|
7978 | | - ReleaseTexture(pigment, false); |
---|
| 8052 | + ReleaseTexture(tex, false); |
---|
7979 | 8053 | } |
---|
7980 | 8054 | |
---|
7981 | 8055 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8004 | 8078 | bump = null; |
---|
8005 | 8079 | } |
---|
8006 | 8080 | |
---|
8007 | | - ReleaseTexture(bump, true); |
---|
| 8081 | + ReleaseTexture(tex, true); |
---|
8008 | 8082 | } |
---|
8009 | 8083 | |
---|
8010 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8084 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8011 | 8085 | { |
---|
8012 | 8086 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8013 | 8087 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8018 | 8092 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8019 | 8093 | |
---|
8020 | 8094 | if (tex != null) |
---|
8021 | | - texture = textures.get(tex); |
---|
| 8095 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8022 | 8096 | |
---|
8023 | 8097 | // //assert( texture != null ); |
---|
8024 | 8098 | // if (texture == null) |
---|
.. | .. |
---|
8112 | 8186 | |
---|
8113 | 8187 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8114 | 8188 | { |
---|
8115 | | - if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8116 | | - ambientOcclusion ) // || !textureon) |
---|
8117 | | - { |
---|
8118 | | - return; // false; |
---|
8119 | | - } |
---|
8120 | | - |
---|
8121 | | - if (tex == null) |
---|
8122 | | - { |
---|
8123 | | - BindTexture(null,false,resolution); |
---|
8124 | | - BindTexture(null,true,resolution); |
---|
8125 | | - return; |
---|
8126 | | - } |
---|
| 8189 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8190 | +// ambientOcclusion ) // || !textureon) |
---|
| 8191 | +// { |
---|
| 8192 | +// return; // false; |
---|
| 8193 | +// } |
---|
| 8194 | +// |
---|
| 8195 | +// if (tex == null) |
---|
| 8196 | +// { |
---|
| 8197 | +// BindTexture(null,false,resolution); |
---|
| 8198 | +// BindTexture(null,true,resolution); |
---|
| 8199 | +// return; |
---|
| 8200 | +// } |
---|
| 8201 | +// |
---|
| 8202 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8203 | +// String bump = Object3D.GetBump(tex); |
---|
| 8204 | +// |
---|
| 8205 | +// usedtextures.add(pigment); |
---|
| 8206 | +// usedtextures.add(bump); |
---|
| 8207 | +// |
---|
| 8208 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8209 | +// { |
---|
| 8210 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8211 | +// // System.out.println("; bump = " + bump); |
---|
| 8212 | +// } |
---|
| 8213 | +// |
---|
| 8214 | +// if (bump.equals("")) |
---|
| 8215 | +// { |
---|
| 8216 | +// bump = null; |
---|
| 8217 | +// } |
---|
| 8218 | +// if (pigment.equals("")) |
---|
| 8219 | +// { |
---|
| 8220 | +// pigment = null; |
---|
| 8221 | +// } |
---|
| 8222 | +// |
---|
| 8223 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8224 | +// BindTexture(pigment, false, resolution); |
---|
| 8225 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8226 | +// BindTexture(bump, true, resolution); |
---|
| 8227 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8228 | +// |
---|
| 8229 | +// return; // true; |
---|
8127 | 8230 | |
---|
8128 | | - String pigment = Object3D.GetPigment(tex); |
---|
8129 | | - String bump = Object3D.GetBump(tex); |
---|
8130 | | - |
---|
8131 | | - usedtextures.put(pigment, pigment); |
---|
8132 | | - usedtextures.put(bump, bump); |
---|
8133 | | - |
---|
8134 | | - //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8135 | | - { |
---|
8136 | | - // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8137 | | - // System.out.println("; bump = " + bump); |
---|
8138 | | - } |
---|
8139 | | - |
---|
8140 | | - if (bump.equals("")) |
---|
8141 | | - { |
---|
8142 | | - bump = null; |
---|
8143 | | - } |
---|
8144 | | - if (pigment.equals("")) |
---|
8145 | | - { |
---|
8146 | | - pigment = null; |
---|
8147 | | - } |
---|
8148 | | - |
---|
8149 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8150 | | - BindTexture(pigment, false, resolution); |
---|
8151 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8152 | | - BindTexture(bump, true, resolution); |
---|
8153 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8154 | | - |
---|
8155 | | - return; // true; |
---|
| 8231 | + BindPigmentTexture(tex, resolution); |
---|
| 8232 | + BindBumpTexture(tex, resolution); |
---|
8156 | 8233 | } |
---|
8157 | 8234 | |
---|
8158 | 8235 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8171 | 8248 | |
---|
8172 | 8249 | String pigment = Object3D.GetPigment(tex); |
---|
8173 | 8250 | |
---|
8174 | | - usedtextures.put(pigment, pigment); |
---|
| 8251 | + usedtextures.add(tex); |
---|
8175 | 8252 | |
---|
8176 | 8253 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8177 | 8254 | { |
---|
.. | .. |
---|
8185 | 8262 | } |
---|
8186 | 8263 | |
---|
8187 | 8264 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8188 | | - BindTexture(pigment, false, resolution); |
---|
| 8265 | + BindTexture(tex, false, resolution); |
---|
8189 | 8266 | } |
---|
8190 | 8267 | |
---|
8191 | 8268 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8204 | 8281 | |
---|
8205 | 8282 | String bump = Object3D.GetBump(tex); |
---|
8206 | 8283 | |
---|
8207 | | - usedtextures.put(bump, bump); |
---|
| 8284 | + usedtextures.add(tex); |
---|
8208 | 8285 | |
---|
8209 | 8286 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8210 | 8287 | { |
---|
.. | .. |
---|
8218 | 8295 | } |
---|
8219 | 8296 | |
---|
8220 | 8297 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8221 | | - BindTexture(bump, true, resolution); |
---|
| 8298 | + BindTexture(tex, true, resolution); |
---|
8222 | 8299 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8223 | 8300 | } |
---|
8224 | 8301 | |
---|
.. | .. |
---|
8242 | 8319 | return fileExists; |
---|
8243 | 8320 | } |
---|
8244 | 8321 | |
---|
8245 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8322 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8246 | 8323 | { |
---|
8247 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8324 | + CacheTexture texturecache = null; |
---|
8248 | 8325 | |
---|
8249 | 8326 | if (tex != null) |
---|
8250 | 8327 | { |
---|
8251 | | - 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 | + } |
---|
8252 | 8335 | |
---|
8253 | 8336 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8254 | 8337 | |
---|
.. | .. |
---|
8258 | 8341 | // else |
---|
8259 | 8342 | // if (!texname.startsWith("/")) |
---|
8260 | 8343 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8261 | | - if (!FileExists(tex)) |
---|
| 8344 | + if (!FileExists(texname)) |
---|
8262 | 8345 | { |
---|
8263 | 8346 | texname = fallbackTextureName; |
---|
8264 | 8347 | } |
---|
8265 | 8348 | |
---|
8266 | 8349 | if (CACHETEXTURE) |
---|
8267 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8268 | | - |
---|
8269 | | - TextureData texturedata = null; |
---|
8270 | | - |
---|
8271 | | - if (texture == null || texture.resolution < resolution) |
---|
8272 | 8350 | { |
---|
8273 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8351 | + if (texdata == null) |
---|
| 8352 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
| 8353 | + else |
---|
| 8354 | + texturecache = bimtextures.get(texdata); |
---|
| 8355 | + } |
---|
| 8356 | + |
---|
| 8357 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
| 8358 | + { |
---|
| 8359 | + TextureData texturedata = null; |
---|
| 8360 | + |
---|
| 8361 | + if (texdata != null) |
---|
| 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 | + |
---|
| 8367 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8368 | + bimtextures.put(texdata, texturecache); |
---|
| 8369 | + } |
---|
| 8370 | + else |
---|
| 8371 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8274 | 8372 | { |
---|
8275 | 8373 | assert(!bump); |
---|
8276 | 8374 | // if (bump) |
---|
.. | .. |
---|
8281 | 8379 | // } |
---|
8282 | 8380 | // else |
---|
8283 | 8381 | // { |
---|
8284 | | - texture = textures.get(tex); |
---|
8285 | | - if (texture == null) |
---|
| 8382 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8383 | + if (texturecache == null) |
---|
8286 | 8384 | { |
---|
8287 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8385 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8288 | 8386 | } |
---|
| 8387 | + else |
---|
| 8388 | + new Exception().printStackTrace(); |
---|
8289 | 8389 | // } |
---|
8290 | 8390 | } else |
---|
8291 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8391 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8292 | 8392 | { |
---|
8293 | 8393 | assert(bump); |
---|
8294 | | - texture = textures.get(tex); |
---|
8295 | | - if (texture == null) |
---|
8296 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8394 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8395 | + if (texturecache == null) |
---|
| 8396 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8397 | + else |
---|
| 8398 | + new Exception().printStackTrace(); |
---|
8297 | 8399 | } else |
---|
8298 | 8400 | { |
---|
8299 | 8401 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8301 | 8403 | // texture = GetResourceTexture("default.png"); |
---|
8302 | 8404 | //} else |
---|
8303 | 8405 | //{ |
---|
8304 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8406 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8305 | 8407 | { |
---|
8306 | | - texture = textures.get(tex); |
---|
8307 | | - if (texture == null) |
---|
8308 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8408 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8409 | + if (texturecache == null) |
---|
| 8410 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8411 | + else |
---|
| 8412 | + new Exception().printStackTrace(); |
---|
8309 | 8413 | } else |
---|
8310 | 8414 | { |
---|
8311 | 8415 | if (textureon) |
---|
.. | .. |
---|
8364 | 8468 | if (texturedata == null) |
---|
8365 | 8469 | throw new Exception(); |
---|
8366 | 8470 | |
---|
8367 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8471 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8368 | 8472 | //texture = GetTexture(tex, bump); |
---|
8369 | 8473 | } |
---|
8370 | 8474 | } |
---|
8371 | 8475 | //} |
---|
8372 | 8476 | } |
---|
8373 | 8477 | |
---|
8374 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8478 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8375 | 8479 | { |
---|
8376 | 8480 | //return false; |
---|
8377 | 8481 | |
---|
8378 | 8482 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8379 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8483 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8380 | 8484 | { |
---|
8381 | 8485 | // String ext = "_highres"; |
---|
8382 | 8486 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8393 | 8497 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8394 | 8498 | if (!cachefile.exists()) |
---|
8395 | 8499 | { |
---|
8396 | | - // cache to disk |
---|
8397 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8398 | | - //buffers[0]. |
---|
8399 | | - |
---|
8400 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8401 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8402 | | - |
---|
8403 | | - // squared size heuristic... |
---|
8404 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8500 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8405 | 8501 | { |
---|
8406 | | - for (int i=pixels.length; --i>=0;) |
---|
8407 | | - { |
---|
8408 | | - int i3 = i*3; |
---|
8409 | | - pixels[i] = 0xFF; |
---|
8410 | | - pixels[i] <<= 8; |
---|
8411 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8412 | | - pixels[i] <<= 8; |
---|
8413 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8414 | | - pixels[i] <<= 8; |
---|
8415 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8416 | | - } |
---|
8417 | | - |
---|
8418 | | - /* |
---|
8419 | | - int r=0,g=0,b=0,a=0; |
---|
8420 | | - for (int i=0; i<width; i++) |
---|
8421 | | - for (int j=0; j<height; j++) |
---|
8422 | | - { |
---|
8423 | | - int index = j*width+i; |
---|
8424 | | - int p = pixels[index]; |
---|
8425 | | - a = ((p>>24) & 0xFF); |
---|
8426 | | - r = ((p>>16) & 0xFF); |
---|
8427 | | - g = ((p>>8) & 0xFF); |
---|
8428 | | - b = (p & 0xFF); |
---|
8429 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8430 | | - } |
---|
8431 | | - /**/ |
---|
8432 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8433 | | - int height = width; |
---|
8434 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8435 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8502 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8503 | + |
---|
8436 | 8504 | ImageWriter writer = null; |
---|
8437 | 8505 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8438 | 8506 | if (iter.hasNext()) { |
---|
8439 | 8507 | writer = (ImageWriter)iter.next(); |
---|
8440 | 8508 | } |
---|
8441 | | - float compressionQuality = 0.9f; |
---|
| 8509 | + |
---|
| 8510 | + float compressionQuality = 0.85f; |
---|
8442 | 8511 | try |
---|
8443 | 8512 | { |
---|
8444 | 8513 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8455 | 8524 | } |
---|
8456 | 8525 | } |
---|
8457 | 8526 | } |
---|
8458 | | - |
---|
| 8527 | + |
---|
| 8528 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8529 | + |
---|
8459 | 8530 | //System.out.println("Texture = " + tex); |
---|
8460 | | - if (textures.containsKey(texname)) |
---|
| 8531 | + if (textures.containsKey(tex)) |
---|
8461 | 8532 | { |
---|
8462 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8533 | + CacheTexture thetex = textures.get(tex); |
---|
8463 | 8534 | thetex.texture.disable(); |
---|
8464 | 8535 | thetex.texture.dispose(); |
---|
8465 | | - textures.remove(texname); |
---|
| 8536 | + textures.remove(tex); |
---|
8466 | 8537 | } |
---|
8467 | 8538 | |
---|
8468 | | - texture.texturedata = texturedata; |
---|
8469 | | - textures.put(texname, texture); |
---|
| 8539 | + //texture.texturedata = texturedata; |
---|
| 8540 | + textures.put(tex, texturecache); |
---|
8470 | 8541 | |
---|
8471 | 8542 | // newtex = true; |
---|
8472 | 8543 | } |
---|
.. | .. |
---|
8482 | 8553 | } |
---|
8483 | 8554 | } |
---|
8484 | 8555 | |
---|
8485 | | - return texture; |
---|
| 8556 | + return texturecache; |
---|
8486 | 8557 | } |
---|
8487 | 8558 | |
---|
8488 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8559 | + static void EmbedTextures(cTexture tex) |
---|
| 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 | + } |
---|
| 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 |
---|
8489 | 8591 | { |
---|
8490 | 8592 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8491 | 8593 | |
---|
.. | .. |
---|
8503 | 8605 | return texture!=null?texture.texture:null; |
---|
8504 | 8606 | } |
---|
8505 | 8607 | |
---|
8506 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(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 |
---|
8507 | 8609 | { |
---|
8508 | 8610 | CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8509 | 8611 | |
---|
8510 | 8612 | return texture!=null?texture.texturedata:null; |
---|
8511 | 8613 | } |
---|
8512 | 8614 | |
---|
8513 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8615 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8514 | 8616 | { |
---|
8515 | 8617 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8516 | 8618 | { |
---|
.. | .. |
---|
11662 | 11764 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11663 | 11765 | |
---|
11664 | 11766 | if (CLEANCACHE) |
---|
11665 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11767 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11666 | 11768 | { |
---|
11667 | | - String tex = e.nextElement(); |
---|
| 11769 | + cTexture tex = e.nextElement(); |
---|
11668 | 11770 | |
---|
11669 | 11771 | // System.out.println("Texture --------- " + tex); |
---|
11670 | 11772 | |
---|
11671 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11773 | + if (tex.equals("WHITE_NOISE:")) |
---|
11672 | 11774 | continue; |
---|
11673 | 11775 | |
---|
11674 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11776 | + if (!usedtextures.contains(tex)) |
---|
11675 | 11777 | { |
---|
| 11778 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11676 | 11779 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11677 | | - textures.get(tex).texture.dispose(); |
---|
11678 | | - 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 | + } |
---|
11679 | 11793 | } |
---|
11680 | 11794 | } |
---|
11681 | 11795 | } |
---|
.. | .. |
---|
14868 | 14982 | // break; |
---|
14869 | 14983 | case 'T': |
---|
14870 | 14984 | CACHETEXTURE ^= true; |
---|
14871 | | - textures.clear(); |
---|
| 14985 | + texturepigment.clear(); |
---|
| 14986 | + texturebump.clear(); |
---|
14872 | 14987 | // repaint(); |
---|
14873 | 14988 | break; |
---|
14874 | 14989 | case 'Y': |
---|