summaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl/impl/GLContextShareSet.java
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2006-02-06 04:52:15 +0000
committerKenneth Russel <[email protected]>2006-02-06 04:52:15 +0000
commita302c87258a1a17dc0eef5ae112cb0d4357be238 (patch)
tree5068ba77f80cd112f741f8d3e2bc9d89537702bc /src/classes/com/sun/opengl/impl/GLContextShareSet.java
parentced30725fdaa23c108605104d0d364055e629a63 (diff)
Further work on FBO support in Java2D/JOGL bridge. Recast how
GLObjectTrackers are specified between contexts and separated this from the maintenance of the GLContextShareSet, although the API (registerForObjectTracking) is in the GLContextShareSet class. If the Java2D/OpenGL pipeline and FBOs are active, causes all JOGL contexts created to share textures and display lists with a context from Java2D (currently acquired from a VolatileImage, but will probably need to change how this is done). GLObjectTrackers however are only shared between JOGL contexts where the user has explicitly requested sharing. This yields the expected semantics of server-side object deletion when the context is destroyed. Upgraded GLJPanel to handle FBO manipulation. Not working yet; more debugging necessary on Java2D side as well. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@585 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/impl/GLContextShareSet.java')
-rw-r--r--src/classes/com/sun/opengl/impl/GLContextShareSet.java110
1 files changed, 60 insertions, 50 deletions
diff --git a/src/classes/com/sun/opengl/impl/GLContextShareSet.java b/src/classes/com/sun/opengl/impl/GLContextShareSet.java
index b0d1b1da4..283a56f85 100644
--- a/src/classes/com/sun/opengl/impl/GLContextShareSet.java
+++ b/src/classes/com/sun/opengl/impl/GLContextShareSet.java
@@ -62,17 +62,6 @@ public class GLContextShareSet {
private Map createdShares = new WeakHashMap();
private Map destroyedShares = new WeakHashMap();
- // When the Java2D/OpenGL pipeline is active and using FBOs to
- // render, we need to track the creation and destruction of
- // server-side OpenGL objects among contexts sharing these objects
- private GLObjectTracker tracker;
-
- public ShareSet() {
- if (isObjectTrackingEnabled()) {
- tracker = new GLObjectTracker();
- }
- }
-
public void add(GLContext ctx) {
if (allShares.put(ctx, dummyValue) == null) {
// FIXME: downcast to GLContextImpl undesirable
@@ -111,57 +100,26 @@ public class GLContextShareSet {
assert res == null : "State of ShareSet corrupted; thought context " +
ctx + " shouldn't have been in destroyed set but was";
}
-
- public GLObjectTracker getObjectTracker() {
- return tracker;
- }
- }
-
- private static boolean isObjectTrackingEnabled() {
- return (Java2D.isOGLPipelineActive() && Java2D.isFBOEnabled());
- }
-
- /** Indicates to callers whether sharing must be registered even for
- contexts which don't share textures and display lists with any
- others. */
- public static boolean isObjectTrackingDebuggingEnabled() {
- return forceTracking;
}
/** Indicate that contexts <code>share1</code> and
- <code>share2</code> will share textures and display lists. */
+ <code>share2</code> will share textures and display lists. Both
+ must be non-null. */
public static synchronized void registerSharing(GLContext share1, GLContext share2) {
+ if (share1 == null || share2 == null) {
+ throw new IllegalArgumentException("Both share1 and share2 must be non-null");
+ }
ShareSet share = entryFor(share1);
- if (share == null && (share2 != null)) {
+ if (share == null) {
share = entryFor(share2);
}
if (share == null) {
share = new ShareSet();
}
share.add(share1);
- if (share2 != null) {
- share.add(share2);
- }
+ share.add(share2);
addEntry(share1, share);
- if (share2 != null) {
- addEntry(share2, share);
- }
- GLObjectTracker tracker = share.getObjectTracker();
- if (tracker != null) {
- // FIXME: downcast to GLContextImpl undesirable
- GLContextImpl impl1 = (GLContextImpl) share1;
- GLContextImpl impl2 = (GLContextImpl) share2;
- if (impl1.getObjectTracker() == null) {
- impl1.setObjectTracker(tracker);
- }
- if ((impl2 != null) && (impl2.getObjectTracker() == null)) {
- impl2.setObjectTracker(tracker);
- }
- assert impl1.getObjectTracker() == tracker : "State of ShareSet corrupted; " +
- "got different-than-expected GLObjectTracker for context 1";
- assert (impl2 == null) || (impl2.getObjectTracker() == tracker) : "State of ShareSet corrupted; " +
- "got different-than-expected GLObjectTracker for context 2";
- }
+ addEntry(share2, share);
}
public static synchronized GLContext getShareContext(GLContext contextToCreate) {
@@ -186,6 +144,49 @@ public class GLContextShareSet {
}
}
+ /** Indicates that the two supplied contexts (which must be able to
+ share textures and display lists) should be in the same
+ namespace for tracking of server-side object creation and
+ deletion. Because the sharing necessary behind the scenes is
+ different than that requested at the user level, the two notions
+ are different. This must be called immediately after the
+ creation of the new context (which is the second argument)
+ before any server-side OpenGL objects have been created in that
+ context. */
+ public static synchronized void registerForObjectTracking(GLContext olderContextOrNull,
+ GLContext newContext) {
+ if (isObjectTrackingEnabled() || isObjectTrackingDebuggingEnabled()) {
+ if (olderContextOrNull != null &&
+ newContext != null) {
+ if (entryFor(olderContextOrNull) != entryFor(newContext)) {
+ throw new IllegalArgumentException("old and new contexts must be able to share textures and display lists");
+ }
+ }
+
+ // FIXME: downcast to GLContextImpl undesirable
+ GLContextImpl impl1 = (GLContextImpl) olderContextOrNull;
+ GLContextImpl impl2 = (GLContextImpl) newContext;
+ GLObjectTracker tracker = null;
+ // Don't share object trackers with the primordial share context from Java2D
+ GLContext j2dShareContext = Java2D.getShareContext();
+ if (impl1 != null && impl1 == j2dShareContext) {
+ impl1 = null;
+ }
+ if (impl1 != null) {
+ tracker = impl1.getObjectTracker();
+ assert (tracker != null)
+ : "registerForObjectTracking was not called properly for the older context";
+ }
+ if (tracker == null) {
+ tracker = new GLObjectTracker();
+ }
+ // Note that we don't assert that the tracker is non-null for
+ // impl2 because the way we use this functionality we actually
+ // overwrite the initially-set object tracker in the new context
+ impl2.setObjectTracker(tracker);
+ }
+ }
+
//----------------------------------------------------------------------
// Internals only below this point
//
@@ -199,4 +200,13 @@ public class GLContextShareSet {
shareMap.put(context, share);
}
}
+
+ private static boolean isObjectTrackingEnabled() {
+ return ((Java2D.isOGLPipelineActive() && Java2D.isFBOEnabled()) ||
+ isObjectTrackingDebuggingEnabled());
+ }
+
+ private static boolean isObjectTrackingDebuggingEnabled() {
+ return forceTracking;
+ }
}