Bug 1381

Summary: GLReadBufferUtil/AWTReadBufferUtil: 'hasAlpha' usage is not functional
Product: [JogAmp] Jogl Reporter: Sven Gothel <sgothel>
Component: coreAssignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: normal CC: askinner, sgothel
Priority: P4    
Version: 2.4.0   
Hardware: All   
OS: all   
Type: DEFECT SCM Refs:
jogl 154e91978498d8b6db9ce34a1f06b298bcf4c361
Workaround: ---

Description Sven Gothel 2019-05-13 10:50:19 CEST
GLReadBufferUtil.readPixelsImpl(..) uses 'hasAlpha' to determine 
the 'PixelFormat.Composition hostPixelComp' and then modifies it 
based on the 'GLPixelAttributes pixelAttribs' composition.

Host and GL pixel composition could be different,
however, this implementation could potentially lead to a different host storage
on the second call w/ 'hasAlpha = true'.

Either (1) store the 'requestedAlpha' immutable and use it always,
or (2) determine 'hasAlpha' with construction.

(2) probably is desired anyways and (1) for better documentation (debugging).
Hence both options probably should be implemented and (2) will also lead to proper host PixelFormat. 

This erroneous behavior is now visible using AWTGLReadBufferUtil,
which can be mitigated using 'hasAlpha = true' in the construction.
Comment 1 Sven Gothel 2019-05-13 11:03:03 CEST
(In reply to Sven Gothel from comment #0)
> Either (1) store the 'requestedAlpha' immutable and use it always,
> or (2) determine 'hasAlpha' with construction.
> 
> (2) probably is desired anyways and (1) for better documentation (debugging).
> Hence both options probably should be implemented and (2) will also lead to
> proper host PixelFormat. 
> 
> This erroneous behavior is now visible using AWTGLReadBufferUtil,
> which can be mitigated using 'hasAlpha = true' in the construction.

(2) 'hasAlpha' cannot be determined w/o a valid GL instance or at least GLProfile at construction,
since none is currently passed in the constructor, 
we need to keep 'hasAlpha' being lazily evaluated by the first readPixel call.

(1) immutable storage of requestedAlpha will resolve this issue

It is up to the AWTGLReadBufferUtil user to use different pixel formats for host and GL, i.e. RGB stored within 32bit INT on the host side being filled by OpenGL with RGBA or BGRA data.
Comment 2 Sven Gothel 2019-05-13 11:21:51 CEST
jogl 154e91978498d8b6db9ce34a1f06b298bcf4c361
Keep host PixelFormat functional using requested immutable alphaRequested + add appropriate API doc