From d1a03d19398960d6e34232f29a30f1d569fba2a7 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 6 Nov 2010 06:26:56 +0100 Subject: Fix buffer size: 64bit GLBufferSizeTracker, hash over addr+size, save fail-fast hash cache, .. Relates to GlueGen 6b6b9b3b81cdc85b7260664ebec547756a6be5d7, branch sgothel_wip_fixes01. Memory object size is ptrdiff_t, hence long (64bit). The hash value must include size as well, otherwise boundaries cannot be verified. (security) Double check hash collisions while adding a new MemoryObject. --- make/config/jogl/gl-impl-CustomJavaCode-gles1.java | 63 ++++++++-------------- 1 file changed, 23 insertions(+), 40 deletions(-) (limited to 'make/config/jogl/gl-impl-CustomJavaCode-gles1.java') diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java index d29fe1645..faff8b89f 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java @@ -249,32 +249,7 @@ private boolean checkPackPBOEnabled(boolean throwException) { return false; } -// Attempt to return the same ByteBuffer object from glMapBufferARB if -// the vertex buffer object's base address and size haven't changed -private static class ARBVBOKey { - private long addr; - private int capacity; - - ARBVBOKey(long addr, int capacity) { - 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/**/ arbVBOCache = new HashMap(); +private HashMap/**/ arbMemCache = new HashMap(); /** Entry point to C language function:
LPVOID glMapBuffer(GLenum target, GLenum access); */ public java.nio.ByteBuffer glMapBuffer(int target, int access) { @@ -282,32 +257,40 @@ public java.nio.ByteBuffer glMapBuffer(int target, int access) { if (__addr_ == 0) { throw new GLException("Method \"glMapBuffer\" not available"); } - int sz = bufferSizeTracker.getBufferSize(bufferStateTracker, - target, - this); + final long sz = bufferSizeTracker.getBufferSize(bufferStateTracker, target, this); if (0 == sz) { return null; } - long addr; - addr = dispatch_glMapBuffer(target, access, __addr_); + final long addr = dispatch_glMapBuffer(target, access, __addr_); if (0 == addr) { return null; } - ARBVBOKey key = new ARBVBOKey(addr, sz); - java.nio.ByteBuffer _res = (java.nio.ByteBuffer) arbVBOCache.get(key); - if (_res == null) { - _res = newDirectByteBuffer(addr, sz); - Buffers.nativeOrder(_res); - arbVBOCache.put(key, _res); + ByteBuffer buffer; + MemoryObject memObj0 = new MemoryObject(addr, sz); // object and key + MemoryObject memObj1 = MemoryObject.getOrAddSafe(arbMemCache, memObj0); + if(memObj0 == memObj1) { + // just added .. + if(null != memObj0.getBuffer()) { + throw new InternalError(); + } + buffer = newDirectByteBuffer(addr, sz); + Buffers.nativeOrder(buffer); + memObj0.setBuffer(buffer); + } else { + // already mapped + buffer = memObj1.getBuffer(); + if(null == buffer) { + throw new InternalError(); + } } - _res.position(0); - return _res; + buffer.position(0); + return buffer; } /** Encapsulates function pointer for OpenGL function
: LPVOID glMapBuffer(GLenum target, GLenum access); */ native private long dispatch_glMapBuffer(int target, int access, long glProcAddress); -native private ByteBuffer newDirectByteBuffer(long addr, int capacity); +native private ByteBuffer newDirectByteBuffer(long addr, long capacity); public void glVertexPointer(GLArrayData array) { if(array.getComponentNumber()==0) return; -- cgit v1.2.3