[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz ./TODO gfx/util/demo.py gzz/gfx/gl/GL.java ...
From: |
Tuomas J. Lukka |
Subject: |
[Gzz-commits] gzz ./TODO gfx/util/demo.py gzz/gfx/gl/GL.java ... |
Date: |
Fri, 17 Jan 2003 09:37:18 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Tuomas J. Lukka <address@hidden> 03/01/17 09:37:17
Modified files:
. : TODO
gfx/util : demo.py
gzz/gfx/gl : GL.java MipzipLoader.java
gzz/mem : MemoryPartitioner.java
Log message:
Mipzip start debugging
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/TODO.diff?tr1=1.520&tr2=1.521&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/util/demo.py.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/gfx/gl/GL.java.diff?tr1=1.40&tr2=1.41&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/gfx/gl/MipzipLoader.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/mem/MemoryPartitioner.java.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
Patches:
Index: gzz/TODO
diff -u gzz/TODO:1.520 gzz/TODO:1.521
--- gzz/TODO:1.520 Fri Jan 17 05:16:59 2003
+++ gzz/TODO Fri Jan 17 09:37:17 2003
@@ -156,6 +156,10 @@
- make pegboard to be only a directive, when all reST could be
compiled using $(JYTHON) metacode/umldoc.py `find doc -name "*.rst"`
- enhancing umltool
+ - include doc/gl in Makefile
+ - rationalize doc directory structure:
+ - Gzz_Frontend_View.rst -> doc/frontend/View.rst
+ (i.e. no Gzz_ prefixes, tree structure explicit)
- a lot of things, which would be easier to handle with better
design, so these will be fixed on the second implementation
round with more object-oriented design
Index: gzz/gfx/util/demo.py
diff -u gzz/gfx/util/demo.py:1.10 gzz/gfx/util/demo.py:1.11
--- gzz/gfx/util/demo.py:1.10 Tue Jan 7 07:53:05 2003
+++ gzz/gfx/util/demo.py Fri Jan 17 09:37:17 2003
@@ -18,7 +18,7 @@
sys.path.insert(0, ".")
-from java.lang import System,Runnable
+from java.lang import System,Runnable,Throwable
import java
from gzz.client import AbstractBinder, AbstractShower, AbstractUpdateManager,
GraphicsAPI, Screen
from gzz.gfx.gl import GL, GLRen, GLSpans, Paper, GLCache
@@ -124,6 +124,9 @@
print "Global help:",globalHelp,"CUR",currentScene.__doc__
+ except java.lang.Throwable, t :
+ print "ERROR WHILE LOADING"
+ t.printStackTrace()
except:
typ, val, tra = sys.exc_info()
l = traceback.format_list(traceback.extract_tb(tra))
Index: gzz/gzz/gfx/gl/GL.java
diff -u gzz/gzz/gfx/gl/GL.java:1.40 gzz/gzz/gfx/gl/GL.java:1.41
--- gzz/gzz/gfx/gl/GL.java:1.40 Thu Jan 16 11:06:28 2003
+++ gzz/gzz/gfx/gl/GL.java Fri Jan 17 09:37:17 2003
@@ -903,6 +903,12 @@
*/
public static native String getGLTokenString(int value);
+ /** If known, return bits per texel of a given format.
+ */
+ public static int bitsPerTexel(String format) {
+ if(format.equals("COMPRESSED_RGB_S3TC_DXT1_EXT")) return 4;
+ return -1;
+ }
}
Index: gzz/gzz/gfx/gl/MipzipLoader.java
diff -u gzz/gzz/gfx/gl/MipzipLoader.java:1.5
gzz/gzz/gfx/gl/MipzipLoader.java:1.6
--- gzz/gzz/gfx/gl/MipzipLoader.java:1.5 Fri Jan 17 03:06:07 2003
+++ gzz/gzz/gfx/gl/MipzipLoader.java Fri Jan 17 09:37:17 2003
@@ -11,12 +11,17 @@
/** A loader for Mipzip files: files of zipped,
* compressed mipmap levels.
+ * <p>
+ * RESPONSIBILITIES: Manage the combination of
+ * a single texture and a mipzip file, creating a "virtualized" texture
+ * of which better-quality versions can be loaded and discarded at will.
*/
public class MipzipLoader {
public static boolean dbg = false;
final static void pa(String s) { System.out.println(s); }
private int goalBaseLevel = 0;
+ private int currentBaseLevel = 0;
private Background bg = null;
private float priority = 0;
@@ -33,6 +38,8 @@
*/
private final String texFormat;
+ private int bitsPerTexel;
+
/** The opened Zip file. At any given
* time, may be null or open.
* Use getZipFile() to get it inside these classes.
@@ -66,6 +73,7 @@
STATE_INTEXTURE = 3;
/** A single mipmap level.
+ * Responsibilities: Know if loaded, load data, teximage data, discard.
*/
private class Level implements Runnable {
@@ -144,11 +152,15 @@
}
+ /** Set the texture parameter "BASE_LEVEL" to the given value.
+ */
synchronized private void setBaseLevel(int level) {
tex.setTexParameter("TEXTURE_2D", "TEXTURE_BASE_LEVEL", level);
+ currentBaseLevel = level;
}
/** Set the base level synchronously: load or discard.
+ * @param level The base level: the lowest-detail level to be loaded
*/
synchronized public void loadToBaseLevelSynch(int level) throws
IOException {
for(int i=0; i<level; i++) {
@@ -163,6 +175,13 @@
/** Set the base level goal for
* asynchronous loading.
+ * Calling this method starts the asynchronous process of loading
+ * or discarding
+ * mipmap levels.
+ * @param level The base level to move towards
+ * @param bg The background thread in which to run the part of loading
+ * which does not need to be in the OpenGL thread.
+ * @param priority The priority to pass to the background thread and
UpdateManager
*/
synchronized public void setGoalBaseLevel(int level,
Background bg, float priority) {
@@ -213,6 +232,8 @@
for(int i=0; i<goalBaseLevel && i < levels.length-1;
i++) {
if(levels[i].state != STATE_NONE) {
+ if(currentBaseLevel <= i)
+ setBaseLevel(i+1);
levels[i].discard();
AbstractUpdateManager.doWhenIdle(r_runGL,
priority);
@@ -229,16 +250,105 @@
}
}
+ /** Get the OpenGL texture for this MipzipLoader.
+ * The only operations on the texture should be
+ * drawing it, or setting the following OpenGL parameters:
+ * <ul>
+ * <li> filtering modes
+ * <li> LOD min, max, bias
+ * <li> shadow parameters
+ * </ul>
+ * Texture base level and max level and the actual texture
+ * images should not be touched.
+ */
+ public GL.Texture getTexture() {
+ return tex;
+ }
+
+ /** Get the amount of memory currently used.
+ * @return Memory, in bytes
+ */
+ public int getMemory() {
+ return getMemory(currentBaseLevel);
+ }
+
+ /** Get the amount of memory used if given level is loaded.
+ * @return Memory, in bytes
+ */
+ public int getMemory(int level) {
+ int bytesForLevel = levels[level].size.width *
levels[level].size.height * bitsPerTexel / 8;
+ int totalBytes = (bytesForLevel * 4) / 3;
+ return totalBytes;
+ }
+
+ /** Get the level that uses at most given amount of memory.
+ * @return The level index.
+ */
+ public int getLevelBytes(int memory) {
+ for(int i = 0; i<levels.length; i++) {
+ if(getMemory(i) <= memory) return i;
+ }
+ return levels.length-1; // XXX
+ }
+
+ float LG2 = (float)Math.log(2);
+ /** Get the level that needs to be used to obtain
+ * the given quality.
+ *
+ * Quality = pixels per texcoord unit, i.e. 1 =
+ * the whole texture is shown in 1 pixel, 100 = texture
+ * shown in 100x100 square (or like).
+ */
+ public int getLevelForQuality(float quality) {
+ int maxdim = Math.max(levels[0].size.height, levels[0].size.width);
+ float ratio = maxdim / quality;
+ int l = (int)(Math.log(ratio) / LG2);
+ l = Math.max(0, l);
+ l = Math.min(levels.length-1, l);
+ return l;
+ }
+
+ public float getQuality() {
+ return getQuality(currentBaseLevel);
+ }
+
+ public float getQuality(int level) {
+ int maxdim = Math.max(levels[level].size.height,
+ levels[level].size.width);
+ return maxdim;
+ }
+
+ /** Get the number of mipmap levels in this mipzip.
+ */
+ public int getNLevels() {
+ return levels.length;
+ }
+
+ /** Get the size, in texels, of a texture level.
+ * The return value must not be altered!
+ */
+ public Dimension getLevelSize(int level) {
+ return levels[level].size;
+ }
+
/** Create a new MipzipLoader for the given mipzip file.
*/
public MipzipLoader(File mipzipFile) throws IOException {
this.mipzipFile = mipzipFile;
this.tex = GL.createTexture();
ZipFile f = getZipFile();
- this.texFormat = f.getEntry("texformat").getComment();
+ if(dbg) {
+ pa("Creating new mipzip loader: "+mipzipFile);
+ for(Enumeration e = f.entries(); e.hasMoreElements(); ) {
+ pa("Entry: " + e.nextElement());
+ }
+ }
+ ZipEntry e = f.getEntry("texformat");
+ if(e == null) throw new IOException("Invalid format: no texformat in
mipzip");
+ this.texFormat = e.getComment();
ArrayList l = new ArrayList();
for(int i=0; i<100; i++) {
- ZipEntry e = f.getEntry(""+i);
+ e = f.getEntry(""+i);
if(e == null) break;
l.add(new Level(i, e.getComment()));
}
@@ -247,6 +357,12 @@
levels[levels.length-1].size.height != 1 ) {
throw new IOException("Not all levels there!");
}
+ bitsPerTexel = GL.bitsPerTexel(texFormat);
+ if(bitsPerTexel < 0) {
+ if(dbg) pa("Warning: memory consumption for "+texFormat+" not
known, assuming 32bpt");
+ bitsPerTexel = 32;
+ }
+ currentBaseLevel = levels.length;
}
}
Index: gzz/gzz/mem/MemoryPartitioner.java
diff -u gzz/gzz/mem/MemoryPartitioner.java:1.7
gzz/gzz/mem/MemoryPartitioner.java:1.8
--- gzz/gzz/mem/MemoryPartitioner.java:1.7 Mon Jan 13 01:48:50 2003
+++ gzz/gzz/mem/MemoryPartitioner.java Fri Jan 17 09:37:17 2003
@@ -22,6 +22,7 @@
*/
package gzz.mem;
+import gzz.client.AbstractUpdateManager;
import gzz.Obs;
import gzz.util.ZZLogger;
@@ -169,8 +170,9 @@
try {
if(dbg) pa("Going to rerate");
rerate();
+ AbstractUpdateManager.chg();
if(dbg) pa("rerated, sleeping");
- Thread.sleep(10);
+ Thread.sleep(20);
} catch(Exception e) {
ZZLogger.exc(e, "gzz.mem.MemoryPartitioner thread!");
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz ./TODO gfx/util/demo.py gzz/gfx/gl/GL.java ...,
Tuomas J. Lukka <=