From 90760ac8eebe7431ac7392e4ebf3f9009e63cd72 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 5 Sep 2019 05:38:25 +0200 Subject: Bug 1390: Fix GLPixelBuffer.GLPixelAttributes::convert(GL, int, boolean) failure on unsupported GL data format/type GLPixelBuffer.GLPixelAttributes::convert(GL, int, boolean) failed on unsupported GL data format/type On Mesa/AMD for GLPBuffer chosen GLCaps used rgba 10/10/10/2 and the GLContext set default values: GL_IMPLEMENTATION_COLOR_READ_FORMAT: 0x1908 GL_RGBA GL_IMPLEMENTATION_COLOR_READ_TYPE: 0x8368 GL_UNSIGNED_INT_2_10_10_10_REV GLPixelBuffer.GLPixelAttributes::getPixelFormat(int format, int type) currently does not handle the type GL_UNSIGNED_INT_2_10_10_10_REV and hence returned a null PixelFormat. Therefor the ctor GLPixelAttributes failed and threw the exception: "Caught GLException: Could not find PixelFormat for format and/or type: PixelAttributes[fmt 0x1908, type 0x8368, null]" This fix has the GLContext default values pre-validated in the convert(..) method and to use default GL_RGBA and GL_UNSIGNED_BYTE fallback values if not supported. This is most important to be future proof. Later we may shall add these 32bit coding 2+10+10+10 and its reverse. --- .../com/jogamp/opengl/util/GLPixelBuffer.java | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/jogl/classes/com') diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java b/src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java index 0e3497bd4..845c23080 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java @@ -321,14 +321,24 @@ public class GLPixelBuffer { } else if( 4 == componentCount || glesReadMode ) { final GLContext ctx = gl.getContext(); final int _dFormat = ctx.getDefaultPixelDataFormat(); - final int dComps = GLBuffers.componentCount(_dFormat); - if( dComps == componentCount || 4 == dComps ) { // accept if desired component count or 4 components - dFormat = _dFormat; - dType = ctx.getDefaultPixelDataType(); - } else { - dFormat = GL.GL_RGBA; - dType = GL.GL_UNSIGNED_BYTE; + final int _dComps = GLBuffers.componentCount(_dFormat); + if( _dComps == componentCount || 4 == _dComps ) { // accept if desired component count or 4 components + // pre-check whether default is supported by implementation + final int _dType = ctx.getDefaultPixelDataType(); + final PixelFormat _pixFmt = getPixelFormat(_dFormat, _dType); + if( null != _pixFmt) { + return new GLPixelAttributes(null, _pixFmt, _dFormat, _dType, pack, true); + } + if( GLContext.DEBUG ) { + System.err.println("GLPixelAttributes.convert("+gl.getGLProfile()+", comps "+componentCount+", pack "+pack+ + "): GL-impl default unsupported: "+ + "[fmt 0x"+Integer.toHexString(_dFormat)+", type 0x"+Integer.toHexString(_dType)+"]: Using std RGBA+UBYTE"); + Thread.dumpStack(); + } + // fall-through intended to set dFormat/dType to std values } + dFormat = GL.GL_RGBA; + dType = GL.GL_UNSIGNED_BYTE; } else { return null; } -- cgit v1.2.3