| .. | .. |
|---|
| 60 | 60 | //boolean REDUCETEXTURE = true; |
|---|
| 61 | 61 | boolean CACHETEXTURE = true; |
|---|
| 62 | 62 | boolean CLEANCACHE = false; // true; |
|---|
| 63 | | - boolean MIPMAP = false; // true; |
|---|
| 63 | + boolean MIPMAP = true; // false; // true; |
|---|
| 64 | 64 | boolean COMPRESSTEXTURE = false; |
|---|
| 65 | 65 | boolean KOMPACTTEXTURE = false; // true; |
|---|
| 66 | 66 | boolean RESIZETEXTURE = false; |
|---|
| .. | .. |
|---|
| 2422 | 2422 | /**/ |
|---|
| 2423 | 2423 | |
|---|
| 2424 | 2424 | // 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>(); |
|---|
| 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>(); |
|---|
| 2428 | + |
|---|
| 2428 | 2429 | int pigmentdepth = 0; |
|---|
| 2429 | 2430 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
|---|
| 2430 | 2431 | int bumpdepth = 0; |
|---|
| .. | .. |
|---|
| 2446 | 2447 | true, |
|---|
| 2447 | 2448 | com.sun.opengl.util.texture.TextureIO.PNG); |
|---|
| 2448 | 2449 | } catch (java.io.IOException e) |
|---|
| 2450 | + { |
|---|
| 2451 | + throw new javax.media.opengl.GLException(e); |
|---|
| 2452 | + } |
|---|
| 2453 | + |
|---|
| 2454 | + if (bump) |
|---|
| 2455 | + texturedata = ConvertBump(texturedata, false); |
|---|
| 2456 | + |
|---|
| 2457 | + com.sun.opengl.util.texture.Texture texture = |
|---|
| 2458 | + com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
|---|
| 2459 | + |
|---|
| 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); |
|---|
| 2462 | + |
|---|
| 2463 | + return texture; |
|---|
| 2464 | + } |
|---|
| 2465 | + |
|---|
| 2466 | + com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
|---|
| 2467 | + { |
|---|
| 2468 | + TextureData texturedata = null; |
|---|
| 2469 | + |
|---|
| 2470 | + try |
|---|
| 2471 | + { |
|---|
| 2472 | + texturedata = |
|---|
| 2473 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
|---|
| 2474 | + name, |
|---|
| 2475 | + true); |
|---|
| 2476 | + } catch (Exception e) |
|---|
| 2449 | 2477 | { |
|---|
| 2450 | 2478 | throw new javax.media.opengl.GLException(e); |
|---|
| 2451 | 2479 | } |
|---|
| .. | .. |
|---|
| 3532 | 3560 | |
|---|
| 3533 | 3561 | System.out.println("LOADING TEXTURE : " + name); |
|---|
| 3534 | 3562 | |
|---|
| 3563 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
|---|
| 3564 | + |
|---|
| 3535 | 3565 | // |
|---|
| 3536 | 3566 | if (false) // compressbit > 0) |
|---|
| 3537 | 3567 | { |
|---|
| .. | .. |
|---|
| 8112 | 8142 | |
|---|
| 8113 | 8143 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
|---|
| 8114 | 8144 | { |
|---|
| 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 | | - } |
|---|
| 8145 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
|---|
| 8146 | +// ambientOcclusion ) // || !textureon) |
|---|
| 8147 | +// { |
|---|
| 8148 | +// return; // false; |
|---|
| 8149 | +// } |
|---|
| 8150 | +// |
|---|
| 8151 | +// if (tex == null) |
|---|
| 8152 | +// { |
|---|
| 8153 | +// BindTexture(null,false,resolution); |
|---|
| 8154 | +// BindTexture(null,true,resolution); |
|---|
| 8155 | +// return; |
|---|
| 8156 | +// } |
|---|
| 8157 | +// |
|---|
| 8158 | +// String pigment = Object3D.GetPigment(tex); |
|---|
| 8159 | +// String bump = Object3D.GetBump(tex); |
|---|
| 8160 | +// |
|---|
| 8161 | +// usedtextures.add(pigment); |
|---|
| 8162 | +// usedtextures.add(bump); |
|---|
| 8163 | +// |
|---|
| 8164 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
|---|
| 8165 | +// { |
|---|
| 8166 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
|---|
| 8167 | +// // System.out.println("; bump = " + bump); |
|---|
| 8168 | +// } |
|---|
| 8169 | +// |
|---|
| 8170 | +// if (bump.equals("")) |
|---|
| 8171 | +// { |
|---|
| 8172 | +// bump = null; |
|---|
| 8173 | +// } |
|---|
| 8174 | +// if (pigment.equals("")) |
|---|
| 8175 | +// { |
|---|
| 8176 | +// pigment = null; |
|---|
| 8177 | +// } |
|---|
| 8178 | +// |
|---|
| 8179 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
|---|
| 8180 | +// BindTexture(pigment, false, resolution); |
|---|
| 8181 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
|---|
| 8182 | +// BindTexture(bump, true, resolution); |
|---|
| 8183 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
|---|
| 8184 | +// |
|---|
| 8185 | +// return; // true; |
|---|
| 8127 | 8186 | |
|---|
| 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; |
|---|
| 8187 | + BindPigmentTexture(tex, resolution); |
|---|
| 8188 | + BindBumpTexture(tex, resolution); |
|---|
| 8156 | 8189 | } |
|---|
| 8157 | 8190 | |
|---|
| 8158 | 8191 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
|---|
| .. | .. |
|---|
| 8165 | 8198 | |
|---|
| 8166 | 8199 | if (tex == null) |
|---|
| 8167 | 8200 | { |
|---|
| 8168 | | - BindTexture(null,false,resolution); |
|---|
| 8201 | + BindTexture(null, null,false,resolution); |
|---|
| 8169 | 8202 | return; |
|---|
| 8170 | 8203 | } |
|---|
| 8171 | 8204 | |
|---|
| 8172 | 8205 | String pigment = Object3D.GetPigment(tex); |
|---|
| 8173 | 8206 | |
|---|
| 8174 | | - usedtextures.put(pigment, pigment); |
|---|
| 8207 | + usedtextures.add(pigment); |
|---|
| 8175 | 8208 | |
|---|
| 8176 | 8209 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
|---|
| 8177 | 8210 | { |
|---|
| .. | .. |
|---|
| 8185 | 8218 | } |
|---|
| 8186 | 8219 | |
|---|
| 8187 | 8220 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
|---|
| 8188 | | - BindTexture(pigment, false, resolution); |
|---|
| 8221 | + BindTexture(tex.pigmenttexture, pigment, false, resolution); |
|---|
| 8189 | 8222 | } |
|---|
| 8190 | 8223 | |
|---|
| 8191 | 8224 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
|---|
| .. | .. |
|---|
| 8198 | 8231 | |
|---|
| 8199 | 8232 | if (tex == null) |
|---|
| 8200 | 8233 | { |
|---|
| 8201 | | - BindTexture(null,true,resolution); |
|---|
| 8234 | + BindTexture(null, null,true,resolution); |
|---|
| 8202 | 8235 | return; |
|---|
| 8203 | 8236 | } |
|---|
| 8204 | 8237 | |
|---|
| 8205 | 8238 | String bump = Object3D.GetBump(tex); |
|---|
| 8206 | 8239 | |
|---|
| 8207 | | - usedtextures.put(bump, bump); |
|---|
| 8240 | + usedtextures.add(bump); |
|---|
| 8208 | 8241 | |
|---|
| 8209 | 8242 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
|---|
| 8210 | 8243 | { |
|---|
| .. | .. |
|---|
| 8218 | 8251 | } |
|---|
| 8219 | 8252 | |
|---|
| 8220 | 8253 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
|---|
| 8221 | | - BindTexture(bump, true, resolution); |
|---|
| 8254 | + BindTexture(tex.bumptexture, bump, true, resolution); |
|---|
| 8222 | 8255 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
|---|
| 8223 | 8256 | } |
|---|
| 8224 | 8257 | |
|---|
| .. | .. |
|---|
| 8242 | 8275 | return fileExists; |
|---|
| 8243 | 8276 | } |
|---|
| 8244 | 8277 | |
|---|
| 8245 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
|---|
| 8278 | + CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception |
|---|
| 8246 | 8279 | { |
|---|
| 8247 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
|---|
| 8280 | + CacheTexture texturecache = null; |
|---|
| 8248 | 8281 | |
|---|
| 8249 | 8282 | if (tex != null) |
|---|
| 8250 | 8283 | { |
|---|
| .. | .. |
|---|
| 8264 | 8297 | } |
|---|
| 8265 | 8298 | |
|---|
| 8266 | 8299 | if (CACHETEXTURE) |
|---|
| 8267 | | - texture = textures.get(texname); // TEXTURE CACHE |
|---|
| 8268 | | - |
|---|
| 8269 | | - TextureData texturedata = null; |
|---|
| 8270 | | - |
|---|
| 8271 | | - if (texture == null || texture.resolution < resolution) |
|---|
| 8272 | 8300 | { |
|---|
| 8301 | + if (bim == null) |
|---|
| 8302 | + texturecache = textures.get(texname); // TEXTURE CACHE |
|---|
| 8303 | + else |
|---|
| 8304 | + texturecache = bimtextures.get(bim); // TEXTURE CACHE |
|---|
| 8305 | + } |
|---|
| 8306 | + |
|---|
| 8307 | + if (texturecache == null || texturecache.resolution < resolution) |
|---|
| 8308 | + { |
|---|
| 8309 | + TextureData texturedata = null; |
|---|
| 8310 | + |
|---|
| 8311 | + if (bim == null) |
|---|
| 8312 | + { |
|---|
| 8313 | + |
|---|
| 8314 | + } |
|---|
| 8315 | + else |
|---|
| 8273 | 8316 | if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
|---|
| 8274 | 8317 | { |
|---|
| 8275 | 8318 | assert(!bump); |
|---|
| .. | .. |
|---|
| 8281 | 8324 | // } |
|---|
| 8282 | 8325 | // else |
|---|
| 8283 | 8326 | // { |
|---|
| 8284 | | - texture = textures.get(tex); |
|---|
| 8285 | | - if (texture == null) |
|---|
| 8327 | + texturecache = textures.get(tex); |
|---|
| 8328 | + if (texturecache == null) |
|---|
| 8286 | 8329 | { |
|---|
| 8287 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
|---|
| 8330 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
|---|
| 8288 | 8331 | } |
|---|
| 8289 | 8332 | // } |
|---|
| 8290 | 8333 | } else |
|---|
| 8291 | 8334 | if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
|---|
| 8292 | 8335 | { |
|---|
| 8293 | 8336 | assert(bump); |
|---|
| 8294 | | - texture = textures.get(tex); |
|---|
| 8295 | | - if (texture == null) |
|---|
| 8296 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
|---|
| 8337 | + texturecache = textures.get(tex); |
|---|
| 8338 | + if (texturecache == null) |
|---|
| 8339 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
|---|
| 8297 | 8340 | } else |
|---|
| 8298 | 8341 | { |
|---|
| 8299 | 8342 | //if (tex.equals("IMMORTAL")) |
|---|
| .. | .. |
|---|
| 8303 | 8346 | //{ |
|---|
| 8304 | 8347 | if (tex.equals("WHITE_NOISE")) |
|---|
| 8305 | 8348 | { |
|---|
| 8306 | | - texture = textures.get(tex); |
|---|
| 8307 | | - if (texture == null) |
|---|
| 8308 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
|---|
| 8349 | + texturecache = textures.get(tex); |
|---|
| 8350 | + if (texturecache == null) |
|---|
| 8351 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
|---|
| 8309 | 8352 | } else |
|---|
| 8310 | 8353 | { |
|---|
| 8311 | 8354 | if (textureon) |
|---|
| .. | .. |
|---|
| 8364 | 8407 | if (texturedata == null) |
|---|
| 8365 | 8408 | throw new Exception(); |
|---|
| 8366 | 8409 | |
|---|
| 8367 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
|---|
| 8410 | + texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
|---|
| 8368 | 8411 | //texture = GetTexture(tex, bump); |
|---|
| 8369 | 8412 | } |
|---|
| 8370 | 8413 | } |
|---|
| 8371 | 8414 | //} |
|---|
| 8372 | 8415 | } |
|---|
| 8373 | 8416 | |
|---|
| 8374 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
|---|
| 8417 | + if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
|---|
| 8375 | 8418 | { |
|---|
| 8376 | 8419 | //return false; |
|---|
| 8377 | 8420 | |
|---|
| 8378 | 8421 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
|---|
| 8379 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
|---|
| 8422 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
|---|
| 8380 | 8423 | { |
|---|
| 8381 | 8424 | // String ext = "_highres"; |
|---|
| 8382 | 8425 | // if (REDUCETEXTURE) |
|---|
| .. | .. |
|---|
| 8465 | 8508 | textures.remove(texname); |
|---|
| 8466 | 8509 | } |
|---|
| 8467 | 8510 | |
|---|
| 8468 | | - texture.texturedata = texturedata; |
|---|
| 8469 | | - textures.put(texname, texture); |
|---|
| 8511 | + //texture.texturedata = texturedata; |
|---|
| 8512 | + textures.put(texname, texturecache); |
|---|
| 8470 | 8513 | |
|---|
| 8471 | 8514 | // newtex = true; |
|---|
| 8472 | 8515 | } |
|---|
| .. | .. |
|---|
| 8482 | 8525 | } |
|---|
| 8483 | 8526 | } |
|---|
| 8484 | 8527 | |
|---|
| 8485 | | - return texture; |
|---|
| 8528 | + return texturecache; |
|---|
| 8486 | 8529 | } |
|---|
| 8487 | 8530 | |
|---|
| 8488 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
|---|
| 8531 | + com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
|---|
| 8489 | 8532 | { |
|---|
| 8490 | | - CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
|---|
| 8533 | + CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
|---|
| 8491 | 8534 | |
|---|
| 8492 | 8535 | if (bump) |
|---|
| 8493 | 8536 | { |
|---|
| .. | .. |
|---|
| 8503 | 8546 | return texture!=null?texture.texture:null; |
|---|
| 8504 | 8547 | } |
|---|
| 8505 | 8548 | |
|---|
| 8506 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception |
|---|
| 8549 | + public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
|---|
| 8507 | 8550 | { |
|---|
| 8508 | | - CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
|---|
| 8551 | + CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
|---|
| 8509 | 8552 | |
|---|
| 8510 | 8553 | return texture!=null?texture.texturedata:null; |
|---|
| 8511 | 8554 | } |
|---|
| 8512 | 8555 | |
|---|
| 8513 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
|---|
| 8556 | + boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
|---|
| 8514 | 8557 | { |
|---|
| 8515 | 8558 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
|---|
| 8516 | 8559 | { |
|---|
| .. | .. |
|---|
| 8519 | 8562 | |
|---|
| 8520 | 8563 | //boolean newtex = false; |
|---|
| 8521 | 8564 | |
|---|
| 8522 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
|---|
| 8565 | + com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
|---|
| 8523 | 8566 | |
|---|
| 8524 | 8567 | if (texture == null) |
|---|
| 8525 | 8568 | return false; |
|---|
| .. | .. |
|---|
| 11006 | 11049 | |
|---|
| 11007 | 11050 | try |
|---|
| 11008 | 11051 | { |
|---|
| 11009 | | - BindTexture(NOISE_TEXTURE, false, 2); |
|---|
| 11052 | + BindTexture(null, NOISE_TEXTURE, false, 2); |
|---|
| 11010 | 11053 | } |
|---|
| 11011 | 11054 | catch (Exception e) |
|---|
| 11012 | 11055 | { |
|---|
| .. | .. |
|---|
| 11671 | 11714 | if (tex.equals("WHITE_NOISE")) |
|---|
| 11672 | 11715 | continue; |
|---|
| 11673 | 11716 | |
|---|
| 11674 | | - if (!usedtextures.containsKey(tex)) |
|---|
| 11717 | + if (!usedtextures.contains(tex)) |
|---|
| 11675 | 11718 | { |
|---|
| 11676 | 11719 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
|---|
| 11677 | 11720 | textures.get(tex).texture.dispose(); |
|---|