diff options
author | Sven Gothel <[email protected]> | 2014-02-13 01:04:47 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-02-13 01:04:47 +0100 |
commit | 1d2515da352a79c239efecdfa3e0fade47779781 (patch) | |
tree | 74e9d8fccd407d0d8557dd4362d6cec2402f740a /src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java | |
parent | 21b68a5e73a672da34b37b5641b779aa1e3fa41d (diff) |
Bug 962 - AWTGLReadBufferUtil should use aligned BufferedImage [for resized images]; Fix GLReadBufferUtil GL_PACK_ROW_LENGTH
AWTGLPixelBuffer is being reused when used via AWTGLPixelBufferProvider
even when resized.
AWTGLPixelBufferProvider uses GLPixelBufferProvider's requiresNewBuffer(..)
which returns true if
- allowRowStride==true and pixel-buffer size < required-size, or
- allowRowStride==false and pixel-buffer size < required _or_ width doesn't match
otherwise it returns true, i.e. the AWTGLPixelBuffer is reused.
Hence the used BufferedImage might need to be aligned,
i.e. using AWTGLPixelBuffer's getAlignedImage(..).
+++
GLReadBufferUtil shall use current texture-data width for GL_PACK_ROW_LENGTH,
not the static GLPixelBuffer's width, which may not reflect image dimension (resize)
+++
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java index b942c9ab2..b7d2980df 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java @@ -151,17 +151,6 @@ public class GLReadBufferUtil { * @see #GLReadBufferUtil(boolean, boolean) */ public boolean readPixels(GL gl, int inX, int inY, int inWidth, int inHeight, boolean mustFlipVertically) { - final int glerr0 = gl.glGetError(); - if(GL.GL_NO_ERROR != glerr0) { - System.err.println("Info: GLReadBufferUtil.readPixels: pre-exisiting GL error 0x"+Integer.toHexString(glerr0)); - } - final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, componentCount); - final int internalFormat; - if(gl.isGL2GL3() && 3 == componentCount) { - internalFormat = GL.GL_RGB; - } else { - internalFormat = (4 == componentCount) ? GL.GL_RGBA : GL.GL_RGB; - } final GLDrawable drawable = gl.getContext().getGLReadDrawable(); final int width, height; if( 0 >= inWidth || drawable.getWidth() < inWidth ) { @@ -174,6 +163,23 @@ public class GLReadBufferUtil { } else { height= inHeight; } + return readPixelsImpl(drawable, gl, inX, inY, width, height, mustFlipVertically); + } + + protected boolean readPixelsImpl(final GLDrawable drawable, final GL gl, + final int inX, final int inY, final int width, final int height, + final boolean mustFlipVertically) { + final int glerr0 = gl.glGetError(); + if(GL.GL_NO_ERROR != glerr0) { + System.err.println("Info: GLReadBufferUtil.readPixels: pre-exisiting GL error 0x"+Integer.toHexString(glerr0)); + } + final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, componentCount); + final int internalFormat; + if(gl.isGL2GL3() && 3 == componentCount) { + internalFormat = GL.GL_RGB; + } else { + internalFormat = (4 == componentCount) ? GL.GL_RGBA : GL.GL_RGB; + } final boolean flipVertically; if( drawable.isGLOriented() ) { @@ -216,7 +222,7 @@ public class GLReadBufferUtil { if(res) { psm.setAlignment(gl, alignment, alignment); if(gl.isGL2GL3()) { - gl.getGL2GL3().glPixelStorei(GL2GL3.GL_PACK_ROW_LENGTH, readPixelBuffer.width); + gl.getGL2GL3().glPixelStorei(GL2GL3.GL_PACK_ROW_LENGTH, width); } readPixelBuffer.clear(); try { |