dispose textures at end of each frame
This commit is contained in:
parent
e80981e0c5
commit
b45e38ef4d
@ -27,6 +27,7 @@ import org.oscim.backend.GLAdapter;
|
|||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
import org.oscim.map.Map;
|
import org.oscim.map.Map;
|
||||||
import org.oscim.renderer.elements.ElementLayers;
|
import org.oscim.renderer.elements.ElementLayers;
|
||||||
|
import org.oscim.renderer.elements.TextureItem;
|
||||||
import org.oscim.utils.pool.Inlist;
|
import org.oscim.utils.pool.Inlist;
|
||||||
import org.oscim.utils.pool.Pool;
|
import org.oscim.utils.pool.Pool;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -174,6 +175,7 @@ public class MapRenderer {
|
|||||||
draw();
|
draw();
|
||||||
|
|
||||||
mBufferPool.releaseBuffers();
|
mBufferPool.releaseBuffers();
|
||||||
|
TextureItem.disposeTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void draw() {
|
private void draw() {
|
||||||
|
@ -144,8 +144,6 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class TexturePool extends SyncPool<TextureItem> {
|
public static class TexturePool extends SyncPool<TextureItem> {
|
||||||
|
|
||||||
private final ArrayList<Integer> mTexDisposed = new ArrayList<Integer>();
|
|
||||||
private final ArrayList<Bitmap> mBitmaps = new ArrayList<Bitmap>(10);
|
private final ArrayList<Bitmap> mBitmaps = new ArrayList<Bitmap>(10);
|
||||||
|
|
||||||
private final int mHeight;
|
private final int mHeight;
|
||||||
@ -226,16 +224,14 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void freeItem(TextureItem t) {
|
protected void freeItem(TextureItem t) {
|
||||||
|
if (!t.ref && t.id >= 0) {
|
||||||
if (!t.ref) {
|
mTexCnt--;
|
||||||
synchronized (mTexDisposed) {
|
synchronized (disposedTextures) {
|
||||||
if (t.id >= 0) {
|
disposedTextures.add(Integer.valueOf(t.id));
|
||||||
mTexDisposed.add(Integer.valueOf(t.id));
|
|
||||||
t.id = -1;
|
t.id = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected void releaseBitmap(TextureItem t) {
|
protected void releaseBitmap(TextureItem t) {
|
||||||
|
|
||||||
@ -253,19 +249,6 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
if (t.bitmap == null)
|
if (t.bitmap == null)
|
||||||
throw new RuntimeException("Missing bitmap for texture");
|
throw new RuntimeException("Missing bitmap for texture");
|
||||||
|
|
||||||
synchronized (mTexDisposed) {
|
|
||||||
int size = mTexDisposed.size();
|
|
||||||
if (size > 0) {
|
|
||||||
int[] tmp = new int[size];
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
tmp[i] = mTexDisposed.get(i).intValue();
|
|
||||||
|
|
||||||
mTexDisposed.clear();
|
|
||||||
GLUtils.glDeleteTextures(size, tmp);
|
|
||||||
mTexCnt -= size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.id < 0) {
|
if (t.id < 0) {
|
||||||
int[] textureIds = GLUtils.glGenTextures(1);
|
int[] textureIds = GLUtils.glGenTextures(1);
|
||||||
t.id = textureIds[0];
|
t.id = textureIds[0];
|
||||||
@ -318,10 +301,28 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
/* Pool for not-pooled textures. Disposed items will only be released
|
/* Pool for not-pooled textures. Disposed items will only be released
|
||||||
* on the GL-Thread and will not be put back in any pool. */
|
* on the GL-Thread and will not be put back in any pool. */
|
||||||
final static TexturePool NOPOOL = new TexturePool(0);
|
final static TexturePool NOPOOL = new TexturePool(0);
|
||||||
|
final static ArrayList<Integer> disposedTextures = new ArrayList<Integer>();
|
||||||
|
|
||||||
private static GL20 GL;
|
private static GL20 GL;
|
||||||
|
|
||||||
static void init(GL20 gl) {
|
static void init(GL20 gl) {
|
||||||
GL = gl;
|
GL = gl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** disposed textures are released by MapRenderer after each frame */
|
||||||
|
public static void disposeTextures() {
|
||||||
|
synchronized (disposedTextures) {
|
||||||
|
|
||||||
|
int size = disposedTextures.size();
|
||||||
|
if (size > 0) {
|
||||||
|
int[] tmp = new int[size];
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
tmp[i] = disposedTextures.get(i).intValue();
|
||||||
|
|
||||||
|
disposedTextures.clear();
|
||||||
|
GLUtils.glDeleteTextures(size, tmp);
|
||||||
|
//mTexCnt -= size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user