summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/FileUtil.java89
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java108
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java181
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/StreamUtil.java98
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java69
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java4
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java1
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java7
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java58
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java13
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java8
11 files changed, 362 insertions, 274 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/GLPixelStorageModes.java b/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java
new file mode 100644
index 000000000..e9cccbb93
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java
@@ -0,0 +1,108 @@
+/**
+ * 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.GLException;
+
+/**
+ * Utility to safely set and restore the pack and unpack pixel storage mode,
+ * regardless of the GLProfile.
+ */
+public class GLPixelStorageModes {
+ int savedPackAlignment;
+ int savedUnpackAlignment;
+ int[] tmp = new int[1];
+ boolean saved = false;
+
+ static int glGetInteger(GL gl, int pname, int[] tmp) {
+ gl.glGetIntegerv(pname, tmp, 0);
+ return tmp[0];
+ }
+
+ private final void save(GL gl) {
+ if(gl.isGL2()) {
+ gl.getGL2().glPushClientAttrib(GL2.GL_CLIENT_PIXEL_STORE_BIT);
+ 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);
+ } else {
+ // core and embedded only deal with pack/unpack alignment
+ savedPackAlignment = glGetInteger(gl, GL2ES2.GL_PACK_ALIGNMENT, tmp);
+ savedUnpackAlignment = glGetInteger(gl, GL2ES2.GL_UNPACK_ALIGNMENT, tmp);
+ }
+ saved = true;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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.isGL2()) {
+ gl.getGL2().glPopClientAttrib();
+ } else {
+ gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, savedPackAlignment);
+ }
+ 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/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/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..be3a1de73 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;
@@ -350,7 +352,7 @@ public class ShaderCode {
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/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)");