diff options
author | Sven Gothel <[email protected]> | 2010-04-17 01:32:26 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-04-17 01:32:26 +0200 |
commit | 8778a3d70f8d57bc4f9142a3f59ea59754f08c1d (patch) | |
tree | 29a0c7fe341fcabf217cba8a0c9774d77b3cb169 | |
parent | 60da84a5ca8fa5e74e995ad0343c8967ba9463a5 (diff) |
JOGL GL4 preperation (cont):
- Cont. on Context creation refactoring (bb028021be2714e66d9b1062298a3e308c649c56)
- Added Windows/WGL implementation
- Added efficienct sharedContext usage if ARB is available,
ie no more temp context has to be created.
- Added more GLProfile GL4* code ..
7 files changed, 277 insertions, 183 deletions
diff --git a/make/java-run-newt.sh b/make/java-run-newt.sh index 39654d03b..cb256e273 100755 --- a/make/java-run-newt.sh +++ b/make/java-run-newt.sh @@ -20,4 +20,9 @@ if [ $MOSX -eq 1 ] ; then X_ARGS="-XstartOnFirstThread" fi -java $X_ARGS -Djava.awt.headless=true com.jogamp.newt.util.MainThread $* 2>&1 | tee java-run-newt.log +# D_ARGS="-Dgluegen.debug.ProcAddressHelper=true -Dgluegen.debug.NativeLibrary=true -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all" +# D_ARGS="-Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all -Djogl.debug.GLSLState" +# D_ARGS="-Dnativewindow.debug.X11Util=true -Djogl.debug.GLDrawableFactory=true" +# D_ARGS="-Dnativewindow.debug.X11Util=true" + +java $X_ARGS -Djava.awt.headless=true $D_ARGS com.jogamp.newt.util.MainThread $* 2>&1 | tee java-run-newt.log diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index 7f9459a48..95706a7a1 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -122,48 +122,123 @@ public class WindowsWGLContext extends GLContextImpl { protected Map/*<String, String>*/ getExtensionNameMap() { return extensionNameMap; } - protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { - return 0; // FIXME + protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); + WGLExt wglExt; + if(null==factory.getSharedContext()) { + wglExt = getWGLExt(); + } else { + wglExt = factory.getSharedContext().getWGLExt(); + } + + boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; + boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ; + boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ; + + long _context=0; + + int attribs[] = { + /* 0 */ WGLExt.WGL_CONTEXT_MAJOR_VERSION_ARB, major, + /* 2 */ WGLExt.WGL_CONTEXT_MINOR_VERSION_ARB, minor, + /* 4 */ WGLExt.WGL_CONTEXT_LAYER_PLANE_ARB, WGLExt.WGL_CONTEXT_LAYER_PLANE_ARB, // default + /* 6 */ WGLExt.WGL_CONTEXT_FLAGS_ARB, 0, + /* 8 */ 0, 0, + /* 10 */ 0 + }; + + if ( major > 3 || major == 3 && minor >= 2 ) { + // FIXME: Verify with a None drawable binding (default framebuffer) + attribs[8+0] = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB; + if( ctBwdCompat ) { + attribs[8+1] = WGLExt.WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; + } else { + attribs[8+1] = WGLExt.WGL_CONTEXT_CORE_PROFILE_BIT_ARB; + } + } + + if ( major >= 3 ) { + if( !ctBwdCompat && ctFwdCompat ) { + attribs[6+1] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + } + if( ctDebug) { + attribs[6+1] |= WGLExt.WGL_CONTEXT_DEBUG_BIT_ARB; + } + } + + _context = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), share, attribs, 0); + if(0==_context) { + if(DEBUG) { + System.err.println("WindowsWGLContext.createContextARB couldn't create "+getGLVersion(null, major, minor, ctp, "@creation")); + } + } else { + // In contrast to GLX no verification with a drawable binding, ie default framebuffer, is necessary, + // if no 3.2 is available creation fails already! + // Nevertheless .. we do it .. + if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), _context)) { + if(DEBUG) { + System.err.println("WindowsWGLContext.createContextARB couldn't make current "+getGLVersion(null, major, minor, ctp, "@creation")); + } + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(_context); + _context = 0; + } } + return _context; + } /** * Creates and initializes an appropriate OpenGL context. Should only be * called by {@link #makeCurrentImpl()}. */ protected void create() { - GLCapabilities glCaps = drawable.getChosenGLCapabilities(); - if(DEBUG) { - System.err.println("WindowsWGLContext.create got "+glCaps); + if(0!=context) { + throw new GLException("context is not null: "+context); } + WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); + GLCapabilities glCaps = drawable.getChosenGLCapabilities(); if (drawable.getNativeWindow().getSurfaceHandle() == 0) { throw new GLException("Internal error: attempted to create OpenGL context without an associated drawable"); } // Windows can set up sharing of display lists after creation time WindowsWGLContext other = (WindowsWGLContext) GLContextShareSet.getShareContext(this); - long hglrc2 = 0; + long share = 0; if (other != null) { - hglrc2 = other.getHGLRC(); - if (hglrc2 == 0) { + share = other.getHGLRC(); + if (share == 0) { throw new GLException("GLContextShareSet returned an invalid OpenGL context"); } } - // To use WGL_ARB_create_context, we have to make a temp context current, - // so we are able to use GetProcAddress - long temp_hglrc = WGL.wglCreateContext(drawable.getNativeWindow().getSurfaceHandle()); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created temp OpenGL context " + toHexString(temp_hglrc) + " for " + this + ", device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + ", not yet sharing"); + int minor[] = new int[1]; + int major[] = new int[1]; + int ctp[] = new int[1]; + boolean createContextARBTried = false; + + // utilize the shared context's GLXExt in case it was using the ARB method and it already exists + if(null!=factory.getSharedContext() && factory.getSharedContext().isCreatedWithARBMethod()) { + if(DEBUG) { + System.err.println("WindowsWGLContext.createContext using shared Context: "+factory.getSharedContext()); + } + hglrc = createContextARB(share, true, major, minor, ctp); + createContextARBTried = true; } - if (temp_hglrc == 0) { - throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle())); - } else { + + long temp_hglrc = 0; + if(0==hglrc) { + // To use WGL_ARB_create_context, we have to make a temp context current, + // so we are able to use GetProcAddress + temp_hglrc = WGL.wglCreateContext(drawable.getNativeWindow().getSurfaceHandle()); + if (temp_hglrc == 0) { + throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle())); + } if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_hglrc)) { throw new GLException("Error making temp context current: 0x" + Integer.toHexString(WGL.GetLastError())); } setGLFunctionAvailability(true, 0, 0, 0); - if( !isFunctionAvailable("wglCreateContextAttribsARB") || + if( createContextARBTried || + !isFunctionAvailable("wglCreateContextAttribsARB") || !isExtensionAvailable("WGL_ARB_create_context") ) { if(glCaps.getGLProfile().isGL3()) { WGL.wglMakeCurrent(0, 0); @@ -173,111 +248,51 @@ public class WindowsWGLContext extends GLContextImpl { // continue with temp context for GL < 3.0 hglrc = temp_hglrc; - if(DEBUG) { - System.err.println("WindowsWGLContext.create done (old ctx < 3.0 - no WGL_ARB_create_context) 0x"+Long.toHexString(hglrc)); - } - } else { - WGLExt wglExt = getWGLExt(); + return; + } + hglrc = createContextARB(share, true, major, minor, ctp); + createContextARBTried=true; + } + + if(0!=hglrc) { + share = 0; // mark as shared .. - // preset with default values - int attribs[] = { - /* 0 */ WGLExt.WGL_CONTEXT_MAJOR_VERSION_ARB, 3, - /* 2 */ WGLExt.WGL_CONTEXT_MINOR_VERSION_ARB, 0, - /* 4 */ WGLExt.WGL_CONTEXT_FLAGS_ARB, 0 /* WGLExt.WGL_CONTEXT_DEBUG_BIT_ARB */, - /* 6 */ 0, 0, - /* 8 */ 0 - }; + // need to update the GL func table .. + setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); - if(glCaps.getGLProfile().isGL3()) { - // Try >= 3.2 core first ! - // In contrast to GLX no verify with a None drawable binding (default framebuffer) is necessary, - // if no 3.2 is available creation fails already! - attribs[0+1] = 3; - attribs[2+1] = 2; - if(glCaps.getGLProfile().isGL3bc()) { - attribs[6+0] = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB; - attribs[6+1] = WGLExt.WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - } - /** - * don't stricten requirements any further, even compatible would be fine - * - } else { - attribs[6+0] = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB; - attribs[6+1] = WGLExt.WGL_CONTEXT_CORE_PROFILE_BIT_ARB; - } - */ - hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0); - if(0==hglrc) { - if(DEBUG) { - System.err.println("WindowsWGLContext.createContext couldn't create >= 3.2 core context - fallback"); - } - // Try >= 3.1 forward compatible - last resort for GL3 ! - attribs[0+1] = 3; - attribs[2+1] = 1; - if(!glCaps.getGLProfile().isGL3bc()) { - attribs[4+1] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; - } - attribs[6+0] = 0; - attribs[6+1] = 0; - } else if(DEBUG) { - System.err.println("WindowsWGLContext.createContext >= 3.2 available 0x"+Long.toHexString(hglrc)); - } - } - if(0==hglrc) { - // 3.1 or 3.0 .. - hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0); - if(DEBUG) { - if(0==hglrc) { - System.err.println("WindowsWGLContext.createContext couldn't create >= 3.0 context - fallback"); - } else { - System.err.println("WindowsWGLContext.createContext >= 3.0 available 0x"+Long.toHexString(hglrc)); - } - } - } + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(temp_hglrc); - if(0==hglrc) { - if(glCaps.getGLProfile().isGL3()) { - WGL.wglMakeCurrent(0, 0); - WGL.wglDeleteContext(temp_hglrc); - throw new GLException("Unable to create OpenGL >= 3.1 context (have WGL_ARB_create_context)"); - } - - // continue with temp context for GL < 3.0 - hglrc = temp_hglrc; - if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) { - throw new GLException("Error making old context current: 0x" + Integer.toHexString(WGL.GetLastError())); - } - updateGLProcAddressTable(0, 0, 0); - if(DEBUG) { - System.err.println("WindowsWGLContext.create done (old ctx < 3.0 - no 3.0) 0x"+Long.toHexString(hglrc)); - } - } else { - hglrc2 = 0; // mark as shared .. - WGL.wglMakeCurrent(0, 0); - WGL.wglDeleteContext(temp_hglrc); - - if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) { - throw new GLException("Error making new context current: 0x" + Integer.toHexString(WGL.GetLastError())); - } - updateGLProcAddressTable(0, 0, 0); - if(DEBUG) { - System.err.println("WindowsWGLContext.create done (new ctx >= 3.0) 0x"+Long.toHexString(hglrc)); - } - } + if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) { + throw new GLException("Cannot make previous verified context current: 0x" + Integer.toHexString(WGL.GetLastError())); + } + } else { + if(glCaps.getGLProfile().isGL3()) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(temp_hglrc); + throw new GLException("WindowsWGLContext.createContext failed, but context > GL2 requested "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "); + } + if(DEBUG) { + System.err.println("WindowsWGLContext.createContext failed, fall back to !ARB context "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")); + } + + // continue with temp context for GL < 3.0 + hglrc = temp_hglrc; + if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) { + WGL.wglMakeCurrent(0, 0); + WGL.wglDeleteContext(hglrc); + throw new GLException("Error making old context current: 0x" + Integer.toHexString(WGL.GetLastError())); } } - if(0!=hglrc2) { - if (!WGL.wglShareLists(hglrc2, hglrc)) { - throw new GLException("wglShareLists(" + toHexString(hglrc2) + + + if(0!=share) { + if (!WGL.wglShareLists(share, hglrc)) { + throw new GLException("wglShareLists(" + toHexString(share) + ", " + toHexString(hglrc) + ") failed: error code 0x" + Integer.toHexString(WGL.GetLastError())); } } GLContextShareSet.contextCreated(this); - WGL.wglMakeCurrent(0, 0); // release immediatly to gain from ARB/EXT wglMakeContextCurrent(draw, read, ctx)! - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created OpenGL context " + toHexString(hglrc) + " for " + this + ", device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + ", sharing with " + toHexString(hglrc2)); - } } protected int makeCurrentImpl() throws GLException { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index e3938f9fe..bc99338ab 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -77,13 +77,22 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements WindowsWGLContext sharedContext=null; boolean canCreateGLPbuffer = false; + // package private .. + final WindowsWGLContext getSharedContext() { + validate(); + return sharedContext; + } + void initShared() { if(null==sharedDrawable) { sharedDrawable = new WindowsDummyWGLDrawable(this, null); - sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null); - sharedContext.makeCurrent(); - canCreateGLPbuffer = sharedContext.getGL().isExtensionAvailable("GL_ARB_pbuffer"); - sharedContext.release(); + WindowsWGLContext _sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null); + { + _sharedContext.makeCurrent(); + canCreateGLPbuffer = _sharedContext.getGL().isExtensionAvailable("GL_ARB_pbuffer"); + _sharedContext.release(); + } + _sharedContext = _sharedContext; if (DEBUG) { System.err.println("!!! SharedContext: "+sharedContext+", pbuffer supported "+canCreateGLPbuffer); } @@ -115,20 +124,30 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (target == null) { throw new IllegalArgumentException("Null target"); } + initShared(); return new WindowsOnscreenWGLDrawable(this, target); } protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) { + validate(); + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + initShared(); return new WindowsOffscreenWGLDrawable(this, target); } public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { validate(); - initShared(); + initShared(); // setup canCreateGLPBuffer return canCreateGLPbuffer; } protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) { + validate(); + if (target == null) { + throw new IllegalArgumentException("Null target"); + } initShared(); final List returnList = new ArrayList(); final GLDrawableFactory factory = this; @@ -160,6 +179,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements } protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + validate(); + initShared(); AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(); NullWindow nw = new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capabilities, chooser, screen) ); @@ -169,6 +190,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements public GLContext createExternalGLContext() { validate(); + initShared(); return WindowsExternalWGLContext.create(this, null); } @@ -179,6 +201,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements public GLDrawable createExternalGLDrawable() { validate(); + initShared(); return WindowsExternalWGLDrawable.create(this, null); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index ad4cb2da5..f5e291c5f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -111,9 +111,16 @@ public abstract class X11GLXContext extends GLContextImpl { protected abstract void create(); protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { + X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); long display = config.getScreen().getDevice().getHandle(); - GLXExt glXExt = getGLXExt(); + + GLXExt glXExt; + if(null==factory.getSharedContext()) { + glXExt = getGLXExt(); + } else { + glXExt = factory.getSharedContext().getGLXExt(); + } boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ; boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ; @@ -121,12 +128,10 @@ public abstract class X11GLXContext extends GLContextImpl { long _context=0; - String verstr = getGLVersion(null, major, minor, ctp, "@creation"); - int attribs[] = { /* 0 */ GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, major, /* 2 */ GLX.GLX_CONTEXT_MINOR_VERSION_ARB, minor, - /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, + /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE, // default /* 6 */ GLX.GLX_CONTEXT_FLAGS_ARB, 0, /* 8 */ 0, 0, /* 10 */ 0 @@ -154,7 +159,7 @@ public abstract class X11GLXContext extends GLContextImpl { _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); if(0==_context) { if(DEBUG) { - System.err.println("X11GLXContext.createContextARB couldn't create "+verstr+" _context"); + System.err.println("X11GLXContext.createContextARB couldn't create "+getGLVersion(null, major, minor, ctp, "@creation")); } } else { if (!GLX.glXMakeContextCurrent(display, @@ -162,13 +167,11 @@ public abstract class X11GLXContext extends GLContextImpl { drawableRead.getNativeWindow().getSurfaceHandle(), _context)) { if(DEBUG) { - System.err.println("X11GLXContext.createContextARB couldn't make "+verstr+" context current"); + System.err.println("X11GLXContext.createContextARB couldn't make current "+getGLVersion(null, major, minor, ctp, "@creation")); } GLX.glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, _context); _context = 0; - } else if(DEBUG) { - System.err.println("X11GLXContext.createContextARB "+verstr+" available "+toHexString(_context)); } } return _context; @@ -180,10 +183,11 @@ public abstract class X11GLXContext extends GLContextImpl { * Note: The direct parameter may be overwritten by the direct state of a shared context. */ protected void createContext(boolean direct) { - X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - if(DEBUG) { - System.err.println("X11GLXContext.createContext got "+config); + if(0!=context) { + throw new GLException("context is not null: "+context); } + X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); long display = config.getScreen().getDevice().getHandle(); X11GLXContext other = (X11GLXContext) GLContextShareSet.getShareContext(this); @@ -198,7 +202,7 @@ public abstract class X11GLXContext extends GLContextImpl { GLCapabilities glCaps = (GLCapabilities) config.getChosenCapabilities(); GLProfile glp = glCaps.getGLProfile(); - isVendorATI = ((X11GLXDrawableFactory)(drawable.getFactoryImpl())).isVendorATI(); + isVendorATI = factory.isVendorATI(); if(config.getFBConfigID()<0) { // not able to use FBConfig @@ -216,70 +220,78 @@ public abstract class X11GLXContext extends GLContextImpl { throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION - if(DEBUG) { - System.err.println("X11GLXContext.createContext(0) done "+toHexString(context)); - } return; } - // To use GLX_ARB_create_context, we have to make a temp context current, - // so we are able to use GetProcAddress - long temp_context = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct); - if (temp_context == 0) { - throw new GLException("Unable to create temp OpenGL context(1)"); - } - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - temp_context)) { - throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + int minor[] = new int[1]; + int major[] = new int[1]; + int ctp[] = new int[1]; + boolean createContextARBTried = false; + + // utilize the shared context's GLXExt in case it was using the ARB method and it already exists + if(null!=factory.getSharedContext() && factory.getSharedContext().isCreatedWithARBMethod()) { + if(DEBUG) { + System.err.println("X11GLXContext.createContext using shared Context: "+factory.getSharedContext()); + } + context = createContextARB(share, direct, major, minor, ctp); + createContextARBTried = true; } - setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION - if( !isFunctionAvailable("glXCreateContextAttribsARB") || - !isExtensionAvailable("GLX_ARB_create_context") ) { - if(glp.isGL3()) { - 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)"); + long temp_context = 0; + if(0==context) { + // To use GLX_ARB_create_context, we have to make a temp context current, + // so we are able to use GetProcAddress + temp_context = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct); + if (temp_context == 0) { + throw new GLException("Unable to create temp OpenGL context(1)"); } + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + temp_context)) { + throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + } + setGLFunctionAvailability(true, 0, 0, 0); // use GL_VERSION - // continue with temp context for GL < 3.0 - context = temp_context; - if(DEBUG) { - System.err.println("X11GLXContext.createContext(1) done (!GLX_ARB_create_context) "+toHexString(context)); + if( createContextARBTried || + !isFunctionAvailable("glXCreateContextAttribsARB") || + !isExtensionAvailable("GLX_ARB_create_context") ) { + if(glp.isGL3()) { + 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)"); + } + + // continue with temp context for GL < 3.0 + context = temp_context; + return; } - return; + context = createContextARB(share, direct, major, minor, ctp); + createContextARBTried=true; } - int minor[] = new int[1]; - int major[] = new int[1]; - int ctp[] = new int[1]; - context = createContextARB(share, direct, major, minor, ctp); - if(0!=context) { // need to update the GL func table .. setGLFunctionAvailability(true, major[0], minor[0], ctp[0]); - GLX.glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); - if (!GLX.glXMakeContextCurrent(display, - drawable.getNativeWindow().getSurfaceHandle(), - drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { - throw new GLException("Cannot make previous verified context current"); - } - if(DEBUG) { - System.err.println("X11GLXContext.createContext(2) done "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "+toHexString(context)); + if(0!=temp_context) { + GLX.glXMakeContextCurrent(display, 0, 0, 0); + GLX.glXDestroyContext(display, temp_context); + if (!GLX.glXMakeContextCurrent(display, + drawable.getNativeWindow().getSurfaceHandle(), + drawableRead.getNativeWindow().getSurfaceHandle(), + context)) { + throw new GLException("Cannot make previous verified context current"); + } } } else { - if(DEBUG) { - System.err.println("X11GLXContext.createContext(2) failed "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")); - } if(!glp.isGL2()) { GLX.glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, temp_context); - throw new GLException("Unable to create context(2) (have GLX_ARB_create_context)"); + throw new GLException("X11GLXContext.createContext failed, but context > GL2 requested "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", "); + } + if(DEBUG) { + System.err.println("X11GLXContext.createContext failed, fall back to !ARB context "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")); } // continue with temp context for GL <= 3.0 @@ -292,9 +304,6 @@ public abstract class X11GLXContext extends GLContextImpl { GLX.glXDestroyContext(display, temp_context); throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); } - if(DEBUG) { - System.err.println("X11GLXContext.createContext(1) done "+toHexString(context)); - } } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index cfcd5cbe3..0d74bb791 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -86,15 +86,24 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna public boolean isVendorNVIDIA() { return isVendorNVIDIA; } private X11DummyGLXDrawable sharedDrawable=null; - private GLContext sharedContext=null; + private X11GLXContext sharedContext=null; + + // package private .. + final X11GLXContext getSharedContext() { + validate(); + return sharedContext; + } private void initShared() { if(null==sharedDrawable) { X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); sharedDrawable = new X11DummyGLXDrawable(sharedScreen, this, null); - sharedContext = sharedDrawable.createContext(null); - sharedContext.makeCurrent(); - sharedContext.release(); + X11GLXContext _sharedContext = (X11GLXContext) sharedDrawable.createContext(null); + { + _sharedContext.makeCurrent(); + _sharedContext.release(); + } + sharedContext = _sharedContext; X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); if (DEBUG) { System.err.println("!!! SharedContext: "+sharedContext); @@ -136,6 +145,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna if (target == null) { throw new IllegalArgumentException("Null target"); } + initShared(); if( isVendorATI() ) { X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } @@ -143,9 +153,11 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna } protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) { + validate(); if (target == null) { throw new IllegalArgumentException("Null target"); } + initShared(); if( isVendorATI() ) { X11Util.markGlobalDisplayUndeletable(target.getDisplayHandle()); // ATI hack .. } @@ -187,6 +199,12 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna } protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) { + validate(); + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + initShared(); + GLDrawableImpl pbufferDrawable; /** @@ -197,7 +215,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna */ boolean usedSharedContext=false; if( isVendorATI() && null == GLContext.getCurrent() ) { - initShared(); sharedContext.makeCurrent(); usedSharedContext=true; } @@ -216,6 +233,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + validate(); + initShared(); X11Lib.XLockDisplay(sharedScreen.getDevice().getHandle()); NullWindow nw = new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, sharedScreen)); X11Lib.XUnlockDisplay(sharedScreen.getDevice().getHandle()); @@ -225,16 +244,19 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna public GLContext createExternalGLContext() { validate(); + initShared(); return X11ExternalGLXContext.create(this, null); } public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { validate(); + initShared(); return canCreateGLPbuffer(device); } public GLDrawable createExternalGLDrawable() { validate(); + initShared(); return X11ExternalGLXDrawable.create(this, null); } diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index a8dbf9213..833ebf192 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -287,6 +287,7 @@ public abstract class GLContext { public final int getGLVersionMinor() { return ctxMajorVersion; } public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } + public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); } /** * Returns a valid OpenGL version string, ie diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 231faab8c..e1fc9f53f 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -715,6 +715,8 @@ public class GLProfile implements Cloneable { private static final boolean isAWTAvailable; private static final boolean isAWTJOGLAvailable; + private static final boolean hasGL4bcImpl; + private static final boolean hasGL4Impl; private static final boolean hasGL3bcImpl; private static final boolean hasGL3Impl; private static final boolean hasGL2Impl; @@ -791,6 +793,8 @@ public class GLProfile implements Cloneable { } // FIXME: check for real GL3 availability .. ? + hasGL4bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl"); + hasGL4Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4Impl"); hasGL3bcImpl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3bcImpl"); hasGL3Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl3.GL3Impl"); hasGL2Impl = hasDesktopGL && NWReflection.isClassAvailable("com.jogamp.opengl.impl.gl2.GL2Impl"); @@ -837,6 +841,8 @@ public class GLProfile implements Cloneable { System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); + System.err.println("GLProfile.static hasGL4bcImpl "+hasGL4bcImpl); + System.err.println("GLProfile.static hasGL4Impl "+hasGL4Impl); System.err.println("GLProfile.static hasGL3bcImpl "+hasGL3bcImpl); System.err.println("GLProfile.static hasGL3Impl "+hasGL3Impl); System.err.println("GLProfile.static hasGL2Impl "+hasGL2Impl); @@ -891,6 +897,7 @@ public class GLProfile implements Cloneable { * Returns the profile implementation */ private static String computeProfileImpl(String profile) { + // FIXME Order of return profiles, after we can test their availability if (GL2ES1.equals(profile)) { if(hasGL2ES12Impl) { return GL2ES12; @@ -908,9 +915,21 @@ public class GLProfile implements Cloneable { return GL3; } else if(hasGL3bcImpl) { return GL3bc; + } else if(hasGL4Impl) { + return GL4; + } else if(hasGL4bcImpl) { + return GL4bc; } else if(hasGLES2Impl) { return GLES2; } + } else if(GL4bc.equals(profile) && hasGL4bcImpl) { + return GL4bc; + } else if(GL4.equals(profile)) { + if(hasGL4Impl) { + return GL4; + } else if(hasGL4bcImpl) { + return GL4bc; + } } else if(GL3bc.equals(profile) && hasGL3bcImpl) { return GL3bc; } else if(GL3.equals(profile)) { |