diff options
author | Sven Gothel <[email protected]> | 2011-11-29 12:38:05 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-11-29 12:38:05 +0100 |
commit | 6b3fae9aebdafd8ed605543272d7d9cbf2f8c5dd (patch) | |
tree | 1284bad3097883c3385c9e7353034d01f151b194 /src/jogl/classes/jogamp/opengl/GLContextImpl.java | |
parent | 7ce949289c71cc4a64e15227c7760974b40e2c33 (diff) |
GLContextImpl*: createImpl() / makeCurrentImpl() refinement / robostness
createImpl(): If successful must leave context current.
makeCurrentImpl(): Is only called if context is not just created,
hence the boolean parameter 'boolean newCreatedContext' is removed.
This clearifies and actually cleans up the native makeContextCurrent/releaseContext call pairs.
MacOSXCGLContext: CGL and NS impl. of native makeContextCurrent/releaseContext uses CGL locking
to provide a thread safety. This is recommended in OS X OpenGL documentation on
[shared context] multithreaded use cases.
Post creation code, as seen in some pbuffer cases is moved to overriden createImpl() methods.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/GLContextImpl.java')
-rw-r--r-- | src/jogl/classes/jogamp/opengl/GLContextImpl.java | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 9611a1651..d43c2d99d 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -360,7 +360,7 @@ public abstract class GLContextImpl extends GLContext { public int makeCurrent() throws GLException { // One context can only be current by one thread, // and one thread can only have one context current! - GLContext current = getCurrent(); + final GLContext current = getCurrent(); if (current != null) { if (current == this) { // Assume we don't need to make this context current again @@ -454,7 +454,6 @@ public abstract class GLContextImpl extends GLContext { if (0 == drawable.getHandle()) { throw new GLException("drawable has invalid handle: "+drawable); } - boolean newCreated = false; if (!isCreated()) { GLProfile.initProfiles( getGLDrawable().getNativeSurface().getGraphicsConfiguration().getScreen().getDevice()); @@ -462,28 +461,30 @@ public abstract class GLContextImpl extends GLContext { if (null != shareWith) { shareWith.getDrawableImpl().lockSurface(); } + boolean created; try { - newCreated = createImpl(shareWith); // may throws exception if fails! + created = createImpl(shareWith); // may throws exception if fails! } finally { if (null != shareWith) { shareWith.getDrawableImpl().unlockSurface(); } } if (DEBUG) { - if(newCreated) { + if(created) { System.err.println(getThreadName() + ": !!! Create GL context OK: " + toHexString(contextHandle) + " for " + getClass().getName()); } else { System.err.println(getThreadName() + ": !!! Create GL context FAILED for " + getClass().getName()); } } - if(!newCreated) { + if(!created) { shallUnlockSurface = true; return CONTEXT_NOT_CURRENT; } GLContextShareSet.contextCreated(this); + return CONTEXT_CURRENT_NEW; } - makeCurrentImpl(newCreated); - return newCreated ? CONTEXT_CURRENT_NEW : CONTEXT_CURRENT ; + makeCurrentImpl(); + return CONTEXT_CURRENT; } catch (RuntimeException e) { shallUnlockSurface = true; throw e; @@ -494,26 +495,41 @@ public abstract class GLContextImpl extends GLContext { } } } - protected abstract void makeCurrentImpl(boolean newCreatedContext) throws GLException; + protected abstract void makeCurrentImpl() throws GLException; + + /** + * Platform dependent entry point for context creation.<br> + * + * This method is called from {@link #makeCurrentLocking()} .. {@link #makeCurrent()} .<br> + * + * The implementation shall verify this context with a + * <code>MakeContextCurrent</code> call.<br> + * + * The implementation <b>must</b> leave the context current.<br> + * + * @param share the shared context or null + * @return the valid and current context if successful, or null + * @throws GLException + */ protected abstract boolean createImpl(GLContextImpl sharedWith) throws GLException ; /** * Platform dependent but harmonized implementation of the <code>ARB_create_context</code> * mechanism to create a context.<br> * - * This method is called from {@link #createContextARB}.<br> + * This method is called from {@link #createContextARB}, {@link #createImpl(GLContextImpl)} .. {@link #makeCurrent()} .<br> * * The implementation shall verify this context with a * <code>MakeContextCurrent</code> call.<br> * - * The implementation shall leave the context current.<br> + * The implementation <b>must</b> leave the context current.<br> * * @param share the shared context or null * @param direct flag if direct is requested * @param ctxOptionFlags <code>ARB_create_context</code> related, see references below * @param major major number * @param minor minor number - * @return the valid context if successfull, or null + * @return the valid and current context if successful, or null * * @see #makeCurrent * @see #CTX_PROFILE_COMPAT |