summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/gl-impl-CustomJavaCode.java13
-rw-r--r--src/native/jogl/BufferUtils.c2
-rw-r--r--src/net/java/games/jogl/util/BufferUtils.java15
3 files changed, 28 insertions, 2 deletions
diff --git a/make/gl-impl-CustomJavaCode.java b/make/gl-impl-CustomJavaCode.java
index bd2be71f6..152458b5b 100644
--- a/make/gl-impl-CustomJavaCode.java
+++ b/make/gl-impl-CustomJavaCode.java
@@ -8,6 +8,19 @@ private static class ARBVBOKey {
this.addr = addr;
this.capacity = capacity;
}
+
+ public int hashCode() {
+ return (int) addr;
+ }
+
+ public boolean equals(Object o) {
+ if ((o == null) || (!(o instanceof ARBVBOKey))) {
+ return false;
+ }
+
+ ARBVBOKey other = (ARBVBOKey) o;
+ return ((addr == other.addr) && (capacity == other.capacity));
+ }
}
private Map/*<ARBVBOKey, ByteBuffer>*/ arbVBOCache = new HashMap();
diff --git a/src/native/jogl/BufferUtils.c b/src/native/jogl/BufferUtils.c
index f10a8ce6d..d5ea5b36e 100644
--- a/src/native/jogl/BufferUtils.c
+++ b/src/native/jogl/BufferUtils.c
@@ -49,6 +49,6 @@
#endif
JNIEXPORT jobject JNICALL
-Java_net_java_games_jogl_util_BufferUtils_bufferOffset(JNIEnv* env, jclass unused, jint offset) {
+Java_net_java_games_jogl_util_BufferUtils_bufferOffset0(JNIEnv* env, jclass unused, jint offset) {
return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) offset, 0);
}
diff --git a/src/net/java/games/jogl/util/BufferUtils.java b/src/net/java/games/jogl/util/BufferUtils.java
index 05125b75e..88afa1c8f 100644
--- a/src/net/java/games/jogl/util/BufferUtils.java
+++ b/src/net/java/games/jogl/util/BufferUtils.java
@@ -40,6 +40,7 @@
package net.java.games.jogl.util;
import java.nio.*;
+import java.util.*;
/** Utility routines for dealing with direct buffers. */
@@ -70,6 +71,8 @@ public class BufferUtils {
return dest;
}
+ private static Map bufferOffsetCache = Collections.synchronizedMap(new HashMap());
+
/** Creates an "offset buffer" for use with the
ARB_vertex_buffer_object extension. The resulting Buffers are
suitable for use with routines such as glVertexPointer <em>when
@@ -77,5 +80,15 @@ public class BufferUtils {
capacity and are not suitable for passing to OpenGL routines
that do not support buffer offsets, or to non-OpenGL
routines. */
- public static native ByteBuffer bufferOffset(int offset);
+ public static ByteBuffer bufferOffset(int offset) {
+ Integer key = new Integer(offset);
+ ByteBuffer buf = (ByteBuffer) bufferOffsetCache.get(key);
+ if (buf == null) {
+ buf = bufferOffset0(offset);
+ bufferOffsetCache.put(key, buf);
+ }
+ return buf;
+ }
+
+ private static native ByteBuffer bufferOffset0(int offset);
}