From deff49c901915e007f43a1df1a0d217a786e9f06 Mon Sep 17 00:00:00 2001
From: Sven Gothel
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.
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/com/jogamp/opengl/GLContext.java | 63 ++++++++++-------------
1 file changed, 26 insertions(+), 37 deletions(-)
(limited to 'src/jogl/classes/com/jogamp/opengl/GLContext.java')
diff --git a/src/jogl/classes/com/jogamp/opengl/GLContext.java b/src/jogl/classes/com/jogamp/opengl/GLContext.java
index f68c029df..3ac5df7d4 100644
--- a/src/jogl/classes/com/jogamp/opengl/GLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/GLContext.java
@@ -237,7 +237,6 @@ public abstract class GLContext {
protected String ctxVersionString;
protected VersionNumberString ctxVendorVersion;
protected VersionNumber ctxGLSLVersion;
- private int currentSwapInterval;
protected GLRendererQuirks glRendererQuirks;
/** Did the drawable association changed ? see {@link GLRendererQuirks#NoSetSwapIntervalPostRetarget} */
@@ -258,7 +257,6 @@ public abstract class GLContext {
ctxGLSLVersion = VersionNumber.zeroVersion;
attachedObjects.clear();
contextHandle=0;
- currentSwapInterval = -1;
glRendererQuirks = null;
drawableRetargeted = false;
}
@@ -1246,50 +1244,41 @@ public abstract class GLContext {
}
/**
- * Set the swap interval of the current context and attached drawable.
- * @param interval Should be ≥ 0. 0 disables the vertical synchronization,
- * where ≥ 1 is the number of vertical refreshes before a swap buffer occurs.
- * A value < 0 is ignored.
+ * Set the swap interval of the current context and attached onscreen {@link GLDrawable}.
+ *
+ * offscreen {@link GLDrawable} are ignored and {@code false} is returned.
+ *
+ *
+ * The {@code interval} semantics:
+ *
+ * - 0 disables the vertical synchronization
+ * - ≥1 is the number of vertical refreshes before a swap buffer occurs
+ * - <0 enables late swaps to occur without synchronization to the video frame, a.k.a EXT_swap_control_tear.
+ * If supported, the absolute value is the minimum number of
+ * video frames between buffer swaps. If not supported, the absolute value is being used, see above.
+ *
+ *
+ *
+ * @param interval see above
* @return true if the operation was successful, otherwise false
- *
* @throws GLException if the context is not current.
+ * @see #getSwapInterval()
*/
- public final boolean setSwapInterval(final int interval) throws GLException {
- validateCurrent();
- if(0<=interval) {
- if( !drawableRetargeted || !hasRendererQuirk(GLRendererQuirks.NoSetSwapIntervalPostRetarget) ) {
- if( setSwapIntervalImpl(interval) ) {
- currentSwapInterval = interval;
- return true;
- }
- }
- }
- return false;
- }
- protected boolean setSwapIntervalImpl(final int interval) {
- return false;
- }
- /** Return the current swap interval.
+ public abstract boolean setSwapInterval(final int interval) throws GLException;
+
+ /**
+ * Return the current swap interval.
*
* If the context has not been made current at all,
- * the default value -1
is returned.
+ * the default value {@code 0} is returned.
*
*
- * For a valid context the default value is 1
- * in case of an EGL based profile (ES1 or ES2) and -1
- * (undefined) for desktop.
+ * For a valid context w/ an onscreen {@link GLDrawable} the default value is {@code 1},
+ * otherwise the default value is {@code 0}.
*
+ * @see #setSwapInterval(int)
*/
- public final int getSwapInterval() {
- return currentSwapInterval;
- }
- protected final void setDefaultSwapInterval() {
- if(this.isGLES()) {
- currentSwapInterval = 1;
- } else {
- currentSwapInterval = -1;
- }
- }
+ public abstract int getSwapInterval();
public final boolean queryMaxSwapGroups(final int[] maxGroups, final int maxGroups_offset,
final int[] maxBarriers, final int maxBarriers_offset) {
--
cgit v1.2.3