<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>975</bug_id>
          
          <creation_ts>2014-02-13 21:32:12 +0100</creation_ts>
          <short_desc>GLJPanel&apos;s OffscreenDrawable shall not double swap (custom swap by GLEventListener using [AWT]GLReadBufferUtil)</short_desc>
          <delta_ts>2014-08-30 20:04:02 +0200</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Jogl</product>
          <component>awt</component>
          <version>2</version>
          <rep_platform>All</rep_platform>
          <op_sys>all</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>---</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sven Gothel">sgothel</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          
          
          <cf_type>---</cf_type>
          <cf_scm_refs>908ebd99d1eb57ce773a1fdd67c76886da86b9e6
82f679b064784213591b460fc5eaa1f5f196fbd1
d46d9ad8f998a7128d9f023294d5f489673d6d8a
41190c3830157abdf9649cbf7767e57108f55075
b96fc594f15fcf9ee0fd238ce8d7a10aea781d32</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>3725</commentid>
    <comment_count>0</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-02-13 21:32:12 +0100</bug_when>
    <thetext>When utilizing [AWT]GLReadBufferUtil it is usually desired to read from the front-buffer
instead the back-buffer. The latter may not be defined, e.g. when using MSAA.

A GLEventListener utilizing [AWT]GLReadBufferUtil,
must perform the drawable.swapBuffers() to be able to read from the front-buffer.

Usually GLAutoDrawable.setAutoSwapBuffer(false) should be called here,
to avoid a double swap - however GLJPanel does not support toggling auto-swap
since it requires to control swap for it&apos;s own read-pixels.

Remedy for GLJPanel:
  - GLJPanel issues helper.setAutoSwapBufferMode(false) - immutable

  - Enable GLJPanel.swapBuffer() if initializes
    This was previously disabled.

  - GLJPanel&apos;s OffscreenBackend listens to  surfaceUpdated,
    to be notified whether postGL needs to swap buffer
    or the drawable.swapBuffer() was already called between preGL and postGL.

See unit tests adding/removing a snapshot GLEventListener
performing swapBuffers() and setting auto-swap accordingly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>3726</commentid>
    <comment_count>1</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-02-13 21:32:56 +0100</bug_when>
    <thetext>908ebd99d1eb57ce773a1fdd67c76886da86b9e6
  fixed as described</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>3728</commentid>
    <comment_count>2</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-02-14 06:39:05 +0100</bug_when>
    <thetext>82f679b064784213591b460fc5eaa1f5f196fbd1
  GLJPanel: Use default auto-swap mechanims

    Refines commit 908ebd99d1eb57ce773a1fdd67c76886da86b9e6
    
    Note that the test case decide whether to auto-swap (after read-pixels)
    or not auto-swap (manual swap before read-pixels).
    
    See UITestCase.swapBuffersBeforeRead(GLCapabilitiesImmutable chosenCaps):
       Determines whether the chosen GLCapabilitiesImmutable requires a swap-buffers before reading pixels.
    
       Usually one uses the default-read-buffer, i.e. GL.GL_FRONT for single-buffer
       and GL.GL_BACK for double-buffer GLDrawables
       and GL.GL_COLOR_ATTACHMENT0 for offscreen framebuffer objects.
       Here swap-buffers shall happen after calling reading pixels, the default.
    
       However, multisampling offscreen GLFBODrawables utilize swap-buffers to downsample
       the multisamples into the readable sampling sink.
       In this case, we require a swap-buffers before reading pixels.
    
       Returns:  chosenCaps.isFBO() &amp;&amp; chosenCaps.getSampleBuffers()
    
    +++
    +++
    
    - GLJPanel:
      - Remove SurfaceUpdatedListener mechanism in favor of
        default auto-swap-buffer via GLDrawableHelper.
        This removes complexity.
    
      - postGL does not need to perform explicit swapBuffer operation,
        but rely on GLDrawableHelper and the default mechanism.
        This is also compatible w/ J2D backend.
    
      - Use GLDrawableHelper for setAutoSwapBufferMode(..) and getAutoSwapBufferMode()
    
    +++
    
    UnitTests:
    
    - UITestCase:
      - Add &apos;boolean swapBuffersBeforeRead(GLCapabilitiesImmutable chosenCaps)&apos;
        to determine whether swapBuffers() must occure before read-pixels. See above.
    
    - GLReadBuffer00Base*
      - remove explicit addSnapshotGLEL/removeSnapshotGLEL
    
      - add TextRendererGLEL, to display frame-count and -dimension
    
      - SnapshotGLEL*
        - simply toggle auto-swap in their init(..) and dispose(..) method!
    
        - clear back-buffer if &apos;swapBuffersBeforeRead&apos;
          to test whether the right buffer is being used for read-pixels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>3745</commentid>
    <comment_count>3</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-02-18 19:13:39 +0100</bug_when>
    <thetext>d46d9ad8f998a7128d9f023294d5f489673d6d8a
    Bug 975 - GLJPanel&apos;s OffscreenDrawable shall not double swap - Refine unit test for visual validation of &apos;no frame lag&apos;
    
    To validate whether a &apos;display&apos; command w/o animator results to the desired frame
    we introduce a &apos;userCounter&apos; in TextRendererGLEL.
    
    The latter gets increased and maybe visually validated by a key-press -&gt; display.
    
    Results: In all modes, MSAA or !MSAA, or flip - the result is valid.
    
    Tested on windows and linux.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>3746</commentid>
    <comment_count>4</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-02-18 21:52:08 +0100</bug_when>
    <thetext>41190c3830157abdf9649cbf7767e57108f55075
   Fix auto-swap mechanism ; Refined API doc getDefaultReadBuffer() ; 
   Add GLDrawableUtil.swapBuffersBeforeRead
    
    Commit 82f679b064784213591b460fc5eaa1f5f196fbd1 which introduces the default swap-buffers
    mechanism is erroneous:
    
    The OffscreenBack backend requires the following operation order:
    
    Order-1:
      [1] - GL display
      [2] - GL swapBuffers (always due to single-buffer non-MSAA or MSAA offscreen drawable)
      [3] - readPixels
    
    +++
    
    Commit 82f679b064784213591b460fc5eaa1f5f196fbd1 however introduced:
    
    Order-2:
      [a] - GL display
      [b] - readPixels
      [c] - GL swapBuffers (always due to single-buffer non-MSAA or MSAA offscreen drawable)
    
    since [a] and [b] happened in Updater&apos;s display method, and [c] followed the same
    triggered by GLAutoDrawableHelper.
    
    +++
    
    The proof, commit d46d9ad8f998a7128d9f023294d5f489673d6d8a, is faulty,
    since it always included the &apos;snapshot&apos; GL event listener
    which turned-off auto-swap and swapped before read-pixels.
    TL;DR it enforced proper Order-1.
    
    +++
    
    This fix allows the Backend to intercept disable GLDrawableHelper&apos;s setAutoSwapBufferMode(..)
    and perform the auto-swap mode itself in the proper Order-1.
    
    The unit test has been refined to optionally disable the snapshot
    to validate auto-swap mode.
    
    +++
    
    Refined GLBase and GLContext&apos;s API doc for &apos;getDefaultReadBuffer()&apos;
    
    +++
    
    Add GLDrawableUtil.swapBuffersBeforeRead(..)
    and reuse it for TileRendererBase (original impl.).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>3747</commentid>
    <comment_count>5</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-02-18 21:52:36 +0100</bug_when>
    <thetext>b96fc594f15fcf9ee0fd238ce8d7a10aea781d32

GLContextImpl/GLDrawableImpl.getDefaultReadBuffer(..): 
   Pass hint whether dedicated read-drawable is being used (double buffering)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4142</commentid>
    <comment_count>6</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-08-30 19:43:54 +0200</bug_when>
    <thetext>Also related Bug 941 and Bug 1020</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4144</commentid>
    <comment_count>7</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2014-08-30 20:04:02 +0200</bug_when>
    <thetext>Test cases:
  com.jogamp.opengl.test.junit.jogl.acore.TestGLReadBuffer01GLJPanelAWT
  com.jogamp.opengl.test.junit.jogl.acore.TestGLReadBuffer01GLCanvasAWT
  com.jogamp.opengl.test.junit.jogl.acore.TestGLReadBuffer01GLWindowNEWT</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>