pooled items now extend pool.Inlist and using generic pool.SyncPool
This commit is contained in:
@@ -36,9 +36,9 @@ import android.util.Log;
|
||||
public class ExtrusionLayer extends Layer {
|
||||
private final static String TAG = ExtrusionLayer.class.getName();
|
||||
private static final float S = GLRenderer.COORD_SCALE;
|
||||
private final VertexPoolItem mVertices;
|
||||
private VertexPoolItem mCurVertices;
|
||||
private final VertexPoolItem mIndices[], mCurIndices[];
|
||||
private final VertexItem mVertices;
|
||||
private VertexItem mCurVertices;
|
||||
private final VertexItem mIndices[], mCurIndices[];
|
||||
private LineClipper mClipper;
|
||||
|
||||
// indices for:
|
||||
@@ -65,12 +65,12 @@ public class ExtrusionLayer extends Layer {
|
||||
this.level = level;
|
||||
|
||||
mGroundResolution = groundResolution;
|
||||
mVertices = mCurVertices = VertexPool.get();
|
||||
mVertices = mCurVertices = VertexItem.pool.get();
|
||||
|
||||
mIndices = new VertexPoolItem[4];
|
||||
mCurIndices = new VertexPoolItem[4];
|
||||
mIndices = new VertexItem[4];
|
||||
mCurIndices = new VertexItem[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
mIndices[i] = mCurIndices[i] = VertexPool.get();
|
||||
mIndices[i] = mCurIndices[i] = VertexItem.pool.get();
|
||||
|
||||
mClipper = new LineClipper(0, 0, Tile.SIZE, Tile.SIZE);
|
||||
}
|
||||
@@ -158,9 +158,9 @@ public class ExtrusionLayer extends Layer {
|
||||
short first = (short) (startVertex + 1);
|
||||
|
||||
for (int k = 0; k < len - 4; k += 2) {
|
||||
if (i == VertexPoolItem.SIZE) {
|
||||
mCurIndices[IND_ROOF].used = VertexPoolItem.SIZE;
|
||||
mCurIndices[IND_ROOF].next = VertexPool.get();
|
||||
if (i == VertexItem.SIZE) {
|
||||
mCurIndices[IND_ROOF].used = VertexItem.SIZE;
|
||||
mCurIndices[IND_ROOF].next = VertexItem.pool.get();
|
||||
mCurIndices[IND_ROOF] = mCurIndices[2].next;
|
||||
indices = mCurIndices[IND_ROOF].vertices;
|
||||
i = 0;
|
||||
@@ -194,7 +194,7 @@ public class ExtrusionLayer extends Layer {
|
||||
|
||||
if (used > 0) {
|
||||
// get back to the last item added..
|
||||
VertexPoolItem it = mIndices[IND_ROOF];
|
||||
VertexItem it = mIndices[IND_ROOF];
|
||||
while (it.next != null)
|
||||
it = it.next;
|
||||
mCurIndices[IND_ROOF] = it;
|
||||
@@ -247,9 +247,9 @@ public class ExtrusionLayer extends Layer {
|
||||
uy = vy;
|
||||
|
||||
/* add bottom and top vertex for each point */
|
||||
if (v == VertexPoolItem.SIZE) {
|
||||
mCurVertices.used = VertexPoolItem.SIZE;
|
||||
mCurVertices.next = VertexPool.get();
|
||||
if (v == VertexItem.SIZE) {
|
||||
mCurVertices.used = VertexItem.SIZE;
|
||||
mCurVertices.next = VertexItem.pool.get();
|
||||
mCurVertices = mCurVertices.next;
|
||||
vertices = mCurVertices.vertices;
|
||||
v = 0;
|
||||
@@ -329,8 +329,8 @@ public class ExtrusionLayer extends Layer {
|
||||
// index id relative to mCurIndices item
|
||||
int ind = mCurIndices[even].used;
|
||||
|
||||
if (ind == VertexPoolItem.SIZE) {
|
||||
mCurIndices[even].next = VertexPool.get();
|
||||
if (ind == VertexItem.SIZE) {
|
||||
mCurIndices[even].next = VertexItem.pool.get();
|
||||
mCurIndices[even] = mCurIndices[even].next;
|
||||
indices = mCurIndices[even].vertices;
|
||||
ind = 0;
|
||||
@@ -348,9 +348,9 @@ public class ExtrusionLayer extends Layer {
|
||||
even = (even == 0 ? 1 : 0);
|
||||
|
||||
/* add roof outline indices */
|
||||
VertexPoolItem it = mCurIndices[IND_OUTLINE];
|
||||
if (it.used == VertexPoolItem.SIZE) {
|
||||
it.next = VertexPool.get();
|
||||
VertexItem it = mCurIndices[IND_OUTLINE];
|
||||
if (it.used == VertexItem.SIZE) {
|
||||
it.next = VertexItem.pool.get();
|
||||
it = mCurIndices[IND_OUTLINE] = it.next;
|
||||
}
|
||||
it.vertices[it.used++] = s1;
|
||||
@@ -377,7 +377,7 @@ public class ExtrusionLayer extends Layer {
|
||||
sbuf.clear();
|
||||
mNumIndices = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (VertexPoolItem vi = mIndices[i]; vi != null; vi = vi.next) {
|
||||
for (VertexItem vi = mIndices[i]; vi != null; vi = vi.next) {
|
||||
sbuf.put(vi.vertices, 0, vi.used);
|
||||
mIndiceCnt[i] += vi.used;
|
||||
}
|
||||
@@ -392,7 +392,7 @@ public class ExtrusionLayer extends Layer {
|
||||
|
||||
// upload vertices
|
||||
sbuf.clear();
|
||||
for (VertexPoolItem vi = mVertices; vi != null; vi = vi.next)
|
||||
for (VertexItem vi = mVertices; vi != null; vi = vi.next)
|
||||
sbuf.put(vi.vertices, 0, vi.used);
|
||||
|
||||
sbuf.flip();
|
||||
@@ -404,10 +404,10 @@ public class ExtrusionLayer extends Layer {
|
||||
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
for (VertexPoolItem i : mIndices)
|
||||
VertexPool.release(i);
|
||||
for (VertexItem i : mIndices)
|
||||
VertexItem.pool.releaseAll(i);
|
||||
|
||||
VertexPool.release(mVertices);
|
||||
VertexItem.pool.releaseAll(mVertices);
|
||||
|
||||
mClipper = null;
|
||||
|
||||
@@ -423,9 +423,9 @@ public class ExtrusionLayer extends Layer {
|
||||
mVertexBO = null;
|
||||
//GLES20.glDeleteBuffers(2, mVboIds, 0);
|
||||
} else {
|
||||
VertexPool.release(mVertices);
|
||||
for (VertexPoolItem i : mIndices)
|
||||
VertexPool.release(i);
|
||||
VertexItem.pool.releaseAll(mVertices);
|
||||
for (VertexItem i : mIndices)
|
||||
VertexItem.pool.releaseAll(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ public class ExtrusionLayer extends Layer {
|
||||
private static ShortBuffer sBuf;
|
||||
|
||||
public static synchronized int triangulate(float[] points, int ppos, int plen, short[] index,
|
||||
int ipos, int rings, int vertexOffset, VertexPoolItem item) {
|
||||
int ipos, int rings, int vertexOffset, VertexItem item) {
|
||||
|
||||
if (!initialized) {
|
||||
// FIXME also cleanup on shutdown!
|
||||
@@ -454,12 +454,12 @@ public class ExtrusionLayer extends Layer {
|
||||
|
||||
for (int k = 0, cnt = 0; k < numIndices; k += cnt) {
|
||||
|
||||
if (item.used == VertexPoolItem.SIZE) {
|
||||
item.next = VertexPool.get();
|
||||
if (item.used == VertexItem.SIZE) {
|
||||
item.next = VertexItem.pool.get();
|
||||
item = item.next;
|
||||
}
|
||||
|
||||
cnt = VertexPoolItem.SIZE - item.used;
|
||||
cnt = VertexItem.SIZE - item.used;
|
||||
|
||||
if (k + cnt > numIndices)
|
||||
cnt = numIndices - k;
|
||||
|
||||
@@ -45,8 +45,8 @@ public abstract class Layer {
|
||||
// - offset in byte in VBO
|
||||
public int offset;
|
||||
|
||||
VertexPoolItem pool;
|
||||
protected VertexPoolItem curItem;
|
||||
VertexItem vertexItems;
|
||||
protected VertexItem curItem;
|
||||
|
||||
abstract protected void compile(ShortBuffer sbuf);
|
||||
abstract protected void clear();
|
||||
|
||||
@@ -179,21 +179,21 @@ public class Layers {
|
||||
// optimization for Line- and PolygonLayer:
|
||||
// collect all pool items and add back in one go
|
||||
private static int addLayerItems(ShortBuffer sbuf, Layer l, byte type, int pos) {
|
||||
VertexPoolItem last = null, items = null;
|
||||
VertexItem last = null, items = null;
|
||||
int size = 0;
|
||||
|
||||
for (; l != null; l = l.next) {
|
||||
if (l.type != type)
|
||||
continue;
|
||||
|
||||
for (VertexPoolItem it = l.pool; it != null; it = it.next) {
|
||||
for (VertexItem it = l.vertexItems; it != null; it = it.next) {
|
||||
if (it.next == null){
|
||||
size += it.used;
|
||||
sbuf.put(it.vertices, 0, it.used);
|
||||
}
|
||||
else{
|
||||
size += VertexPoolItem.SIZE;
|
||||
sbuf.put(it.vertices, 0, VertexPoolItem.SIZE);
|
||||
size += VertexItem.SIZE;
|
||||
sbuf.put(it.vertices, 0, VertexItem.SIZE);
|
||||
}
|
||||
last = it;
|
||||
}
|
||||
@@ -205,13 +205,13 @@ public class Layers {
|
||||
pos += l.verticesCnt;
|
||||
|
||||
last.next = items;
|
||||
items = l.pool;
|
||||
items = l.vertexItems;
|
||||
last = null;
|
||||
|
||||
l.pool = null;
|
||||
l.vertexItems = null;
|
||||
l.curItem = null;
|
||||
}
|
||||
VertexPool.release(items);
|
||||
VertexItem.pool.releaseAll(items);
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -220,15 +220,15 @@ public class Layers {
|
||||
// offset of layer data in vbo
|
||||
l.offset = sbuf.position() * SHORT_BYTES;
|
||||
|
||||
for (VertexPoolItem it = l.pool; it != null; it = it.next) {
|
||||
for (VertexItem it = l.vertexItems; it != null; it = it.next) {
|
||||
if (it.next == null)
|
||||
sbuf.put(it.vertices, 0, it.used);
|
||||
else
|
||||
sbuf.put(it.vertices, 0, VertexPoolItem.SIZE);
|
||||
sbuf.put(it.vertices, 0, VertexItem.SIZE);
|
||||
}
|
||||
|
||||
VertexPool.release(l.pool);
|
||||
l.pool = null;
|
||||
VertexItem.pool.releaseAll(l.vertexItems);
|
||||
l.vertexItems = null;
|
||||
}
|
||||
|
||||
// cleanup only when layers are not used by tile or overlay anymore!
|
||||
@@ -237,9 +237,9 @@ public class Layers {
|
||||
// clear line and polygon layers directly
|
||||
Layer l = baseLayers;
|
||||
while (l != null) {
|
||||
if (l.pool != null) {
|
||||
VertexPool.release(l.pool);
|
||||
l.pool = null;
|
||||
if (l.vertexItems != null) {
|
||||
VertexItem.pool.releaseAll(l.vertexItems);
|
||||
l.vertexItems = null;
|
||||
l.curItem = null;
|
||||
}
|
||||
l = l.next;
|
||||
|
||||
@@ -85,10 +85,10 @@ public final class LineLayer extends Layer {
|
||||
else if (line.cap == Cap.SQUARE)
|
||||
squared = true;
|
||||
|
||||
if (pool == null)
|
||||
curItem = pool = VertexPool.get();
|
||||
if (vertexItems == null)
|
||||
curItem = vertexItems = VertexItem.pool.get();
|
||||
|
||||
VertexPoolItem si = curItem;
|
||||
VertexItem si = curItem;
|
||||
short v[] = si.vertices;
|
||||
int opos = si.used;
|
||||
|
||||
@@ -175,8 +175,8 @@ public final class LineLayer extends Layer {
|
||||
// when the endpoint is outside the tile region omit round caps.
|
||||
boolean outside = (x < tmin || x > tmax || y < tmin || y > tmax);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -193,8 +193,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = dx;
|
||||
v[opos++] = dy;
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -204,8 +204,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = dx;
|
||||
v[opos++] = dy;
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -218,8 +218,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = (short) (2 | ddx & DIR_MASK);
|
||||
v[opos++] = (short) (2 | ddy & DIR_MASK);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -233,8 +233,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = (short) (0 | ddx & DIR_MASK);
|
||||
v[opos++] = (short) (1 | ddy & DIR_MASK);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -273,8 +273,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = dx;
|
||||
v[opos++] = dy;
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -284,8 +284,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = dx;
|
||||
v[opos++] = dy;
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -366,8 +366,8 @@ public final class LineLayer extends Layer {
|
||||
ddx = -ddx;
|
||||
ddy = -ddy;
|
||||
}
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -377,8 +377,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = (short) (0 | ddx & DIR_MASK);
|
||||
v[opos++] = (short) (1 | ddy & DIR_MASK);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -401,8 +401,8 @@ public final class LineLayer extends Layer {
|
||||
|
||||
outside = (x < tmin || x > tmax || y < tmin || y > tmax);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si.next = VertexItem.pool.get();
|
||||
si = si.next;
|
||||
opos = 0;
|
||||
v = si.vertices;
|
||||
@@ -425,8 +425,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = (short) (0 | ddx & DIR_MASK);
|
||||
v[opos++] = (short) (1 | ddy & DIR_MASK);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -436,8 +436,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = (short) (2 | -ddx & DIR_MASK);
|
||||
v[opos++] = (short) (1 | -ddy & DIR_MASK);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -454,8 +454,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = dx;
|
||||
v[opos++] = dy;
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -471,8 +471,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = dx;
|
||||
v[opos++] = dy;
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -502,8 +502,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = (short) (0 | (flip ? -ddx : ddx) & DIR_MASK);
|
||||
v[opos++] = (short) (1 | (flip ? -ddy : ddy) & DIR_MASK);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
@@ -519,8 +519,8 @@ public final class LineLayer extends Layer {
|
||||
v[opos++] = dx;
|
||||
v[opos++] = dy;
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ public final class LineTexLayer extends Layer {
|
||||
|
||||
public void addLine(float[] points, short[] index) {
|
||||
|
||||
if (pool == null) {
|
||||
curItem = pool = VertexPool.get();
|
||||
if (vertexItems == null) {
|
||||
curItem = vertexItems = VertexItem.pool.get();
|
||||
|
||||
// HACK add one vertex offset when compiling
|
||||
// buffer otherwise one cant use the full
|
||||
@@ -103,7 +103,7 @@ public final class LineTexLayer extends Layer {
|
||||
verticesCnt = 1;
|
||||
}
|
||||
|
||||
VertexPoolItem si = curItem;
|
||||
VertexItem si = curItem;
|
||||
|
||||
short v[] = si.vertices;
|
||||
int opos = si.used;
|
||||
@@ -169,8 +169,8 @@ public final class LineTexLayer extends Layer {
|
||||
short dx = (short) (ux * DIR_SCALE);
|
||||
short dy = (short) (uy * DIR_SCALE);
|
||||
|
||||
if (opos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (opos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
opos = 0;
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ public final class PolygonLayer extends Layer {
|
||||
PolygonLayer(int layer) {
|
||||
this.level = layer;
|
||||
this.type = Layer.POLYGON;
|
||||
curItem = VertexPool.get();
|
||||
pool = curItem;
|
||||
curItem = VertexItem.pool.get();
|
||||
vertexItems = curItem;
|
||||
}
|
||||
|
||||
public void addPolygon(float[] points, short[] index) {
|
||||
short center = (short) ((Tile.SIZE >> 1) * S);
|
||||
|
||||
VertexPoolItem si = curItem;
|
||||
VertexItem si = curItem;
|
||||
short[] v = si.vertices;
|
||||
int outPos = si.used;
|
||||
|
||||
@@ -54,8 +54,8 @@ public final class PolygonLayer extends Layer {
|
||||
|
||||
int inPos = pos;
|
||||
|
||||
if (outPos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (outPos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
outPos = 0;
|
||||
}
|
||||
@@ -64,8 +64,8 @@ public final class PolygonLayer extends Layer {
|
||||
v[outPos++] = center;
|
||||
|
||||
for (int j = 0; j < length; j += 2) {
|
||||
if (outPos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (outPos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
outPos = 0;
|
||||
}
|
||||
@@ -73,8 +73,8 @@ public final class PolygonLayer extends Layer {
|
||||
v[outPos++] = (short) (points[inPos++] * S);
|
||||
}
|
||||
|
||||
if (outPos == VertexPoolItem.SIZE) {
|
||||
si = si.next = VertexPool.get();
|
||||
if (outPos == VertexItem.SIZE) {
|
||||
si = si.next = VertexItem.pool.get();
|
||||
v = si.vertices;
|
||||
outPos = 0;
|
||||
}
|
||||
|
||||
@@ -14,47 +14,28 @@
|
||||
*/
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.oscim.utils.pool.SyncPool;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class SymbolItem {
|
||||
private static Object lock = new Object();
|
||||
private static SymbolItem pool;
|
||||
public class SymbolItem extends Inlist<SymbolItem> {
|
||||
|
||||
public static SymbolItem get() {
|
||||
synchronized (lock) {
|
||||
if (pool == null)
|
||||
return new SymbolItem();
|
||||
public final static SyncPool<SymbolItem> pool = new SyncPool<SymbolItem>() {
|
||||
|
||||
SymbolItem ti = pool;
|
||||
pool = pool.next;
|
||||
|
||||
ti.next = null;
|
||||
|
||||
return ti;
|
||||
@Override
|
||||
protected SymbolItem createItem() {
|
||||
return new SymbolItem();
|
||||
}
|
||||
}
|
||||
|
||||
public static void release(SymbolItem ti) {
|
||||
if (ti == null)
|
||||
return;
|
||||
|
||||
synchronized (lock) {
|
||||
while (ti != null) {
|
||||
SymbolItem next = ti.next;
|
||||
|
||||
ti.drawable = null;
|
||||
ti.bitmap = null;
|
||||
|
||||
ti.next = pool;
|
||||
pool = ti;
|
||||
|
||||
ti = next;
|
||||
}
|
||||
@Override
|
||||
protected void clearItem(SymbolItem it) {
|
||||
// drop references
|
||||
it.drawable = null;
|
||||
it.bitmap = null;
|
||||
}
|
||||
}
|
||||
|
||||
SymbolItem next;
|
||||
};
|
||||
|
||||
public Bitmap bitmap;
|
||||
public Drawable drawable;
|
||||
@@ -65,5 +46,4 @@ public class SymbolItem {
|
||||
|
||||
// center, top, bottom, left, right, top-left...
|
||||
// byte placement;
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
import org.oscim.renderer.TextureObject;
|
||||
import org.oscim.renderer.TextureRenderer;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
@@ -27,8 +26,8 @@ import android.util.Log;
|
||||
public final class SymbolLayer extends TextureLayer {
|
||||
private final static String TAG = SymbolLayer.class.getSimpleName();
|
||||
|
||||
private final static int TEXTURE_WIDTH = TextureObject.TEXTURE_WIDTH;
|
||||
private final static int TEXTURE_HEIGHT = TextureObject.TEXTURE_HEIGHT;
|
||||
private final static int TEXTURE_WIDTH = TextureItem.TEXTURE_WIDTH;
|
||||
private final static int TEXTURE_HEIGHT = TextureItem.TEXTURE_HEIGHT;
|
||||
private final static float SCALE = 8.0f;
|
||||
|
||||
SymbolItem symbols;
|
||||
@@ -63,7 +62,7 @@ public final class SymbolLayer extends TextureLayer {
|
||||
|
||||
verticesCnt += 4;
|
||||
|
||||
SymbolItem item = SymbolItem.get();
|
||||
SymbolItem item = SymbolItem.pool.get();
|
||||
item.drawable = drawable;
|
||||
item.x = x;
|
||||
item.y = y;
|
||||
@@ -93,9 +92,9 @@ public final class SymbolLayer extends TextureLayer {
|
||||
short offsetIndices = 0;
|
||||
short curIndices = 0;
|
||||
|
||||
curItem = VertexPool.get();
|
||||
pool = curItem;
|
||||
VertexPoolItem si = curItem;
|
||||
curItem = VertexItem.pool.get();
|
||||
vertexItems = curItem;
|
||||
VertexItem si = curItem;
|
||||
|
||||
int pos = si.used;
|
||||
short buf[] = si.vertices;
|
||||
@@ -104,7 +103,7 @@ public final class SymbolLayer extends TextureLayer {
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
|
||||
TextureObject to = TextureObject.get();
|
||||
TextureItem to = TextureItem.pool.get();
|
||||
textures = to;
|
||||
mCanvas.setBitmap(to.bitmap);
|
||||
|
||||
@@ -140,7 +139,7 @@ public final class SymbolLayer extends TextureLayer {
|
||||
offsetIndices = numIndices;
|
||||
curIndices = 0;
|
||||
|
||||
to.next = TextureObject.get();
|
||||
to.next = TextureItem.pool.get();
|
||||
to = to.next;
|
||||
|
||||
mCanvas.setBitmap(to.bitmap);
|
||||
@@ -196,9 +195,9 @@ public final class SymbolLayer extends TextureLayer {
|
||||
short tx = (short) ((int) (SCALE * it2.x) & LBIT_MASK | (it2.billboard ? 1 : 0));
|
||||
short ty = (short) (SCALE * it2.y);
|
||||
|
||||
if (pos == VertexPoolItem.SIZE) {
|
||||
si.used = VertexPoolItem.SIZE;
|
||||
si = si.next = VertexPool.get();
|
||||
if (pos == VertexItem.SIZE) {
|
||||
si.used = VertexItem.SIZE;
|
||||
si = si.next = VertexItem.pool.get();
|
||||
buf = si.vertices;
|
||||
pos = 0;
|
||||
}
|
||||
@@ -249,12 +248,12 @@ public final class SymbolLayer extends TextureLayer {
|
||||
|
||||
@Override
|
||||
protected void clear() {
|
||||
TextureObject.release(textures);
|
||||
SymbolItem.release(symbols);
|
||||
VertexPool.release(pool);
|
||||
TextureItem.pool.releaseAll(textures);
|
||||
SymbolItem.pool.releaseAll(symbols);
|
||||
VertexItem.pool.releaseAll(vertexItems);
|
||||
textures = null;
|
||||
symbols = null;
|
||||
pool = null;
|
||||
vertexItems = null;
|
||||
verticesCnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,117 +15,45 @@
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
import org.oscim.theme.renderinstruction.Text;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.oscim.utils.pool.SyncPool;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class TextItem {
|
||||
private final static String TAG = TextItem.class.getName();
|
||||
public class TextItem extends Inlist<TextItem> {
|
||||
//private final static String TAG = TextItem.class.getName();
|
||||
private final static int MAX_POOL = 250;
|
||||
|
||||
private static Object lock = new Object();
|
||||
private static TextItem pool;
|
||||
private static int count = 0;
|
||||
private static int inPool = 0;
|
||||
public final static SyncPool<TextItem> pool = new SyncPool<TextItem>(MAX_POOL) {
|
||||
|
||||
public static TextItem get() {
|
||||
synchronized (lock) {
|
||||
if (pool == null) {
|
||||
count++;
|
||||
return new TextItem();
|
||||
}
|
||||
|
||||
inPool--;
|
||||
TextItem ti = pool;
|
||||
pool = pool.next;
|
||||
|
||||
ti.next = null;
|
||||
//ti.active = 0;
|
||||
return ti;
|
||||
@Override
|
||||
protected TextItem createItem() {
|
||||
return new TextItem();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearItem(TextItem ti) {
|
||||
// drop references
|
||||
ti.string = null;
|
||||
ti.text = null;
|
||||
ti.n1 = null;
|
||||
ti.n2 = null;
|
||||
}
|
||||
};
|
||||
|
||||
public static TextItem copy(TextItem orig) {
|
||||
synchronized (lock) {
|
||||
TextItem ti = pool;
|
||||
|
||||
if (ti == null) {
|
||||
count++;
|
||||
ti = new TextItem();
|
||||
} else {
|
||||
inPool--;
|
||||
pool = pool.next;
|
||||
}
|
||||
TextItem ti = pool.get();
|
||||
|
||||
ti.next = null;
|
||||
ti.next = null;
|
||||
|
||||
ti.x = orig.x;
|
||||
ti.y = orig.y;
|
||||
ti.x = orig.x;
|
||||
ti.y = orig.y;
|
||||
|
||||
ti.x1 = orig.x1;
|
||||
ti.y1 = orig.y1;
|
||||
ti.x2 = orig.x2;
|
||||
ti.y2 = orig.y2;
|
||||
ti.x1 = orig.x1;
|
||||
ti.y1 = orig.y1;
|
||||
ti.x2 = orig.x2;
|
||||
ti.y2 = orig.y2;
|
||||
|
||||
return ti;
|
||||
}
|
||||
}
|
||||
|
||||
// public static void append(TextItem ti, TextItem in) {
|
||||
// if (ti == null)
|
||||
// return;
|
||||
// if (ti.next == null) {
|
||||
// in.next = ti.next;
|
||||
// ti.next = in;
|
||||
// }
|
||||
//
|
||||
// TextItem t = ti;
|
||||
// while (t.next != null)
|
||||
// t = t.next;
|
||||
//
|
||||
// in.next = t.next;
|
||||
// t.next = in;
|
||||
// }
|
||||
|
||||
public static void release(TextItem ti) {
|
||||
if (ti == null)
|
||||
return;
|
||||
|
||||
if (inPool > MAX_POOL) {
|
||||
while (ti != null) {
|
||||
TextItem next = ti.next;
|
||||
|
||||
// drop references
|
||||
ti.string = null;
|
||||
ti.text = null;
|
||||
ti.n1 = null;
|
||||
ti.n2 = null;
|
||||
ti = next;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (lock) {
|
||||
while (ti != null) {
|
||||
TextItem next = ti.next;
|
||||
ti.next = pool;
|
||||
|
||||
// drop references
|
||||
ti.string = null;
|
||||
ti.text = null;
|
||||
ti.n1 = null;
|
||||
ti.n2 = null;
|
||||
|
||||
pool = ti;
|
||||
|
||||
ti = next;
|
||||
|
||||
inPool++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void printPool() {
|
||||
Log.d(TAG, "in pool " + inPool + " / " + count);
|
||||
return ti;
|
||||
}
|
||||
|
||||
public TextItem set(float x, float y, String string, Text text) {
|
||||
@@ -137,33 +65,6 @@ public class TextItem {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextItem move(TextItem ti, float dx, float dy) {
|
||||
this.x = dx + ti.x;
|
||||
this.y = dy + ti.y;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public TextItem move(TextItem ti, float dx, float dy, float scale) {
|
||||
this.x = (dx + ti.x) * scale;
|
||||
this.y = (dy + ti.y) * scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void clone(TextItem ti){
|
||||
this.string = ti.string;
|
||||
this.text = ti.text;
|
||||
this.width = ti.width;
|
||||
this.length = ti.length;
|
||||
}
|
||||
|
||||
public void setAxisAlignedBBox() {
|
||||
this.x1 = x - width / 2;
|
||||
this.y1 = y - text.fontHeight / 2;
|
||||
this.x2 = x + width / 2;
|
||||
this.y2 = y + text.fontHeight / 2;
|
||||
}
|
||||
|
||||
public static boolean bboxOverlaps(TextItem it1, TextItem it2, float add) {
|
||||
if (it1.y1 < it1.y2) {
|
||||
if (it2.y1 < it2.y2)
|
||||
@@ -194,7 +95,7 @@ public class TextItem {
|
||||
}
|
||||
|
||||
// link to next node
|
||||
public TextItem next;
|
||||
//public TextItem next;
|
||||
|
||||
// center
|
||||
public float x, y;
|
||||
|
||||
@@ -14,18 +14,16 @@
|
||||
*/
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
import org.oscim.renderer.TextureObject;
|
||||
import org.oscim.renderer.TextureRenderer;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.util.Log;
|
||||
|
||||
public final class TextLayer extends TextureLayer {
|
||||
|
||||
//private static String TAG = TextureLayer.class.getName();
|
||||
|
||||
private final static int TEXTURE_WIDTH = TextureObject.TEXTURE_WIDTH;
|
||||
private final static int TEXTURE_HEIGHT = TextureObject.TEXTURE_HEIGHT;
|
||||
private final static int TEXTURE_WIDTH = TextureItem.TEXTURE_WIDTH;
|
||||
private final static int TEXTURE_HEIGHT = TextureItem.TEXTURE_HEIGHT;
|
||||
private final static float SCALE = 8.0f;
|
||||
private final static int LBIT_MASK = 0xfffffffe;
|
||||
|
||||
@@ -45,25 +43,6 @@ public final class TextLayer extends TextureLayer {
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
public boolean removeText(TextItem item) {
|
||||
|
||||
if (item == labels) {
|
||||
labels = labels.next;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (TextItem prev = labels, it = labels.next; it != null; it = it.next) {
|
||||
|
||||
if (it == item) {
|
||||
prev.next = it.next;
|
||||
return true;
|
||||
}
|
||||
prev = it;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addText(TextItem item) {
|
||||
TextItem it = labels;
|
||||
|
||||
@@ -97,13 +76,11 @@ public final class TextLayer extends TextureLayer {
|
||||
|
||||
@Override
|
||||
public boolean prepare() {
|
||||
if (TextureRenderer.debug)
|
||||
Log.d("...", "prepare");
|
||||
|
||||
short numIndices = 0;
|
||||
short offsetIndices = 0;
|
||||
|
||||
VertexPoolItem vi = pool = VertexPool.get();
|
||||
VertexItem vi = vertexItems = VertexItem.pool.get();
|
||||
int pos = vi.used; // 0
|
||||
short buf[] = vi.vertices;
|
||||
|
||||
@@ -114,7 +91,7 @@ public final class TextLayer extends TextureLayer {
|
||||
float y = 0;
|
||||
float yy;
|
||||
|
||||
TextureObject to = TextureObject.get();
|
||||
TextureItem to = TextureItem.pool.get();
|
||||
textures = to;
|
||||
mCanvas.setBitmap(to.bitmap);
|
||||
|
||||
@@ -136,7 +113,7 @@ public final class TextLayer extends TextureLayer {
|
||||
to.vertices = (short) (numIndices - offsetIndices);
|
||||
offsetIndices = numIndices;
|
||||
|
||||
to.next = TextureObject.get();
|
||||
to.next = TextureItem.pool.get();
|
||||
to = to.next;
|
||||
|
||||
mCanvas.setBitmap(to.bitmap);
|
||||
@@ -227,9 +204,9 @@ public final class TextLayer extends TextureLayer {
|
||||
short tx = (short) (tmp | (it.text.caption ? 1 : 0));
|
||||
short ty = (short) (SCALE * it.y);
|
||||
|
||||
if (pos == VertexPoolItem.SIZE) {
|
||||
vi.used = VertexPoolItem.SIZE;
|
||||
vi = vi.next = VertexPool.get();
|
||||
if (pos == VertexItem.SIZE) {
|
||||
vi.used = VertexItem.SIZE;
|
||||
vi = vi.next = VertexItem.pool.get();
|
||||
buf = vi.vertices;
|
||||
pos = 0;
|
||||
}
|
||||
@@ -288,12 +265,12 @@ public final class TextLayer extends TextureLayer {
|
||||
|
||||
@Override
|
||||
protected void clear() {
|
||||
TextureObject.release(textures);
|
||||
TextItem.release(labels);
|
||||
VertexPool.release(pool);
|
||||
TextureItem.pool.releaseAll(textures);
|
||||
TextItem.pool.releaseAll(labels);
|
||||
VertexItem.pool.releaseAll(vertexItems);
|
||||
textures = null;
|
||||
labels = null;
|
||||
pool = null;
|
||||
vertexItems = null;
|
||||
verticesCnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
200
src/org/oscim/renderer/layer/TextureItem.java
Normal file
200
src/org/oscim/renderer/layer/TextureItem.java
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright 2012, 2013 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.oscim.renderer.TextureRenderer;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.oscim.utils.pool.SyncPool;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLUtils;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* @author Hannes Janetzek
|
||||
*/
|
||||
public class TextureItem extends Inlist<TextureItem> {
|
||||
private final static String TAG = TextureItem.class.getName();
|
||||
|
||||
// texture ID
|
||||
public int id;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
||||
// vertex offset from which this texture is referenced
|
||||
public short offset;
|
||||
public short vertices;
|
||||
|
||||
// temporary Bitmap
|
||||
public Bitmap bitmap;
|
||||
|
||||
TextureItem(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public final static SyncPool<TextureItem> pool = new SyncPool<TextureItem>() {
|
||||
|
||||
@Override
|
||||
public void init(int num) {
|
||||
this.pool = null;
|
||||
|
||||
int[] textureIds = new int[num];
|
||||
GLES20.glGenTextures(num, textureIds, 0);
|
||||
|
||||
for (int i = 1; i < num; i++) {
|
||||
initTexture(textureIds[i]);
|
||||
TextureItem to = new TextureItem(textureIds[i]);
|
||||
|
||||
to.next = this.pool;
|
||||
this.pool = to;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureItem get() {
|
||||
TextureItem it = super.get();
|
||||
|
||||
it.bitmap = TextureItem.getBitmap();
|
||||
it.bitmap.eraseColor(Color.TRANSPARENT);
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextureItem createItem() {
|
||||
return new TextureItem(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearItem(TextureItem it) {
|
||||
TextureItem.releaseBitmap(it);
|
||||
}
|
||||
};
|
||||
|
||||
private static ArrayList<Bitmap> mBitmaps;
|
||||
|
||||
public final static int TEXTURE_WIDTH = 256;
|
||||
public final static int TEXTURE_HEIGHT = 256;
|
||||
|
||||
private static int mBitmapFormat;
|
||||
private static int mBitmapType;
|
||||
|
||||
/**
|
||||
* This function may only be used in GLRenderer Thread.
|
||||
*
|
||||
* @param to the TextureObjet to compile and upload
|
||||
*/
|
||||
public static void uploadTexture(TextureItem to) {
|
||||
|
||||
if (TextureRenderer.debug)
|
||||
Log.d(TAG, "upload texture " + to.id);
|
||||
|
||||
if (to.id < 0) {
|
||||
int[] textureIds = new int[1];
|
||||
GLES20.glGenTextures(1, textureIds, 0);
|
||||
to.id = textureIds[0];
|
||||
initTexture(to.id);
|
||||
|
||||
if (TextureRenderer.debug)
|
||||
Log.d(TAG, "new texture " + to.id);
|
||||
}
|
||||
|
||||
uploadTexture(to, to.bitmap, mBitmapFormat, mBitmapType,
|
||||
TEXTURE_WIDTH, TEXTURE_HEIGHT);
|
||||
|
||||
TextureItem.releaseBitmap(to);
|
||||
}
|
||||
|
||||
public static void uploadTexture(TextureItem to, Bitmap bitmap,
|
||||
int format, int type, int w, int h) {
|
||||
|
||||
if (to == null) {
|
||||
Log.d(TAG, "no texture!");
|
||||
return;
|
||||
}
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, to.id);
|
||||
if (to.width == w && to.height == h)
|
||||
GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
|
||||
else {
|
||||
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format, bitmap, type, 0);
|
||||
to.width = w;
|
||||
to.height = h;
|
||||
}
|
||||
}
|
||||
|
||||
static void initTexture(int id) {
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, id);
|
||||
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
|
||||
GLES20.GL_LINEAR);
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
|
||||
GLES20.GL_LINEAR);
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
|
||||
GLES20.GL_CLAMP_TO_EDGE); // Set U Wrapping
|
||||
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
|
||||
GLES20.GL_CLAMP_TO_EDGE); // Set V Wrapping
|
||||
}
|
||||
|
||||
public static void init(int num) {
|
||||
pool.init(num);
|
||||
|
||||
mBitmaps = new ArrayList<Bitmap>(10);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Bitmap bitmap = Bitmap.createBitmap(
|
||||
TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
|
||||
mBitmaps.add(bitmap);
|
||||
}
|
||||
|
||||
mBitmapFormat = GLUtils.getInternalFormat(mBitmaps.get(0));
|
||||
mBitmapType = GLUtils.getType(mBitmaps.get(0));
|
||||
}
|
||||
|
||||
static Bitmap getBitmap() {
|
||||
synchronized (mBitmaps) {
|
||||
|
||||
int size = mBitmaps.size();
|
||||
if (size == 0) {
|
||||
Bitmap bitmap = Bitmap.createBitmap(
|
||||
TEXTURE_WIDTH, TEXTURE_HEIGHT,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
|
||||
if (TextureRenderer.debug)
|
||||
Log.d(TAG, "alloc bitmap: " +
|
||||
android.os.Debug.getNativeHeapAllocatedSize() / (1024 * 1024));
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
return mBitmaps.remove(size - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void releaseBitmap(TextureItem it) {
|
||||
synchronized (mBitmaps) {
|
||||
|
||||
if (it.bitmap != null) {
|
||||
mBitmaps.add(it.bitmap);
|
||||
it.bitmap = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,14 +16,13 @@ package org.oscim.renderer.layer;
|
||||
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import org.oscim.renderer.TextureObject;
|
||||
|
||||
/**
|
||||
* @author Hannes Janetzek
|
||||
*/
|
||||
public abstract class TextureLayer extends Layer {
|
||||
// holds textures and offset in vbo
|
||||
public TextureObject textures;
|
||||
public TextureItem textures;
|
||||
|
||||
// scale mode
|
||||
public boolean fixed;
|
||||
@@ -35,8 +34,8 @@ public abstract class TextureLayer extends Layer {
|
||||
@Override
|
||||
protected void compile(ShortBuffer sbuf) {
|
||||
|
||||
for (TextureObject to = textures; to != null; to = to.next)
|
||||
TextureObject.uploadTexture(to);
|
||||
for (TextureItem to = textures; to != null; to = to.next)
|
||||
TextureItem.uploadTexture(to);
|
||||
|
||||
// add vertices to vbo
|
||||
Layers.addPoolItems(this, sbuf);
|
||||
|
||||
@@ -14,11 +14,29 @@
|
||||
*/
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
public class VertexPoolItem {
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.oscim.utils.pool.SyncPool;
|
||||
|
||||
public class VertexItem extends Inlist<VertexItem> {
|
||||
|
||||
private static final int MAX_POOL = 500;
|
||||
|
||||
public final static SyncPool<VertexItem> pool = new SyncPool<VertexItem>(MAX_POOL) {
|
||||
|
||||
@Override
|
||||
protected VertexItem createItem() {
|
||||
return new VertexItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearItem(VertexItem it) {
|
||||
it.used = 0;
|
||||
}
|
||||
};
|
||||
|
||||
public final short[] vertices = new short[SIZE];
|
||||
|
||||
public int used;
|
||||
public VertexPoolItem next;
|
||||
|
||||
// must be multiple of
|
||||
// 4 (LineLayer/PolygonLayer),
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class VertexPool {
|
||||
private static final int POOL_LIMIT = 5000;
|
||||
|
||||
static private VertexPoolItem pool = null;
|
||||
static private int count = 0;
|
||||
static private int countAll = 0;
|
||||
|
||||
public static synchronized void init() {
|
||||
count = 0;
|
||||
countAll = 0;
|
||||
pool = null;
|
||||
}
|
||||
|
||||
public static VertexPoolItem getNext(VertexPoolItem prev) {
|
||||
VertexPoolItem it = get();
|
||||
if (prev != null) {
|
||||
prev.next = it;
|
||||
prev.used = VertexPoolItem.SIZE;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
public static synchronized VertexPoolItem get() {
|
||||
|
||||
if (pool == null && count > 0) {
|
||||
Log.d("VertexPool", "BUG wrong count: " + count);
|
||||
}
|
||||
if (pool == null) {
|
||||
countAll++;
|
||||
return new VertexPoolItem();
|
||||
}
|
||||
|
||||
count--;
|
||||
|
||||
if (count < 0) {
|
||||
int c = 0;
|
||||
|
||||
for (VertexPoolItem tmp = pool; tmp != null; tmp = tmp.next)
|
||||
c++;
|
||||
|
||||
Log.d("VertexPool", "BUG wrong count: " + count + " left" + c);
|
||||
return new VertexPoolItem();
|
||||
}
|
||||
|
||||
VertexPoolItem it = pool;
|
||||
pool = pool.next;
|
||||
it.used = 0;
|
||||
it.next = null;
|
||||
return it;
|
||||
}
|
||||
|
||||
public static synchronized void release(VertexPoolItem items) {
|
||||
if (items == null)
|
||||
return;
|
||||
|
||||
// limit pool items
|
||||
if (countAll < POOL_LIMIT) {
|
||||
|
||||
VertexPoolItem last = items;
|
||||
|
||||
while (true) {
|
||||
count++;
|
||||
|
||||
if (last.next == null)
|
||||
break;
|
||||
|
||||
last = last.next;
|
||||
}
|
||||
|
||||
last.next = pool;
|
||||
pool = items;
|
||||
|
||||
} else {
|
||||
VertexPoolItem prev, tmp = items;
|
||||
while (tmp != null) {
|
||||
prev = tmp;
|
||||
tmp = tmp.next;
|
||||
|
||||
countAll--;
|
||||
prev.next = null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user