From 40f408aaee14abd85d391008b4d22977dc586b50 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sun, 21 Jul 2019 16:45:10 -0400 Subject: [PATCH] Prepare bimtexture. --- CameraPane.java | 219 ++++++++++++++++++++++++++++++++---------------------- 1 files changed, 131 insertions(+), 88 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index 52608e6..1364b89 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -60,7 +60,7 @@ //boolean REDUCETEXTURE = true; boolean CACHETEXTURE = true; boolean CLEANCACHE = false; // true; - boolean MIPMAP = false; // true; + boolean MIPMAP = true; // false; // true; boolean COMPRESSTEXTURE = false; boolean KOMPACTTEXTURE = false; // true; boolean RESIZETEXTURE = false; @@ -2422,9 +2422,10 @@ /**/ // TEXTURE static Texture texture; - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>(); + static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>(); + static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>(); + static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>(); + int pigmentdepth = 0; public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; int bumpdepth = 0; @@ -2446,6 +2447,33 @@ true, com.sun.opengl.util.texture.TextureIO.PNG); } catch (java.io.IOException e) + { + throw new javax.media.opengl.GLException(e); + } + + if (bump) + texturedata = ConvertBump(texturedata, false); + + com.sun.opengl.util.texture.Texture texture = + com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); + + texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); + texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); + + return texture; + } + + com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) + { + TextureData texturedata = null; + + try + { + texturedata = + com.sun.opengl.util.texture.TextureIO.newTextureData( + name, + true); + } catch (Exception e) { throw new javax.media.opengl.GLException(e); } @@ -3532,6 +3560,8 @@ System.out.println("LOADING TEXTURE : " + name); + Object x = texturedata.getMipmapData(); // .getBuffer(); + // if (false) // compressbit > 0) { @@ -7930,7 +7960,7 @@ String pigment = Object3D.GetPigment(tex); String bump = Object3D.GetBump(tex); - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); // System.out.println("; bump = " + bump); @@ -7964,7 +7994,7 @@ String pigment = Object3D.GetPigment(tex); - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); // System.out.println("; bump = " + bump); @@ -7993,7 +8023,7 @@ String bump = Object3D.GetBump(tex); - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); // System.out.println("; bump = " + bump); @@ -8112,47 +8142,50 @@ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE { - if (// DrawMode() != 0 || /*tex == null ||*/ - ambientOcclusion ) // || !textureon) - { - return; // false; - } - - if (tex == null) - { - BindTexture(null,false,resolution); - BindTexture(null,true,resolution); - return; - } +// if (// DrawMode() != 0 || /*tex == null ||*/ +// ambientOcclusion ) // || !textureon) +// { +// return; // false; +// } +// +// if (tex == null) +// { +// BindTexture(null,false,resolution); +// BindTexture(null,true,resolution); +// return; +// } +// +// String pigment = Object3D.GetPigment(tex); +// String bump = Object3D.GetBump(tex); +// +// usedtextures.add(pigment); +// usedtextures.add(bump); +// +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) +// { +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); +// // System.out.println("; bump = " + bump); +// } +// +// if (bump.equals("")) +// { +// bump = null; +// } +// if (pigment.equals("")) +// { +// pigment = null; +// } +// +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); +// BindTexture(pigment, false, resolution); +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); +// BindTexture(bump, true, resolution); +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); +// +// return; // true; - String pigment = Object3D.GetPigment(tex); - String bump = Object3D.GetBump(tex); - - usedtextures.put(pigment, pigment); - usedtextures.put(bump, bump); - - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) - { - // System.out.print("BIND +++++++++++++++ pigment = " + pigment); - // System.out.println("; bump = " + bump); - } - - if (bump.equals("")) - { - bump = null; - } - if (pigment.equals("")) - { - pigment = null; - } - - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); - BindTexture(pigment, false, resolution); - GetGL().glActiveTexture(GetGL().GL_TEXTURE2); - BindTexture(bump, true, resolution); - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); - - return; // true; + BindPigmentTexture(tex, resolution); + BindBumpTexture(tex, resolution); } /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE @@ -8165,15 +8198,15 @@ if (tex == null) { - BindTexture(null,false,resolution); + BindTexture(null, null,false,resolution); return; } String pigment = Object3D.GetPigment(tex); - usedtextures.put(pigment, pigment); + usedtextures.add(pigment); - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { // System.out.print("BIND +++++++++++++++ pigment = " + pigment); // System.out.println("; bump = " + bump); @@ -8185,7 +8218,7 @@ } GetGL().glActiveTexture(GetGL().GL_TEXTURE0); - BindTexture(pigment, false, resolution); + BindTexture(tex.pigmenttexture, pigment, false, resolution); } /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE @@ -8198,15 +8231,15 @@ if (tex == null) { - BindTexture(null,true,resolution); + BindTexture(null, null,true,resolution); return; } String bump = Object3D.GetBump(tex); - usedtextures.put(bump, bump); + usedtextures.add(bump); - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { // System.out.print("BIND +++++++++++++++ pigment = " + pigment); // System.out.println("; bump = " + bump); @@ -8218,7 +8251,7 @@ } GetGL().glActiveTexture(GetGL().GL_TEXTURE2); - BindTexture(bump, true, resolution); + BindTexture(tex.bumptexture, bump, true, resolution); GetGL().glActiveTexture(GetGL().GL_TEXTURE0); } @@ -8242,9 +8275,9 @@ return fileExists; } - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception + CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception { - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; + CacheTexture texturecache = null; if (tex != null) { @@ -8264,12 +8297,22 @@ } if (CACHETEXTURE) - texture = textures.get(texname); // TEXTURE CACHE - - TextureData texturedata = null; - - if (texture == null || texture.resolution < resolution) { + if (bim == null) + texturecache = textures.get(texname); // TEXTURE CACHE + else + texturecache = bimtextures.get(bim); // TEXTURE CACHE + } + + if (texturecache == null || texturecache.resolution < resolution) + { + TextureData texturedata = null; + + if (bim == null) + { + + } + else if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) { assert(!bump); @@ -8281,19 +8324,19 @@ // } // else // { - texture = textures.get(tex); - if (texture == null) + texturecache = textures.get(tex); + if (texturecache == null) { - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); } // } } else if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) { assert(bump); - texture = textures.get(tex); - if (texture == null) - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); + texturecache = textures.get(tex); + if (texturecache == null) + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); } else { //if (tex.equals("IMMORTAL")) @@ -8303,9 +8346,9 @@ //{ if (tex.equals("WHITE_NOISE")) { - texture = textures.get(tex); - if (texture == null) - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); + texturecache = textures.get(tex); + if (texturecache == null) + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); } else { if (textureon) @@ -8364,19 +8407,19 @@ if (texturedata == null) throw new Exception(); - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); + texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); //texture = GetTexture(tex, bump); } } //} } - if (/*CACHETEXTURE &&*/ texture != null && textureon) + if (/*CACHETEXTURE &&*/ texturecache != null && textureon) { //return false; // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) { // String ext = "_highres"; // if (REDUCETEXTURE) @@ -8465,8 +8508,8 @@ textures.remove(texname); } - texture.texturedata = texturedata; - textures.put(texname, texture); + //texture.texturedata = texturedata; + textures.put(texname, texturecache); // newtex = true; } @@ -8482,12 +8525,12 @@ } } - return texture; + return texturecache; } - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception + com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception { - CacheTexture texture = GetCacheTexture(tex, bump, resolution); + CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); if (bump) { @@ -8503,26 +8546,26 @@ return texture!=null?texture.texture:null; } - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception + public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception { - CacheTexture texture = GetCacheTexture(tex, bump, resolution); + CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); return texture!=null?texture.texturedata:null; } - com.sun.opengl.util.texture.Texture BindTexture(String tex, boolean bump, int resolution) throws Exception + boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception { if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) { return false; } - boolean newtex = false; + //boolean newtex = false; - com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); + com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); if (texture == null) - return texture; + return false; /**/ if (textureon || tex.equals("DEFAULT_TEXTURE") || tex.equals("DEFAULT_TEXTURE_BUMP") || tex.equals("WHITE_NOISE")) // || tex.equals("IMMORTAL")) @@ -8549,7 +8592,7 @@ texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); - return newtex; + return true; // Warning: not used. } ShadowBuffer shadowPBuf; @@ -11006,7 +11049,7 @@ try { - BindTexture(NOISE_TEXTURE, false, 2); + BindTexture(null, NOISE_TEXTURE, false, 2); } catch (Exception e) { @@ -11671,7 +11714,7 @@ if (tex.equals("WHITE_NOISE")) continue; - if (!usedtextures.containsKey(tex)) + if (!usedtextures.contains(tex)) { // System.out.println("DISPOSE +++++++++++++++ " + tex); textures.get(tex).texture.dispose(); -- Gitblit v1.6.2