From 9c6946c4cf89fd91493a0c16160db5c84f48c614 Mon Sep 17 00:00:00 2001
From: Kenneth Russel <kbrussel@alum.mit.edu>
Date: Sun, 28 May 2006 23:40:58 +0000
Subject: Fixed Issue 224: External context dosen't work with GLCanvas

Added short-circuiting of logic to prevent the current GLContext from
being released due to makeCurrent() of an external GLContext.


git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@784 232f8b59-042b-4e1e-8c03-345bb8c30851
---
 .../opengl/impl/macosx/MacOSXExternalGLContext.java    | 18 ++++++++++++++++++
 .../opengl/impl/windows/WindowsExternalGLContext.java  | 18 ++++++++++++++++++
 .../com/sun/opengl/impl/x11/X11ExternalGLContext.java  | 18 ++++++++++++++++++
 3 files changed, 54 insertions(+)

(limited to 'src/classes')

diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXExternalGLContext.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXExternalGLContext.java
index 7a0b53a98..ceda14f3b 100644
--- a/src/classes/com/sun/opengl/impl/macosx/MacOSXExternalGLContext.java
+++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXExternalGLContext.java
@@ -45,6 +45,7 @@ import com.sun.opengl.impl.*;
 public class MacOSXExternalGLContext extends MacOSXGLContext {
   private boolean firstMakeCurrent = true;
   private boolean created = true;
+  private GLContext lastContext;
 
   public MacOSXExternalGLContext() {
     super(null, null);
@@ -74,6 +75,23 @@ public class MacOSXExternalGLContext extends MacOSXGLContext {
     return true;
   }
 
+  public int makeCurrent() throws GLException {
+    // Save last context if necessary to allow external GLContexts to
+    // talk to other GLContexts created by this library
+    GLContext cur = getCurrent();
+    if (cur != null && cur != this) {
+      lastContext = cur;
+      setCurrent(null);
+    }
+    return super.makeCurrent();
+  }  
+
+  public void release() throws GLException {
+    super.release();
+    setCurrent(lastContext);
+    lastContext = null;
+  }
+
   protected int makeCurrentImpl() throws GLException {
     if (firstMakeCurrent) {
       firstMakeCurrent = false;
diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java
index cd51f4eb1..a73cc7ac4 100755
--- a/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java
+++ b/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java
@@ -47,6 +47,7 @@ import com.sun.opengl.impl.*;
 public class WindowsExternalGLContext extends WindowsGLContext {
   private boolean firstMakeCurrent = true;
   private boolean created = true;
+  private GLContext lastContext;
 
   public WindowsExternalGLContext() {
     super(null, null, true);
@@ -61,6 +62,23 @@ public class WindowsExternalGLContext extends WindowsGLContext {
     resetGLFunctionAvailability();
   }
 
+  public int makeCurrent() throws GLException {
+    // Save last context if necessary to allow external GLContexts to
+    // talk to other GLContexts created by this library
+    GLContext cur = getCurrent();
+    if (cur != null && cur != this) {
+      lastContext = cur;
+      setCurrent(null);
+    }
+    return super.makeCurrent();
+  }  
+
+  public void release() throws GLException {
+    super.release();
+    setCurrent(lastContext);
+    lastContext = null;
+  }
+
   protected int makeCurrentImpl() throws GLException {
     if (firstMakeCurrent) {
       firstMakeCurrent = false;
diff --git a/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java
index 80d9c6f1a..89b769eee 100755
--- a/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java
+++ b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java
@@ -45,6 +45,7 @@ import com.sun.opengl.impl.*;
 public class X11ExternalGLContext extends X11GLContext {
   private boolean firstMakeCurrent = true;
   private boolean created = true;
+  private GLContext lastContext;
 
   public X11ExternalGLContext() {
     super(null, null);
@@ -65,6 +66,23 @@ public class X11ExternalGLContext extends X11GLContext {
   protected void create() {
   }
 
+  public int makeCurrent() throws GLException {
+    // Save last context if necessary to allow external GLContexts to
+    // talk to other GLContexts created by this library
+    GLContext cur = getCurrent();
+    if (cur != null && cur != this) {
+      lastContext = cur;
+      setCurrent(null);
+    }
+    return super.makeCurrent();
+  }  
+
+  public void release() throws GLException {
+    super.release();
+    setCurrent(lastContext);
+    lastContext = null;
+  }
+
   protected int makeCurrentImpl() throws GLException {
     mostRecentDisplay = drawable.getDisplay();
     if (firstMakeCurrent) {
-- 
cgit v1.2.3