gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz doc/gl/Mipzip.rst gfx/util/texpacker.py gzz...


From: Tuomas J. Lukka
Subject: [Gzz-commits] gzz doc/gl/Mipzip.rst gfx/util/texpacker.py gzz...
Date: Thu, 16 Jan 2003 11:06:28 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Tuomas J. Lukka <address@hidden>        03/01/16 11:06:28

Modified files:
        doc/gl         : Mipzip.rst 
        gfx/util       : texpacker.py 
        gzz/gfx/gl     : GL.java MipzipLoader.java 

Log message:
        Mipzipping almost there

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/doc/gl/Mipzip.rst.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/util/texpacker.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/gfx/gl/GL.java.diff?tr1=1.39&tr2=1.40&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/gfx/gl/MipzipLoader.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text

Patches:
Index: gzz/doc/gl/Mipzip.rst
diff -u gzz/doc/gl/Mipzip.rst:1.3 gzz/doc/gl/Mipzip.rst:1.4
--- gzz/doc/gl/Mipzip.rst:1.3   Thu Jan 16 09:37:51 2003
+++ gzz/doc/gl/Mipzip.rst       Thu Jan 16 11:06:28 2003
@@ -7,7 +7,32 @@
 and discard mipmap levels.
 
 The Mipzip file format is simple: a zip file with a single entry
-for each mipmap level, and some metadata entries.
+for each mipmap level, and a metadata entry "texformat".
+The metadata is stored in comments so that unzip -l will show it.
+The format is stored as an callGL-accepted OpenGL token, e.g.
+``COMPRESSED_RGB_S3TC_DXT1_EXT``.
+
+..  UML:: mipzipformat
+
+    class MipzipFile
+       assoc compos - multi(1) FormatData
+       assoc compos - multi(n) LevelData
+
+    class FormatData
+       fields
+           name: "texformat"
+           comment: texformatname
+
+    class LevelData
+       fields
+           name: "i"
+           comment: resolution
+           content: data
+
+    ---
+
+    horizontally(80, foo, FormatData, LevelData);
+    vertically(80, bar, MipzipFile, foo);
 
 Due to the requirements of memory handling and GL threads,
 we need to separate loading the mipmap level and teximaging
Index: gzz/gfx/util/texpacker.py
diff -u gzz/gfx/util/texpacker.py:1.1 gzz/gfx/util/texpacker.py:1.2
--- gzz/gfx/util/texpacker.py:1.1       Thu Jan 16 06:24:36 2003
+++ gzz/gfx/util/texpacker.py   Thu Jan 16 11:06:28 2003
@@ -15,6 +15,8 @@
 prop = System.getProperties()
 prop.setProperty("gzzclient", "gl")
 
+format = "COMPRESSED_RGB_S3TC_DXT1_EXT"
+
 from gzz.gfx.gl import GL
 from gzz.client import GraphicsAPI
 
@@ -43,13 +45,19 @@
        w = roundup2(d.width)
        h = roundup2(d.height)
        tex = GL.createTexture()
-       tex.loadNull2D(0, "COMPRESSED_RGB_S3TC_DXT1_EXT", w, h, 0, "RGB", 
"FLOAT")
+       tex.loadNull2D(0, format, w, h, 0, "RGB", "FLOAT")
        print "WH: ",w, h
        tex.loadSubImage(0, im, 0, 0, 0, 0, chomp4(d.width), chomp4(d.height))
 
        of = texfile + ".mipzip"
 
        out = zip.ZipOutputStream(io.FileOutputStream(of)) 
+
+       entry = zip.ZipEntry("texformat")
+       entry.setComment(format)
+       entry.setSize(0)
+       out.putNextEntry(entry)
+       out.closeEntry()
 
        l = 0
        while 1:
Index: gzz/gzz/gfx/gl/GL.java
diff -u gzz/gzz/gfx/gl/GL.java:1.39 gzz/gzz/gfx/gl/GL.java:1.40
--- gzz/gzz/gfx/gl/GL.java:1.39 Thu Jan 16 08:25:56 2003
+++ gzz/gzz/gfx/gl/GL.java      Thu Jan 16 11:06:28 2003
@@ -396,6 +396,9 @@
         */
        public int getTexId() { return getId(); }
 
+       public void setTexParameter(String target, String param, float value) {
+           this.setTexParameter(target, param, ""+value);
+       }
        public void setTexParameter(String target, String param, String value) {
            call("BindTexture "+target+" "+getTexId()+"\n"+
                    "TexParameter "+target+" "+param+" "+value+"\n"+
Index: gzz/gzz/gfx/gl/MipzipLoader.java
diff -u gzz/gzz/gfx/gl/MipzipLoader.java:1.3 
gzz/gzz/gfx/gl/MipzipLoader.java:1.4
--- gzz/gzz/gfx/gl/MipzipLoader.java:1.3        Thu Jan 16 09:37:51 2003
+++ gzz/gzz/gfx/gl/MipzipLoader.java    Thu Jan 16 11:06:28 2003
@@ -3,6 +3,7 @@
 package gzz.gfx.gl;
 import java.awt.Dimension;
 import java.io.*;
+import java.util.*;
 import java.util.zip.*;
 import gzz.*;
 
@@ -30,15 +31,36 @@
      */
     private ZipFile zip;
 
+    private final Level[] levels;
+
+    /** 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 {
+       ZipFile f = getZipFile();
+       synchronized(f) {
+           ZipEntry e = f.getEntry(name);
+           byte[] loadedData = new byte[(int)e.getSize()];
+           InputStream i = f.getInputStream(e);
+           i.read(loadedData);
+           i.close();
+           return loadedData;
+       }
+    }
+
     /** A single mipmap level.
      */
-    class Level {
+    private class Level {
+
+       /** Whether this level is loaded into
+        * the texture.
+        */
+       boolean loaded = false;
 
        /** The index of this level.
         */
@@ -53,24 +75,88 @@
        byte[] loadedData;
 
        /** Load the data for this mipmap level
-        * synchronously.
+        * synchronously into memory. This method
+        * does not cause TexImage to be called
+        * and can therefore be called in any
+        * thread.
         */
        synchronized void loadData() throws IOException {
-           if(loadedData != null) return;
-           ZipFile f = getZipFile();
-           ZipEntry e = f.getEntry(""+level);
-           
+           if(loaded || loadedData != null) return;
+           // Not sure if required, but safer
+           loadedData = readEntry(""+level);
        }
 
+       /** Call TexImage and afterwards discard the loaded data.
+        * Must be called in GL thread.
+        */
        synchronized void texImage() {
+           if(loadedData == null)
+               return;
+           tex.compressedTexImage(level, texFormat,
+                       size.width, size.height, 0,
+                       loadedData);
+           loaded = true;
+           loadedData = null;
+       }
+
+       /** Discard the texture level from the GL side.
+        * Done by loading an 1x1 image in its place.
+        * Hope this really works.
+        */
+       synchronized void discard() {
+           if(!loaded) return;
+           tex.loadNull2D(level, texFormat, 1, 1, 0, "RGB", "FLOAT");
+           loaded = false;
        }
 
+       /** 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 {
+           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);
+       }
+
+    }
+
+    synchronized private void setBaseLevel(int level) {
+       tex.setTexParameter("TEXTURE_2D", "TEXTURE_BASE_LEVEL", level);
     }
 
-    public MipzipLoader(File f) {
-       this.mipzipFile = f;
+    /** Set the base level synchronously: load or discard.
+     */
+    synchronized public void loadToBaseLevelSynch(int level) throws 
IOException {
+       for(int i=0; i<level; i++) {
+           levels[i].discard();
+       }
+       for(int i=level; i<levels.length; i++) {
+           levels[i].loadData();
+           levels[i].texImage();
+       }
+       setBaseLevel(level);
+    }
+
+    public MipzipLoader(File mipzipFile) throws IOException {
+       this.mipzipFile = mipzipFile;
        this.tex = GL.createTexture();
-       this.texFormat = "";
+       ZipFile f = getZipFile();
+       this.texFormat = f.getEntry("texformat").getComment();
+       ArrayList l = new ArrayList();
+       for(int i=0; i<100; i++) {
+           ZipEntry 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!");
+       }
     }
 
 }




reply via email to

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