cleanup extrusion layer when it was not compiled

This commit is contained in:
Hannes Janetzek 2013-01-11 09:42:35 +01:00
parent 2e8bcd865a
commit 5b3b299217
2 changed files with 18 additions and 95 deletions

View File

@ -401,6 +401,10 @@ public class ExtrusionLayer extends Layer {
protected void clear() { protected void clear() {
if (compiled) { if (compiled) {
GLES20.glDeleteBuffers(2, mVboIds, 0); GLES20.glDeleteBuffers(2, mVboIds, 0);
} else {
VertexPool.release(mVertices);
for (VertexPoolItem i : mIndices)
VertexPool.release(i);
} }
} }

View File

@ -25,7 +25,6 @@ public class Layers {
// mixed Polygon and Line layers // mixed Polygon and Line layers
public Layer layers; public Layer layers;
public Layer textureLayers; public Layer textureLayers;
public Layer extrusionLayers; public Layer extrusionLayers;
@ -87,72 +86,6 @@ public class Layers {
return ret; return ret;
} }
// public boolean uploadLayers(BufferObject vbo, boolean addFill, boolean limit) {
//
// int newSize = getSize();
// if (newSize == 0) {
// // Log.d(TAG, "empty");
// return true;
// }
//
// GLES20.glBindBuffer(GL_ARRAY_BUFFER, vbo.id);
//
// // use multiple buffers to avoid overwriting buffer while current
// // data is uploaded (or rather the blocking which is probably done to
// // avoid overwriting)
// int curBuffer = uploadCnt++ % rotateBuffers;
//
// ShortBuffer sbuf = shortBuffer[curBuffer];
//
// // add fill coordinates
// if (addFill)
// newSize += 8;
//
// if (sbuf.capacity() < newSize) {
// sbuf = ByteBuffer
// .allocateDirect(newSize * SHORT_BYTES)
// .order(ByteOrder.nativeOrder())
// .asShortBuffer();
//
// shortBuffer[curBuffer] = sbuf;
// } else {
// sbuf.clear();
// // if (addFill)
// // sbuf.position(8);
// }
//
// if (addFill)
// sbuf.put(mFillCoords, 0, 8);
//
// compile(sbuf, addFill);
//
// sbuf.flip();
//
// if (newSize != sbuf.remaining()) {
// Log.d(TAG, "wrong size: "
// + newSize + " "
// + sbuf.position() + " "
// + sbuf.limit() + " "
// + sbuf.remaining());
// return false;
// }
// newSize *= SHORT_BYTES;
//
// // reuse memory allocated for vbo when possible and allocated
// // memory is less then four times the new data
// if (vbo.size > newSize && vbo.size < newSize * 4
// && !limit) {
// GLES20.glBufferSubData(GL_ARRAY_BUFFER, 0, newSize, sbuf);
// } else {
// //mBufferMemoryUsage += newSize - vbo.size;
// vbo.size = newSize;
// GLES20.glBufferData(GL_ARRAY_BUFFER, vbo.size, sbuf, GL_DYNAMIC_DRAW);
// //mBufferMemoryUsage += vbo.size;
// }
//
// return true;
// }
private static int LINE_VERTEX_SHORTS = 4; private static int LINE_VERTEX_SHORTS = 4;
private static int POLY_VERTEX_SHORTS = 2; private static int POLY_VERTEX_SHORTS = 2;
private static int TEXTURE_VERTEX_SHORTS = 6; private static int TEXTURE_VERTEX_SHORTS = 6;
@ -196,6 +129,7 @@ public class Layers {
tl.compile(sbuf); tl.compile(sbuf);
} }
// extrusion layers are compiled by extrusion overlay
// for (Layer l = extrusionLayers; l != null; l = l.next) { // for (Layer l = extrusionLayers; l != null; l = l.next) {
// ExtrusionLayer tl = (ExtrusionLayer) l; // ExtrusionLayer tl = (ExtrusionLayer) l;
// tl.compile(sbuf); // tl.compile(sbuf);
@ -235,6 +169,7 @@ public class Layers {
} }
static void addPoolItems(Layer l, ShortBuffer sbuf) { static void addPoolItems(Layer l, ShortBuffer sbuf) {
// offset of layer data in vbo
l.offset = sbuf.position() * 2; // (* short-bytes) l.offset = sbuf.position() * 2; // (* short-bytes)
for (VertexPoolItem it = l.pool; it != null; it = it.next) { for (VertexPoolItem it = l.pool; it != null; it = it.next) {
@ -250,44 +185,28 @@ public class Layers {
// cleanup only when layers are not used by tile or overlay anymore! // cleanup only when layers are not used by tile or overlay anymore!
public void clear() { public void clear() {
while (layers != null) {
Layer l = layers;
if (l.pool != null) {
VertexPool.release(l.pool);
l.pool = null;
l.curItem = null;
}
layers = layers.next;
}
Layer l = textureLayers; // clear line and polygon layers directly
Layer l = layers;
while (l != null) { while (l != null) {
l.clear();
if (l.pool != null) { if (l.pool != null) {
VertexPool.release(l.pool); VertexPool.release(l.pool);
l.pool = null; l.pool = null;
l.curItem = null; l.curItem = null;
} }
l = l.next; l = l.next;
} }
for (l = textureLayers; l != null; l = l.next) {
VertexPool.release(l.pool);
l.clear();
}
for (l = extrusionLayers; l != null; l = l.next) {
l.clear();
}
layers = null;
textureLayers = null; textureLayers = null;
l = extrusionLayers;
while (l != null) {
l.clear();
if (l.pool != null) {
VertexPool.release(l.pool);
l.pool = null;
l.curItem = null;
}
l = l.next;
}
extrusionLayers = null; extrusionLayers = null;
} }
} }