diff options
author | Michael Bien <[email protected]> | 2009-08-08 21:43:30 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-08-08 21:43:30 +0200 |
commit | 8ef9d7364a942c19ec5e1f306e08193e83f4fea6 (patch) | |
tree | 6dcf95825d2933992199a7062b15e38d3f721c95 /src/jogl/classes/com/sun/opengl/impl/x11/glx | |
parent | 2a8e9876ca4567de3b08813c280d006f9b2c32e6 (diff) | |
parent | fb3e50b4e7e11df911a83ab7966cf8f293c20da2 (diff) |
Merge branch 'master' of ssh://[email protected]/jogl~jogl-git
Diffstat (limited to 'src/jogl/classes/com/sun/opengl/impl/x11/glx')
6 files changed, 132 insertions, 65 deletions
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..d5a5f3433 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 @@ -142,7 +142,7 @@ public abstract class X11GLXContext extends GLContextImpl { if(config.getFBConfigID()<0) { // not able to use FBConfig if(glCaps.getGLProfile().isGL3()) { - throw new GLException("Unable to create OpenGL 3.1 context"); + throw new GLException("Unable to create OpenGL >= 3.1 context"); } context = GLX.glXCreateContext(display, config.getXVisualInfo(), share, direct); if (context == 0) { @@ -178,11 +178,9 @@ public abstract class X11GLXContext extends GLContextImpl { if( !isFunctionAvailable("glXCreateContextAttribsARB") || !isExtensionAvailable("GLX_ARB_create_context") ) { if(glCaps.getGLProfile().isGL3()) { - if (!GLX.glXMakeContextCurrent(display, 0, 0, 0)) { - throw new GLException("Error freeing temp OpenGL context"); - } + GLX.glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create OpenGL 3.1 context (no GLX_ARB_create_context)"); + throw new GLException("Unable to create OpenGL >= 3.1 context (no GLX_ARB_create_context)"); } // continue with temp context for GL < 3.0 @@ -195,47 +193,99 @@ public abstract class X11GLXContext extends GLContextImpl { // preset with default values int attribs[] = { - GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - GLX.GLX_CONTEXT_MINOR_VERSION_ARB, 0, - GLX.GLX_CONTEXT_FLAGS_ARB, 0, - GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, - 0 + /* 0 */ GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + /* 2 */ GLX.GLX_CONTEXT_MINOR_VERSION_ARB, 0, + /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, + /* 6 */ GLX.GLX_CONTEXT_FLAGS_ARB, 0 /* GLX.GLX_CONTEXT_DEBUG_BIT_ARB */, + /* 8 */ 0, 0, + /* 10 */ 0 }; if(glCaps.getGLProfile().isGL3()) { - attribs[1] |= 3; - attribs[3] |= 1; - attribs[5] |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /* | GLX.GLX_CONTEXT_DEBUG_BIT_ARB */; + // Try >= 3.2 core first + // and verify with a None drawable binding (default framebuffer) + attribs[0+1] = 3; + attribs[2+1] = 2; + // FIXME NV Bug: attribs[8+0] = GLX.GLX_CONTEXT_PROFILE_MASK_ARB; + // FIXME NV Bug: attribs[8+1] = GLX.GLX_CONTEXT_CORE_PROFILE_BIT_ARB; + + context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + if(0!=context) { + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawable.getNativeWindow().getSurfaceHandle(), + context)) { + if(DEBUG) { + System.err.println("X11GLXContext.createContext couldn't make >= 3.2 core context current - fallback"); + } + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, context); + context = 0; + } else if(DEBUG) { + System.err.println("X11GLXContext.createContext >= 3.2 available 0x"+Long.toHexString(context)); + } + } else { + if(DEBUG) { + System.err.println("X11GLXContext.createContext couldn't create >= 3.2 core context - fallback"); + } + } + if(0==context) { + // Try >= 3.1 forward compatible - last resort for GL3 ! + attribs[0+1] = 3; + attribs[2+1] = 1; + attribs[6+1] |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + attribs[8+0] = 0; + attribs[8+1] = 0; + } + } + if(0==context) { + // 3.1 or 3.0 .. + context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + if(0!=context) { + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawable.getNativeWindow().getSurfaceHandle(), + context)) { + if(DEBUG) { + System.err.println("X11GLXContext.createContext couldn't make >= 3.0 core context current - fallback"); + } + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, context); + context = 0; + } else if(DEBUG) { + System.err.println("X11GLXContext.createContext >= 3.0 available 0x"+Long.toHexString(context)); + } + } else { + if(DEBUG) { + System.err.println("X11GLXContext.createContext couldn't create >= 3.0 core context - fallback"); + } + } } - context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); if(0==context) { if(glCaps.getGLProfile().isGL3()) { - if (!GLX.glXMakeContextCurrent(display, 0, 0, 0)) { - throw new GLException("Error freeing temp OpenGL context"); - } + GLX.glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create OpenGL 3.1 context (have GLX_ARB_create_context)"); + throw new GLException("Unable to create OpenGL >= 3.1 context (have GLX_ARB_create_context)"); } // continue with temp context for GL < 3.0 context = temp_context; + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawable.getNativeWindow().getSurfaceHandle(), + context)) { + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_context); + throw new GLException("Error making context (old) current: display 0x"+Long.toHexString(display)+", context 0x"+Long.toHexString(context)+", drawable "+drawable); + } if(DEBUG) { System.err.println("X11GLXContext.createContext done (old ctx < 3.0 - no 3.0) 0x"+Long.toHexString(context)); } } else { - if (!GLX.glXMakeContextCurrent(display, 0, 0, 0)) { - throw new GLException("Error freeing temp OpenGL context"); - } GLX.glXDestroyContext(display, temp_context); // need to update the GL func table .. - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawable.getNativeWindow().getSurfaceHandle(), - context)) { - throw new GLException("Error making context (new) current: display 0x"+Long.toHexString(display)+", context 0x"+Long.toHexString(context)+", drawable "+drawable); - } updateGLProcAddressTable(); if(DEBUG) { System.err.println("X11GLXContext.createContext done (new ctx >= 3.0) 0x"+Long.toHexString(context)); @@ -349,7 +399,6 @@ public abstract class X11GLXContext extends GLContextImpl { } protected void updateGLProcAddressTable() { - super.updateGLProcAddressTable(); if (DEBUG) { System.err.println(getThreadName() + ": !!! Initializing GLX extension address table"); } @@ -359,6 +408,7 @@ public abstract class X11GLXContext extends GLContextImpl { glXExtProcAddressTable = new GLXExtProcAddressTable(); } resetProcAddressTable(getGLXExtProcAddressTable()); + super.updateGLProcAddressTable(); } public synchronized String getPlatformExtensionsString() { @@ -396,11 +446,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 +457,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/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java index 738714ecb..1abc36c58 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java @@ -76,26 +76,23 @@ public abstract class X11GLXDrawable extends GLDrawableImpl { } } - public void swapBuffers() throws GLException { - GLCapabilities caps = (GLCapabilities)getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); - if (caps.getDoubleBuffered()) { - boolean didLock = false; - try { - if ( !isSurfaceLocked() ) { - // Usually the surface shall be locked within [makeCurrent .. swap .. release] - if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { - return; - } - didLock=true; + protected void swapBuffersImpl() { + boolean didLock = false; + try { + if ( !isSurfaceLocked() ) { + // Usually the surface shall be locked within [makeCurrent .. swap .. release] + if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { + return; } + didLock=true; + } - GLX.glXSwapBuffers(component.getDisplayHandle(), component.getSurfaceHandle()); + GLX.glXSwapBuffers(component.getDisplayHandle(), component.getSurfaceHandle()); - } finally { - if(didLock) { - unlockSurface(); - } - } + } finally { + if(didLock) { + unlockSurface(); + } } } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java index 4cd174bec..dbf69e865 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java @@ -198,7 +198,7 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem String glXExtensions = GLX.glXQueryExtensionsString(display, screen); if (glXExtensions == null || glXExtensions.indexOf("GLX_NV_float_buffer") < 0) { - throw new GLException("Floating-point pbuffers on X11 currently require NVidia hardware"); + throw new GLException("Floating-point pbuffers on X11 currently require NVidia hardware: "+glXExtensions); } res[idx++] = GLXExt.GLX_FLOAT_COMPONENTS_NV; res[idx++] = GL.GL_TRUE; diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 9cb7eac08..074fbda5f 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -89,7 +89,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac xvis = X11GLXGraphicsConfiguration.XVisualID2XVisualInfo(display, visID); caps = X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(glProfile, display, xvis, onscreen, usePBuffer, isMultisampleAvailable); - int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(caps, true, isMultisampleAvailable, 0, 0); + int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(caps, true, isMultisampleAvailable, display, screen); int[] count = { -1 }; PointerBuffer fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0); if (fbcfgsL == null || fbcfgsL.limit()<1) { @@ -186,19 +186,19 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); - int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, true, isMultisampleAvailable, 0, 0); + int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, true, isMultisampleAvailable, display, screen); int[] count = { -1 }; fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0); if (fbcfgsL == null || fbcfgsL.limit()<1) { if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: glXChooseFBConfig ("+x11Screen+","+capabilities+"): "+fbcfgsL+", "+count[0]); + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig ("+x11Screen+","+capabilities+"): "+fbcfgsL+", "+count[0]); } return null; } if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfgsL.get(0) ) ) { if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: GLX FBConfig invalid: ("+x11Screen+","+capabilities+"): "+fbcfgsL+", fbcfg: 0x"+Long.toHexString(fbcfgsL.get(0))); + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("+x11Screen+","+capabilities+"): "+fbcfgsL+", fbcfg: 0x"+Long.toHexString(fbcfgsL.get(0))); } return null; } @@ -215,11 +215,19 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac try { chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); } catch (NativeWindowException e) { - throw new GLException(e); + if(DEBUG) { + e.printStackTrace(); + } + chosen = -1; } } - - if (chosen < 0 || chosen >= caps.length) { + if (chosen < 0) { + // keep on going .. + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. unable to choose config, using first"); + } + chosen = 0; // default .. + } else if (chosen >= caps.length) { throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } @@ -228,9 +236,12 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac retXVisualInfo = GLX.glXGetVisualFromFBConfigCopied(display, fbcfgsL.get(chosen)); if (retXVisualInfo==null) { if(DEBUG) { - System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: glXGetVisualFromFBConfig ("+x11Screen+", "+fbcfgsL.get(chosen) +": "+fbcfgsL); + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetVisualFromFBConfig ("+x11Screen+", "+fbcfgsL.get(chosen) +" (Continue: "+(false==caps[chosen].isOnscreen())+"):\n\t"+caps[chosen]); + } + if(caps[chosen].isOnscreen()) { + // Onscreen drawables shall have a XVisual .. + return null; } - return null; } } finally { NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); @@ -255,7 +266,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac GLCapabilities[] caps = null; int recommendedIndex = -1; XVisualInfo retXVisualInfo = null; - int chosen; + int chosen=-1; NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); try { @@ -263,7 +274,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); - int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, false, isMultisampleAvailable, 0, 0); + int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(capabilities, false, isMultisampleAvailable, display, screen); XVisualInfo[] infos = null; XVisualInfo recommendedVis = GLX.glXChooseVisualCopied(display, screen, attribs, 0); @@ -293,9 +304,18 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac try { chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); } catch (NativeWindowException e) { - throw new GLException(e); + if(DEBUG) { + e.printStackTrace(); + } + chosen = -1; } - if (chosen < 0 || chosen >= caps.length) { + if (chosen < 0) { + // keep on going .. + if(DEBUG) { + System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationXVisual Failed .. unable to choose config, using first"); + } + chosen = 0; // default .. + } else if (chosen >= caps.length) { throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } if (infos[chosen] == null) { diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java index 51938df5f..768f6b8e8 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java @@ -133,6 +133,6 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { getFactoryImpl().unlockToolkit(); } } - public void swapBuffers() throws GLException { + protected void swapBuffersImpl() { } } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java index eecd92a53..bee24fa47 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java @@ -148,6 +148,6 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { return GLPbuffer.NV_FLOAT; } - public void swapBuffers() throws GLException { + protected void swapBuffersImpl() { } } |