From 6b3fae9aebdafd8ed605543272d7d9cbf2f8c5dd Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 29 Nov 2011 12:38:05 +0100 Subject: 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. --- src/jogl/classes/jogamp/opengl/GLContextImpl.java | 38 ++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/GLContextImpl.java') 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.
+ * + * This method is called from {@link #makeCurrentLocking()} .. {@link #makeCurrent()} .
+ * + * The implementation shall verify this context with a + * MakeContextCurrent call.
+ * + * The implementation must leave the context current.
+ * + * @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 ARB_create_context * mechanism to create a context.
* - * This method is called from {@link #createContextARB}.
+ * This method is called from {@link #createContextARB}, {@link #createImpl(GLContextImpl)} .. {@link #makeCurrent()} .
* * The implementation shall verify this context with a * MakeContextCurrent call.
* - * The implementation shall leave the context current.
+ * The implementation must leave the context current.
* * @param share the shared context or null * @param direct flag if direct is requested * @param ctxOptionFlags ARB_create_context 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 -- cgit v1.2.3