summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-04-22 05:30:41 +0200
committerSven Gothel <[email protected]>2011-04-22 05:30:41 +0200
commita5430cf16727fdc7bcfb17ef251018cc479d5f5d (patch)
tree9a51e41b666fe9ed40c1e7c530dd4dcdf0e45bba /src/jogl/classes
parent31d948b5f5432837c3a52e9891f60d9189011c91 (diff)
GLContext changes:
change: putAttachedObject(String) -> attachObject(String) putAttachedObject(int) -> attachObject(int) new: validateCurrent() the 'int' mapped/attached objects are using the IntIntHashMap now
Diffstat (limited to 'src/jogl/classes')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java44
1 files changed, 32 insertions, 12 deletions
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();
}
/**
@@ -259,6 +262,15 @@ public abstract class GLContext {
}
/**
+ * @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
* new GLContext implementations; not for use by end users.
@@ -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
*/