add osmdroid overlays + bonuspack
This commit is contained in:
@@ -35,6 +35,5 @@ public abstract class Layer {
|
||||
VertexPoolItem pool;
|
||||
protected VertexPoolItem curItem;
|
||||
|
||||
protected void clear() {
|
||||
}
|
||||
abstract protected void clear();
|
||||
}
|
||||
|
||||
@@ -118,6 +118,10 @@ public class Layers {
|
||||
TextureLayer sl = (TextureLayer) l;
|
||||
sl.compile(sbuf);
|
||||
}
|
||||
|
||||
// FIXME
|
||||
addLayerItems(sbuf, textureLayers, Layer.SYMBOL, 0);
|
||||
|
||||
}
|
||||
|
||||
private static void addLayerItems(ShortBuffer sbuf, Layer l, byte type, int pos) {
|
||||
@@ -162,14 +166,22 @@ public class Layers {
|
||||
layers = layers.next;
|
||||
}
|
||||
|
||||
while (textureLayers != null) {
|
||||
textureLayers.clear();
|
||||
Layer l = textureLayers;
|
||||
while (l != null) {
|
||||
|
||||
// TextureLayer sl = (TextureLayer) textureLayers;
|
||||
// if (sl.textures != null)
|
||||
// TextureObject.release(sl.textures);
|
||||
l.clear();
|
||||
|
||||
textureLayers = textureLayers.next;
|
||||
if (l.pool != null) {
|
||||
VertexPool.release(l.pool);
|
||||
l.pool = null;
|
||||
l.curItem = null;
|
||||
}
|
||||
|
||||
// if (l instanceof TextLayer)
|
||||
// ((TextLayer) l).clear();
|
||||
|
||||
l = l.next;
|
||||
}
|
||||
textureLayers = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,11 +49,18 @@ public final class LineLayer extends Layer {
|
||||
outlines = link;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* line extrusion is based on code from GLMap
|
||||
* (https://github.com/olofsj/GLMap/) by olofsj
|
||||
*
|
||||
* @param points
|
||||
* array of points as float x_n = i, y_n = i+1
|
||||
* @param index
|
||||
* array of line indices holding the length of the individual
|
||||
* lines
|
||||
* @param closed
|
||||
* whether to connect start- and end-point
|
||||
*/
|
||||
|
||||
public void addLine(float[] points, short[] index, boolean closed) {
|
||||
float x, y, nextX, nextY, prevX, prevY;
|
||||
float a, ux, uy, vx, vy, wx, wy;
|
||||
@@ -83,7 +90,7 @@ public final class LineLayer extends Layer {
|
||||
if (length < 0)
|
||||
break;
|
||||
|
||||
// save some vertices
|
||||
// Note: just a hack to save some vertices
|
||||
if (rounded && i > 200)
|
||||
rounded = false;
|
||||
|
||||
@@ -520,4 +527,8 @@ public final class LineLayer extends Layer {
|
||||
si.used = opos;
|
||||
curItem = si;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clear() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,4 +87,7 @@ public final class PolygonLayer extends Layer {
|
||||
curItem = si;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clear() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,55 @@
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class SymbolItem {
|
||||
private static Object lock = new Object();
|
||||
private static SymbolItem pool;
|
||||
|
||||
public static SymbolItem get() {
|
||||
synchronized (lock) {
|
||||
if (pool == null)
|
||||
return new SymbolItem();
|
||||
|
||||
SymbolItem ti = pool;
|
||||
pool = pool.next;
|
||||
|
||||
ti.next = null;
|
||||
|
||||
return ti;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SymbolItem next;
|
||||
|
||||
public Bitmap bitmap;
|
||||
public Drawable drawable;
|
||||
public float x;
|
||||
public float y;
|
||||
public boolean billboard;
|
||||
public int state;
|
||||
|
||||
// center, top, bottom, left, right, top-left...
|
||||
byte placement;
|
||||
// byte placement;
|
||||
|
||||
}
|
||||
|
||||
@@ -20,34 +20,37 @@ import org.oscim.renderer.TextureObject;
|
||||
import org.oscim.renderer.TextureRenderer;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
|
||||
// TODO share one static texture for all poi map symabols
|
||||
|
||||
public final class SymbolLayer extends TextureLayer {
|
||||
private static String TAG = SymbolLayer.class.getSimpleName();
|
||||
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 float SCALE = 8.0f;
|
||||
|
||||
private static short[] mVertices;
|
||||
|
||||
SymbolItem symbols;
|
||||
|
||||
private Canvas mCanvas;
|
||||
private Rect mRect = new Rect();
|
||||
|
||||
public SymbolLayer() {
|
||||
if (mVertices == null)
|
||||
mVertices = new short[TextureRenderer.MAX_ITEMS * 24];
|
||||
type = Layer.SYMBOL;
|
||||
fixed = true;
|
||||
mCanvas = new Canvas();
|
||||
}
|
||||
|
||||
public void addSymbol(SymbolItem item) {
|
||||
|
||||
verticesCnt += 4;
|
||||
|
||||
SymbolItem it = symbols;
|
||||
|
||||
for (; it != null; it = it.next) {
|
||||
for (SymbolItem it = symbols; it != null; it = it.next) {
|
||||
if (it.bitmap == item.bitmap) {
|
||||
// insert after same bitmap
|
||||
item.next = it.next;
|
||||
it.next = item;
|
||||
return;
|
||||
@@ -58,30 +61,77 @@ public final class SymbolLayer extends TextureLayer {
|
||||
symbols = item;
|
||||
}
|
||||
|
||||
public void addDrawable(Drawable drawable, int state, float x, float y) {
|
||||
|
||||
verticesCnt += 4;
|
||||
|
||||
SymbolItem item = SymbolItem.get();
|
||||
item.drawable = drawable;
|
||||
item.x = x;
|
||||
item.y = y;
|
||||
item.billboard = true;
|
||||
item.state = state;
|
||||
|
||||
for (SymbolItem it = symbols; it != null; it = it.next) {
|
||||
if (it.drawable == item.drawable && it.state == item.state) {
|
||||
// insert after same drawable
|
||||
item.next = it.next;
|
||||
it.next = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
item.next = symbols;
|
||||
symbols = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
void compile(ShortBuffer sbuf) {
|
||||
if (TextureRenderer.debug)
|
||||
Log.d("...", "compile");
|
||||
|
||||
for (TextureObject to = textures; to != null; to = to.next)
|
||||
TextureObject.uploadTexture(to);
|
||||
}
|
||||
|
||||
private final static int LBIT_MASK = 0xfffffffe;
|
||||
|
||||
// TODO ... reuse texture when only symbol position changed
|
||||
@Override
|
||||
public void compile(ShortBuffer sbuf) {
|
||||
public boolean prepare() {
|
||||
|
||||
short numIndices = 0;
|
||||
short offsetIndices = 0;
|
||||
short curIndices = 0;
|
||||
|
||||
int pos = 0;
|
||||
short buf[] = mVertices;
|
||||
int bufLen = buf.length;
|
||||
curItem = VertexPool.get();
|
||||
pool = curItem;
|
||||
VertexPoolItem si = curItem;
|
||||
|
||||
int pos = si.used;
|
||||
short buf[] = si.vertices;
|
||||
|
||||
int advanceY = 0;
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
|
||||
Canvas canvas = TextureObject.getCanvas();
|
||||
TextureObject to = TextureObject.get();
|
||||
textures = to;
|
||||
mCanvas.setBitmap(to.bitmap);
|
||||
|
||||
int maxIndices = TextureRenderer.MAX_ITEMS * TextureRenderer.INDICES_PER_SPRITE;
|
||||
|
||||
for (SymbolItem it = symbols; it != null;) {
|
||||
float width, height;
|
||||
|
||||
// add bitmap
|
||||
float width = it.bitmap.getWidth();
|
||||
float height = it.bitmap.getHeight();
|
||||
if (it.bitmap != null) {
|
||||
// add bitmap
|
||||
width = it.bitmap.getWidth();
|
||||
height = it.bitmap.getHeight();
|
||||
} else {
|
||||
width = it.drawable.getIntrinsicWidth();
|
||||
height = it.drawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
if (height > advanceY)
|
||||
advanceY = (int) height;
|
||||
@@ -91,43 +141,67 @@ public final class SymbolLayer extends TextureLayer {
|
||||
y += advanceY;
|
||||
advanceY = (int) (height + 0.5f);
|
||||
|
||||
if (y + height > TEXTURE_HEIGHT) {
|
||||
Log.d(TAG, "reached max symbols");
|
||||
|
||||
TextureObject to = TextureObject.uploadCanvas(offsetIndices, numIndices);
|
||||
offsetIndices = numIndices;
|
||||
|
||||
to.next = textures;
|
||||
textures = to;
|
||||
|
||||
sbuf.put(buf, 0, pos);
|
||||
pos = 0;
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
advanceY = (int) height;
|
||||
}
|
||||
}
|
||||
|
||||
canvas.drawBitmap(it.bitmap, x, y, null);
|
||||
if (y + height > TEXTURE_HEIGHT || curIndices == maxIndices) {
|
||||
Log.d(TAG, "reached max symbols: " + numIndices);
|
||||
|
||||
float hw = width / 2.0f;
|
||||
float hh = height / 2.0f;
|
||||
to.offset = offsetIndices;
|
||||
to.vertices = curIndices;
|
||||
|
||||
short x1 = (short) (SCALE * (-hw));
|
||||
short x2 = (short) (SCALE * (hw));
|
||||
short y1 = (short) (SCALE * (hh));
|
||||
short y2 = (short) (SCALE * (-hh));
|
||||
numIndices += curIndices;
|
||||
offsetIndices = numIndices;
|
||||
curIndices = 0;
|
||||
|
||||
to.next = TextureObject.get();
|
||||
to = to.next;
|
||||
|
||||
mCanvas.setBitmap(to.bitmap);
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
advanceY = (int) height;
|
||||
}
|
||||
|
||||
if (it.bitmap != null) {
|
||||
mCanvas.drawBitmap(it.bitmap, x, y, null);
|
||||
} else {
|
||||
it.drawable.copyBounds(mRect);
|
||||
it.drawable.setBounds((int) x, (int) y, (int) (x + width), (int) (y + height));
|
||||
it.drawable.draw(mCanvas);
|
||||
it.drawable.setBounds(mRect);
|
||||
}
|
||||
|
||||
short x1, y1, x2, y2;
|
||||
|
||||
if (it.bitmap != null) {
|
||||
float hw = width / 2.0f;
|
||||
float hh = height / 2.0f;
|
||||
x1 = (short) (SCALE * (-hw));
|
||||
x2 = (short) (SCALE * (hw));
|
||||
y1 = (short) (SCALE * (hh));
|
||||
y2 = (short) (SCALE * (-hh));
|
||||
} else {
|
||||
// use drawable offsets (for marker hotspot)
|
||||
x2 = (short) (SCALE * (mRect.left));
|
||||
y2 = (short) (SCALE * (mRect.top));
|
||||
x1 = (short) (SCALE * (mRect.right));
|
||||
y1 = (short) (SCALE * (mRect.bottom));
|
||||
|
||||
}
|
||||
|
||||
short u1 = (short) (SCALE * x);
|
||||
short v1 = (short) (SCALE * y);
|
||||
short u2 = (short) (SCALE * (x + width));
|
||||
short v2 = (short) (SCALE * (y + height));
|
||||
|
||||
// add symbol items referencing the same bitmap
|
||||
// add symbol items referencing the same bitmap / drawable
|
||||
for (SymbolItem it2 = it;; it2 = it2.next) {
|
||||
|
||||
if (it2 == null || it2.bitmap != it.bitmap) {
|
||||
if (it2 == null
|
||||
// || (curIndices == maxIndices)
|
||||
|| (it.drawable != null && it2.drawable != it.drawable)
|
||||
|| (it.bitmap != null && it2.bitmap != it.bitmap)) {
|
||||
it = it2;
|
||||
break;
|
||||
}
|
||||
@@ -166,24 +240,41 @@ public final class SymbolLayer extends TextureLayer {
|
||||
buf[pos++] = v1;
|
||||
|
||||
// six elements used to draw the four vertices
|
||||
numIndices += 6;
|
||||
curIndices += TextureRenderer.INDICES_PER_SPRITE;
|
||||
|
||||
if (pos == VertexPoolItem.SIZE) {
|
||||
si.used = VertexPoolItem.SIZE;
|
||||
si = si.next = VertexPool.get();
|
||||
buf = si.vertices;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
// FIXME this does not work, need to draw bitmap on next
|
||||
// texture...
|
||||
if (pos == bufLen) {
|
||||
sbuf.put(buf, 0, pos);
|
||||
pos = 0;
|
||||
}
|
||||
// if (pos == bufLen) {
|
||||
// sbuf.put(buf, 0, pos);
|
||||
// pos = 0;
|
||||
// }
|
||||
|
||||
x += width;
|
||||
}
|
||||
}
|
||||
|
||||
TextureObject to = TextureObject.uploadCanvas(offsetIndices, numIndices);
|
||||
to.offset = offsetIndices;
|
||||
to.vertices = curIndices;
|
||||
|
||||
to.next = textures;
|
||||
textures = to;
|
||||
si.used = pos;
|
||||
curItem = si;
|
||||
|
||||
sbuf.put(buf, 0, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clear() {
|
||||
TextureObject.release(textures);
|
||||
SymbolItem.release(symbols);
|
||||
textures = null;
|
||||
symbols = null;
|
||||
verticesCnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@ public class TextItem {
|
||||
|
||||
TextItem ti = pool;
|
||||
pool = pool.next;
|
||||
|
||||
ti.next = null;
|
||||
|
||||
return ti;
|
||||
}
|
||||
}
|
||||
@@ -73,5 +75,6 @@ public class TextItem {
|
||||
public Text text;
|
||||
public float width;
|
||||
public short x1, y1, x2, y2;
|
||||
|
||||
// public byte placement
|
||||
}
|
||||
|
||||
@@ -25,26 +25,28 @@ import android.util.Log;
|
||||
|
||||
public final class TextLayer extends TextureLayer {
|
||||
|
||||
private static String TAG = TextureLayer.class.getSimpleName();
|
||||
// private static String TAG = TextureLayer.class.getSimpleName();
|
||||
|
||||
private final static int TEXTURE_WIDTH = TextureObject.TEXTURE_WIDTH;
|
||||
private final static int TEXTURE_HEIGHT = TextureObject.TEXTURE_HEIGHT;
|
||||
private final static float SCALE = 8.0f;
|
||||
private final static int LBIT_MASK = 0xfffffffe;
|
||||
|
||||
private static short[] mVertices;
|
||||
private static int mFontPadX = 1;
|
||||
private static int mFontPadY = 1;
|
||||
|
||||
TextItem labels;
|
||||
|
||||
private Canvas mCanvas;
|
||||
|
||||
public TextItem getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public TextLayer() {
|
||||
if (mVertices == null)
|
||||
mVertices = new short[TextureRenderer.MAX_ITEMS * 24];
|
||||
type = Layer.SYMBOL;
|
||||
mCanvas = new Canvas();
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
public void addText(TextItem item) {
|
||||
@@ -53,8 +55,10 @@ public final class TextLayer extends TextureLayer {
|
||||
|
||||
for (; it != null; it = it.next) {
|
||||
if (it.text == item.text) {
|
||||
// insert after text of same type
|
||||
item.next = it.next;
|
||||
it.next = item;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -64,24 +68,44 @@ public final class TextLayer extends TextureLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(ShortBuffer sbuf) {
|
||||
int numLabel = 0;
|
||||
void compile(ShortBuffer sbuf) {
|
||||
if (TextureRenderer.debug)
|
||||
Log.d("...", "compile");
|
||||
|
||||
for (TextureObject to = textures; to != null; to = to.next)
|
||||
TextureObject.uploadTexture(to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepare() {
|
||||
if (TextureRenderer.debug)
|
||||
Log.d("...", "prepare");
|
||||
|
||||
// int numLabel = 0;
|
||||
// int numTextures = 0;
|
||||
|
||||
short numIndices = 0;
|
||||
short offsetIndices = 0;
|
||||
|
||||
int pos = 0;
|
||||
short buf[] = mVertices;
|
||||
int bufLen = buf.length;
|
||||
curItem = VertexPool.get();
|
||||
pool = curItem;
|
||||
|
||||
VertexPoolItem si = curItem;
|
||||
|
||||
int pos = si.used;
|
||||
short buf[] = si.vertices;
|
||||
|
||||
int advanceY = 0;
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float yy;
|
||||
|
||||
Canvas canvas = TextureObject.getCanvas();
|
||||
TextureObject to = TextureObject.get();
|
||||
textures = to;
|
||||
mCanvas.setBitmap(to.bitmap);
|
||||
|
||||
for (TextItem it = labels; it != null; it = it.next) {
|
||||
numLabel++;
|
||||
// numLabel++;
|
||||
|
||||
float width = it.width + 2 * mFontPadX;
|
||||
float height = (int) (it.text.fontHeight) + 2 * mFontPadY + 0.5f;
|
||||
@@ -99,33 +123,27 @@ public final class TextLayer extends TextureLayer {
|
||||
// numLabel + " "
|
||||
// + ((numIndices - offsetIndices) / 6));
|
||||
|
||||
// need to sync bitmap upload somehow???
|
||||
TextureObject to = TextureObject.uploadCanvas(offsetIndices, numIndices);
|
||||
to.offset = offsetIndices;
|
||||
to.vertices = (short) (numIndices - offsetIndices);
|
||||
offsetIndices = numIndices;
|
||||
|
||||
to.next = textures;
|
||||
textures = to;
|
||||
to.next = TextureObject.get();
|
||||
to = to.next;
|
||||
|
||||
sbuf.put(buf, 0, pos);
|
||||
pos = 0;
|
||||
mCanvas.setBitmap(to.bitmap);
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
advanceY = (int) height;
|
||||
|
||||
// clear bitmap, TODO rotate two canvas to reduce the chance
|
||||
// of having upload lock draing to the canvas?
|
||||
canvas = TextureObject.getCanvas();
|
||||
// numTextures++;
|
||||
}
|
||||
}
|
||||
|
||||
yy = y + (height - 1) - it.text.fontDescent - mFontPadY;
|
||||
|
||||
if (it.text.stroke != null)
|
||||
canvas.drawText(it.string, x + it.width / 2, yy, it.text.stroke);
|
||||
mCanvas.drawText(it.string, x + it.width / 2, yy, it.text.stroke);
|
||||
|
||||
canvas.drawText(it.string, x + it.width / 2, yy, it.text.paint);
|
||||
mCanvas.drawText(it.string, x + it.width / 2, yy, it.text.paint);
|
||||
|
||||
// FIXME !!!
|
||||
if (width > TEXTURE_WIDTH)
|
||||
@@ -207,30 +225,41 @@ public final class TextLayer extends TextureLayer {
|
||||
// six indices to draw the four vertices
|
||||
numIndices += 6;
|
||||
|
||||
// FIXME this does not work, need to draw bitmap on next
|
||||
// texture...
|
||||
if (pos == bufLen) {
|
||||
Log.d(TAG, "--- reached max label per texture " + numLabel);
|
||||
sbuf.put(buf, 0, pos);
|
||||
if (pos == VertexPoolItem.SIZE) {
|
||||
si.used = VertexPoolItem.SIZE;
|
||||
si = si.next = VertexPool.get();
|
||||
buf = si.vertices;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
// FIXME this does not work, need to draw bitmap on next
|
||||
// texture...
|
||||
// if (numLabel == TextureRenderer.MAX_ITEMS) {
|
||||
// Log.d(TAG, "--- reached max label per texture " + numLabel);
|
||||
// sbuf.put(buf, 0, pos);
|
||||
// pos = 0;
|
||||
// }
|
||||
|
||||
x += width;
|
||||
}
|
||||
|
||||
TextureObject to = TextureObject.uploadCanvas(offsetIndices, numIndices);
|
||||
to.offset = offsetIndices;
|
||||
to.vertices = (short) (numIndices - offsetIndices);
|
||||
|
||||
to.next = textures;
|
||||
textures = to;
|
||||
|
||||
sbuf.put(buf, 0, pos);
|
||||
si.used = pos;
|
||||
curItem = si;
|
||||
|
||||
// Log.d(TAG, "added labels " + numTextures + " " + numLabel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clear() {
|
||||
TextureObject.release(textures);
|
||||
TextItem.release(labels);
|
||||
textures = null;
|
||||
labels = null;
|
||||
verticesCnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@ import org.oscim.renderer.TextureObject;
|
||||
|
||||
public abstract class TextureLayer extends Layer {
|
||||
public TextureObject textures;
|
||||
public boolean fixed;
|
||||
|
||||
/**
|
||||
* @param sbuf
|
||||
* buffer to add vertices
|
||||
*/
|
||||
void compile(ShortBuffer sbuf) {
|
||||
}
|
||||
abstract void compile(ShortBuffer sbuf);
|
||||
|
||||
abstract public boolean prepare();
|
||||
}
|
||||
|
||||
@@ -15,15 +15,12 @@
|
||||
package org.oscim.renderer.layer;
|
||||
|
||||
public class VertexPoolItem {
|
||||
final short[] vertices;
|
||||
final short[] vertices = new short[SIZE];
|
||||
|
||||
int used;
|
||||
VertexPoolItem next;
|
||||
|
||||
VertexPoolItem() {
|
||||
vertices = new short[SIZE];
|
||||
used = 0;
|
||||
}
|
||||
|
||||
// must be multiple of 4 (expected in LineLayer/PolygonLayer)
|
||||
static final int SIZE = 256;
|
||||
// and 24 (Texture Layer)
|
||||
static final int SIZE = 360;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user