From a5430cf16727fdc7bcfb17ef251018cc479d5f5d Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Fri, 22 Apr 2011 05:30:41 +0200
Subject: GLContext changes:

change:
  putAttachedObject(String) -> attachObject(String)
  putAttachedObject(int) -> attachObject(int)

new:
  validateCurrent()

  the 'int' mapped/attached objects are using the IntIntHashMap now
---
 src/jogl/classes/javax/media/opengl/GLContext.java | 44 ++++++++++++++++------
 1 file changed, 32 insertions(+), 12 deletions(-)

(limited to 'src/jogl/classes/javax/media/opengl')

diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index f5d47d27c..a81bc5f27 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -43,6 +43,9 @@ package javax.media.opengl;
 import java.util.HashMap;
 import java.util.HashSet;
 import javax.media.nativewindow.AbstractGraphicsDevice;
+
+import com.jogamp.common.util.IntObjectHashMap;
+
 import jogamp.opengl.Debug;
 import jogamp.opengl.GLContextImpl;
 
@@ -91,9 +94,10 @@ public abstract class GLContext {
   /** GLContext {@link com.jogamp.gluegen.runtime.ProcAddressTable} caching related: GL hardware implementation */
   protected static final int CTX_IMPL_ACCEL_HARD = 1 << 1;
 
-  private static ThreadLocal currentContext = new ThreadLocal();
+  private static ThreadLocal<GLContext> currentContext = new ThreadLocal<GLContext>();
 
-  private HashMap/*<int, Object>*/ attachedObjects = new HashMap();
+  private HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>();
+  private IntObjectHashMap attachedObjectsByInt = new IntObjectHashMap();
 
   /** The underlying native OpenGL context */
   protected long contextHandle;
@@ -112,9 +116,8 @@ public abstract class GLContext {
       ctxMinorVersion=-1;
       ctxOptions=0;
       ctxVersionString=null;
-      if(null!=attachedObjects) {
-        attachedObjects.clear();
-      }
+      attachedObjectsByString.clear();
+      attachedObjectsByInt.clear();
       contextHandle=0;
   }
 
@@ -248,7 +251,7 @@ public abstract class GLContext {
    * is current.
    */
   public static GLContext getCurrent() {
-    return (GLContext) currentContext.get();
+    return currentContext.get();
   }
 
   /**
@@ -258,6 +261,15 @@ public abstract class GLContext {
     return getCurrent() == this ; 
   }
 
+  /**
+   * @throws GLException if this GLContext is not current on this thread
+   */
+  public final void validateCurrent() throws GLException {  
+    if(getCurrent() != this) {
+        throw new GLException("Given GL context not current");
+    }
+  }
+  
   /**
    * Sets the thread-local variable returned by {@link #getCurrent}
    * and has no other side-effects. For use by third parties adding
@@ -314,32 +326,40 @@ public abstract class GLContext {
    * Returns the attached user object for the given name to this GLContext.
    */
   public final Object getAttachedObject(int name) {
-    return attachedObjects.get(new Integer(name));
+    return attachedObjectsByInt.get(name);
   }
 
   /**
    * Returns the attached user object for the given name to this GLContext.
    */
   public final Object getAttachedObject(String name) {
-    return attachedObjects.get(name);
+    return attachedObjectsByString.get(name);
   }
 
   /**
    * Sets the attached user object for the given name to this GLContext.
    * Returns the previously set object or null.
    */
-  public final Object putAttachedObject(int name, Object obj) {
-    return attachedObjects.put(new Integer(name), obj);
+  public final Object attachObject(int name, Object obj) {
+    return attachedObjectsByInt.put(name, obj);
   }
 
+  public final Object detachObject(int name) {
+      return attachedObjectsByInt.remove(name);
+  }
+  
   /**
    * Sets the attached user object for the given name to this GLContext.
    * Returns the previously set object or null.
    */
-  public final Object putAttachedObject(String name, Object obj) {
-    return attachedObjects.put(name, obj);
+  public final Object attachObject(String name, Object obj) {
+    return attachedObjectsByString.put(name, obj);
   }
 
+  public final Object detachObject(String name) {
+      return attachedObjectsByString.remove(name);
+  }
+  
   /**
    * Classname, GL, GLDrawable
    */
-- 
cgit v1.2.3