From 061782e92de56a89677881a6d4b1896243993e1d Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Tue, 3 Sep 2013 05:28:16 +0200 Subject: [PATCH] fix: clear static GLRenderer.BufferPool on init fix: clear static BufferObject pool on init - fixes garbage buffers when restarting android app --- vtm/src/org/oscim/renderer/BufferObject.java | 17 ++-- vtm/src/org/oscim/renderer/GLRenderer.java | 86 +++++++++++--------- 2 files changed, 58 insertions(+), 45 deletions(-) diff --git a/vtm/src/org/oscim/renderer/BufferObject.java b/vtm/src/org/oscim/renderer/BufferObject.java index 86d58f20..6c16483b 100644 --- a/vtm/src/org/oscim/renderer/BufferObject.java +++ b/vtm/src/org/oscim/renderer/BufferObject.java @@ -86,8 +86,8 @@ public final class BufferObject { Log.d(TAG, "now: " + mBufferMemoryUsage / MB + "MB"); } - private static BufferObject pool[] = new BufferObject[2]; - static int counter[] = new int[2]; + private final static BufferObject pool[] = new BufferObject[2]; + private final static int counter[] = new int[2]; public static synchronized BufferObject get(int target, int size) { @@ -197,12 +197,19 @@ public final class BufferObject { } } - static synchronized void init(int num) { + + static synchronized void clear() { mBufferMemoryUsage = 0; - // FIXME!!!!! pool = new BufferObject[2]; + pool[0] = null; + pool[1] = null; + counter[0] = 0; + counter[1] = 0; + } + + static synchronized void init(int num) { createBuffers(GL20.GL_ARRAY_BUFFER, num); - counter[0] = num; + counter[0] += num; } } diff --git a/vtm/src/org/oscim/renderer/GLRenderer.java b/vtm/src/org/oscim/renderer/GLRenderer.java index bc27040c..c5a68d44 100644 --- a/vtm/src/org/oscim/renderer/GLRenderer.java +++ b/vtm/src/org/oscim/renderer/GLRenderer.java @@ -104,6 +104,46 @@ public class GLRenderer { public static long frametime; + // Do not use the same buffer to upload data within a frame twice + // - Contrary to what the OpenGL doc says data seems *not* to be + // *always* copied after glBufferData returns... + // - Somehow it does always copy when using Android GL bindings + // but not when using libgdx bindings (LWJGL or AndroidGL20) + + static class BufferPool extends Pool { + private BufferItem mUsedBuffers; + + @Override + protected BufferItem createItem() { + // unused; + return null; + } + + public BufferItem get(int size) { + BufferItem b = pool; + + if (b == null) { + b = new BufferItem(); + } else { + pool = b.next; + b.next = null; + } + if (b.tmpBufferSize < size) + b.growBuffer(size); + + mUsedBuffers = Inlist.push(mUsedBuffers, b); + + return b; + } + + public void releaseBuffers() { + releaseAll(mUsedBuffers); + mUsedBuffers = null; + } + } + + private static BufferPool mBufferPool; + /** * @param map * the MapView @@ -128,6 +168,12 @@ public class GLRenderer { mFillCoords[5] = min; mFillCoords[6] = max; mFillCoords[7] = min; + + mBufferPool = new BufferPool(); + + // FIXME should be done in 'destroy' method + // clear all previous vbo refs + BufferObject.clear(); } public static void setBackgroundColor(int color) { @@ -159,46 +205,6 @@ public class GLRenderer { } } - static class BufferPool extends Pool { - private BufferItem mUsedBuffers; - - @Override - protected BufferItem createItem() { - // unused; - return null; - } - - public BufferItem get(int size) { - BufferItem b = pool; - - if (b == null) { - b = new BufferItem(); - } else { - pool = b.next; - b.next = null; - } - if (b.tmpBufferSize < size) - b.growBuffer(size); - - mUsedBuffers = Inlist.push(mUsedBuffers, b); - - return b; - } - - public void releaseBuffers() { - mBufferPool.releaseAll(mUsedBuffers); - mUsedBuffers = null; - } - - } - - // Do not use the same buffer to upload data within a frame twice - // - Contrary to what the OpenGL doc says data seems *not* to be - // *always* copied after glBufferData returns... - // - Somehow it does always copy when using Android GL bindings - // but not when using libgdx bindings (LWJGL or AndroidGL20) - private static BufferPool mBufferPool = new BufferPool(); - /** * Only use on GL Thread! Get a native ShortBuffer for temporary use. */