summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp
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 /src/jogl/classes/com/jogamp
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
Diffstat (limited to 'src/jogl/classes/com/jogamp')
-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
4 files changed, 193 insertions, 84 deletions
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;