fenfire-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ff-cvs] libvob org/nongnu/libvob/gl/MipzipLoader.java v...


From: Tuomas J. Lukka
Subject: [ff-cvs] libvob org/nongnu/libvob/gl/MipzipLoader.java v...
Date: Mon, 06 Oct 2003 04:50:38 -0400

CVSROOT:        /cvsroot/libvob
Module name:    libvob
Branch:         
Changes by:     Tuomas J. Lukka <address@hidden>        03/10/06 04:50:38

Modified files:
        org/nongnu/libvob/gl: MipzipLoader.java 
        vob/demo/aniso : probe1.py 
Added files:
        doc            : mipzip.rst 
        doc/basalt     : memorymanagement.rst 
        org/nongnu/libvob/gl: MipzipFile.java 
Removed files:
        doc            : memorymanagement.rst 

Log message:
        Arch sync

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/doc/mipzip.rst?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/doc/basalt/memorymanagement.rst?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/gl/MipzipFile.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/gl/MipzipLoader.java.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/demo/aniso/probe1.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: libvob/org/nongnu/libvob/gl/MipzipLoader.java
diff -u libvob/org/nongnu/libvob/gl/MipzipLoader.java:1.9 
libvob/org/nongnu/libvob/gl/MipzipLoader.java:1.10
--- libvob/org/nongnu/libvob/gl/MipzipLoader.java:1.9   Fri Sep 12 14:44:31 2003
+++ libvob/org/nongnu/libvob/gl/MipzipLoader.java       Mon Oct  6 04:50:38 2003
@@ -3,20 +3,20 @@
  *    
  *    Copyright (c) 2003, : Tuomas J. Lukka
  *    
- *    This file is part of Gzz.
+ *    This file is part of Libvob.
  *    
- *    Gzz is free software; you can redistribute it and/or modify it under
+ *    Libvob is free software; you can redistribute it and/or modify it under
  *    the terms of the GNU Lesser General Public License as published by
  *    the Free Software Foundation; either version 2 of the License, or
  *    (at your option) any later version.
  *    
- *    Gzz is distributed in the hope that it will be useful, but WITHOUT
+ *    Libvob is distributed in the hope that it will be useful, but WITHOUT
  *    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  *    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
  *    Public License for more details.
  *    
  *    You should have received a copy of the GNU Lesser General
- *    Public License along with Gzz; if not, write to the Free
+ *    Public License along with Libvob; if not, write to the Free
  *    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  *    MA  02111-1307  USA
  *    
@@ -45,13 +45,6 @@
     public static boolean dbg = false;
     final static void pa(String s) { System.out.println(s); }
 
-    /** I have a hunch that zlib might not be re-entrant
-     * and that that would be causing our problems,
-     * since loading a level synchronously
-     * at the beginning mixed everything.
-     */
-    private static Object zlibLock = new Object();
-
     private int goalBaseLevel = -15;
     private int currentBaseLevel = 1000;
 
@@ -65,32 +58,21 @@
     private Background bg = null;
     private float priority = 0;
 
-    /** The file in which the mipmaps are stored.
-     */
-    private final File mipzipFile;
+    private final MipzipFile mipzipFile;
+
+    public MipzipFile getMipzipFile() {
+       return mipzipFile;
+    }
 
     /** The texture.
      */
     private final GL.Texture tex;
 
-    /** The compressed format.
-     */
-    private final String texFormat;
-    private final boolean compressedFormat;
 
     private int bitsPerTexel;
 
-    /** The opened Zip file. At any given
-     * time, may be null or open. 
-     * Use getZipFile() to get it inside these classes.
-     */
-    private ZipFile zip;
-
     private final Level[] levels;
 
-    /** The size of the original image embedded in the mipzip file, in texture 
coordinates.
-     */
-    public final float origWidth, origHeight;
 
     private String filterSettings;
 
@@ -102,32 +84,6 @@
        reFilter();
     }
 
-    /** Open (if not already open) and return the ZipFile.
-     */
-    synchronized private ZipFile getZipFile() throws IOException {
-       if(zip == null)
-           zip = new ZipFile(mipzipFile);
-       return zip;
-    }
-
-    synchronized private byte[] readEntry(String name) throws IOException {
-       synchronized(zlibLock) {
-           ZipFile f = getZipFile();
-           ZipEntry e = f.getEntry(name);
-           byte[] loadedData = new byte[(int)e.getSize()];
-           InputStream i = f.getInputStream(e);
-           int offs = 0;
-           while(offs < loadedData.length) {
-               int res = i.read(loadedData, offs, loadedData.length - offs);
-               if(res < 0) throw new IOException("EOF");
-               offs += res;
-           }
-           i.close();
-           f.close(); zip = null;
-           return loadedData;
-       }
-    }
-
     private static final int STATE_NONE = 1,
                             STATE_DATALOADED = 2,
                             STATE_INTEXTURE = 3;
@@ -146,10 +102,6 @@
         */
        int level;
 
-       /** Sizes of the mipmap levels.
-        */
-       Dimension size;
-
        /** The data loaded from the disk.
         */
        byte[] loadedData;
@@ -166,7 +118,7 @@
                        " "+state);
            if(state != STATE_NONE) return;
            if(loadedData == null) 
-               loadedData = readEntry(""+level);
+               loadedData = mipzipFile.getLevelData(level);
            state = STATE_DATALOADED;
        }
 
@@ -180,13 +132,14 @@
                pa("TexImage "+MipzipLoader.this+" "+level+
                        " "+state);
            if(state != STATE_DATALOADED) return;
-           if(compressedFormat)
-               tex.compressedTexImage(level, texFormat,
+           Dimension size = mipzipFile.getLevelSize(level);
+           if(mipzipFile.getIsCompressedFormat())
+               tex.compressedTexImage(level, mipzipFile.getTexFormat(),
                            size.width, size.height, 0,
                            loadedData);
            else
                tex.texImage2D(level, "RGB", size.width, size.height,
-                           0, texFormat, "BYTE", loadedData);
+                           0, mipzipFile.getTexFormat(), "BYTE", loadedData);
                            
            state = STATE_INTEXTURE;
            loadedData = null;
@@ -229,15 +182,9 @@
 
        /** Create a level.
         * @param l The mipmap level index
-        * @param s The size string from the comment in the file, e.g."64x128"
         */
-       Level(int l, String s) throws IOException {
+       Level(int l) throws IOException {
            this.level = l;
-           int i = s.indexOf('x');
-           if(i < 0) throw new IOException("Invalid size string");
-           int w = Integer.parseInt(s.substring(0,i));
-           int h = Integer.parseInt(s.substring(i+1));
-           size = new Dimension(w, h);
        }
 
     }
@@ -429,7 +376,8 @@
     public int getMemory(int level) {
        if(level < 0) level = 0;
        if(level > levels.length-1) level = levels.length-1;
-       int bytesForLevel = levels[level].size.width * 
levels[level].size.height * bitsPerTexel / 8;
+       Dimension size = mipzipFile.getLevelSize(level);
+       int bytesForLevel = size.width * size.height * bitsPerTexel / 8;
        int totalBytes = (bytesForLevel * 4) / 3;
        return totalBytes;
     }
@@ -453,7 +401,8 @@
      * shown in 100x100 square (or like).
      */
     public int getLevelForQuality(float quality) {
-       int maxdim = Math.max(levels[0].size.height, levels[0].size.width);
+       Dimension size = mipzipFile.getLevelSize(0);
+       int maxdim = Math.max(size.height, size.width);
        float ratio = maxdim / quality;
        int l = (int)(Math.log(ratio) / LG2);
        int lc = Math.max(0, l);
@@ -469,8 +418,9 @@
     }
 
     public float getQuality(int level) {
-       int maxdim = Math.max(levels[level].size.height, 
-                               levels[level].size.width);
+       Dimension size = mipzipFile.getLevelSize(level);
+       int maxdim = Math.max(size.height, 
+                               size.width);
        return maxdim;
     }
 
@@ -484,56 +434,24 @@
      * The return value must not be altered!
      */
     public Dimension getLevelSize(int level) {
-       return levels[level].size;
+       return mipzipFile.getLevelSize(level);
     }
 
     /** Create a new MipzipLoader for the given mipzip file.
      * Must be run in the GL thread.
      */
-    public MipzipLoader(File mipzipFile) throws IOException {
-       this.mipzipFile = mipzipFile;
+    public MipzipLoader(File file) throws IOException {
+       this.mipzipFile = new MipzipFile(file);
        this.tex = GL.createTexture();
-       synchronized(zlibLock) {
-           ZipFile f = getZipFile();
-           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();
-           this.compressedFormat = texFormat.indexOf("COMPRESS") != -1;
-
-           e = f.getEntry("origsize");
-           if(e == null) throw new IOException("Invalid format: no origsize in 
mipzip");
-           String origSize = e.getComment();
-
-           {
-               int i = origSize.indexOf('x');
-               if(i < 0) throw new IOException("Invalid size string");
-               origWidth = Float.parseFloat(origSize.substring(0,i));
-               origHeight = Float.parseFloat(origSize.substring(i+1));
-           }
+       bitsPerTexel = GL.bitsPerTexel(mipzipFile.getTexFormat());
 
+       levels = new Level[this.mipzipFile.getNLevels()];
+       for(int i=0; i<levels.length; i++)
+           levels[i] = new Level(i);
 
-           ArrayList l = new ArrayList();
-           for(int i=0; i<100; i++) {
-               e = f.getEntry(""+i);
-               if(e == null) break;
-               l.add(new Level(i, e.getComment()));
-           }
-           levels = (Level[])l.toArray(new Level[l.size()]);
-           if( levels[levels.length-1].size.width != 1 ||
-               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");
+           pa("------- Warning: memory consumption for "+
+                       mipzipFile.getTexFormat()+" not known, assuming 32bpt");
            bitsPerTexel = 32; 
        }
        maxBaseLevel = levels.length - 3;
Index: libvob/vob/demo/aniso/probe1.py
diff -u libvob/vob/demo/aniso/probe1.py:1.1 libvob/vob/demo/aniso/probe1.py:1.2
--- libvob/vob/demo/aniso/probe1.py:1.1 Mon Sep 29 09:39:04 2003
+++ libvob/vob/demo/aniso/probe1.py     Mon Oct  6 04:50:38 2003
@@ -13,83 +13,29 @@
 maxsize = 2**nlevels
 
 ebytes = jarray.zeros( 4 * maxsize*maxsize, 'b')
-ibyte = jarray.array( [-1, -1, -1, -1], 'b')
+tex = vob.gl.GL.createTexture()
 
-print ibyte
-
-textures = []
 
 #for i in range(0,300): ebytes[i] = -1
 #for i in range(300,600): ebytes[i] = 127
 
 
 for i in range(0, nlevels + 1):
-    tex = vob.gl.GL.createTexture()
-    for mip in range(0, nlevels + 1):
-       tex.texImage2D(mip, "RGBA", 
-           maxsize >> mip, maxsize >> mip, 0,
-           "RGBA", "UNSIGNED_BYTE", ebytes)
-       if mip == i:
-           #ibyte[0] = -1 * (i % 2 != 0)
-           #ibyte[1] = -1 * (i % 4 != 0)
-           #ibyte[2] = -1 * (i % 8 != 0)
-           tex.texSubImage2D(mip, 0, 0, 1, 1, 0, 
-               "RGBA", "UNSIGNED_BYTE", ibyte);
+    tex.texImage2D(i, "RGBA", 
+       maxsize >> i, maxsize >> i, 0,
+       "RGBA", "UNSIGNED_BYTE", ebytes)
            
-       tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAG_FILTER", "LINEAR")
-       tex.setTexParameter("TEXTURE_2D", "TEXTURE_MIN_FILTER", 
"LINEAR_MIPMAP_LINEAR")
-       tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAX_ANISOTROPY_EXT", "20")
-
-    textures.append(tex)
-
-# This program offsets the post-texture-matrix
-# texcoord0 by texcoord1, allowing us to select the different texels
-# in the texture space to show.
-
-prog = GL.createProgram("""!!ARBvp1.0
-
-ATTRIB iPos         = vertex.position;
-ATTRIB iTex0         = vertex.texcoord[0];
-ATTRIB iTex1         = vertex.texcoord[1];
-PARAM  mvp[4]       = { state.matrix.mvp };
-PARAM  texmat[4]       = { state.matrix.texture[0] };
-
-TEMP t0;
-
-# Transform vertex normally
-DP4   result.position.x, mvp[0], iPos;     
-DP4   result.position.y, mvp[1], iPos;
-DP4   result.position.z, mvp[2], iPos;
-DP4   result.position.w, mvp[3], iPos;
-
-# Transform texturecoord0 using the texture matrix, and
-# add texture1 to the result.
-
-DP4   t0.x, texmat[0], iTex0;
-DP4   t0.y, texmat[1], iTex0;
-DP4   t0.z, texmat[2], iTex0;
-DP4   t0.w, texmat[3], iTex0;
-
-ADD   t0.xy, t0, iTex1;
-
-MOV result.texcoord[0], t0;
+tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAG_FILTER", "LINEAR")
+tex.setTexParameter("TEXTURE_2D", "TEXTURE_MIN_FILTER", "LINEAR_MIPMAP_LINEAR")
+tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAX_ANISOTROPY_EXT", "20")
 
-END""")
 
-
-# Create a display list of quads suitable to use with the previous 
-# program
 xoffs = 0
 list = ["""
-    Enable VERTEX_PROGRAM_ARB
-    BindProgram VERTEX_PROGRAM_ARB %s
-""" % prog.getProgId()
-]
+    BindTexture TEXTURE_2D %s
+""" % tex.getTexId()]
+
 for i in range(0, nlevels + 1):
-    list.append("""
-       BindTexture TEXTURE_2D %s
-       Begin QUADS
-    """ % textures[i].getTexId())
     for x in range(0, maxsize >> i):
        for y in range(0, maxsize >> i):
            xt = x * (1. / (maxsize >> i))
@@ -99,7 +45,8 @@
            xp = xm+1
            yp = ym+1
            list.append("""
-               MultiTexCoord TEXTURE1 %(xt)s %(yt)s
+               TexSubImage2D TEXTURE_2D  %(i)s %(x)s %(y)s 1 1 RGBA 1 1 1 1
+               Begin QUADS
                TexCoord 0 0
                Vertex %(xm)s %(ym)s
                TexCoord 0 1
@@ -108,10 +55,9 @@
                Vertex %(xp)s %(yp)s
                TexCoord 1 0
                Vertex %(xp)s %(ym)s
+               End
+               TexSubImage2D TEXTURE_2D  %(i)s %(x)s %(y)s 1 1 RGBA 0.5 0.5 
0.5 0.5
            """% locals())
-    list.append("""
-       End 
-    """)
     xoffs += maxsize >> i
     xoffs += 2
 
@@ -141,12 +87,26 @@
        texturemat = vs.scaleCS(texturerot, "C", self.sx, self.sy)
 
 
-       vs.put(getDListNocoords("""
+       vs.put(getDListNocoords(vob.putil.nvcode.parseCombiner("""
            Enable TEXTURE_2D
            Disable BLEND
            Disable ALPHA_TEST
            Color 1 1 1
            TexEnv TEXTURE_ENV TEXTURE_ENV_MODE REPLACE
+
+
+           # Strengthen by multiplying by 4
+
+           Enable REGISTER_COMBINERS_NV
+
+           SPARE0 = ( (+TEX0) + (-.5) ) * 4
+
+           SPARE0 =  (+SPARE0) + (.5) 
+
+           color = SPARE0
+           alpha = 1
+
+
            # MatrixMode TEXTURE
            # LoadIdentity
            # PushMatrix
@@ -154,7 +114,7 @@
            # Rotate 30 0 0 1
            # Scale 0.2 0.1 1
            # # Scale 1 1 1
-       """))
+       """)))
        vs.put(GLRen.createTransMatrix("TEXTURE"),
                texturemat)
        vs.put(list)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]