From deff49c901915e007f43a1df1a0d217a786e9f06 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Thu, 27 Aug 2015 13:15:44 +0200
Subject: Bug 1202 - Add support of Adaptive Vsync via
 [GLX|WGL]_EXT_swap_control_tear

[GLX|WGL]_EXT_swap_control_tear extensions support
asynchronous buffer swaps, i.e. adaptive Vsync.

<https://www.opengl.org/wiki/SwapInterval_aka_vsync#Adaptive_Vsync>
<https://www.opengl.org/registry/specs/EXT/wgl_swap_control_tear.txt>
<https://www.opengl.org/registry/specs/EXT/glx_swap_control_tear.txt>

<http://keithp.com/blogs/async_flip/>

The extensions utilizes a negative interval value,
enabling late swaps to occur without synchronization to the video frame.

Hence '-1' has new semantics, previously it was the 'default value'
of 'untouched vsync interval'.

New default is:
  - 0 for unrealized context
  - 1 for realized context

+++

It requires [GLX|WGL]_EXT_swap_control,
hence we shall ensure to use use this extension
in the implementation of GLContext.setSwapInterval(..).

+++

Mesa3D seems to support GLX_SGI_swap_control only.

+++

Implemented on Windows and X11.

+++

On GNU/Linux using NVidia driver w/ my setup(*), sadly the query
  GLX.glXQueryDrawable(displayHandle, drawable.getHandle(), GLX.GLX_LATE_SWAPS_TEAR_EXT, val);
always returns zero here, indicating async vsync is not supported.

(Queried the attribute for every frame in windowed or fullscreen mode)

Fullscreen
(*)
  - Debian 8
  - Kernel 3.16
  - KDE/Kwin
  - GL Version     4.5 (Core profile, arb, compat[ES2, ES3, ES31], FBO, hardware) - 4.5.0 NVIDIA 355.06 [GL 4.5.0, vendor 355.6.0 (NVIDIA 355.06)]
  - GL_RENDERER    GeForce GTX 660/PCIe/SSE2
  - Samsung U28D590 (DFP-4): Internal DisplayPort

+++
---
 src/jogl/classes/jogamp/opengl/egl/EGLContext.java | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

(limited to 'src/jogl/classes/jogamp/opengl/egl/EGLContext.java')

diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
index b6a05aeeb..b64bb375a 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
@@ -51,7 +51,6 @@ import jogamp.opengl.GLContextImpl;
 import jogamp.opengl.GLDrawableImpl;
 import jogamp.opengl.egl.EGLExtImpl;
 import jogamp.opengl.egl.EGLExtProcAddressTable;
-import jogamp.opengl.windows.wgl.WindowsWGLContext;
 
 import com.jogamp.common.ExceptionUtils;
 import com.jogamp.common.nio.Buffers;
@@ -432,11 +431,20 @@ public class EGLContext extends GLContextImpl {
     }
 
     @Override
-    protected boolean setSwapIntervalImpl(final int interval) {
+    protected final Integer setSwapIntervalImpl(final int interval) {
         if( hasRendererQuirk(GLRendererQuirks.NoSetSwapInterval) ) {
-            return false;
+            return null;
         }
-        return EGL.eglSwapInterval(drawable.getNativeSurface().getDisplayHandle(), interval);
+        final int useInterval;
+        if( 0 > interval ) {
+            useInterval = Math.abs(interval);
+        } else {
+            useInterval = interval;
+        }
+        if( EGL.eglSwapInterval(drawable.getNativeSurface().getDisplayHandle(), useInterval) ) {
+            return Integer.valueOf(useInterval);
+        }
+        return null;
     }
 
     static long eglGetProcAddress(final long eglGetProcAddressHandle, final String procname)
-- 
cgit v1.2.3