diff options
Diffstat (limited to 'src/jogl/classes')
17 files changed, 794 insertions, 484 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/FileUtil.java b/src/jogl/classes/com/jogamp/opengl/util/FileUtil.java deleted file mode 100644 index 6ad0da825..000000000 --- a/src/jogl/classes/com/jogamp/opengl/util/FileUtil.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.opengl.util; - -import java.io.*; - -/** Utilities for dealing with files. */ - -public class FileUtil { - private FileUtil() {} - - /** - * Returns the lowercase suffix of the given file name (the text - * after the last '.' in the file name). Returns null if the file - * name has no suffix. Only operates on the given file name; - * performs no I/O operations. - * - * @param file name of the file - * @return lowercase suffix of the file name - * @throws NullPointerException if file is null - */ - - public static String getFileSuffix(File file) { - return getFileSuffix(file.getName()); - } - - /** - * Returns the lowercase suffix of the given file name (the text - * after the last '.' in the file name). Returns null if the file - * name has no suffix. Only operates on the given file name; - * performs no I/O operations. - * - * @param filename name of the file - * @return lowercase suffix of the file name - * @throws NullPointerException if filename is null - */ - public static String getFileSuffix(String filename) { - int lastDot = filename.lastIndexOf('.'); - if (lastDot < 0) { - return null; - } - return toLowerCase(filename.substring(lastDot + 1)); - } - - private static String toLowerCase(String arg) { - if (arg == null) { - return null; - } - - return arg.toLowerCase(); - } -} diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java b/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java index efe3a7675..f2e742cda 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java @@ -42,60 +42,145 @@ import com.jogamp.common.nio.Buffers; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL2GL3; +import javax.media.opengl.GLException; import java.nio.*; /** * Utility routines for dealing with direct buffers. * @author Kenneth Russel + * @author Sven Gothel * @author Michael Bien */ public class GLBuffers extends Buffers { + /** + * @param glType shall be one of + * GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, + * GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE, + * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, + * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, + * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, + * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, + * GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, + * GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV + * GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV, + * GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT_32_UNSIGNED_INT_24_8_REV (25) + * @return -1 if glType is unhandled, otherwise the actual value > 0 + */ public static final int sizeOfGLType(int glType) { - switch (glType) { - case GL.GL_UNSIGNED_BYTE: - return SIZEOF_BYTE; + switch (glType) { // 25 case GL.GL_BYTE: + case GL.GL_UNSIGNED_BYTE: + case GL2GL3.GL_UNSIGNED_BYTE_3_3_2: + case GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV: return SIZEOF_BYTE; - case GL.GL_UNSIGNED_SHORT: - return SIZEOF_SHORT; + case GL.GL_SHORT: + case GL.GL_UNSIGNED_SHORT: + case GL.GL_UNSIGNED_SHORT_5_6_5: + case GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV: + case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4: + case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1: + case GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV: return SIZEOF_SHORT; - case GL.GL_FLOAT: - return SIZEOF_FLOAT; + case GL.GL_FIXED: - return SIZEOF_INT; case GL2ES2.GL_INT: + case GL.GL_UNSIGNED_INT: + case GL2GL3.GL_UNSIGNED_INT_8_8_8_8: + case GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV: + case GL2GL3.GL_UNSIGNED_INT_10_10_10_2: + case GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV: + case GL2GL3.GL_UNSIGNED_INT_24_8: + case GL2GL3.GL_UNSIGNED_INT_10F_11F_11F_REV: + case GL2GL3.GL_UNSIGNED_INT_5_9_9_9_REV: return SIZEOF_INT; - case GL2ES2.GL_UNSIGNED_INT: - return SIZEOF_INT; + + case GL2GL3.GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + return SIZEOF_LONG; + + case GL.GL_FLOAT: + return SIZEOF_FLOAT; + case GL2.GL_DOUBLE: return SIZEOF_DOUBLE; } return -1; } - + + /** + * @param glType shall be one of + * GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, + * GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE, + * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, + * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, + * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, + * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, + * GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, + * GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV + * GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV, + * GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT_32_UNSIGNED_INT_24_8_REV (25) + * @return null if glType is unhandled, otherwise the new Buffer object + */ public static final Buffer newDirectGLBuffer(int glType, int numElements) { switch (glType) { - case GL.GL_UNSIGNED_BYTE: case GL.GL_BYTE: + case GL.GL_UNSIGNED_BYTE: + case GL2GL3.GL_UNSIGNED_BYTE_3_3_2: + case GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV: return newDirectByteBuffer(numElements); - case GL.GL_UNSIGNED_SHORT: + case GL.GL_SHORT: + case GL.GL_UNSIGNED_SHORT: + case GL.GL_UNSIGNED_SHORT_5_6_5: + case GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV: + case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4: + case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1: + case GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV: return newDirectShortBuffer(numElements); - case GL.GL_FLOAT: - return newDirectFloatBuffer(numElements); + case GL.GL_FIXED: case GL2ES2.GL_INT: - case GL2ES2.GL_UNSIGNED_INT: + case GL.GL_UNSIGNED_INT: + case GL2GL3.GL_UNSIGNED_INT_8_8_8_8: + case GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV: + case GL2GL3.GL_UNSIGNED_INT_10_10_10_2: + case GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV: + case GL2GL3.GL_UNSIGNED_INT_24_8: + case GL2GL3.GL_UNSIGNED_INT_10F_11F_11F_REV: + case GL2GL3.GL_UNSIGNED_INT_5_9_9_9_REV: return newDirectIntBuffer(numElements); + + case GL2GL3.GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + return newDirectLongBuffer(numElements); + + case GL.GL_FLOAT: + return newDirectFloatBuffer(numElements); + case GL2.GL_DOUBLE: return newDirectDoubleBuffer(numElements); } return null; } + /** + * @param glType shall be one of + * GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, + * GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE, + * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, + * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, + * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, + * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, + * GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, + * GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV + * GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV, + * GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT_32_UNSIGNED_INT_24_8_REV (25) + * @return null if glType is unhandled or parent is null or bufLen is 0, otherwise the new Buffer object + */ public static final Buffer sliceGLBuffer(ByteBuffer parent, int bytePos, int byteLen, int glType) { if (parent == null || byteLen == 0) { return null; @@ -104,24 +189,309 @@ public class GLBuffers extends Buffers { parent.limit(bytePos + byteLen); switch (glType) { - case GL.GL_UNSIGNED_BYTE: case GL.GL_BYTE: + case GL.GL_UNSIGNED_BYTE: + case GL2GL3.GL_UNSIGNED_BYTE_3_3_2: + case GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV: return parent.slice(); - case GL.GL_UNSIGNED_SHORT: + case GL.GL_SHORT: + case GL.GL_UNSIGNED_SHORT: + case GL.GL_UNSIGNED_SHORT_5_6_5: + case GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV: + case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4: + case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1: + case GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV: return parent.asShortBuffer(); - case GL.GL_FLOAT: - return parent.asFloatBuffer(); + case GL.GL_FIXED: - case GL2ES2.GL_INT: + case GL2GL3.GL_INT: case GL2ES2.GL_UNSIGNED_INT: + case GL2GL3.GL_UNSIGNED_INT_8_8_8_8: + case GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV: + case GL2GL3.GL_UNSIGNED_INT_10_10_10_2: + case GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV: + case GL2GL3.GL_UNSIGNED_INT_24_8: + case GL2GL3.GL_UNSIGNED_INT_10F_11F_11F_REV: + case GL2GL3.GL_UNSIGNED_INT_5_9_9_9_REV: return parent.asIntBuffer(); + + case GL2GL3.GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + return parent.asLongBuffer(); + + case GL.GL_FLOAT: + return parent.asFloatBuffer(); + case GL2.GL_DOUBLE: return parent.asDoubleBuffer(); } return null; } + private static final int glGetInteger(GL gl, int pname, int[] tmp) { + gl.glGetIntegerv(pname, tmp, 0); + return tmp[0]; + } + + /** + * Returns the number of bytes required to read/write a memory buffer via OpenGL + * using the current GL pixel storage state and the given parameters. + * + * <p>This method is security critical, hence it throws an exception (fail-fast) + * in case of an invalid alignment. In case we forgot to handle + * proper values, please contact the maintainer.</p> + * + * @param gl the current GL object + * + * @param tmp a pass through integer array of size >= 1 used to store temp data (performance) + * + * @param bytesPerElement bytes per element + * @param width in pixels + * @param height in pixels + * @param depth in pixels + * @param pack true for read mode GPU -> CPU (pack), otherwise false for write mode CPU -> GPU (unpack) + * @return required minimum size of the buffer in bytes + * @throws GLException if alignment is invalid. Please contact the maintainer if this is our bug. + */ + public static final int sizeof(GL gl, int tmp[], + int bytesPerElement, int width, int height, int depth, + boolean pack) { + int rowLength = 0; + int skipRows = 0; + int skipPixels = 0; + int alignment = 1; + int imageHeight = 0; + int skipImages = 0; + + if (pack) { + alignment = glGetInteger(gl, GL.GL_PACK_ALIGNMENT, tmp); + if(gl.isGL2GL3()) { + rowLength = glGetInteger(gl, GL2GL3.GL_PACK_ROW_LENGTH, tmp); + skipRows = glGetInteger(gl, GL2GL3.GL_PACK_SKIP_ROWS, tmp); + skipPixels = glGetInteger(gl, GL2GL3.GL_PACK_SKIP_PIXELS, tmp); + if (depth > 1) { + imageHeight = glGetInteger(gl, GL2GL3.GL_PACK_IMAGE_HEIGHT, tmp); + skipImages = glGetInteger(gl, GL2GL3.GL_PACK_SKIP_IMAGES, tmp); + } + } + } else { + alignment = glGetInteger(gl, GL.GL_UNPACK_ALIGNMENT, tmp); + if(gl.isGL2GL3 ()) { + rowLength = glGetInteger(gl, GL2GL3.GL_UNPACK_ROW_LENGTH, tmp); + skipRows = glGetInteger(gl, GL2GL3.GL_UNPACK_SKIP_ROWS, tmp); + skipPixels = glGetInteger(gl, GL2GL3.GL_UNPACK_SKIP_PIXELS, tmp); + if (depth > 1) { + imageHeight = glGetInteger(gl, GL2GL3.GL_UNPACK_IMAGE_HEIGHT, tmp); + skipImages = glGetInteger(gl, GL2GL3.GL_UNPACK_SKIP_IMAGES, tmp); + } + } + } + + // Try to deal somewhat correctly with potentially invalid values + width = Math.max(0, width ); + height = Math.max(1, height); // min 1D + depth = Math.max(1, depth ); // min 1 * imageSize + skipRows = Math.max(0, skipRows); + skipPixels = Math.max(0, skipPixels); + alignment = Math.max(1, alignment); + skipImages = Math.max(0, skipImages); + + imageHeight = ( imageHeight > 0 ) ? imageHeight : height; + rowLength = ( rowLength > 0 ) ? rowLength : width; + + int rowLengthInBytes = rowLength * bytesPerElement; + int skipBytes = skipPixels * bytesPerElement; + + switch(alignment) { + case 1: + break; + case 2: + case 4: + case 8: { + // x % 2n == x & (2n - 1) + int remainder = rowLengthInBytes & ( alignment - 1 ); + if (remainder > 0) { + rowLengthInBytes += alignment - remainder; + } + remainder = skipBytes & ( alignment - 1 ); + if (remainder > 0) { + skipBytes += alignment - remainder; + } + } + break; + default: + throw new GLException("Invalid alignment "+alignment+", must be 2**n (1,2,4,8). Pls notify the maintainer in case this is our bug."); + } + + /** + * skipImages, depth, skipPixels and skipRows are static offsets. + * + * skipImages and depth are in multiples of image size. + * + * skipBytes and rowLengthInBytes are aligned + * + * rowLengthInBytes is the aligned byte offset + * from line n to line n+1 at the same x-axis position. + */ + return + skipBytes + // aligned skipPixels * bpp + ( skipImages + depth - 1 ) * imageHeight * rowLengthInBytes + // aligned whole images + ( skipRows + height - 1 ) * rowLengthInBytes + // aligned lines + width * bytesPerElement; // last line + } + + /** + * Returns the number of bytes required to read/write a memory buffer via OpenGL + * using the current GL pixel storage state and the given parameters. + * + * <p>This method is security critical, hence it throws an exception (fail-fast) + * in case either the format, type or alignment is unhandled. In case we forgot to handle + * proper values, please contact the maintainer.</p> + * + * @param gl the current GL object + * + * @param tmp a pass through integer array of size >= 1 used to store temp data (performance) + * + * @param format must be one of + * GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, + * GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_LUMINANCE, + * GL_RG, GL_LUMINANCE_ALPHA, + * GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_ABGR_EXT, + * GL_RED_INTEGER, GL_GREEN_INTEGER, GL_BLUE_INTEGER, + * GL_RG_INTEGER, GL_RGB_INTEGER, GL_BGR_INTEGER, + * GL_RGBA_INTEGER, GL_BGRA_INTEGER (24) + * + * @param type must be one of + * GL_BITMAP, + * GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, + * GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE, + * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, + * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, + * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, + * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, + * GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, + * GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV + * GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV, + * GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT_32_UNSIGNED_INT_24_8_REV (26) + * + * @param width in pixels + * @param height in pixels + * @param depth in pixels + * @param pack true for read mode GPU -> CPU, otherwise false for write mode CPU -> GPU + * @return required minimum size of the buffer in bytes + * @throws GLException if format, type or alignment is not handled. Please contact the maintainer if this is our bug. + */ + public static final int sizeof(GL gl, int tmp[], + int format, int type, int width, int height, int depth, + boolean pack) throws GLException { + int elements = 0; + int esize = 0; + + if (width < 0) return 0; + if (height < 0) return 0; + if (depth < 0) return 0; + + switch (format) /* 24 */ { + case GL2.GL_COLOR_INDEX: + case GL2GL3.GL_STENCIL_INDEX: + case GL2GL3.GL_DEPTH_COMPONENT: + case GL2GL3.GL_DEPTH_STENCIL: + case GL2GL3.GL_RED: + case GL2GL3.GL_RED_INTEGER: + case GL2GL3.GL_GREEN: + case GL2GL3.GL_GREEN_INTEGER: + case GL2GL3.GL_BLUE: + case GL2GL3.GL_BLUE_INTEGER: + case GL.GL_ALPHA: + case GL.GL_LUMINANCE: + elements = 1; + break; + case GL.GL_LUMINANCE_ALPHA: + case GL2GL3.GL_RG: + case GL2GL3.GL_RG_INTEGER: + elements = 2; + break; + case GL.GL_RGB: + case GL2GL3.GL_RGB_INTEGER: + case GL2GL3.GL_BGR: + case GL2GL3.GL_BGR_INTEGER: + elements = 3; + break; + case GL.GL_RGBA: + case GL2GL3.GL_RGBA_INTEGER: + case GL2GL3.GL_BGRA: + case GL2GL3.GL_BGRA_INTEGER: + case GL2.GL_ABGR_EXT: + elements = 4; + break; + /* FIXME ?? + case GL.GL_HILO_NV: + elements = 2; + break; */ + default: + throw new GLException("format 0x"+Integer.toHexString(format)+" not supported [yet], pls notify the maintainer in case this is our bug."); + } + + switch (type) /* 26 */ { + case GL2.GL_BITMAP: + if (GL2.GL_COLOR_INDEX == format || GL2GL3.GL_STENCIL_INDEX == format) { + return (depth * (height * ((width+7)/8))); + } + case GL.GL_BYTE: + case GL.GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL.GL_SHORT: + case GL.GL_UNSIGNED_SHORT: + case GL.GL_HALF_FLOAT: + esize = 2; + break; + case GL2ES2.GL_INT: + case GL.GL_UNSIGNED_INT: + case GL.GL_FLOAT: + esize = 4; + break; + case GL2GL3.GL_DOUBLE: + esize = 8; + break; + + case GL2GL3.GL_UNSIGNED_BYTE_3_3_2: + case GL2GL3.GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL.GL_UNSIGNED_SHORT_5_6_5: + case GL2GL3.GL_UNSIGNED_SHORT_5_6_5_REV: + case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4: + case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1: + case GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL2GL3.GL_UNSIGNED_INT_8_8_8_8: + case GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV: + case GL2GL3.GL_UNSIGNED_INT_10_10_10_2: + case GL2GL3.GL_UNSIGNED_INT_2_10_10_10_REV: + case GL2GL3.GL_UNSIGNED_INT_24_8: + case GL2GL3.GL_UNSIGNED_INT_10F_11F_11F_REV: + case GL2GL3.GL_UNSIGNED_INT_5_9_9_9_REV: + esize = 4; + elements = 1; + break; + case GL2GL3.GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + esize = 8; + elements = 1; + break; + + default: + throw new GLException("type 0x"+Integer.toHexString(type)+"/"+"format 0x"+Integer.toHexString(format)+" not supported [yet], pls notify the maintainer in case this is our bug."); + } + + return sizeof(gl, tmp, elements * esize, width, height, depth, pack); + } + //---------------------------------------------------------------------- // Conversion routines // diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java b/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java new file mode 100644 index 000000000..05eb67269 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java @@ -0,0 +1,136 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.util; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL2GL3; +import javax.media.opengl.GLException; + +/** + * Utility to safely set and restore the pack and unpack pixel storage mode, + * regardless of the GLProfile. + */ +public class GLPixelStorageModes { + private int[] savedGL2GL3Modes = new int[8]; + private int[] savedAlignment = new int[2]; + private boolean saved = false; + + /** + * Sets the {@link GL2ES2.GL_PACK_ALIGNMENT}. Saves the pixel storage modes if not saved yet. + */ + public final void setPackAlignment(GL gl, int packAlignment) { + if(!saved) { save(gl); } + gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, packAlignment); + } + + /** + * Sets the {@link GL2ES2.GL_UNPACK_ALIGNMENT}. Saves the pixel storage modes if not saved yet. + */ + public final void setUnpackAlignment(GL gl, int unpackAlignment) { + if(!saved) { save(gl); } + gl.glPixelStorei(GL2ES2.GL_UNPACK_ALIGNMENT, unpackAlignment); + } + + /** + * Sets the {@link GL2ES2.GL_PACK_ALIGNMENT} and {@link GL2ES2.GL_UNPACK_ALIGNMENT}. + * Saves the pixel storage modes if not saved yet. + */ + public final void setAlignment(GL gl, int packAlignment, int unpackAlignment) { + setPackAlignment(gl, packAlignment); + setUnpackAlignment(gl, unpackAlignment); + } + + private final void save(GL gl) { + if(gl.isGL2GL3()) { + if(gl.isGL2()) { + gl.getGL2().glPushClientAttrib(GL2.GL_CLIENT_PIXEL_STORE_BIT); + } else { + gl.glGetIntegerv(GL2ES2.GL_PACK_ALIGNMENT, savedAlignment, 0); + gl.glGetIntegerv(GL2ES2.GL_UNPACK_ALIGNMENT, savedAlignment, 1); + gl.glGetIntegerv(GL2GL3.GL_PACK_ROW_LENGTH, savedGL2GL3Modes, 0); + gl.glGetIntegerv(GL2GL3.GL_PACK_SKIP_ROWS, savedGL2GL3Modes, 1); + gl.glGetIntegerv(GL2GL3.GL_PACK_SKIP_PIXELS, savedGL2GL3Modes, 2); + gl.glGetIntegerv(GL2GL3.GL_PACK_SWAP_BYTES, savedGL2GL3Modes, 3); + gl.glGetIntegerv(GL2GL3.GL_UNPACK_ROW_LENGTH, savedGL2GL3Modes, 4); + gl.glGetIntegerv(GL2GL3.GL_UNPACK_SKIP_ROWS, savedGL2GL3Modes, 5); + gl.glGetIntegerv(GL2GL3.GL_UNPACK_SKIP_PIXELS, savedGL2GL3Modes, 6); + gl.glGetIntegerv(GL2GL3.GL_UNPACK_SWAP_BYTES, savedGL2GL3Modes, 7); + } + gl.glPixelStorei(GL2GL3.GL_PACK_ROW_LENGTH, 0); + gl.glPixelStorei(GL2GL3.GL_PACK_SKIP_ROWS, 0); + gl.glPixelStorei(GL2GL3.GL_PACK_SKIP_PIXELS, 0); + gl.glPixelStorei(GL2GL3.GL_PACK_SWAP_BYTES, 0); + gl.glPixelStorei(GL2GL3.GL_UNPACK_ROW_LENGTH, 0); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_ROWS, 0); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_PIXELS, 0); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SWAP_BYTES, 0); + } else { + // embedded deals with pack/unpack alignment only + gl.glGetIntegerv(GL2ES2.GL_PACK_ALIGNMENT, savedAlignment, 0); + gl.glGetIntegerv(GL2ES2.GL_UNPACK_ALIGNMENT, savedAlignment, 1); + } + saved = true; + } + + /** + * Restores the pixel storage mode. + * @throws GLException if not saved via one of the set methods. + */ + public final void restore(GL gl) throws GLException { + if(!saved) { + throw new GLException("pixel storage modes not saved"); + } + + if(gl.isGL2GL3()) { + if(gl.isGL2()) { + gl.getGL2().glPopClientAttrib(); + } else { + gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, savedAlignment[0]); + gl.glPixelStorei(GL2ES2.GL_UNPACK_ALIGNMENT, savedAlignment[1]); + gl.glPixelStorei(GL2GL3.GL_PACK_ROW_LENGTH, savedGL2GL3Modes[0]); + gl.glPixelStorei(GL2GL3.GL_PACK_SKIP_ROWS, savedGL2GL3Modes[1]); + gl.glPixelStorei(GL2GL3.GL_PACK_SKIP_PIXELS, savedGL2GL3Modes[2]); + gl.glPixelStorei(GL2GL3.GL_PACK_SWAP_BYTES, savedGL2GL3Modes[3]); + gl.glPixelStorei(GL2GL3.GL_UNPACK_ROW_LENGTH, savedGL2GL3Modes[4]); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_ROWS, savedGL2GL3Modes[5]); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_PIXELS, savedGL2GL3Modes[6]); + gl.glPixelStorei(GL2GL3.GL_UNPACK_SWAP_BYTES, savedGL2GL3Modes[7]); + } + } else { + // embedded deals with pack/unpack alignment only + gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, savedAlignment[0]); + gl.glPixelStorei(GL2ES2.GL_UNPACK_ALIGNMENT, savedAlignment[1]); + } + saved = false; + } +} + + diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java new file mode 100644 index 000000000..e5cf7d0d0 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java @@ -0,0 +1,181 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.util; + +import com.jogamp.common.nio.Buffers; + +import java.io.File; +import java.io.IOException; +import java.nio.*; +import javax.media.opengl.*; + +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; + +/** + * Utility to read out the current FB to TextureData, optionally writing the data back to a texture object. + * <p>May be used directly to write the TextureData to file (screenshot).</p> + */ +public class GLReadBufferUtil { + protected final int components, alignment; + protected final Texture readTexture; + protected final GLPixelStorageModes psm; + + protected int readPixelSizeLast = 0; + protected ByteBuffer readPixelBuffer = null; + protected TextureData readTextureData = null; + + /** + * @param alpha true for RGBA readPixels, otherwise RGB readPixels + * @param write2Texture true if readPixel's TextureData shall be written to a 2d Texture + */ + public GLReadBufferUtil(boolean alpha, boolean write2Texture) { + components = alpha ? 4 : 3 ; + alignment = alpha ? 4 : 1 ; + readTexture = write2Texture ? new Texture(GL.GL_TEXTURE_2D) : null ; + psm = new GLPixelStorageModes(); + } + + public boolean isValid() { + return null!=readTextureData && null!=readPixelBuffer ; + } + + /** + * @return the raw pixel ByteBuffer, filled by {@link #readPixels(GLAutoDrawable, boolean)} + */ + public ByteBuffer getPixelBuffer() { return readPixelBuffer; } + + /** + * rewind the raw pixel ByteBuffer + */ + public void rewindPixelBuffer() { if( null != readPixelBuffer ) { readPixelBuffer.rewind(); } } + + /** + * @return the resulting TextureData, filled by {@link #readPixels(GLAutoDrawable, boolean)} + */ + public TextureData getTextureData() { return readTextureData; } + + /** + * @return the Texture object filled by {@link #readPixels(GLAutoDrawable, boolean)}, + * if this instance writes to a 2d Texture, otherwise null. + * @see #GLReadBufferUtil(boolean, boolean) + */ + public Texture getTexture() { return readTexture; } + + /** + * Write the TextureData filled by {@link #readPixels(GLAutoDrawable, boolean)} to file + */ + public void write(File dest) { + try { + TextureIO.write(readTextureData, dest); + rewindPixelBuffer(); + } catch (IOException ex) { + throw new RuntimeException("can not write to file: " + dest.getAbsolutePath(), ex); + } + } + + /** + * Read the drawable's pixels to TextureData and Texture, if requested at construction + * + * @param gl the current GL object + * @param drawable the drawable to read from + * @param flip weather to flip the data vertically or not + * + * @see #GLReadBufferUtil(boolean, boolean) + */ + public void readPixels(GL gl, GLDrawable drawable, boolean flip) { + final int textureInternalFormat, textureDataFormat; + final int textureDataType = GL.GL_UNSIGNED_BYTE; + if(4 == components) { + textureInternalFormat=GL.GL_RGBA; + textureDataFormat=GL.GL_RGBA; + } else { + textureInternalFormat=GL.GL_RGB; + textureDataFormat=GL.GL_RGB; + } + final int readPixelSize = drawable.getWidth() * drawable.getHeight() * components ; + boolean newData = false; + if(readPixelSize>readPixelSizeLast) { + readPixelBuffer = Buffers.newDirectByteBuffer(readPixelSize); + readPixelSizeLast = readPixelSize ; + try { + readTextureData = new TextureData( + gl.getGLProfile(), + textureInternalFormat, + drawable.getWidth(), drawable.getHeight(), + 0, + textureDataFormat, + textureDataType, + false, false, + flip, + readPixelBuffer, + null /* Flusher */); + newData = true; + } catch (Exception e) { + readTextureData = null; + readPixelBuffer = null; + readPixelSizeLast = 0; + throw new RuntimeException("can not fetch offscreen texture", e); + } + } + if(null!=readPixelBuffer) { + psm.setAlignment(gl, alignment, alignment); + readPixelBuffer.clear(); + gl.glReadPixels(0, 0, drawable.getWidth(), drawable.getHeight(), textureDataFormat, textureDataType, readPixelBuffer); + readPixelBuffer.rewind(); + if(null != readTexture) { + if(newData) { + readTexture.updateImage(gl, readTextureData); + } else { + readTexture.updateSubImage(gl, readTextureData, 0, + 0, 0, // src offset + 0, 0, // dst offset + drawable.getWidth(), drawable.getHeight()); + } + readPixelBuffer.rewind(); + } + psm.restore(gl); + } + } + + public void dispose(GL gl) { + if(null != readTexture) { + readTexture.destroy(gl); + readTextureData = null; + } + if(null != readPixelBuffer) { + readPixelBuffer.clear(); + readPixelBuffer = null; + } + readPixelSizeLast = 0; + } + +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/Locator.java b/src/jogl/classes/com/jogamp/opengl/util/Locator.java deleted file mode 100644 index 0176b575a..000000000 --- a/src/jogl/classes/com/jogamp/opengl/util/Locator.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.opengl.util; - -import java.io.*; -import java.net.*; - -/** Utilities for dealing with resources. */ - -public class Locator { - private Locator() {} - - /** - * Locates the resource using 'getResource(String path, ClassLoader cl)', - * with this context ClassLoader and the path as is, - * as well with the context's package name path plus the path. - * - * @see #getResource(String, ClassLoader) - */ - public static URL getResource(Class context, String path) { - if(null == path) { - return null; - } - ClassLoader contextCL = (null!=context)?context.getClassLoader():null; - URL url = getResource(path, contextCL); - if (url == null && null!=context) { - // Try again by scoping the path within the class's package - String className = context.getName().replace('.', '/'); - int lastSlash = className.lastIndexOf('/'); - if (lastSlash >= 0) { - String tmpPath = className.substring(0, lastSlash + 1) + path; - url = getResource(tmpPath, contextCL); - } - } - return url; - } - - /** - * Locates the resource using the ClassLoader's facility, - * the absolute URL and absolute file. - * - * @see ClassLoader#getResource(String) - * @see ClassLoader#getSystemResource(String) - * @see URL#URL(String) - * @see File#File(String) - */ - public static URL getResource(String path, ClassLoader cl) { - if(null == path) { - return null; - } - URL url = null; - if (cl != null) { - url = cl.getResource(path); - if(!urlExists(url)) { - url = null; - } - } - if(null == url) { - url = ClassLoader.getSystemResource(path); - if(!urlExists(url)) { - url = null; - } - } - if(null == url) { - try { - url = new URL(path); - if(!urlExists(url)) { - url = null; - } - } catch (MalformedURLException e) { } - } - if(null == url) { - try { - File file = new File(path); - if(file.exists()) { - url = file.toURL(); - } else { - } - } catch (MalformedURLException e) {} - } - return url; - } - - /** - * Generates a path for the 'relativeFile' relative to the 'baseLocation'. - * - * @param baseLocation denotes a directory - * @param relativeFile denotes a relative file to the baseLocation - */ - public static String getRelativeOf(File baseLocation, String relativeFile) { - if(null == relativeFile) { - return null; - } - - while (baseLocation != null && relativeFile.startsWith("../")) { - baseLocation = baseLocation.getParentFile(); - relativeFile = relativeFile.substring(3); - } - if (baseLocation != null) { - final File file = new File(baseLocation, relativeFile); - // Handle things on Windows - return file.getPath().replace('\\', '/'); - } - return null; - } - - /** - * Generates a path for the 'relativeFile' relative to the 'baseLocation'. - * - * @param baseLocation denotes a URL to a file - * @param relativeFile denotes a relative file to the baseLocation's parent directory - */ - public static String getRelativeOf(URL baseLocation, String relativeFile) { - String urlPath = baseLocation.getPath(); - - if ( baseLocation.toString().startsWith("jar") ) { - JarURLConnection jarConnection; - try { - jarConnection = (JarURLConnection) baseLocation.openConnection(); - urlPath = jarConnection.getEntryName(); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - // Try relative path first - return getRelativeOf(new File(urlPath).getParentFile(), relativeFile); - } - - /** - * Returns true, if the url exists, - * trying to open a connection. - */ - public static boolean urlExists(URL url) { - boolean v = false; - if(null!=url) { - try { - URLConnection uc = url.openConnection(); - v = true; - } catch (IOException ioe) { } - } - return v; - } - -} - diff --git a/src/jogl/classes/com/jogamp/opengl/util/StreamUtil.java b/src/jogl/classes/com/jogamp/opengl/util/StreamUtil.java deleted file mode 100644 index 4cf8cb1f0..000000000 --- a/src/jogl/classes/com/jogamp/opengl/util/StreamUtil.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.opengl.util; - -import java.io.*; -import java.nio.*; - -/** Utilities for dealing with streams. */ - -public class StreamUtil { - private StreamUtil() {} - - public static byte[] readAll2Array(InputStream stream) throws IOException { - BytesRead bytesRead = readAllImpl(stream); - byte[] data = bytesRead.data; - if (bytesRead.payloadLen != data.length) { - data = new byte[bytesRead.payloadLen]; - System.arraycopy(bytesRead.data, 0, data, 0, bytesRead.payloadLen); - } - return data; - } - - public static ByteBuffer readAll2Buffer(InputStream stream) throws IOException { - BytesRead bytesRead = readAllImpl(stream); - return GLBuffers.newDirectByteBuffer(bytesRead.data, 0, bytesRead.payloadLen); - } - - private static BytesRead readAllImpl(InputStream stream) throws IOException { - // FIXME: Shall we do this here ? - if( !(stream instanceof BufferedInputStream) ) { - stream = new BufferedInputStream(stream); - } - int avail = stream.available(); - byte[] data = new byte[avail]; - int numRead = 0; - int pos = 0; - do { - if (pos + avail > data.length) { - byte[] newData = new byte[pos + avail]; - System.arraycopy(data, 0, newData, 0, pos); - data = newData; - } - numRead = stream.read(data, pos, avail); - if (numRead >= 0) { - pos += numRead; - } - avail = stream.available(); - } while (avail > 0 && numRead >= 0); - - return new BytesRead(pos, data); - } - - private static class BytesRead { - BytesRead(int payloadLen, byte[] data) { - this.payloadLen=payloadLen; - this.data=data; - } - int payloadLen; - byte[] data; - } -} diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/Overlay.java b/src/jogl/classes/com/jogamp/opengl/util/awt/Overlay.java index 1275c9391..73d694cd9 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/awt/Overlay.java +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/Overlay.java @@ -42,7 +42,6 @@ package com.jogamp.opengl.util.awt; import java.awt.Graphics2D; import javax.media.opengl.*; -import com.jogamp.opengl.util.texture.*; /** Provides a Java 2D overlay on top of an arbitrary GLDrawable, making it easier to do things like draw text and images on top of diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java b/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java index 7019d720f..fa66673fd 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java @@ -36,17 +36,20 @@ package com.jogamp.opengl.util.awt; -import java.awt.image.*; -import java.io.*; -import java.nio.*; -import java.nio.channels.*; -import javax.imageio.*; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferByte; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; -import javax.media.opengl.glu.gl2.*; +import javax.imageio.ImageIO; +import javax.media.opengl.GL2; +import javax.media.opengl.GLException; +import javax.media.opengl.glu.gl2.GLUgl2; -import com.jogamp.opengl.util.*; +import com.jogamp.common.util.IOUtil; +import com.jogamp.opengl.util.GLPixelStorageModes; +import com.jogamp.opengl.util.TGAWriter; /** Utilities for taking screenshots of OpenGL applications. */ @@ -148,8 +151,8 @@ public class Screenshot { GL2 gl = GLUgl2.getCurrentGL2(); // Set up pixel storage modes - PixelStorageModes psm = new PixelStorageModes(); - psm.save(gl); + GLPixelStorageModes psm = new GLPixelStorageModes(); + psm.setPackAlignment(gl, 1); int readbackType = (alpha ? GL2.GL_ABGR_EXT : GL2.GL_BGR); @@ -255,8 +258,8 @@ public class Screenshot { GL2 gl = GLUgl2.getCurrentGL2(); // Set up pixel storage modes - PixelStorageModes psm = new PixelStorageModes(); - psm.save(gl); + GLPixelStorageModes psm = new GLPixelStorageModes(); + psm.setPackAlignment(gl, 1); // read the BGR values into the image gl.glReadPixels(x, y, width, height, readbackType, @@ -375,7 +378,7 @@ public class Screenshot { int width, int height, boolean alpha) throws IOException, GLException { - String fileSuffix = FileUtil.getFileSuffix(file); + String fileSuffix = IOUtil.getFileSuffix(file); if (alpha && (fileSuffix.equals("jpg") || fileSuffix.equals("jpeg"))) { // JPEGs can't deal properly with alpha channels alpha = false; @@ -387,46 +390,10 @@ public class Screenshot { } } - private static int glGetInteger(GL2 gl, int pname, int[] tmp) { - gl.glGetIntegerv(pname, tmp, 0); - return tmp[0]; - } - private static void checkExtABGR() { GL2 gl = GLUgl2.getCurrentGL2(); if (!gl.isExtensionAvailable("GL_EXT_abgr")) { throw new IllegalArgumentException("Saving alpha channel requires GL_EXT_abgr"); } - } - - static class PixelStorageModes { - int packAlignment; - int packRowLength; - int packSkipRows; - int packSkipPixels; - int packSwapBytes; - int[] tmp = new int[1]; - - void save(GL2 gl) { - packAlignment = glGetInteger(gl, GL2.GL_PACK_ALIGNMENT, tmp); - packRowLength = glGetInteger(gl, GL2.GL_PACK_ROW_LENGTH, tmp); - packSkipRows = glGetInteger(gl, GL2.GL_PACK_SKIP_ROWS, tmp); - packSkipPixels = glGetInteger(gl, GL2.GL_PACK_SKIP_PIXELS, tmp); - packSwapBytes = glGetInteger(gl, GL2.GL_PACK_SWAP_BYTES, tmp); - - gl.glPixelStorei(GL2.GL_PACK_ALIGNMENT, 1); - gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, 0); - gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, 0); - gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, 0); - gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, 0); - } - - void restore(GL2 gl) { - gl.glPixelStorei(GL2.GL_PACK_ALIGNMENT, packAlignment); - gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, packRowLength); - gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, packSkipRows); - gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, packSkipPixels); - gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, packSwapBytes); - } - } + } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java index ad17dd288..12d80e42c 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -29,6 +29,8 @@ package com.jogamp.opengl.util.glsl; import com.jogamp.common.nio.Buffers; +import com.jogamp.common.util.IOUtil; + import javax.media.opengl.*; import com.jogamp.opengl.util.*; import jogamp.opengl.Debug; @@ -299,13 +301,13 @@ public class ShaderCode { URL nextURL = null; // Try relative path first - String next = Locator.getRelativeOf(url, includeFile); + String next = IOUtil.getRelativeOf(url, includeFile); if(null != next) { - nextURL = Locator.getResource(context, next); + nextURL = IOUtil.getResource(context, next); } if (nextURL == null) { // Try absolute path - nextURL = Locator.getResource(context, includeFile); + nextURL = IOUtil.getResource(context, includeFile); } if (nextURL == null) { // Fail @@ -335,7 +337,7 @@ public class ShaderCode { } public static String readShaderSource(Class context, String path) { - URL url = Locator.getResource(context, path); + URL url = IOUtil.getResource(context, path); if (url == null) { return null; } @@ -346,11 +348,11 @@ public class ShaderCode { public static ByteBuffer readShaderBinary(Class context, String path) { try { - URL url = Locator.getResource(context, path); + URL url = IOUtil.getResource(context, path); if (url == null) { return null; } - return StreamUtil.readAll2Buffer(new BufferedInputStream(url.openStream())); + return IOUtil.copyStream2ByteBuffer( new BufferedInputStream( url.openStream() ) ); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java index a0eed50ea..1f79890dc 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/sdk/CompileShader.java @@ -1,5 +1,7 @@ package com.jogamp.opengl.util.glsl.sdk; +import com.jogamp.common.util.IOUtil; + import javax.media.opengl.*; import com.jogamp.opengl.util.*; import com.jogamp.opengl.util.glsl.*; @@ -51,7 +53,7 @@ public abstract class CompileShader { String justName = basename(resourceName); outName = justName.substring(0, justName.length() - suffixLen) + ShaderCode.getFileSuffix(true, type); - URL resourceURL = Locator.getResource(null, resourceName); + URL resourceURL = IOUtil.getResource(null, resourceName); String dirName = dirname(resourceURL.getPath()); outName = dirName + File.separator + "bin" + File.separator + @@ -63,7 +65,7 @@ public abstract class CompileShader { public void processOneShader(String resourceName, String outName, int type) throws IOException, UnsupportedEncodingException, InterruptedException { - URL resourceURL = Locator.getResource(null, resourceName); + URL resourceURL = IOUtil.getResource(null, resourceName); String dirName = dirname(resourceURL.getPath()); String shader = ShaderCode.readShaderSource(null, resourceName); diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java index 35604ba30..08f56ef27 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java @@ -43,7 +43,6 @@ import javax.media.opengl.*; import javax.media.opengl.glu.*; import javax.media.nativewindow.NativeWindowFactory; import jogamp.opengl.*; -import com.jogamp.opengl.util.texture.*; import com.jogamp.opengl.util.texture.spi.*; /** diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java index f598422bf..149a2d46c 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java @@ -36,10 +36,11 @@ package com.jogamp.opengl.util.texture; -import java.nio.*; +import java.nio.Buffer; -import javax.media.opengl.*; -import com.jogamp.opengl.util.*; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.util.GLBuffers; /** * Represents the data for an OpenGL texture. This is separated from diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java index 792f80ff8..5be7f922b 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2011 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -39,16 +40,33 @@ package com.jogamp.opengl.util.texture; -import java.io.*; -import java.net.*; -import java.nio.*; -import java.util.*; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; import jogamp.opengl.Debug; -import com.jogamp.opengl.util.*; -import com.jogamp.opengl.util.texture.spi.*; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.opengl.util.texture.spi.DDSImage; +import com.jogamp.opengl.util.texture.spi.NetPbmTextureWriter; +import com.jogamp.opengl.util.texture.spi.SGIImage; +import com.jogamp.opengl.util.texture.spi.TGAImage; +import com.jogamp.opengl.util.texture.spi.TextureProvider; +import com.jogamp.opengl.util.texture.spi.TextureWriter; /** <P> Provides input and output facilities for both loading OpenGL textures from disk and streams as well as writing textures already @@ -177,7 +195,7 @@ public class TextureIO { boolean mipmap, String fileSuffix) throws IOException { if (fileSuffix == null) { - fileSuffix = FileUtil.getFileSuffix(file); + fileSuffix = IOUtil.getFileSuffix(file); } return newTextureDataImpl(glp, file, 0, 0, mipmap, fileSuffix); } @@ -234,7 +252,7 @@ public class TextureIO { boolean mipmap, String fileSuffix) throws IOException { if (fileSuffix == null) { - fileSuffix = FileUtil.getFileSuffix(url.getPath()); + fileSuffix = IOUtil.getFileSuffix(url.getPath()); } return newTextureDataImpl(glp, url, 0, 0, mipmap, fileSuffix); } @@ -288,7 +306,7 @@ public class TextureIO { } if (fileSuffix == null) { - fileSuffix = FileUtil.getFileSuffix(file); + fileSuffix = IOUtil.getFileSuffix(file); } return newTextureDataImpl(glp, file, internalFormat, pixelFormat, mipmap, fileSuffix); @@ -380,7 +398,7 @@ public class TextureIO { } if (fileSuffix == null) { - fileSuffix = FileUtil.getFileSuffix(url.getPath()); + fileSuffix = IOUtil.getFileSuffix(url.getPath()); } return newTextureDataImpl(glp, url, internalFormat, pixelFormat, mipmap, fileSuffix); @@ -437,7 +455,7 @@ public class TextureIO { public static Texture newTexture(File file, boolean mipmap) throws IOException, GLException { GL gl = GLContext.getCurrentGL(); GLProfile glp = gl.getGLProfile(); - TextureData data = newTextureData(glp, file, mipmap, FileUtil.getFileSuffix(file)); + TextureData data = newTextureData(glp, file, mipmap, IOUtil.getFileSuffix(file)); Texture texture = newTexture(gl, data); data.flush(); return texture; @@ -494,7 +512,7 @@ public class TextureIO { */ public static Texture newTexture(URL url, boolean mipmap, String fileSuffix) throws IOException, GLException { if (fileSuffix == null) { - fileSuffix = FileUtil.getFileSuffix(url.getPath()); + fileSuffix = IOUtil.getFileSuffix(url.getPath()); } GL gl = GLContext.getCurrentGL(); GLProfile glp = gl.getGLProfile(); @@ -878,7 +896,7 @@ public class TextureIO { boolean mipmap, String fileSuffix) throws IOException { if (DDS.equals(fileSuffix) || - DDS.equals(FileUtil.getFileSuffix(file))) { + DDS.equals(IOUtil.getFileSuffix(file))) { DDSImage image = DDSImage.read(file); return newTextureData(glp, image, internalFormat, pixelFormat, mipmap); } @@ -893,7 +911,7 @@ public class TextureIO { String fileSuffix) throws IOException { if (DDS.equals(fileSuffix) || DDSImage.isDDSImage(stream)) { - byte[] data = StreamUtil.readAll2Array(stream); + byte[] data = IOUtil.copyStream2ByteArray(stream); ByteBuffer buf = ByteBuffer.wrap(data); DDSImage image = DDSImage.read(buf); return newTextureData(glp, image, internalFormat, pixelFormat, mipmap); @@ -1014,7 +1032,7 @@ public class TextureIO { internalFormat, pixelFormat, mipmap, - ((fileSuffix != null) ? fileSuffix : FileUtil.getFileSuffix(file))); + ((fileSuffix != null) ? fileSuffix : IOUtil.getFileSuffix(file))); } finally { inStream.close(); } @@ -1113,7 +1131,7 @@ public class TextureIO { static class DDSTextureWriter implements TextureWriter { public boolean write(File file, TextureData data) throws IOException { - if (DDS.equals(FileUtil.getFileSuffix(file))) { + if (DDS.equals(IOUtil.getFileSuffix(file))) { // See whether the DDS writer can handle this TextureData int pixelFormat = data.getPixelFormat(); int pixelType = data.getPixelType(); @@ -1162,7 +1180,7 @@ public class TextureIO { static class SGITextureWriter implements TextureWriter { public boolean write(File file, TextureData data) throws IOException { - String fileSuffix = FileUtil.getFileSuffix(file); + String fileSuffix = IOUtil.getFileSuffix(file); if (SGI.equals(fileSuffix) || SGI_RGB.equals(fileSuffix)) { // See whether the SGI writer can handle this TextureData @@ -1206,7 +1224,7 @@ public class TextureIO { static class TGATextureWriter implements TextureWriter { public boolean write(File file, TextureData data) throws IOException { - if (TGA.equals(FileUtil.getFileSuffix(file))) { + if (TGA.equals(IOUtil.getFileSuffix(file))) { // See whether the TGA writer can handle this TextureData int pixelFormat = data.getPixelFormat(); int pixelType = data.getPixelType(); diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java index 499dce7fb..ae9618490 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java @@ -40,13 +40,12 @@ package com.jogamp.opengl.util.texture.spi; import java.io.*; -import java.net.*; import java.nio.*; import javax.media.opengl.*; -import com.jogamp.opengl.util.*; + +import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.texture.*; -import com.jogamp.opengl.util.texture.spi.*; public class NetPbmTextureWriter implements TextureWriter { int magic; @@ -87,17 +86,17 @@ public class NetPbmTextureWriter implements TextureWriter { // file suffix selection if (0==magic) { - if (PPM.equals(FileUtil.getFileSuffix(file))) { + if (PPM.equals(IOUtil.getFileSuffix(file))) { magic = 6; - } else if (PAM.equals(FileUtil.getFileSuffix(file))) { + } else if (PAM.equals(IOUtil.getFileSuffix(file))) { magic = 7; } else { return false; } } - int pixelFormat = data.getPixelFormat(); - int pixelType = data.getPixelType(); + final int pixelFormat = data.getPixelFormat(); + final int pixelType = data.getPixelType(); if ((pixelFormat == GL.GL_RGB || pixelFormat == GL.GL_RGBA) && (pixelType == GL.GL_BYTE || diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java index 405211204..89d0d20a1 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java @@ -42,12 +42,12 @@ package com.jogamp.opengl.util.texture.spi.awt; import java.awt.Graphics; import java.awt.image.*; import java.io.*; -import java.net.*; import java.nio.*; import javax.imageio.*; import javax.media.opengl.*; -import com.jogamp.opengl.util.*; + +import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.awt.*; import com.jogamp.opengl.util.texture.*; import com.jogamp.opengl.util.texture.spi.*; @@ -101,7 +101,7 @@ public class IIOTextureWriter implements TextureWriter { ImageUtil.flipImageVertically(image); // Happened to notice that writing RGBA images to JPEGS is broken - if (TextureIO.JPG.equals(FileUtil.getFileSuffix(file)) && + if (TextureIO.JPG.equals(IOUtil.getFileSuffix(file)) && image.getType() == BufferedImage.TYPE_4BYTE_ABGR) { BufferedImage tmpImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); @@ -111,7 +111,7 @@ public class IIOTextureWriter implements TextureWriter { image = tmpImage; } - return ImageIO.write(image, FileUtil.getFileSuffix(file), file); + return ImageIO.write(image, IOUtil.getFileSuffix(file), file); } throw new IOException("ImageIO writer doesn't support this pixel format / type (only GL_RGB/A + bytes)"); diff --git a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java index 31990af37..572955fd3 100644 --- a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java +++ b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java @@ -31,10 +31,11 @@ import java.io.IOException; import javax.media.opengl.GLException; import com.jogamp.common.util.IntObjectHashMap; +import com.jogamp.common.util.IOUtil; + import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontSet; import com.jogamp.graph.font.FontFactory; -import com.jogamp.opengl.util.Locator; import java.net.URL; public class UbuntuFontLoader implements FontSet { @@ -121,7 +122,7 @@ public class UbuntuFontLoader implements FontSet { Font abspath(String fname, int family, int style) { final String err = "Problem loading font "+fname+", stream "+relPath+fname; try { - URL url = Locator.getResource(UbuntuFontLoader.class, relPath+fname); + URL url = IOUtil.getResource(UbuntuFontLoader.class, relPath+fname); if(null == url) { throw new GLException(err); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java index 179e4ed2c..cb0d1a372 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java @@ -56,7 +56,7 @@ public class TypecastFontConstructor implements FontConstructor { public Font create(URL furl) throws IOException { final File tf = File.createTempFile( "joglfont", ".ttf"); - final int len = IOUtil.copyURLToFile(furl, tf); + final int len = IOUtil.copyURL2File(furl, tf); if(len==0) { tf.delete(); throw new GLException("Font of stream "+furl+" was zero bytes"); |