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.
---
iCameraPane.java | 2
CameraPane.java | 203 ++++++++++++++++++++++++++++++--------------------
GroupEditor.java | 2
cTexture.java | 13 --
4 files changed, 128 insertions(+), 92 deletions(-)
diff --git a/CameraPane.java b/CameraPane.java
index b55d184..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)
{
@@ -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,13 +8198,13 @@
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))
{
@@ -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,13 +8231,13 @@
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))
{
@@ -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,14 +8546,14 @@
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;
}
- boolean 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)
{
@@ -8519,7 +8562,7 @@
//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 false;
@@ -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();
diff --git a/GroupEditor.java b/GroupEditor.java
index 9edd20b..ff6c98d 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -4163,7 +4163,7 @@
try
{
- texturedata = Globals.theRenderer.GetTextureData(pigment, false, node.texres);
+ texturedata = Globals.theRenderer.GetTextureData(tex.pigmenttexture, pigment, false, node.texres);
}
catch (Exception e)
{
diff --git a/cTexture.java b/cTexture.java
index ed790cb..a839d58 100644
--- a/cTexture.java
+++ b/cTexture.java
@@ -1,12 +1,5 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+import java.awt.image.BufferedImage;
-/**
- *
- * @author nbriere
- */
public class cTexture implements java.io.Serializable
{
static final long serialVersionUID = 8278178842384985286L;
@@ -38,6 +31,6 @@
}
String name;
- byte[] pigmentstream;
- byte[] bumpstream;
+ BufferedImage pigmenttexture;
+ BufferedImage bumptexture;
}
diff --git a/iCameraPane.java b/iCameraPane.java
index 8fef1f6..d404e84 100644
--- a/iCameraPane.java
+++ b/iCameraPane.java
@@ -86,7 +86,7 @@
void setCursor(java.awt.Cursor cursor);
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception;
+ com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception;
void repaint();
--
Gitblit v1.6.2