fix: clear static GLRenderer.BufferPool on init
fix: clear static BufferObject pool on init - fixes garbage buffers when restarting android app
This commit is contained in:
parent
eee41e093c
commit
061782e92d
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<BufferItem> {
|
||||
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<BufferItem> {
|
||||
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.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user