aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-05-13 11:20:34 +0200
committerSven Gothel <[email protected]>2019-05-13 11:20:34 +0200
commit154e91978498d8b6db9ce34a1f06b298bcf4c361 (patch)
treeec5b9104c81bcbc60def54e621397559298fc992 /src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
parentea3edf9cfc6b6fda9780c540e1de099c97207bc1 (diff)
Bug 1381: Keep host PixelFormat functional using requested immutable alphaRequested + add appropriate API doc
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
index 3fa856a47..ce4f451e0 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
@@ -54,24 +54,33 @@ public class GLReadBufferUtil {
protected final GLPixelBufferProvider pixelBufferProvider;
protected final Texture readTexture;
protected final GLPixelStorageModes psm;
+ protected final boolean alphaRequested;
protected boolean hasAlpha;
protected GLPixelBuffer readPixelBuffer = null;
protected TextureData readTextureData = null;
/**
- * @param alpha true for RGBA readPixels, otherwise RGB readPixels. Disclaimer: Alpha maybe forced on ES platforms!
+ * Using the default {@link GLPixelBuffer}: {@link GLPixelBuffer#defaultProviderNoRowStride}.
+ *
+ * @param requestAlpha true for RGBA readPixels, otherwise RGB readPixels. Disclaimer: {@link #hasAlpha()}==true maybe forced depending on the used {@link GLPixelBufferProvider}, i.e. on ES platforms, when calling {@link #readPixels(GL, int, int, int, int, boolean) readPixels}.
* @param write2Texture true if readPixel's TextureData shall be written to a 2d Texture
*/
- public GLReadBufferUtil(final boolean alpha, final boolean write2Texture) {
- this(GLPixelBuffer.defaultProviderNoRowStride, alpha, write2Texture);
+ public GLReadBufferUtil(final boolean requestAlpha, final boolean write2Texture) {
+ this(GLPixelBuffer.defaultProviderNoRowStride, requestAlpha, write2Texture);
}
- public GLReadBufferUtil(final GLPixelBufferProvider pixelBufferProvider, final boolean alpha, final boolean write2Texture) {
+ /**
+ * @param pixelBufferProvider custom {@link GLPixelBuffer}
+ * @param requestAlpha true for RGBA readPixels, otherwise RGB readPixels. Disclaimer: {@link #hasAlpha()}==true maybe forced depending on the used {@link GLPixelBufferProvider}, i.e. on ES platforms, when calling {@link #readPixels(GL, int, int, int, int, boolean) readPixels}.
+ * @param write2Texture true if readPixel's TextureData shall be written to a 2d Texture
+ */
+ public GLReadBufferUtil(final GLPixelBufferProvider pixelBufferProvider, final boolean requestAlpha, final boolean write2Texture) {
this.pixelBufferProvider = pixelBufferProvider;
this.readTexture = write2Texture ? new Texture(GL.GL_TEXTURE_2D) : null ;
this.psm = new GLPixelStorageModes();
- this.hasAlpha = alpha; // preset
+ this.alphaRequested = requestAlpha;
+ this.hasAlpha = requestAlpha; // preset
}
/** Returns the {@link GLPixelBufferProvider} used by this instance. */
@@ -81,6 +90,7 @@ public class GLReadBufferUtil {
return null!=readTextureData && null!=readPixelBuffer && readPixelBuffer.isValid();
}
+ /** Returns true if the OpenGL read data contains alpha. This value is lazily determined after the first call of {@link #readPixels(GL, int, int, int, int, boolean) readPixels} */
public boolean hasAlpha() { return hasAlpha; }
public GLPixelStorageModes getGLPixelStorageModes() { return psm; }
@@ -173,14 +183,19 @@ public class GLReadBufferUtil {
if(GL.GL_NO_ERROR != glerr0) {
System.err.println("Info: GLReadBufferUtil.readPixels: pre-exisiting GL error 0x"+Integer.toHexString(glerr0));
}
- final int reqCompCount = hasAlpha ? 4 : 3;
+ final int reqCompCount = alphaRequested ? 4 : 3; // see Bug 1381: we keep host PixelFormat functional using requested immutable alphaRequested
final PixelFormat.Composition hostPixelComp = pixelBufferProvider.getHostPixelComp(gl.getGLProfile(), reqCompCount);
final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, reqCompCount, true);
final int componentCount = pixelAttribs.pfmt.comp.componentCount();
hasAlpha = 0 <= pixelAttribs.pfmt.comp.find(PixelFormat.CType.A);
- final int alignment = 4 == componentCount ? 4 : 1 ;
- final int internalFormat = 4 == componentCount ? GL.GL_RGBA : GL.GL_RGB;
-
+ final int alignment, internalFormat;
+ if( 4 == componentCount ) {
+ alignment = 4;
+ internalFormat = GL.GL_RGBA;
+ } else {
+ alignment = 1;
+ internalFormat = GL.GL_RGB;
+ }
final boolean flipVertically;
if( drawable.isGLOriented() ) {
flipVertically = mustFlipVertically;