Normand Briere
2019-07-21 40f408aaee14abd85d391008b4d22977dc586b50
CameraPane.java
....@@ -60,7 +60,7 @@
6060 //boolean REDUCETEXTURE = true;
6161 boolean CACHETEXTURE = true;
6262 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
63
+ boolean MIPMAP = true; // false; // true;
6464 boolean COMPRESSTEXTURE = false;
6565 boolean KOMPACTTEXTURE = false; // true;
6666 boolean RESIZETEXTURE = false;
....@@ -2422,9 +2422,10 @@
24222422 /**/
24232423
24242424 // 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
+
24282429 int pigmentdepth = 0;
24292430 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24302431 int bumpdepth = 0;
....@@ -2446,6 +2447,33 @@
24462447 true,
24472448 com.sun.opengl.util.texture.TextureIO.PNG);
24482449 } 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)
24492477 {
24502478 throw new javax.media.opengl.GLException(e);
24512479 }
....@@ -3532,6 +3560,8 @@
35323560
35333561 System.out.println("LOADING TEXTURE : " + name);
35343562
3563
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3564
+
35353565 //
35363566 if (false) // compressbit > 0)
35373567 {
....@@ -7930,7 +7960,7 @@
79307960 String pigment = Object3D.GetPigment(tex);
79317961 String bump = Object3D.GetBump(tex);
79327962
7933
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7963
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79347964 {
79357965 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79367966 // System.out.println("; bump = " + bump);
....@@ -7964,7 +7994,7 @@
79647994
79657995 String pigment = Object3D.GetPigment(tex);
79667996
7967
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7997
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79687998 {
79697999 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79708000 // System.out.println("; bump = " + bump);
....@@ -7993,7 +8023,7 @@
79938023
79948024 String bump = Object3D.GetBump(tex);
79958025
7996
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8026
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79978027 {
79988028 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79998029 // System.out.println("; bump = " + bump);
....@@ -8112,47 +8142,50 @@
81128142
81138143 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81148144 {
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;
81278186
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);
81568189 }
81578190
81588191 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8165,15 +8198,15 @@
81658198
81668199 if (tex == null)
81678200 {
8168
- BindTexture(null,false,resolution);
8201
+ BindTexture(null, null,false,resolution);
81698202 return;
81708203 }
81718204
81728205 String pigment = Object3D.GetPigment(tex);
81738206
8174
- usedtextures.put(pigment, pigment);
8207
+ usedtextures.add(pigment);
81758208
8176
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8209
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81778210 {
81788211 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81798212 // System.out.println("; bump = " + bump);
....@@ -8185,7 +8218,7 @@
81858218 }
81868219
81878220 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8188
- BindTexture(pigment, false, resolution);
8221
+ BindTexture(tex.pigmenttexture, pigment, false, resolution);
81898222 }
81908223
81918224 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8198,15 +8231,15 @@
81988231
81998232 if (tex == null)
82008233 {
8201
- BindTexture(null,true,resolution);
8234
+ BindTexture(null, null,true,resolution);
82028235 return;
82038236 }
82048237
82058238 String bump = Object3D.GetBump(tex);
82068239
8207
- usedtextures.put(bump, bump);
8240
+ usedtextures.add(bump);
82088241
8209
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8242
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108243 {
82118244 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82128245 // System.out.println("; bump = " + bump);
....@@ -8218,7 +8251,7 @@
82188251 }
82198252
82208253 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8221
- BindTexture(bump, true, resolution);
8254
+ BindTexture(tex.bumptexture, bump, true, resolution);
82228255 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82238256 }
82248257
....@@ -8242,9 +8275,9 @@
82428275 return fileExists;
82438276 }
82448277
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
82468279 {
8247
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8280
+ CacheTexture texturecache = null;
82488281
82498282 if (tex != null)
82508283 {
....@@ -8264,12 +8297,22 @@
82648297 }
82658298
82668299 if (CACHETEXTURE)
8267
- texture = textures.get(texname); // TEXTURE CACHE
8268
-
8269
- TextureData texturedata = null;
8270
-
8271
- if (texture == null || texture.resolution < resolution)
82728300 {
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
82738316 if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82748317 {
82758318 assert(!bump);
....@@ -8281,19 +8324,19 @@
82818324 // }
82828325 // else
82838326 // {
8284
- texture = textures.get(tex);
8285
- if (texture == null)
8327
+ texturecache = textures.get(tex);
8328
+ if (texturecache == null)
82868329 {
8287
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8330
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82888331 }
82898332 // }
82908333 } else
82918334 if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82928335 {
82938336 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);
82978340 } else
82988341 {
82998342 //if (tex.equals("IMMORTAL"))
....@@ -8303,9 +8346,9 @@
83038346 //{
83048347 if (tex.equals("WHITE_NOISE"))
83058348 {
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);
83098352 } else
83108353 {
83118354 if (textureon)
....@@ -8364,19 +8407,19 @@
83648407 if (texturedata == null)
83658408 throw new Exception();
83668409
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);
83688411 //texture = GetTexture(tex, bump);
83698412 }
83708413 }
83718414 //}
83728415 }
83738416
8374
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8417
+ if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
83758418 {
83768419 //return false;
83778420
83788421 // 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"))
83808423 {
83818424 // String ext = "_highres";
83828425 // if (REDUCETEXTURE)
....@@ -8465,8 +8508,8 @@
84658508 textures.remove(texname);
84668509 }
84678510
8468
- texture.texturedata = texturedata;
8469
- textures.put(texname, texture);
8511
+ //texture.texturedata = texturedata;
8512
+ textures.put(texname, texturecache);
84708513
84718514 // newtex = true;
84728515 }
....@@ -8482,12 +8525,12 @@
84828525 }
84838526 }
84848527
8485
- return texture;
8528
+ return texturecache;
84868529 }
84878530
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
84898532 {
8490
- CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8533
+ CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
84918534
84928535 if (bump)
84938536 {
....@@ -8503,26 +8546,26 @@
85038546 return texture!=null?texture.texture:null;
85048547 }
85058548
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
85078550 {
8508
- CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8551
+ CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
85098552
85108553 return texture!=null?texture.texturedata:null;
85118554 }
85128555
8513
- com.sun.opengl.util.texture.Texture 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
85148557 {
85158558 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85168559 {
85178560 return false;
85188561 }
85198562
8520
- boolean newtex = false;
8563
+ //boolean newtex = false;
85218564
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);
85238566
85248567 if (texture == null)
8525
- return texture;
8568
+ return false;
85268569 /**/
85278570
85288571 if (textureon || tex.equals("DEFAULT_TEXTURE") || tex.equals("DEFAULT_TEXTURE_BUMP") || tex.equals("WHITE_NOISE")) // || tex.equals("IMMORTAL"))
....@@ -8549,7 +8592,7 @@
85498592 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85508593 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85518594
8552
- return newtex;
8595
+ return true; // Warning: not used.
85538596 }
85548597
85558598 ShadowBuffer shadowPBuf;
....@@ -11006,7 +11049,7 @@
1100611049
1100711050 try
1100811051 {
11009
- BindTexture(NOISE_TEXTURE, false, 2);
11052
+ BindTexture(null, NOISE_TEXTURE, false, 2);
1101011053 }
1101111054 catch (Exception e)
1101211055 {
....@@ -11671,7 +11714,7 @@
1167111714 if (tex.equals("WHITE_NOISE"))
1167211715 continue;
1167311716
11674
- if (!usedtextures.containsKey(tex))
11717
+ if (!usedtextures.contains(tex))
1167511718 {
1167611719 // System.out.println("DISPOSE +++++++++++++++ " + tex);
1167711720 textures.get(tex).texture.dispose();