summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-05-26 19:18:43 +0200
committerSven Gothel <[email protected]>2014-05-26 19:18:43 +0200
commitfc1e98790a02b4fa7922f3cdd9d437f87d7c99e5 (patch)
treec45b50fcb963b44013887214b6adbd83e2d2ba48
parent93bbc064a1a4cf80079f28e48a5deb50de4a9e66 (diff)
Bug 1010 - Fix ES3.glPixelStorei and revalidate GLPixelStorageModes
Remove GLES3Impl.glPixelStorei pname validation which was true for ES2 impl, but is no more valid for ES3, which accepts more values than GL_PACK_ALIGNMENT & GL_UNPACK_ALIGNMENT. Revalidate GLPixelStorageModes: - Properly support ES3 PixelStorageModes - Revalidate PixelStorageModes for all GL profiles - Properly reset values at save - Separate PACK and UNPACK save/reset/restore implementation
-rw-r--r--make/config/jogl/gl-es3-impl.cfg4
-rw-r--r--make/scripts/tests.sh10
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java268
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java3
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java3
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java3
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLJPanel.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/GLStateTracker.java19
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/glu/TestBug694ScaleImageUnpackBufferSizeAWT.java48
9 files changed, 238 insertions, 124 deletions
diff --git a/make/config/jogl/gl-es3-impl.cfg b/make/config/jogl/gl-es3-impl.cfg
index 2e5e36e9c..9682e49af 100644
--- a/make/config/jogl/gl-es3-impl.cfg
+++ b/make/config/jogl/gl-es3-impl.cfg
@@ -48,12 +48,8 @@ TagNativeBinding true
# Add PixelStorei StateTracker
#
-# Add input validation to glPixelStorei, just to be sure.
CustomJavaCode GLES3Impl private static final int params_offset = 0; // just a helper for JavaPrologue ..
-JavaPrologue glPixelStorei if (pname != GL_PACK_ALIGNMENT && pname != GL_UNPACK_ALIGNMENT) {
-JavaPrologue glPixelStorei throw new GLException("Unsupported pixel store parameter name 0x" + Integer.toHexString(pname));
-JavaPrologue glPixelStorei }
JavaPrologue glPixelStorei glStateTracker.setInt(pname, param);
JavaPrologue glGetIntegerv if ( glStateTracker.getInt(pname, params, params_offset) ) { return; }
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 97cd99850..7fe7d6ddd 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -156,6 +156,7 @@ function jrun() {
#D_ARGS="-Djogl.debug.AudioSink"
#D_ARGS="-Djogl.debug.GLArrayData"
#D_ARGS="-Dnewt.debug.Screen -Dnewt.debug.Window"
+ #D_ARGS="-Dnewt.debug.Window"
#D_ARGS="-Dnewt.debug.Screen"
#D_ARGS="-Dnewt.test.Screen.disableRandR13"
#D_ARGS="-Dnewt.test.Screen.disableScreenMode -Dnewt.debug.Screen"
@@ -275,6 +276,10 @@ function jrun() {
export USE_CLASSPATH=$JOGAMP_ALL_AWT_CLASSPATH
echo USE_CLASSPATH $USE_CLASSPATH
X_ARGS="-Djava.awt.headless=false $X_ARGS"
+ elif [ $swton -eq 1 ] ; then
+ export USE_CLASSPATH=$JOGAMP_ALL_AWT_CLASSPATH
+ echo USE_CLASSPATH $USE_CLASSPATH
+ X_ARGS="-Djava.awt.headless=true $X_ARGS"
else
#export USE_CLASSPATH=$JOGAMP_ALL_AWT_CLASSPATH
export USE_CLASSPATH=$JOGAMP_ALL_NOAWT_CLASSPATH
@@ -357,7 +362,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestGearsES1NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestOlympicES1NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestRedSquareES1NEWT $*
-#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
+testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestHiDPIBufferedImage01AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestHiDPIBufferedImage02AWT $*
@@ -535,7 +540,8 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.newt.TestGLWindowInvisiblePointer01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestDisplayLifecycle01NEWT
#testnoawt com.jogamp.opengl.test.junit.newt.TestDisplayLifecycle02NEWT
-testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00aNEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00aNEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00bNEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00cNEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01aNEWT $*
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java b/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java
index b6cff85f8..34b493586 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLPixelStorageModes.java
@@ -36,49 +36,56 @@ import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLException;
/**
- * Utility to safely set and restore the pack and unpack pixel storage mode,
+ * Utility to safely set and restore the PACK and UNPACK pixel storage mode,
* regardless of the GLProfile.
+ * <p>
+ * PACK for GPU to CPU transfers, e.g. {@link GL#glReadPixels(int, int, int, int, int, int, java.nio.Buffer) ReadPixels}, etc.
+ * </p>
+ * <p>
+ * UNPACK for CPU o GPU transfers, e.g. {@link GL#glTexImage2D(int, int, int, int, int, int, int, int, long) TexImage2D}, etc
+ * </p>
*/
public class GLPixelStorageModes {
- private final int[] savedGL2GL3Modes = new int[8];
- private final int[] savedAlignment = new int[2];
- private boolean saved = false;
+ private final int[] cachePack = new int[8];
+ private final int[] cacheUnpack = new int[8];
+ private boolean savedPack = false;
+ private boolean savedUnpack = false;
- /** Create instance w/o {@link #save(GL)} */
+ /** Create instance w/o {@link #saveAll(GL)} */
public GLPixelStorageModes() {}
- /** Create instance w/ {@link #save(GL)} */
- public GLPixelStorageModes(GL gl) { save(gl); }
+ /** Create instance w/ {@link #saveAll(GL)} */
+ public GLPixelStorageModes(final GL gl) { saveAll(gl); }
/**
* Sets the {@link GL#GL_PACK_ALIGNMENT}.
* <p>
- * Saves the pixel storage modes if not saved yet.
+ * Saves the PACK pixel storage modes if not saved yet, see {@link #savePack(GL)}.
* </p>
*/
- public final void setPackAlignment(GL gl, int packAlignment) {
- save(gl);
+ public final void setPackAlignment(final GL gl, final int packAlignment) {
+ savePack(gl);
gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, packAlignment);
}
/**
* Sets the {@link GL#GL_UNPACK_ALIGNMENT}.
* <p>
- * Saves the pixel storage modes if not saved yet.
+ * Saves the UNPACK pixel storage modes if not saved yet, see {@link #saveUnpack(GL)}.
* </p>
*/
- public final void setUnpackAlignment(GL gl, int unpackAlignment) {
- save(gl);
+ public final void setUnpackAlignment(final GL gl, final int unpackAlignment) {
+ saveUnpack(gl);
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, unpackAlignment);
}
/**
* Sets the {@link GL#GL_PACK_ALIGNMENT} and {@link GL#GL_UNPACK_ALIGNMENT}.
* <p>
- * Saves the pixel storage modes if not saved yet.
+ * Saves the PACK and UNPACK pixel storage modes if not saved yet, see {@link #saveAll(GL)}.
* </p>
*/
- public final void setAlignment(GL gl, int packAlignment, int unpackAlignment) {
+ public final void setAlignment(final GL gl, final int packAlignment, final int unpackAlignment) {
setPackAlignment(gl, packAlignment);
setUnpackAlignment(gl, unpackAlignment);
}
@@ -86,114 +93,219 @@ public class GLPixelStorageModes {
/**
* Sets the {@link GL2ES3#GL_PACK_ROW_LENGTH}.
* <p>
- * Saves the pixel storage modes if not saved yet.
+ * Saves the PACK pixel storage modes if not saved yet, see {@link #savePack(GL)}.
* </p>
*/
- public final void setPackRowLength(GL2ES3 gl, int packRowLength) {
- save(gl);
+ public final void setPackRowLength(final GL2ES3 gl, final int packRowLength) {
+ savePack(gl);
gl.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, packRowLength);
}
/**
* Sets the {@link GL2ES2#GL_UNPACK_ROW_LENGTH}.
* <p>
- * Saves the pixel storage modes if not saved yet.
+ * Saves the UNPACK pixel storage modes if not saved yet, see {@link #saveUnpack(GL)}.
* </p>
*/
- public final void setUnpackRowLength(GL2ES2 gl, int unpackRowLength) {
- save(gl);
+ public final void setUnpackRowLength(final GL2ES2 gl, final int unpackRowLength) {
+ saveUnpack(gl);
gl.glPixelStorei(GL2ES2.GL_UNPACK_ROW_LENGTH, unpackRowLength);
}
/**
* Sets the {@link GL2ES3#GL_PACK_ROW_LENGTH} and {@link GL2ES2#GL_UNPACK_ROW_LENGTH}.
* <p>
- * Saves the pixel storage modes if not saved yet.
+ * Saves the PACK and UNPACK pixel storage modes if not saved yet, see {@link #saveAll(GL)}.
* </p>
*/
- public final void setRowLength(GL2ES3 gl, int packRowLength, int unpackRowLength) {
+ public final void setRowLength(final GL2ES3 gl, final int packRowLength, final int unpackRowLength) {
setPackRowLength(gl, packRowLength);
setUnpackRowLength(gl, unpackRowLength);
}
/**
- * Save the pixel storage mode, if not saved yet.
+ * Saves PACK and UNPACK pixel storage modes and {@link #resetAll(GL) resets} them,
+ * i.e. issues {@link #savePack(GL)} and {@link #saveUnpack(GL)}.
+ * <p>
+ * Operation is skipped, if the modes were already saved.
+ * </p>
* <p>
* Restore via {@link #restore(GL)}
* </p>
*/
- public final void save(GL gl) {
- if(saved) {
- return;
+ public final void saveAll(final GL gl) {
+ savePack(gl);
+ saveUnpack(gl);
+ }
+
+ /**
+ * Resets PACK and UNPACK pixel storage modes to their default value,
+ * i.e. issues {@link #resetPack(GL)} and {@link #resetUnpack(GL)}.
+ */
+ public final void resetAll(final GL gl) {
+ resetPack(gl);
+ resetUnpack(gl);
+ }
+
+ /**
+ * Restores PACK and UNPACK pixel storage mode previously saved w/ {@link #saveAll(GL)}
+ * or {@link #savePack(GL)} and {@link #saveUnpack(GL)}.
+ * @throws GLException if neither PACK nor UNPACK modes were saved.
+ */
+ public final void restore(final GL gl) throws GLException {
+ if(!savedPack && !savedUnpack) {
+ throw new GLException("Neither PACK nor UNPACK pixel storage modes were saved");
+ }
+ if( savedPack ) {
+ restorePack(gl);
+ savedPack = false;
}
+ if( savedUnpack ) {
+ restoreUnpack(gl);
+ savedUnpack = false;
+ }
+ }
+ /**
+ * Resets PACK pixel storage modes to their default value.
+ */
+ public final void resetPack(final GL gl) {
+ // Compared w/ ES2, ES3 and GL3-core spec
+ gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, 4); // es2, es3, gl3
if( gl.isGL2ES3() ) {
- 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(GL2ES3.GL_PACK_ROW_LENGTH, savedGL2GL3Modes, 0);
- gl.glGetIntegerv(GL2ES3.GL_PACK_SKIP_ROWS, savedGL2GL3Modes, 1);
- gl.glGetIntegerv(GL2ES3.GL_PACK_SKIP_PIXELS, savedGL2GL3Modes, 2);
- gl.glGetIntegerv(GL2ES2.GL_UNPACK_ROW_LENGTH, savedGL2GL3Modes, 4);
- gl.glGetIntegerv(GL2ES2.GL_UNPACK_SKIP_ROWS, savedGL2GL3Modes, 5);
- gl.glGetIntegerv(GL2ES2.GL_UNPACK_SKIP_PIXELS, savedGL2GL3Modes, 6);
- if( gl.isGL2GL3() ) {
- gl.glGetIntegerv(GL2GL3.GL_PACK_SWAP_BYTES, savedGL2GL3Modes, 3);
- gl.glGetIntegerv(GL2GL3.GL_UNPACK_SWAP_BYTES, savedGL2GL3Modes, 7);
- }
- }
- gl.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, 0);
- gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_ROWS, 0);
- gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_PIXELS, 0);
- gl.glPixelStorei(GL2ES2.GL_UNPACK_ROW_LENGTH, 0);
- gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_ROWS, 0);
- gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_PIXELS, 0);
+ gl.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, 0); // es3, gl3
+ gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_ROWS, 0); // es3, gl3
+ gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_PIXELS, 0); // es3, gl3
if( gl.isGL2GL3() ) {
- gl.glPixelStorei(GL2GL3.GL_PACK_SWAP_BYTES, 0);
- gl.glPixelStorei(GL2GL3.GL_UNPACK_SWAP_BYTES, 0);
+ gl.glPixelStorei(GL2GL3.GL_PACK_SWAP_BYTES, GL.GL_FALSE); // gl3
+ gl.glPixelStorei(GL2GL3.GL_PACK_LSB_FIRST, GL.GL_FALSE); // gl3
+ gl.glPixelStorei(GL2GL3.GL_PACK_IMAGE_HEIGHT, 0); // gl3
+ gl.glPixelStorei(GL2GL3.GL_PACK_SKIP_IMAGES, 0); // gl3
}
+ }
+ }
+ /**
+ * Saves PACK pixel storage modes and {@link #resetPack(GL) resets} them.
+ * <p>
+ * Operation is skipped, if the modes were already saved.
+ * </p>
+ * <p>
+ * Restore via {@link #restore(GL)}
+ * </p>
+ */
+ public final void savePack(final GL gl) {
+ if(savedPack) {
+ return;
+ }
+ if( gl.isGL2() ) {
+ // See GLStateTracker.pushAttrib(GL2.GL_CLIENT_PIXEL_STORE_BIT)
+ gl.getGL2().glPushClientAttrib(GL2.GL_CLIENT_PIXEL_STORE_BIT);
} else {
// ES1 or ES2 deals with pack/unpack alignment only
- gl.glGetIntegerv(GL2ES2.GL_PACK_ALIGNMENT, savedAlignment, 0);
- gl.glGetIntegerv(GL2ES2.GL_UNPACK_ALIGNMENT, savedAlignment, 1);
+ gl.glGetIntegerv(GL2ES2.GL_PACK_ALIGNMENT, cachePack, 0);
+ if( gl.isGL2ES3() ) {
+ gl.glGetIntegerv(GL2ES3.GL_PACK_ROW_LENGTH, cachePack, 1);
+ gl.glGetIntegerv(GL2ES3.GL_PACK_SKIP_ROWS, cachePack, 2);
+ gl.glGetIntegerv(GL2ES3.GL_PACK_SKIP_PIXELS, cachePack, 3);
+ if( gl.isGL2GL3() ) {
+ gl.glGetIntegerv(GL2GL3.GL_PACK_SWAP_BYTES, cachePack, 4);
+ gl.glGetIntegerv(GL2GL3.GL_PACK_LSB_FIRST, cachePack, 5);
+ gl.glGetIntegerv(GL2GL3.GL_PACK_IMAGE_HEIGHT, cachePack, 6);
+ gl.glGetIntegerv(GL2GL3.GL_PACK_SKIP_IMAGES, cachePack, 7);
+ }
+ }
+ }
+ savedPack = true;
+ resetPack(gl);
+ }
+ private final void restorePack(final GL gl) {
+ if( gl.isGL2() ) {
+ gl.getGL2().glPopClientAttrib();
+ } else {
+ gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, cachePack[0]);
+ if( gl.isGL2ES3() ) {
+ gl.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, cachePack[1]);
+ gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_ROWS, cachePack[2]);
+ gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_PIXELS, cachePack[3]);
+ if( gl.isGL2GL3() ) {
+ gl.glPixelStorei(GL2GL3.GL_PACK_SWAP_BYTES, cachePack[4]);
+ gl.glPixelStorei(GL2GL3.GL_PACK_LSB_FIRST, cachePack[5]);
+ gl.glPixelStorei(GL2GL3.GL_PACK_IMAGE_HEIGHT, cachePack[6]);
+ gl.glPixelStorei(GL2GL3.GL_PACK_SKIP_IMAGES, cachePack[7]);
+ }
+ }
}
- saved = true;
}
/**
- * Restores the pixel storage mode.
- * @throws GLException if not saved via one of the set methods.
+ * Resets UNPACK pixel storage modes to their default value.
*/
- public final void restore(GL gl) throws GLException {
- if(!saved) {
- throw new GLException("pixel storage modes not saved");
- }
-
+ public final void resetUnpack(final GL gl) {
+ // Compared w/ ES2, ES3 and GL3-core spec
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_ALIGNMENT, 4); // es2, es3, gl3
if( gl.isGL2ES3() ) {
- 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(GL2ES3.GL_PACK_ROW_LENGTH, savedGL2GL3Modes[0]);
- gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_ROWS, savedGL2GL3Modes[1]);
- gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_PIXELS, savedGL2GL3Modes[2]);
- gl.glPixelStorei(GL2ES2.GL_UNPACK_ROW_LENGTH, savedGL2GL3Modes[4]);
- gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_ROWS, savedGL2GL3Modes[5]);
- gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_PIXELS, savedGL2GL3Modes[6]);
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_ROW_LENGTH, 0); // es3, gl3
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_ROWS, 0); // es3, gl3
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_PIXELS, 0); // es3, gl3
+ gl.glPixelStorei(GL2ES3.GL_UNPACK_IMAGE_HEIGHT, 0); // es3, gl3
+ gl.glPixelStorei(GL2ES3.GL_UNPACK_SKIP_IMAGES, 0); // es3, gl3
+ if( gl.isGL2GL3() ) {
+ gl.glPixelStorei(GL2GL3.GL_UNPACK_SWAP_BYTES, GL.GL_FALSE); // gl3
+ gl.glPixelStorei(GL2GL3.GL_UNPACK_LSB_FIRST, GL.GL_FALSE); // gl3
+ }
+ }
+ }
+ /**
+ * Saves UNPACK pixel storage modes and {@link #resetUnpack(GL) resets} them.
+ * <p>
+ * Operation is skipped, if the modes were already saved.
+ * </p>
+ * <p>
+ * Restore via {@link #restore(GL)}
+ * </p>
+ */
+ public final void saveUnpack(final GL gl) {
+ if(savedUnpack) {
+ return;
+ }
+ if( gl.isGL2() ) {
+ // See GLStateTracker.pushAttrib(GL2.GL_CLIENT_PIXEL_STORE_BIT)
+ gl.getGL2().glPushClientAttrib(GL2.GL_CLIENT_PIXEL_STORE_BIT);
+ } else {
+ // ES1 or ES2 deals with pack/unpack alignment only
+ gl.glGetIntegerv(GL2ES2.GL_UNPACK_ALIGNMENT, cacheUnpack, 0);
+ if( gl.isGL2ES3() ) {
+ gl.glGetIntegerv(GL2ES2.GL_UNPACK_ROW_LENGTH, cacheUnpack, 1);
+ gl.glGetIntegerv(GL2ES2.GL_UNPACK_SKIP_ROWS, cacheUnpack, 2);
+ gl.glGetIntegerv(GL2ES2.GL_UNPACK_SKIP_PIXELS, cacheUnpack, 3);
+ gl.glGetIntegerv(GL2ES3.GL_UNPACK_IMAGE_HEIGHT, cacheUnpack, 4);
+ gl.glGetIntegerv(GL2ES3.GL_UNPACK_SKIP_IMAGES, cacheUnpack, 5);
if( gl.isGL2GL3() ) {
- gl.glPixelStorei(GL2GL3.GL_PACK_SWAP_BYTES, savedGL2GL3Modes[3]);
- gl.glPixelStorei(GL2GL3.GL_UNPACK_SWAP_BYTES, savedGL2GL3Modes[7]);
+ gl.glGetIntegerv(GL2GL3.GL_UNPACK_SWAP_BYTES, cacheUnpack, 6);
+ gl.glGetIntegerv(GL2GL3.GL_UNPACK_LSB_FIRST, cacheUnpack, 7);
}
}
+ }
+ savedUnpack = true;
+ resetUnpack(gl);
+ }
+ private final void restoreUnpack(final GL gl) {
+ if( gl.isGL2() ) {
+ gl.getGL2().glPopClientAttrib();
} else {
- // ES1 or ES2 deals with pack/unpack alignment only
- gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, savedAlignment[0]);
- gl.glPixelStorei(GL2ES2.GL_UNPACK_ALIGNMENT, savedAlignment[1]);
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_ALIGNMENT, cacheUnpack[0]);
+ if( gl.isGL2ES3() ) {
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_ROW_LENGTH, cacheUnpack[1]);
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_ROWS, cacheUnpack[2]);
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_PIXELS, cacheUnpack[3]);
+ gl.glPixelStorei(GL2ES3.GL_UNPACK_IMAGE_HEIGHT, cacheUnpack[4]);
+ gl.glPixelStorei(GL2ES3.GL_UNPACK_SKIP_IMAGES, cacheUnpack[5]);
+ if( gl.isGL2GL3() ) {
+ gl.glPixelStorei(GL2GL3.GL_UNPACK_SWAP_BYTES, cacheUnpack[6]);
+ gl.glPixelStorei(GL2GL3.GL_UNPACK_LSB_FIRST, cacheUnpack[7]);
+ }
+ }
}
- saved = false;
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
index 2b4795aaa..680984cdb 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
@@ -33,7 +33,6 @@ import java.io.IOException;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES3;
-import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLDrawable;
import javax.media.opengl.GLException;
@@ -221,7 +220,7 @@ public class GLReadBufferUtil {
}
boolean res = null!=readPixelBuffer && readPixelBuffer.isValid();
if(res) {
- psm.setAlignment(gl, alignment, alignment);
+ psm.setPackAlignment(gl, alignment);
if(gl.isGL2ES3()) {
final GL2ES3 gl2es3 = gl.getGL2ES3();
gl2es3.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, width);
diff --git a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java
index 1c87dad4e..0a3a9d513 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java
@@ -152,8 +152,7 @@ public class RandomTileRenderer extends TileRendererBase {
// be sure OpenGL rendering is finished
gl.glFlush();
- // save current glPixelStore values
- psm.save(gl);
+ // implicitly save current glPixelStore values
psm.setPackAlignment(gl, 1);
final GL2ES3 gl2es3;
final int readBuffer;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java
index 7f86b14c6..887312a64 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java
@@ -455,8 +455,7 @@ public class TileRenderer extends TileRendererBase {
// be sure OpenGL rendering is finished
gl.glFlush();
- // save current glPixelStore values
- psm.save(gl);
+ // implicitly save current glPixelStore values
psm.setPackAlignment(gl, 1);
final GL2ES3 gl2es3;
final int readBuffer;
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index c8102973f..e712f2fa2 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -1724,8 +1724,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.readPixels: - frameCount "+frameCount);
}
- // Save current modes
- psm.setAlignment(gl, alignment, alignment);
+ // Save PACK modes, reset them to defaults and set alignment
+ psm.setPackAlignment(gl, alignment);
if(gl.isGL2ES3()) {
final GL2ES3 gl2es3 = gl.getGL2ES3();
gl2es3.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, panelWidth);
diff --git a/src/jogl/classes/jogamp/opengl/GLStateTracker.java b/src/jogl/classes/jogamp/opengl/GLStateTracker.java
index 0e451741c..706d51323 100644
--- a/src/jogl/classes/jogamp/opengl/GLStateTracker.java
+++ b/src/jogl/classes/jogamp/opengl/GLStateTracker.java
@@ -57,10 +57,11 @@ public class GLStateTracker {
/** Minimum value of MAX_CLIENT_ATTRIB_STACK_DEPTH */
public static final int MIN_CLIENT_ATTRIB_STACK_DEPTH = 16;
- /** static size of pixel state map */
- static final int PIXEL_STATE_MAP_SIZE = 16;
+ /** static size of pixel state map
+ private static final int PIXEL_STATE_MAP_SIZE = 16;
+ */
/** avoid rehash of static size pixel state map */
- static final int PIXEL_STATE_MAP_CAPACITY = 32;
+ private static final int PIXEL_STATE_MAP_CAPACITY = 32;
private volatile boolean enabled = true;
@@ -111,7 +112,7 @@ public class GLStateTracker {
/** @return true if found in our map, otherwise false,
* which forces the caller to query GL. */
- public final boolean getInt(int pname, int[] params, int params_offset) {
+ public final boolean getInt(final int pname, final int[] params, final int params_offset) {
if(enabled) {
final int value = pixelStateMap.get(pname);
if(0xFFFFFFFF != value) {
@@ -124,7 +125,7 @@ public class GLStateTracker {
/** @return true if found in our map, otherwise false,
* which forces the caller to query GL. */
- public final boolean getInt(int pname, IntBuffer params, int dummy) {
+ public final boolean getInt(final int pname, final IntBuffer params, final int dummy) {
if(enabled) {
final int value = pixelStateMap.get(pname);
if(0xFFFFFFFF != value) {
@@ -135,15 +136,15 @@ public class GLStateTracker {
return false;
}
- public final void setInt(int pname, int param) {
+ public final void setInt(final int pname, final int param) {
if(enabled) {
pixelStateMap.put(pname, param);
}
}
- public final void pushAttrib(int flags) {
+ public final void pushAttrib(final int flags) {
if(enabled) {
- SavedState state = new SavedState(); // empty-slot
+ final SavedState state = new SavedState(); // empty-slot
if( 0 != (flags&GL2.GL_CLIENT_PIXEL_STORE_BIT) ) {
// save client pixel-store state
state.setPixelStateMap(pixelStateMap);
@@ -157,7 +158,7 @@ public class GLStateTracker {
if(stack.isEmpty()) {
throw new GLException("stack contains no elements");
}
- SavedState state = stack.remove(stack.size()-1); // pop
+ final SavedState state = stack.remove(stack.size()-1); // pop
if(null==state) {
throw new GLException("null stack element (remaining stack size "+stack.size()+")");
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestBug694ScaleImageUnpackBufferSizeAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestBug694ScaleImageUnpackBufferSizeAWT.java
index ca5b089e1..c79affef1 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestBug694ScaleImageUnpackBufferSizeAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestBug694ScaleImageUnpackBufferSizeAWT.java
@@ -3,14 +3,14 @@
*
* 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
@@ -20,12 +20,12 @@
* 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.test.junit.jogl.glu;
import java.awt.Frame;
@@ -64,7 +64,7 @@ public class TestBug694ScaleImageUnpackBufferSizeAWT extends UITestCase implemen
public void display(GLAutoDrawable drawable) {
if( !testDone ) {
testDone = true;
-
+
final GL gl = drawable.getGL();
GLU glu = GLU.createGLU(gl);
testGLUScaleImage(gl, glu, 0); // default 4
@@ -74,39 +74,41 @@ public class TestBug694ScaleImageUnpackBufferSizeAWT extends UITestCase implemen
glu.destroy();
}
}
-
+
boolean testDone = false;
-
+
private void testGLUScaleImage(GL gl, GLU glu, int unpackAlignment) {
- final GLPixelStorageModes psm = new GLPixelStorageModes(gl);
+ final GLPixelStorageModes psm = new GLPixelStorageModes();
if(0 < unpackAlignment) {
psm.setUnpackAlignment(gl, unpackAlignment);
}
-
+
final int widthin = 213;
final int heightin = 213;
-
+
final int widthout = 256;
final int heightout = 256;
-
+
final int glFormat = GL.GL_LUMINANCE;
final int glType = GL.GL_UNSIGNED_BYTE;
final int tmp[] = new int[1];
-
+
final int unpackSizeInLen = GLBuffers.sizeof(gl, tmp, glFormat, glType, widthin, heightin, 1, false);
final int unpackSizeOutLen = GLBuffers.sizeof(gl, tmp, glFormat, glType, widthout, heightout, 1, false);
-
+
System.err.println("Unpack-Alignment "+unpackAlignment+": in-size "+unpackSizeInLen);
System.err.println("Unpack-Alignment "+unpackAlignment+": out-size "+unpackSizeOutLen);
-
+
ByteBuffer bufferIn = Buffers.newDirectByteBuffer(unpackSizeInLen);
ByteBuffer bufferOut = Buffers.newDirectByteBuffer(unpackSizeOutLen);
-
+
glu.gluScaleImage( GL.GL_LUMINANCE,
widthin, heightin, GL.GL_UNSIGNED_BYTE, bufferIn,
widthout, heightout, GL.GL_UNSIGNED_BYTE, bufferOut );
-
- psm.restore(gl);
+
+ if(0 < unpackAlignment) {
+ psm.restore(gl);
+ }
}
/* @Override */
@@ -124,10 +126,10 @@ public class TestBug694ScaleImageUnpackBufferSizeAWT extends UITestCase implemen
GLCapabilities glCapabilities = new GLCapabilities(glprofile);
final GLCanvas canvas = new GLCanvas(glCapabilities);
canvas.addGLEventListener( this );
-
+
final Frame frame = new Frame("Test");
frame.add(canvas);
- frame.setSize(256, 256);
+ frame.setSize(256, 256);
frame.validate();
try {
@@ -139,11 +141,11 @@ public class TestBug694ScaleImageUnpackBufferSizeAWT extends UITestCase implemen
t.printStackTrace();
Assume.assumeNoException(t);
}
-
+
canvas.display();
Thread.sleep(200);
-
+
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
@@ -154,7 +156,7 @@ public class TestBug694ScaleImageUnpackBufferSizeAWT extends UITestCase implemen
} catch (Throwable t) {
t.printStackTrace();
Assume.assumeNoException(t);
- }
+ }
}
public static void main(String args[]) {