- rename class Tiles -> TileSet

- cleanup + comments
This commit is contained in:
Hannes Janetzek 2012-11-24 19:37:33 +01:00
parent 64c56ce7df
commit 3dc36e108a
8 changed files with 77 additions and 98 deletions

View File

@ -98,7 +98,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
// happens rarely, unless you live on Fidschi
/* package */static int mHolderCount;
/* package */static Tiles mDrawTiles;
/* package */static TileSet mDrawTiles;
static boolean[] vertexArray = { false, false };
@ -142,20 +142,17 @@ public class GLRenderer implements GLSurfaceView.Renderer {
else
xx = x - xmax;
if (xx < 0 || xx >= xmax) {
// Log.d(TAG, "out of bounds " + y + " " + x + "/" + xx);
if (xx < 0 || xx >= xmax)
continue;
}
for (int i = cnt; i < cnt + mHolderCount; i++)
if (tiles[i].tileX == x && tiles[i].tileY == y) {
found = true;
break;
}
if (found) {
// Log.d(TAG, "already added " + y + " " + x + "/" + xx);
if (found)
continue;
}
for (int i = 0; i < cnt; i++)
if (tiles[i].tileX == xx && tiles[i].tileY == y) {
@ -163,10 +160,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
break;
}
if (tile == null) {
// Log.d(TAG, "not found " + y + " " + x + "/" + xx);
if (tile == null)
continue;
}
holder = new MapTile(x, y, mZoom);
holder.isVisible = true;
@ -211,17 +206,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
shortBuffer[i] = bbuf.asShortBuffer();
shortBuffer[i].put(mFillCoords, 0, 8);
}
// overlays = new ArrayList<RenderOverlay>();
// mOverlays.add(new OverlayGrid(mapView));
// mOverlays.add(new OverlayTest(mapView));
// overlays.add(new OverlayText(mapView));
}
// private static ArrayList<RenderOverlay> overlays;
public static void setRenderTheme(RenderTheme t) {
mClearColor = GlUtils.colorToFloat(t.getMapBackground());
mUpdateColor = true;
@ -233,7 +219,6 @@ public class GLRenderer implements GLSurfaceView.Renderer {
int newSize = layers.getSize();
if (newSize == 0) {
// FIXME why are there so many tiles empty?
// Log.d(TAG, "empty");
return true;
}
@ -252,7 +237,6 @@ public class GLRenderer implements GLSurfaceView.Renderer {
if (addFill)
newSize += 8;
// probably not a good idea to do this in gl thread...
if (sbuf.capacity() < newSize) {
sbuf = ByteBuffer
.allocateDirect(newSize * SHORT_BYTES)
@ -260,16 +244,15 @@ public class GLRenderer implements GLSurfaceView.Renderer {
.asShortBuffer();
shortBuffer[curBuffer] = sbuf;
if (addFill)
sbuf.put(mFillCoords, 0, 8);
} else {
sbuf.clear();
if (addFill)
sbuf.put(mFillCoords, 0, 8);
// if (addFill)
// sbuf.position(8);
}
if (addFill)
sbuf.put(mFillCoords, 0, 8);
layers.compile(sbuf, addFill);
sbuf.flip();
@ -279,8 +262,6 @@ public class GLRenderer implements GLSurfaceView.Renderer {
+ sbuf.position() + " "
+ sbuf.limit() + " "
+ sbuf.remaining());
// tile.newData = false;
return false;
}
newSize *= SHORT_BYTES;
@ -291,10 +272,10 @@ public class GLRenderer implements GLSurfaceView.Renderer {
&& mBufferMemoryUsage < LIMIT_BUFFERS) {
GLES20.glBufferSubData(GL_ARRAY_BUFFER, 0, newSize, sbuf);
} else {
mBufferMemoryUsage -= vbo.size;
mBufferMemoryUsage += newSize - vbo.size;
vbo.size = newSize;
GLES20.glBufferData(GL_ARRAY_BUFFER, vbo.size, sbuf, GL_DYNAMIC_DRAW);
mBufferMemoryUsage += vbo.size;
//mBufferMemoryUsage += vbo.size;
}
return true;
@ -303,7 +284,9 @@ public class GLRenderer implements GLSurfaceView.Renderer {
private static boolean uploadTileData(MapTile tile) {
if (tile.layers != null) {
tile.isReady = uploadLayers(tile.layers, tile.vbo, true);
if (!tile.isReady) {
Log.d(TAG, "uploadTileData " + tile + " is empty!");
tile.layers.clear();
tile.layers = null;
}
@ -466,11 +449,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
tileCnt += mHolderCount;
// Log.d(TAG, "visible: " + tileCnt);
/* compile layer data and upload to VBOs */
uploadCnt = 0;
// compile data and upload to VBOsi
for (int i = 0; i < tileCnt; i++) {
MapTile tile = tiles[i];
@ -514,15 +494,15 @@ public class GLRenderer implements GLSurfaceView.Renderer {
tilesChanged |= (uploadCnt > 0);
// update overlays
/* update overlays */
List<RenderOverlay> overlays = mMapView.getOverlayManager().getRenderLayers();
for (int i = 0, n = overlays.size(); i < n; i++)
overlays.get(i).update(mMapPosition, changed, tilesChanged);
/* draw base layer */
GLES20.glEnable(GL_DEPTH_TEST);
GLES20.glEnable(GL_POLYGON_OFFSET_FILL);
mDrawCount = 0;
for (int i = 0; i < tileCnt; i++) {
@ -543,11 +523,9 @@ public class GLRenderer implements GLSurfaceView.Renderer {
GLES20.glDisable(GL_POLYGON_OFFSET_FILL);
GLES20.glDisable(GL_DEPTH_TEST);
// Log.d(TAG, "tiles: " + mDrawCount);
mDrawSerial++;
/* draw overlays */
GLES20.glEnable(GL_BLEND);
// call overlay renderer
@ -599,9 +577,6 @@ public class GLRenderer implements GLSurfaceView.Renderer {
mapPosition.viewMatrix, 0);
PolygonRenderer.debugDraw(mMVPMatrix, mDebugCoords, 1);
}
// mMapView.getOverlayManager().onUpdate(mMapPosition);
}
// used to not draw a tile twice per frame.
@ -732,13 +707,11 @@ public class GLRenderer implements GLSurfaceView.Renderer {
if (width <= 0 || height <= 0)
return;
// boolean changed = true;
// if (mWidth == width || mHeight == height)
// changed = false;
mWidth = width;
mHeight = height;
GLES20.glScissor(0, 0, mWidth, mHeight);
float s = MapViewPosition.VIEW_SCALE;
float aspect = mHeight / (float) mWidth;
@ -802,8 +775,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
TextureRenderer.init();
TextureObject.init(10);
// glEnable(GL_SCISSOR_TEST);
// glScissor(0, 0, mWidth, mHeight);
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
GLES20.glClearStencil(0);
GLES20.glDisable(GLES20.GL_CULL_FACE);
GLES20.glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

View File

@ -90,20 +90,20 @@ public final class LineRenderer {
GLES20.glUseProgram(lineProgram[mode]);
int va = hLineVertexPosition[mode];
//if (!GLRenderer.vertexArray[va]) {
GLES20.glEnableVertexAttribArray(va);
// int va = hLineVertexPosition[mode];
// if (!GLRenderer.vertexArray[va]) {
// GLES20.glEnableVertexAttribArray(va);
// GLRenderer.vertexArray[va] = true;
//}
// }
va = hLineTexturePosition[mode];
//if (!GLRenderer.vertexArray[va]) {
GLES20.glEnableVertexAttribArray(va);
// va = hLineTexturePosition[mode];
// if (!GLRenderer.vertexArray[va]) {
// GLES20.glEnableVertexAttribArray(va);
// GLRenderer.vertexArray[va] = true;
//}
// }
// GLES20.glEnableVertexAttribArray(hLineVertexPosition[mode]);
// GLES20.glEnableVertexAttribArray(hLineTexturePosition[mode]);
GLES20.glEnableVertexAttribArray(hLineVertexPosition[mode]);
GLES20.glEnableVertexAttribArray(hLineTexturePosition[mode]);
GLES20.glVertexAttribPointer(hLineVertexPosition[mode], 2, GLES20.GL_SHORT,
false, 8, bufferOffset + LINE_VERTICES_DATA_POS_OFFSET);

View File

@ -102,15 +102,16 @@ public final class PolygonRenderer {
f = 1.0f;
}
f *= l.area.color[3];
if (!blend) {
glEnable(GL_BLEND);
blend = true;
}
if (f != 1) {
f *= l.area.color[3];
GlUtils.setColor(hPolygonColor, l.area.color, f);
} else {
glUniform4fv(hPolygonColor, 1, l.area.color, 0);
}
} else if (l.area.blend == zoom) {
/* blend colors */
f = scale - 1.0f;
@ -168,17 +169,18 @@ public final class PolygonRenderer {
glUseProgram(polygonProgram);
int va = hPolygonVertexPosition;
//if (!GLRenderer.vertexArray[va]) {
GLES20.glEnableVertexAttribArray(va);
// int va = hPolygonVertexPosition;
// if (!GLRenderer.vertexArray[va]) {
// GLES20.glEnableVertexAttribArray(va);
// GLRenderer.vertexArray[va] = true;
//}
//va = va == 0 ? 1 : 0;
//if (GLRenderer.vertexArray[va]) {
// }
// va = va == 0 ? 1 : 0;
// if (GLRenderer.vertexArray[va]) {
// GLES20.glDisableVertexAttribArray(va);
// GLRenderer.vertexArray[va] = false;
//}
// GLES20.glEnableVertexAttribArray(hPolygonVertexPosition);
// }
GLES20.glEnableVertexAttribArray(hPolygonVertexPosition);
glVertexAttribPointer(hPolygonVertexPosition, 2, GLES20.GL_SHORT,
false, 0, POLYGON_VERTICES_DATA_POS_OFFSET);

View File

@ -61,8 +61,8 @@ public class TileManager {
static int mUpdateCnt;
static Object tilelock = new Object();
static Tiles mCurrentTiles;
/* package */static Tiles mNewTiles;
static TileSet mCurrentTiles;
/* package */static TileSet mNewTiles;
static int tileCounter;
@ -191,8 +191,8 @@ public class TileManager {
int num = Math.max(mWidth, mHeight);
int size = Tile.TILE_SIZE >> 1;
int numTiles = (num * num) / (size * size) * 4;
mNewTiles = new Tiles(numTiles);
mCurrentTiles = new Tiles(numTiles);
mNewTiles = new TileSet(numTiles);
mCurrentTiles = new TileSet(numTiles);
GLRenderer.drawlock.unlock();
@ -239,7 +239,7 @@ public class TileManager {
}
}
public static Tiles getActiveTiles(Tiles td) {
public static TileSet getActiveTiles(TileSet td) {
if (mCurrentTiles == null)
return td;
@ -258,7 +258,7 @@ public class TileManager {
MapTile[] nextTiles;
if (td == null) {
td = new Tiles(newTiles.length);
td = new TileSet(newTiles.length);
} else if (td.serial > mUpdateCnt) {
Log.d(TAG, "ignore previous tile data " + td.cnt);
// tile data was cleared, ignore tiles
@ -280,7 +280,7 @@ public class TileManager {
return td;
}
// public void releaseTiles(Tiles tiles) {
// public void releaseTiles(TileSet tiles) {
//
// }
@ -332,7 +332,7 @@ public class TileManager {
for (int i = 0, n = mCurrentTiles.cnt; i < n; i++)
curTiles[i].unlock();
Tiles tmp = mCurrentTiles;
TileSet tmp = mCurrentTiles;
mCurrentTiles = mNewTiles;
mNewTiles = tmp;

View File

@ -15,20 +15,20 @@
package org.oscim.renderer;
/**
* use with TileManager.getActiveTiles(Tiles) to get the current tiles. tiles
* use with TileManager.getActiveTiles(TileSet) to get the current tiles. tiles
* are locked to not be modifed until getActiveTiles passes them back on a
* second invocation or TODO: implement TileManager.releaseTiles(Tiles).
* second invocation or TODO: implement TileManager.releaseTiles(TileSet).
*/
public final class Tiles {
public final class TileSet {
public int cnt = 0;
public MapTile[] tiles;
int serial;
Tiles() {
TileSet() {
}
Tiles(int numTiles) {
TileSet(int numTiles) {
tiles = new MapTile[numTiles];
}
}

View File

@ -28,6 +28,7 @@ public class Layers {
private Layer mCurLayer;
// get or add the line- or polygon-layer for a level.
public Layer getLayer(int level, byte type) {
Layer l = layers;
Layer ret = null;
@ -177,9 +178,6 @@ public class Layers {
l.curItem = null;
}
// if (l instanceof TextLayer)
// ((TextLayer) l).clear();
l = l.next;
}
textureLayers = null;

View File

@ -20,7 +20,7 @@ import org.oscim.core.Tile;
import org.oscim.renderer.GLRenderer;
import org.oscim.renderer.MapTile;
import org.oscim.renderer.TileManager;
import org.oscim.renderer.Tiles;
import org.oscim.renderer.TileSet;
import org.oscim.renderer.layer.TextItem;
import org.oscim.renderer.layer.TextLayer;
import org.oscim.utils.FastMath;
@ -34,7 +34,7 @@ import android.util.FloatMath;
public class OverlayText extends RenderOverlay {
private Tiles tiles;
private TileSet tiles;
private LabelThread mThread;
private MapPosition mWorkPos;

View File

@ -46,6 +46,8 @@ public abstract class RenderOverlay {
public BufferObject vbo;
protected float[] mvp = new float[16];
public RenderOverlay(MapView mapView) {
mMapView = mapView;
mMapPosition = new MapPosition();
@ -68,7 +70,7 @@ public abstract class RenderOverlay {
* @param positionChanged
* true when MapPosition has changed
* @param tilesChanged
* true when loaded tiles changed
* true when current tiles changed
*/
public synchronized void update(MapPosition curPos, boolean positionChanged,
boolean tilesChanged) {
@ -86,8 +88,15 @@ public abstract class RenderOverlay {
// }
}
float[] mvp = new float[16];
/**
* Default overlay render function
* @param pos
* current MapPosition
* @param mv
* current model-view matrix
* @param proj
* current projection matrix
*/
public synchronized void render(MapPosition pos, float[] mv, float[] proj) {
float div = setMatrix(pos, mv);
@ -105,8 +114,6 @@ public abstract class RenderOverlay {
}
}
// float scale = curPos.scale / div;
for (Layer l = layers.textureLayers; l != null;) {
l = TextureRenderer.draw(l, (mMapPosition.scale / pos.scale) * div, proj, mv,