diff options
author | sg215889 <[email protected]> | 2009-07-30 22:09:24 -0700 |
---|---|---|
committer | sg215889 <[email protected]> | 2009-07-30 22:09:24 -0700 |
commit | 9a4619d5ab1c0441dfb273d057e288b4bf4c6dbc (patch) | |
tree | 32a937f2eefbf31f6785b9e2bea805cb0f86cb6c /src | |
parent | cd0ec06b5e8a5ec39c8162e87d23c935b506021e (diff) |
Fix SwapInterval (return value, check ctx current, egl), add getSwapInterval.
Diffstat (limited to 'src')
8 files changed, 60 insertions, 36 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java index c60cccec6..fa7e1ade7 100644 --- a/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java @@ -284,11 +284,23 @@ public abstract class GLContextImpl extends GLContext { public abstract ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3); - /* - * Sets the swap interval for onscreen OpenGL contexts. Has no - * effect for offscreen contexts. - */ public void setSwapInterval(final int interval) { + GLContext current = getCurrent(); + if (current != this) { + throw new GLException("This context is not current. Current context: "+current+ + ", this context "+this); + } + setSwapIntervalImpl(interval); + } + + protected int currentSwapInterval = -1; // default: not set yet .. + + public int getSwapInterval() { + return currentSwapInterval; + } + + protected void setSwapIntervalImpl(final int interval) { + // nop per default .. } /** Maps the given "platform-independent" function name to a real function diff --git a/src/jogl/classes/com/sun/opengl/impl/egl/EGLContext.java b/src/jogl/classes/com/sun/opengl/impl/egl/EGLContext.java index 45fe0fcd3..1a75f03a9 100755 --- a/src/jogl/classes/com/sun/opengl/impl/egl/EGLContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/egl/EGLContext.java @@ -261,6 +261,12 @@ public abstract class EGLContext extends GLContextImpl { } } + protected void setSwapIntervalImpl(int interval) { + if (EGL.eglSwapInterval(drawable.getDisplay(), interval)) { + currentSwapInterval = interval ; + } + } + public abstract void bindPbufferToTexture(); public abstract void releasePbufferFromTexture(); diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java index b424e9516..f60dd1645 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java @@ -337,11 +337,12 @@ public abstract class MacOSXCGLContext extends GLContextImpl return ""; } - public void setSwapInterval(int interval) { + protected void setSwapIntervalImpl(int interval) { if (nsContext == 0) { throw new GLException("OpenGL context not current"); } CGL.setSwapInterval(nsContext, interval); + currentSwapInterval = interval ; } public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java index d702150d3..4ea3519bf 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java @@ -121,11 +121,12 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { } } - public void setSwapInterval(int interval) { + protected void setSwapIntervalImpl(int interval) { if (nsContext == 0) { throw new GLException("OpenGL context not current"); } impl.setSwapInterval(nsContext, interval); + currentSwapInterval = impl.getSwapInterval() ; } public int getFloatingPointMode() { @@ -210,6 +211,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { public boolean makeCurrent(long ctx); public boolean release(long ctx); public void setSwapInterval(long ctx, int interval); + public int getSwapInterval(); } // NSOpenGLContext-based implementation @@ -241,8 +243,14 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { return CGL.clearCurrentContext(ctx); } + private int currentSwapInterval = 0 ; + public void setSwapInterval(long ctx, int interval) { CGL.setSwapInterval(ctx, interval); + currentSwapInterval = interval ; + } + public int getSwapInterval() { + return currentSwapInterval; } } @@ -344,5 +352,8 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { public void setSwapInterval(long ctx, int interval) { // For now not supported (not really relevant for off-screen contexts anyway) } + public int getSwapInterval() { + return 0; + } } } diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java index 4423f8da5..22b0ffe55 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java @@ -144,10 +144,6 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL } } - public void setSwapInterval(int interval) { - // Not supported in this context implementation - } - public void setOpenGLMode(int mode) { if (mode != MacOSXCGLDrawable.CGL_MODE) throw new GLException("OpenGL mode switching not supported for Java2D GLContexts"); diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java index 1bc3acada..92a563445 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -332,29 +332,12 @@ public class WindowsWGLContext extends GLContextImpl { } } - public boolean isFunctionAvailable(String glFunctionName) - { - boolean available = super.isFunctionAvailable(glFunctionName); - - // Sanity check for implementations that use proc addresses for run-time - // linking: if the function IS available, then make sure there's a proc - // address for it if it's an extension or not part of the OpenGL 1.1 core - // (post GL 1.1 functions are run-time linked on windows). - /* FIXME: - assert(!available || - (getGLProcAddressTable().getAddressFor(mapToRealGLFunctionName(glFunctionName)) != 0 || - FunctionAvailabilityCache.isPartOfGLCore("1.1", mapToRealGLFunctionName(glFunctionName))) - ); */ - - return available; - } - - public void setSwapInterval(int interval) { - // FIXME: make the context current first? Currently assumes that - // will not be necessary. Make the caller do this? + protected void setSwapIntervalImpl(int interval) { WGLExt wglExt = getWGLExt(); if (wglExt.isExtensionAvailable("WGL_EXT_swap_control")) { - wglExt.wglSwapIntervalEXT(interval); + if ( wglExt.wglSwapIntervalEXT(interval) ) { + currentSwapInterval = interval ; + } } } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java index 57abcf588..718d55aa0 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java @@ -396,11 +396,9 @@ public abstract class X11GLXContext extends GLContextImpl { private int hasSwapIntervalSGI = 0; - public void setSwapInterval(int interval) { + protected void setSwapIntervalImpl(int interval) { getDrawableImpl().getFactoryImpl().lockToolkit(); try { - // FIXME: make the context current first? Currently assumes that - // will not be necessary. Make the caller do this? GLXExt glXExt = getGLXExt(); if(0==hasSwapIntervalSGI) { try { @@ -409,7 +407,9 @@ public abstract class X11GLXContext extends GLContextImpl { } if (hasSwapIntervalSGI>0) { try { - glXExt.glXSwapIntervalSGI(interval); + if( 0 == glXExt.glXSwapIntervalSGI(interval) ) { + currentSwapInterval = interval; + } } catch (Throwable t) { hasSwapIntervalSGI=-1; } } } finally { diff --git a/src/jogl/classes/javax/media/opengl/GLBase.java b/src/jogl/classes/javax/media/opengl/GLBase.java index 7b59344cc..92498077b 100644 --- a/src/jogl/classes/javax/media/opengl/GLBase.java +++ b/src/jogl/classes/javax/media/opengl/GLBase.java @@ -227,9 +227,24 @@ public interface GLBase { until swapping buffers. The default, which is platform-specific, is usually either 0 or 1. This function is not guaranteed to have an effect, and in particular only affects heavyweight - onscreen components. */ + onscreen components. + + @see #getSwapInterval + @throws GLException if this context is not the current + */ public void setSwapInterval(int interval); + /** Provides a platform-independent way to get the swap + interval set by {@link #setSwapInterval}. <br> + + If the interval is not set by {@link #setSwapInterval} yet, + -1 is returned, indicating that the platforms default + is being used. + + @see #setSwapInterval + */ + public int getSwapInterval(); + /** * Returns an object through which platform-specific OpenGL extensions * (EGL, GLX, WGL, etc.) may be accessed. The data type of the returned |