diff options
author | Sven Gothel <[email protected]> | 2010-06-02 04:04:19 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-06-02 04:04:19 +0200 |
commit | dd0400a41478c1f365414b8c760eee1c91105280 (patch) | |
tree | f485f7216126b5e7e3931462b2e1ce7adb47458f /src/jogl/classes/com/jogamp/opengl/impl/x11/glx | |
parent | 3d53317d3a0748cb3fd1a71f88f6cd4f5de9d4cb (diff) |
JOGL: Unified GLContext native handle
- All GLContext implementations are using the contextHandle of the super class.
- GLContext.getHandle() exposes contextHandle for API cross access
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/impl/x11/glx')
3 files changed, 62 insertions, 76 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java index 139c0deed..8792ac08e 100755 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java @@ -48,12 +48,11 @@ import com.jogamp.nativewindow.impl.x11.*; public class X11ExternalGLXContext extends X11GLXContext { private boolean firstMakeCurrent = true; - private boolean created = true; private GLContext lastContext; - private X11ExternalGLXContext(Drawable drawable, long context) { + private X11ExternalGLXContext(Drawable drawable, long ctx) { super(drawable, null); - this.context = context; + this.contextHandle = ctx; GLContextShareSet.contextCreated(this); setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java @@ -62,8 +61,8 @@ public class X11ExternalGLXContext extends X11GLXContext { protected static X11ExternalGLXContext create(GLDrawableFactory factory, GLProfile glp) { ((GLDrawableFactoryImpl)factory).lockToolkit(); try { - long context = GLX.glXGetCurrentContext(); - if (context == 0) { + long ctx = GLX.glXGetCurrentContext(); + if (ctx == 0) { throw new GLException("Error: current context null"); } long display = GLX.glXGetCurrentDisplay(); @@ -75,15 +74,15 @@ public class X11ExternalGLXContext extends X11GLXContext { throw new GLException("Error: attempted to make an external GLDrawable without a drawable/context current"); } int[] val = new int[1]; - GLX.glXQueryContext(display, context, GLX.GLX_SCREEN, val, 0); + GLX.glXQueryContext(display, ctx, GLX.GLX_SCREEN, val, 0); X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val[0]); - GLX.glXQueryContext(display, context, GLX.GLX_FBCONFIG_ID, val, 0); + GLX.glXQueryContext(display, ctx, GLX.GLX_FBCONFIG_ID, val, 0); X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfiguration.create(glp, x11Screen, val[0]); NullWindow nw = new NullWindow(cfg); nw.setSurfaceHandle(drawable); - return new X11ExternalGLXContext(new Drawable(factory, nw), context); + return new X11ExternalGLXContext(new Drawable(factory, nw), ctx); } finally { ((GLDrawableFactoryImpl)factory).unlockToolkit(); } @@ -121,14 +120,10 @@ public class X11ExternalGLXContext extends X11GLXContext { } protected void destroyImpl() throws GLException { - created = false; + contextHandle = 0; GLContextShareSet.contextDestroyed(this); } - public boolean isCreated() { - return created; - } - // Need to provide the display connection to extension querying APIs static class Drawable extends X11GLXDrawable { Drawable(GLDrawableFactory factory, NativeWindow comp) { 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 76a6830d5..b81521729 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 @@ -51,7 +51,6 @@ import com.jogamp.gluegen.runtime.ProcAddressTable; import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; public abstract class X11GLXContext extends GLContextImpl { - protected long context; private boolean glXQueryExtensionsStringInitialized; private boolean glXQueryExtensionsStringAvailable; private static final Map/*<String, String>*/ functionNameMap; @@ -128,12 +127,12 @@ public abstract class X11GLXContext extends GLContextImpl { return res; } - protected void destroyContextARBImpl(long _context) { + protected void destroyContextARBImpl(long ctx) { X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); long display = config.getScreen().getDevice().getHandle(); glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, _context); + GLX.glXDestroyContext(display, ctx); } protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) { @@ -152,7 +151,7 @@ public abstract class X11GLXContext extends GLContextImpl { boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ; boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ; - long _context=0; + long ctx=0; final int idx_flags = 6; final int idx_profile = 8; @@ -186,7 +185,7 @@ public abstract class X11GLXContext extends GLContextImpl { } try { - _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); + ctx = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); } catch (RuntimeException re) { if(DEBUG) { System.err.println("X11GLXContext.createContextARB glXCreateContextAttribsARB failed: "+re+", with "+getGLVersion(major, minor, ctp, "@creation")); @@ -194,22 +193,22 @@ public abstract class X11GLXContext extends GLContextImpl { } } if(DEBUG) { - System.err.println("X11GLXContext.createContextARB success: "+(0!=_context)+" - "+getGLVersion(major, minor, ctp, "@creation")+", bwdCompat "+ctBwdCompat+", fwdCompat "+ctFwdCompat); + System.err.println("X11GLXContext.createContextARB success: "+(0!=ctx)+" - "+getGLVersion(major, minor, ctp, "@creation")+", bwdCompat "+ctBwdCompat+", fwdCompat "+ctFwdCompat); } - if(0!=_context) { + if(0!=ctx) { if (!glXMakeContextCurrent(display, drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), - _context)) { + ctx)) { if(DEBUG) { System.err.println("X11GLXContext.createContextARB couldn't make current "+getGLVersion(major, minor, ctp, "@creation")); } glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, _context); - _context = 0; + GLX.glXDestroyContext(display, ctx); + ctx = 0; } } - return _context; + return ctx; } /** @@ -218,8 +217,8 @@ 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) { - if(0!=context) { - throw new GLException("context is not null: "+context); + if(0!=contextHandle) { + throw new GLException("context is not null: "+contextHandle); } X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); @@ -228,7 +227,7 @@ public abstract class X11GLXContext extends GLContextImpl { X11GLXContext other = (X11GLXContext) GLContextShareSet.getShareContext(this); long share = 0; if (other != null) { - share = other.getContext(); + share = other.getHandle(); if (share == 0) { throw new GLException("GLContextShareSet returned an invalid OpenGL context"); } @@ -244,15 +243,15 @@ public abstract class X11GLXContext extends GLContextImpl { if(glp.isGL3()) { throw new GLException("Unable to create OpenGL >= 3.1 context"); } - context = GLX.glXCreateContext(display, config.getXVisualInfo(), share, direct); - if (context == 0) { + contextHandle = GLX.glXCreateContext(display, config.getXVisualInfo(), share, direct); + if (contextHandle == 0) { throw new GLException("Unable to create context(0)"); } if (!glXMakeContextCurrent(display, drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { - throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + contextHandle)) { + throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(contextHandle)+", drawable "+drawable); } setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION return; @@ -268,23 +267,23 @@ public abstract class X11GLXContext extends GLContextImpl { if(DEBUG) { System.err.println("X11GLXContext.createContext using shared Context: "+factory.getSharedContext()); } - context = createContextARB(share, direct, major, minor, ctp); + contextHandle = createContextARB(share, direct, major, minor, ctp); createContextARBTried = true; } - long temp_context = 0; - if(0==context) { + long temp_ctx = 0; + if(0==contextHandle) { // 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) { + temp_ctx = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct); + if (temp_ctx == 0) { throw new GLException("Unable to create temp OpenGL context(1)"); } if (!glXMakeContextCurrent(display, drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), - temp_context)) { - throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(temp_context)+", drawable "+drawable); + temp_ctx)) { + throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(temp_ctx)+", drawable "+drawable); } setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION @@ -293,33 +292,33 @@ public abstract class X11GLXContext extends GLContextImpl { !isExtensionAvailable("GLX_ARB_create_context") ) { if(glp.isGL3()) { glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); + GLX.glXDestroyContext(display, temp_ctx); throw new GLException("Unable to create OpenGL >= 3.1 context (failed GLX_ARB_create_context), GLProfile "+glp+", Drawable "+drawable); } // continue with temp context for GL < 3.0 - context = temp_context; + contextHandle = temp_ctx; return; } - context = createContextARB(share, direct, major, minor, ctp); + contextHandle = createContextARB(share, direct, major, minor, ctp); createContextARBTried=true; } - if(0!=context) { - if(0!=temp_context) { + if(0!=contextHandle) { + if(0!=temp_ctx) { glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); + GLX.glXDestroyContext(display, temp_ctx); if (!glXMakeContextCurrent(display, drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + contextHandle)) { throw new GLException("Cannot make previous verified context current"); } } } else { if(glp.isGL3()) { glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); + GLX.glXDestroyContext(display, temp_ctx); throw new GLException("X11GLXContext.createContext failed, but context > GL2 requested "+getGLVersion(major[0], minor[0], ctp[0], "@creation")+", "); } if(DEBUG) { @@ -327,14 +326,14 @@ public abstract class X11GLXContext extends GLContextImpl { } // continue with temp context for GL <= 3.0 - context = temp_context; + contextHandle = temp_ctx; if (!glXMakeContextCurrent(display, drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + contextHandle)) { glXMakeContextCurrent(display, 0, 0, 0); - GLX.glXDestroyContext(display, temp_context); - throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable); + GLX.glXDestroyContext(display, temp_ctx); + throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(contextHandle)+", drawable "+drawable); } } } @@ -378,34 +377,34 @@ public abstract class X11GLXContext extends GLContextImpl { getDrawableImpl().getFactoryImpl().lockToolkit(); try { - boolean created = false; - if (context == 0) { - create(); - created = true; + boolean newCreated = false; + if (!isCreated()) { + create(); // throws exception if fails! + newCreated = true; GLContextShareSet.contextCreated(this); if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); + System.err.println(getThreadName() + ": !!! Created GL context " + toHexString(contextHandle) + " for " + getClass().getName()); } } - if (GLX.glXGetCurrentContext() != context) { + if (GLX.glXGetCurrentContext() != contextHandle) { if (!glXMakeContextCurrent(dpy, drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), - context)) { + contextHandle)) { throw new GLException("Error making context current: "+this); } - if (DEBUG && (VERBOSE || created)) { + if (DEBUG && (VERBOSE || isCreated())) { System.err.println(getThreadName() + ": glXMakeCurrent(display " + toHexString(dpy)+ ", drawable " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + ", drawableRead " + toHexString(drawableRead.getNativeWindow().getSurfaceHandle()) + - ", context " + toHexString(context) + ") succeeded"); + ", context " + toHexString(contextHandle) + ") succeeded"); } } - if (created) { + if(newCreated) { setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); return CONTEXT_CURRENT_NEW; } @@ -430,18 +429,18 @@ public abstract class X11GLXContext extends GLContextImpl { protected void destroyImpl() throws GLException { getDrawableImpl().getFactoryImpl().lockToolkit(); try { - if (context != 0) { + if (contextHandle != 0) { if (DEBUG) { System.err.println("glXDestroyContext(" + toHexString(drawable.getNativeWindow().getDisplayHandle()) + ", " + - toHexString(context) + ")"); + toHexString(contextHandle) + ")"); } - GLX.glXDestroyContext(drawable.getNativeWindow().getDisplayHandle(), context); + GLX.glXDestroyContext(drawable.getNativeWindow().getDisplayHandle(), contextHandle); if (DEBUG) { - System.err.println("!!! Destroyed OpenGL context " + context); + System.err.println("!!! Destroyed OpenGL context " + contextHandle); } - context = 0; + contextHandle = 0; GLContextShareSet.contextDestroyed(this); } } finally { @@ -449,13 +448,9 @@ public abstract class X11GLXContext extends GLContextImpl { } } - public boolean isCreated() { - return (context != 0); - } - public void copy(GLContext source, int mask) throws GLException { - long dst = getContext(); - long src = ((X11GLXContext) source).getContext(); + long dst = getHandle(); + long src = source.getHandle(); if (src == 0) { throw new GLException("Source OpenGL context has not been created"); } @@ -583,10 +578,6 @@ public abstract class X11GLXContext extends GLContextImpl { // Internals only below this point // - public long getContext() { - return context; - } - private boolean isVendorATI = false; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java index c89a5efd5..710f93e98 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java @@ -63,6 +63,6 @@ public class X11OnscreenGLXContext extends X11GLXContext { protected void create() { createContext(true); - isIndirect = !GLX.glXIsDirect(drawable.getNativeWindow().getDisplayHandle(), context); + isIndirect = !GLX.glXIsDirect(drawable.getNativeWindow().getDisplayHandle(), contextHandle); } } |