diff --git a/src/org/oscim/renderer/BaseLayer.java b/src/org/oscim/renderer/BaseLayer.java index 053346a7..3c2f85a7 100644 --- a/src/org/oscim/renderer/BaseLayer.java +++ b/src/org/oscim/renderer/BaseLayer.java @@ -22,6 +22,7 @@ import static org.oscim.generator.JobTile.STATE_READY; import org.oscim.core.MapPosition; import org.oscim.renderer.layer.Layer; import org.oscim.utils.FastMath; +import org.oscim.utils.GlUtils; import android.opengl.GLES20; import android.opengl.Matrix; @@ -78,28 +79,39 @@ public class BaseLayer { if (tile.lastDraw == mDrawSerial) return; - float div = FastMath.pow(tile.zoomLevel - pos.zoomLevel); - tile.lastDraw = mDrawSerial; float[] mvp = mMVPMatrix; - setMatrix(mvp, tile, div, pos); - if (tile.holder != null) - tile = tile.holder; + //setMatrix(mvp, tile, div, pos); - if (tile.layers == null) + MapTile t = tile; + if (t.holder != null) + t = t.holder; + + if (t.layers == null) return; - // set depth offset (used for clipping to tile boundaries) - GLES20.glPolygonOffset(-1, -GLRenderer.depthOffset(tile)); + // set Model matrix for tile + float div = FastMath.pow(tile.zoomLevel - pos.zoomLevel); + float x = (float) (tile.pixelX - pos.x * div); + float y = (float) (tile.pixelY - pos.y * div); + float scale = pos.scale / div; + GlUtils.setTileMatrix(mvp, x, y, scale); - GLES20.glBindBuffer(GL_ARRAY_BUFFER, tile.vbo.id); + // add view-projection matrix + Matrix.multiplyMM(mvp, 0, mVPMatrix, 0, mvp, 0); + + // set depth offset (used for clipping to tile boundaries) + GLES20.glPolygonOffset(-1, -GLRenderer.depthOffset(t)); + + GLES20.glBindBuffer(GL_ARRAY_BUFFER, t.vbo.id); boolean clipped = false; - int simpleShader = (pos.tilt == 0 ? 1 : 0); + // simple line shader does not take forward shortening into account + int simpleShader = (pos.tilt < 1 ? 1 : 0); - for (Layer l = tile.layers.layers; l != null;) { + for (Layer l = t.layers.layers; l != null;) { switch (l.type) { case Layer.POLYGON: @@ -118,7 +130,7 @@ public class BaseLayer { GLES20.glEnable(GL_BLEND); l = LineRenderer.draw(pos, l, mvp, div, simpleShader, - tile.layers.lineOffset); + t.layers.lineOffset); break; } } @@ -133,30 +145,6 @@ public class BaseLayer { // } } - private static void setMatrix(float[] matrix, MapTile tile, - float div, MapPosition pos) { - - float x = (float) (tile.pixelX - pos.x * div); - float y = (float) (tile.pixelY - pos.y * div); - float scale = pos.scale / div; - - for (int i = 0; i < 16; i++) - matrix[i] = 0; - - // translate relative to map center - matrix[12] = x * scale; - matrix[13] = y * scale; - - // scale to tile to world coordinates - scale /= GLRenderer.COORD_MULTIPLIER; - matrix[0] = scale; - matrix[5] = scale; - matrix[10] = 1; - matrix[15] = 1; - - Matrix.multiplyMM(matrix, 0, mVPMatrix, 0, matrix, 0); - } - private static boolean drawProxyChild(MapTile tile, MapPosition pos) { int drawn = 0; for (int i = 0; i < 4; i++) { diff --git a/src/org/oscim/renderer/overlays/ExtrusionOverlay.java b/src/org/oscim/renderer/overlays/ExtrusionOverlay.java index e758b05a..e0e14fee 100644 --- a/src/org/oscim/renderer/overlays/ExtrusionOverlay.java +++ b/src/org/oscim/renderer/overlays/ExtrusionOverlay.java @@ -54,7 +54,7 @@ public class ExtrusionOverlay extends RenderOverlay { private boolean initialized = false; - // TODO sum up size used while filling layer only up to: + // FIXME sum up size used while filling layer only up to: private int BUFFERSIZE = 65536 * 2; private TileSet mTileSet; private ShortBuffer mShortBuffer; @@ -104,8 +104,8 @@ public class ExtrusionOverlay extends RenderOverlay { } // keep a list of tiles available for rendering - if (mTiles == null || mTiles.length != tiles.length) - mTiles = new MapTile[tiles.length]; + if (mTiles == null || mTiles.length < mTileSet.cnt * 4) + mTiles = new MapTile[mTileSet.cnt * 4]; ExtrusionLayer el; if (curPos.zoomLevel >= 17) { @@ -139,7 +139,6 @@ public class ExtrusionOverlay extends RenderOverlay { if (el == null || !el.compiled) continue; - // TODO check overflow, even if very unlikely... mTiles[ready++] = c; } } @@ -317,19 +316,9 @@ public class ExtrusionOverlay extends RenderOverlay { float y = (float) (tile.pixelY - mapPosition.y * div); float scale = mapPosition.scale / div; - for (int i = 0; i < 16; i++) - matrix[i] = 0; - - // translate relative to map center - matrix[12] = x * scale; - matrix[13] = y * scale; - - // scale to tile to world coordinates - scale /= GLRenderer.COORD_MULTIPLIER; - matrix[0] = scale; - matrix[5] = scale; - matrix[10] = scale / 1000f; - matrix[15] = 1; + GlUtils.setTileMatrix(matrix, x, y, scale); + // scale height + matrix[10] = scale / (1000f * GLRenderer.COORD_MULTIPLIER); Matrix.multiplyMM(matrix, 0, proj, 0, matrix, 0); } diff --git a/src/org/oscim/utils/GlUtils.java b/src/org/oscim/utils/GlUtils.java index 838870e5..f4417451 100644 --- a/src/org/oscim/utils/GlUtils.java +++ b/src/org/oscim/utils/GlUtils.java @@ -14,6 +14,8 @@ */ package org.oscim.utils; +import org.oscim.renderer.GLRenderer; + import android.graphics.Bitmap; import android.opengl.GLES20; import android.opengl.GLUtils; @@ -186,4 +188,25 @@ public class GlUtils { c[2] = (color >> 0 & 0xff) / 255.0f * c[3]; return c; } + + public static void setTileMatrix(float[] matrix, float tx, float ty, float s) { + // scale tile relative to map scale + matrix[0] = matrix[5] = s / GLRenderer.COORD_MULTIPLIER; + matrix[1] = 0; + matrix[2] = 0; + matrix[3] = 0; + matrix[4] = 0; + + matrix[6] = 0; + matrix[7] = 0; + matrix[8] = 0; + matrix[9] = 0; + matrix[10] = 1; + matrix[11] = 0; + // translate relative to map center + matrix[12] = tx * s; + matrix[13] = ty * s; + matrix[14] = 0; + matrix[15] = 1; + } }