Ejemplo n.º 1
0
def getTex(s):
    if not imgs.has_key(s):
        print "Load image ", s
        imgs[s] = GL.createImage(s)
        texs[s] = GL.createTexRect(imgs[s])
    return texs[s]
Ejemplo n.º 2
0
def makeMipzip(image,
               mipzip,
               maxwidth=-1,
               maxheight=-1,
               texformat=None,
               internalTexFormat=None,
               uncompressedTexType=None):
    """Convert the given image file into a mipzip file.

    image -- the image file name
    mipzip -- the mipzip file name
    maxwidth -- if image is wider than maxwidth, cut off edge
    maxheight -- if image is taller than maxheight, cut off edge
    texformat -- The texture format to use
    internalTexFormat -- The internal texture format to represent the data in
                         for compressed textures, same as texformat
    uncompressedTexType -- The datatype (relevant only for uncompressed
			   textures)
    """

    if texformat == None:
        if not defaultTexFormat:
            _init()
        texformat = defaultTexFormat

    print "TEXFORMAT: ", texformat, defaultTexFormat
    isCompressed = (java.lang.String(texformat).indexOf("COMPRESS") >= 0)

    if internalTexFormat == None:
        internalTexFormat = texformat

    if not isCompressed:
        if uncompressedTexType == None:
            uncompressedTexType = "UNSIGNED_BYTE"

    _init()
    GL.freeQueue()

    im = GL.createImage(image)
    d0 = im.getSize()
    print d0
    d = java.awt.Dimension(
        _clipmax(d0.width, maxwidth),
        _clipmax(d0.height, maxheight),
    )

    w = roundup2(d.width)
    h = roundup2(d.height)
    tex = GL.createTexture()
    tex.loadNull2D('TEXTURE_2D', 0, internalTexFormat, w, h, 0, "RGB", "BYTE")
    print "WH: ", w, h
    tex.loadSubImage(0, im, 0, 0, 0, 0, chomp4(d.width), chomp4(d.height))

    print "Write ", mipzip

    out = zip.ZipOutputStream(java.io.FileOutputStream(mipzip))

    def metaEntry(name, comment):
        entry = zip.ZipEntry(name)
        entry.setComment(comment)
        entry.setSize(0)
        out.putNextEntry(entry)
        out.closeEntry()

    metaEntry("texformat", texformat)

    if not isCompressed:
        metaEntry("internaltexformat", internalTexFormat)
        metaEntry("datatype", uncompressedTexType)

    metaEntry("origsize", "%sx%s" % (d.width / float(w), d.height / float(h)))

    l = 0
    while 1:
        w = int(tex.getLevelParameter(l, "TEXTURE_WIDTH")[0])
        h = int(tex.getLevelParameter(l, "TEXTURE_HEIGHT")[0])
        print "WH: ", w, h

        if isCompressed:
            bytes = tex.getCompressedTexImage(l)
        else:
            bpt = bytesPerTexel(texformat, uncompressedTexType)

            bytes = jarray.zeros(bpt * w * h, "b")
            tex.getTexImage(l, texformat, uncompressedTexType, bytes)

        print "Bytes: ", l, len(bytes)
        entry = zip.ZipEntry(str(l))
        entry.setComment("%sx%s" % (int(w), int(h)))
        entry.setSize(len(bytes))
        out.putNextEntry(entry)
        out.write(bytes)
        out.closeEntry()
        if w == 1 and h == 1: break
        l += 1
    out.close()
    del tex
    java.lang.System.gc()
    GL.freeQueue()