From 2ff67d078d11511b0b86559d4767dfa8956ac799 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Mon, 6 May 2013 04:36:24 +0200 Subject: [PATCH] move renderer.layer to renderer.sublayers and renderer.overlays to renderer.layers --- jni/triangle/TriangleJni.c | 2 +- .../oscim/layers/overlay/BuildingOverlay.java | 6 +- .../oscim/layers/overlay/ItemizedOverlay.java | 6 +- .../oscim/layers/overlay/LabelingOverlay.java | 6 +- src/org/oscim/layers/overlay/MapScaleBar.java | 49 ++---- src/org/oscim/layers/overlay/PathOverlay.java | 6 +- src/org/oscim/layers/tile/MapTile.java | 20 ++- src/org/oscim/layers/tile/TileManager.java | 16 +- src/org/oscim/layers/tile/TileRenderer.java | 10 +- .../layers/tile/bitmap/BitmapTileLayer.java | 4 +- .../oscim/layers/tile/test/TestTileLayer.java | 4 +- .../layers/tile/vector/MapTileLoader.java | 12 +- .../layers/tile/vector/WayDecorator.java | 2 +- src/org/oscim/renderer/GLRenderer.java | 2 +- src/org/oscim/renderer/RenderLayer.java | 84 +++++----- .../BasicRenderLayer.java} | 28 ++-- .../renderer/layers/BitmapRenderLayer.java | 97 ++++++++++++ .../CustomRenderLayer.java} | 6 +- .../ExtrusionRenderLayer.java} | 10 +- .../renderer/layers/GridRenderLayer.java | 137 ++++++++++++++++ .../renderer/layers/LabelRenderLayer.java | 29 ++++ .../TextRenderLayer.java} | 55 +++---- .../test/AtlasRenderLayer.java} | 19 +-- .../layers/test/ModelRenderLayer.java | 144 +++++++++++++++++ .../test/TestRenderLayer.java} | 60 ++++--- .../oscim/renderer/overlays/GridOverlay.java | 148 ------------------ .../{layer => sublayers}/BitmapLayer.java | 2 +- .../{layer => sublayers}/BitmapRenderer.java | 10 +- .../{layer => sublayers}/ExtrusionLayer.java | 2 +- .../renderer/{layer => sublayers}/Layer.java | 2 +- .../renderer/{layer => sublayers}/Layers.java | 26 ++- .../{layer => sublayers}/LineLayer.java | 2 +- .../{layer => sublayers}/LineRenderer.java | 8 +- .../{layer => sublayers}/LineTexLayer.java | 2 +- .../{layer => sublayers}/LineTexRenderer.java | 2 +- .../oscim/renderer/sublayers/MeshLayer.java | 40 +++++ .../renderer/sublayers/MeshRenderer.java | 19 +++ .../{layer => sublayers}/PolygonLayer.java | 2 +- .../{layer => sublayers}/PolygonRenderer.java | 2 +- .../{layer => sublayers}/SymbolItem.java | 2 +- .../{layer => sublayers}/SymbolLayer.java | 2 +- .../{layer => sublayers}/TextItem.java | 6 +- .../{layer => sublayers}/TextLayer.java | 10 +- .../{layer => sublayers}/TextureAtlas.java | 2 +- .../{layer => sublayers}/TextureItem.java | 2 +- .../{layer => sublayers}/TextureLayer.java | 2 +- .../{layer => sublayers}/TextureRenderer.java | 9 +- .../{layer => sublayers}/VertexItem.java | 12 +- .../oscim/theme/renderinstruction/Line.java | 38 +---- 49 files changed, 726 insertions(+), 440 deletions(-) rename src/org/oscim/renderer/{overlays/BasicOverlay.java => layers/BasicRenderLayer.java} (80%) create mode 100644 src/org/oscim/renderer/layers/BitmapRenderLayer.java rename src/org/oscim/renderer/{overlays/CustomOverlay.java => layers/CustomRenderLayer.java} (96%) rename src/org/oscim/renderer/{overlays/ExtrusionOverlay.java => layers/ExtrusionRenderLayer.java} (97%) create mode 100644 src/org/oscim/renderer/layers/GridRenderLayer.java create mode 100644 src/org/oscim/renderer/layers/LabelRenderLayer.java rename src/org/oscim/renderer/{overlays/TextOverlay.java => layers/TextRenderLayer.java} (92%) rename src/org/oscim/renderer/{overlays/AtlasTest.java => layers/test/AtlasRenderLayer.java} (84%) create mode 100644 src/org/oscim/renderer/layers/test/ModelRenderLayer.java rename src/org/oscim/renderer/{overlays/TestOverlay.java => layers/test/TestRenderLayer.java} (78%) delete mode 100644 src/org/oscim/renderer/overlays/GridOverlay.java rename src/org/oscim/renderer/{layer => sublayers}/BitmapLayer.java (98%) rename src/org/oscim/renderer/{layer => sublayers}/BitmapRenderer.java (96%) rename src/org/oscim/renderer/{layer => sublayers}/ExtrusionLayer.java (99%) rename src/org/oscim/renderer/{layer => sublayers}/Layer.java (97%) rename src/org/oscim/renderer/{layer => sublayers}/Layers.java (92%) rename src/org/oscim/renderer/{layer => sublayers}/LineLayer.java (99%) rename src/org/oscim/renderer/{layer => sublayers}/LineRenderer.java (96%) rename src/org/oscim/renderer/{layer => sublayers}/LineTexLayer.java (99%) rename src/org/oscim/renderer/{layer => sublayers}/LineTexRenderer.java (99%) create mode 100644 src/org/oscim/renderer/sublayers/MeshLayer.java create mode 100644 src/org/oscim/renderer/sublayers/MeshRenderer.java rename src/org/oscim/renderer/{layer => sublayers}/PolygonLayer.java (98%) rename src/org/oscim/renderer/{layer => sublayers}/PolygonRenderer.java (99%) rename src/org/oscim/renderer/{layer => sublayers}/SymbolItem.java (97%) rename src/org/oscim/renderer/{layer => sublayers}/SymbolLayer.java (99%) rename src/org/oscim/renderer/{layer => sublayers}/TextItem.java (97%) rename src/org/oscim/renderer/{layer => sublayers}/TextLayer.java (96%) rename src/org/oscim/renderer/{layer => sublayers}/TextureAtlas.java (99%) rename src/org/oscim/renderer/{layer => sublayers}/TextureItem.java (99%) rename src/org/oscim/renderer/{layer => sublayers}/TextureLayer.java (97%) rename src/org/oscim/renderer/{layer => sublayers}/TextureRenderer.java (96%) rename src/org/oscim/renderer/{layer => sublayers}/VertexItem.java (84%) diff --git a/jni/triangle/TriangleJni.c b/jni/triangle/TriangleJni.c index bc9c51bd..77fadda6 100644 --- a/jni/triangle/TriangleJni.c +++ b/jni/triangle/TriangleJni.c @@ -42,7 +42,7 @@ static void printPoly(TriangleIO *in) { } } -jint Java_org_oscim_renderer_layer_ExtrusionLayer_triangulate(JNIEnv *env, jclass c, +jint Java_org_oscim_renderer_sublayers_ExtrusionLayer_triangulate(JNIEnv *env, jclass c, jfloatArray obj_points, jint pos, jint len, jint num_rings, jobject indice_buf, jint offset) { jshort* indices = (jshort*) (*env)->GetDirectBufferAddress(env, indice_buf); diff --git a/src/org/oscim/layers/overlay/BuildingOverlay.java b/src/org/oscim/layers/overlay/BuildingOverlay.java index f55c1cd1..91ad372b 100644 --- a/src/org/oscim/layers/overlay/BuildingOverlay.java +++ b/src/org/oscim/layers/overlay/BuildingOverlay.java @@ -15,7 +15,7 @@ package org.oscim.layers.overlay; import org.oscim.core.MapPosition; -import org.oscim.renderer.overlays.ExtrusionOverlay; +import org.oscim.renderer.layers.ExtrusionRenderLayer; import org.oscim.view.MapView; import android.os.CountDownTimer; @@ -28,11 +28,11 @@ import android.view.MotionEvent; public class BuildingOverlay extends Overlay { private final static String TAG = BuildingOverlay.class.getName(); - final ExtrusionOverlay mExtLayer; + final ExtrusionRenderLayer mExtLayer; public BuildingOverlay(MapView mapView, org.oscim.layers.tile.TileRenderLayer tileRenderLayer) { super(mapView); - mExtLayer = new ExtrusionOverlay(mapView, tileRenderLayer); + mExtLayer = new ExtrusionRenderLayer(mapView, tileRenderLayer); mLayer = mExtLayer; } diff --git a/src/org/oscim/layers/overlay/ItemizedOverlay.java b/src/org/oscim/layers/overlay/ItemizedOverlay.java index fc32d351..81a9a89d 100644 --- a/src/org/oscim/layers/overlay/ItemizedOverlay.java +++ b/src/org/oscim/layers/overlay/ItemizedOverlay.java @@ -27,8 +27,8 @@ import org.oscim.core.PointD; import org.oscim.core.Tile; import org.oscim.layers.overlay.OverlayItem.HotspotPlace; import org.oscim.renderer.GLRenderer.Matrices; -import org.oscim.renderer.layer.SymbolLayer; -import org.oscim.renderer.overlays.BasicOverlay; +import org.oscim.renderer.layers.BasicRenderLayer; +import org.oscim.renderer.sublayers.SymbolLayer; import org.oscim.utils.GeometryUtils; import org.oscim.view.MapView; @@ -76,7 +76,7 @@ public abstract class ItemizedOverlay extends Overlay private int mSize; - class ItemOverlay extends BasicOverlay { + class ItemOverlay extends BasicRenderLayer { private final SymbolLayer mSymbolLayer; private final float[] mBox = new float[8]; diff --git a/src/org/oscim/layers/overlay/LabelingOverlay.java b/src/org/oscim/layers/overlay/LabelingOverlay.java index d93b28b0..2cb82f57 100644 --- a/src/org/oscim/layers/overlay/LabelingOverlay.java +++ b/src/org/oscim/layers/overlay/LabelingOverlay.java @@ -15,7 +15,7 @@ package org.oscim.layers.overlay; import org.oscim.layers.tile.TileRenderLayer; -import org.oscim.renderer.overlays.TextOverlay; +import org.oscim.renderer.layers.TextRenderLayer; import org.oscim.view.MapView; import android.util.Log; @@ -26,11 +26,11 @@ import android.view.MotionEvent; */ public class LabelingOverlay extends Overlay { private final static String TAG = LabelingOverlay.class.getName(); - final TextOverlay mTextLayer; + final TextRenderLayer mTextLayer; public LabelingOverlay(MapView mapView, TileRenderLayer tileRenderLayer) { super(mapView); - mTextLayer = new TextOverlay(mapView, tileRenderLayer); + mTextLayer = new TextRenderLayer(mapView, tileRenderLayer); mLayer = mTextLayer; } diff --git a/src/org/oscim/layers/overlay/MapScaleBar.java b/src/org/oscim/layers/overlay/MapScaleBar.java index f1da0bf8..dee64334 100644 --- a/src/org/oscim/layers/overlay/MapScaleBar.java +++ b/src/org/oscim/layers/overlay/MapScaleBar.java @@ -21,10 +21,7 @@ import java.util.Map; import org.oscim.core.MapPosition; import org.oscim.core.MercatorProjection; import org.oscim.layers.Layer; -import org.oscim.renderer.GLRenderer.Matrices; -import org.oscim.renderer.layer.BitmapLayer; -import org.oscim.renderer.layer.BitmapRenderer; -import org.oscim.renderer.overlays.BasicOverlay; +import org.oscim.renderer.layers.BitmapRenderLayer; import org.oscim.view.MapView; import android.graphics.Bitmap; @@ -74,8 +71,8 @@ public class MapScaleBar extends Layer { private final double mPrevScale = -1; private final Map mTextFields; - /* private */final Bitmap mMapScaleBitmap; - /* private */boolean mUpdateBitmap; + private final Bitmap mMapScaleBitmap; + private final BitmapRenderLayer mBitmapLayer; public MapScaleBar(MapView mapView) { super(mapView); @@ -91,39 +88,10 @@ public class MapScaleBar extends Layer { configurePaints(); mRedrawNeeded = true; - - mLayer = new BasicOverlay(mapView) { - private boolean initialized; - - @Override - public void update(MapPosition pos, boolean changed, Matrices m) { - if (!initialized) { - BitmapLayer l = new BitmapLayer(true); - l.setBitmap(mMapScaleBitmap, BITMAP_WIDTH, BITMAP_HEIGHT); - layers.textureLayers = l; - newData = true; - } - - if (mUpdateBitmap) { - newData = true; - mUpdateBitmap = false; - } - } - - @Override - public void compile() { - synchronized (mMapScaleBitmap) { - super.compile(); - } - } - - @Override - public synchronized void render(MapPosition pos, Matrices m) { - // scale up 1.2 - m.useScreenCoordinates(false, 8 / 1.2f); - BitmapRenderer.draw(layers.textureLayers, 1, m); - } - }; + mLayer = mBitmapLayer = new BitmapRenderLayer(mapView); + mBitmapLayer.setBitmap(mMapScaleBitmap, 0, 0, + (int)(BITMAP_WIDTH * 1.2f), + (int)(BITMAP_HEIGHT * 1.2f)); } @Override @@ -163,9 +131,10 @@ public class MapScaleBar extends Layer { } synchronized (mMapScaleBitmap) { redrawMapScaleBitmap(scaleBarLength, mapScaleValue); - mUpdateBitmap = true; } + mBitmapLayer.updateBitmap(); + mRedrawNeeded = false; } diff --git a/src/org/oscim/layers/overlay/PathOverlay.java b/src/org/oscim/layers/overlay/PathOverlay.java index be829f02..fc95fa94 100644 --- a/src/org/oscim/layers/overlay/PathOverlay.java +++ b/src/org/oscim/layers/overlay/PathOverlay.java @@ -27,8 +27,8 @@ import org.oscim.core.Tile; import org.oscim.graphics.Paint.Cap; import org.oscim.layers.Layer; import org.oscim.renderer.GLRenderer.Matrices; -import org.oscim.renderer.layer.LineLayer; -import org.oscim.renderer.overlays.BasicOverlay; +import org.oscim.renderer.layers.BasicRenderLayer; +import org.oscim.renderer.sublayers.LineLayer; import org.oscim.theme.renderinstruction.Line; import org.oscim.utils.FastMath; import org.oscim.utils.LineClipper; @@ -44,7 +44,7 @@ public class PathOverlay extends Layer { /** Line style */ /* package */Line mLineStyle; - class RenderPath extends BasicOverlay { + class RenderPath extends BasicRenderLayer { private static final byte MAX_ZOOM = 20; private final double MAX_SCALE; diff --git a/src/org/oscim/layers/tile/MapTile.java b/src/org/oscim/layers/tile/MapTile.java index 1bc85d1d..755402c2 100644 --- a/src/org/oscim/layers/tile/MapTile.java +++ b/src/org/oscim/layers/tile/MapTile.java @@ -15,8 +15,9 @@ package org.oscim.layers.tile; import org.oscim.core.Tile; -import org.oscim.renderer.layer.Layers; -import org.oscim.renderer.layer.TextItem; +import org.oscim.renderer.BufferObject; +import org.oscim.renderer.sublayers.Layers; +import org.oscim.renderer.sublayers.TextItem; import org.oscim.utils.quadtree.QuadTree; /** @@ -185,4 +186,19 @@ public final class MapTile extends Tile { state = STATE_LOADING; } + void clear(){ + if (layers != null) { + // TODO move this to layers clear + if (layers.vbo != null) { + BufferObject.release(layers.vbo); + layers.vbo = null; + } + + layers.clear(); + layers = null; + } + + TextItem.pool.releaseAll(labels); + + } } diff --git a/src/org/oscim/layers/tile/TileManager.java b/src/org/oscim/layers/tile/TileManager.java index 314e0521..9d0cbe29 100644 --- a/src/org/oscim/layers/tile/TileManager.java +++ b/src/org/oscim/layers/tile/TileManager.java @@ -24,9 +24,7 @@ import java.util.Arrays; import org.oscim.core.MapPosition; import org.oscim.core.Tile; -import org.oscim.renderer.BufferObject; import org.oscim.renderer.GLRenderer; -import org.oscim.renderer.layer.TextItem; import org.oscim.utils.FastMath; import org.oscim.utils.ScanBox; import org.oscim.utils.quadtree.QuadTree; @@ -154,7 +152,6 @@ public class TileManager { // and VBOs might be lost // VertexPool.init(); //} - // clear cache index //QuadTree.init(); @@ -402,18 +399,7 @@ public class TileManager { if (t == null) return; - if (t.layers != null) { - // TODO move this to layers clear - if (t.layers.vbo != null) { - BufferObject.release(t.layers.vbo); - t.layers.vbo = null; - } - - t.layers.clear(); - t.layers = null; - } - - TextItem.pool.releaseAll(t.labels); + t.clear(); mIndex.remove(t); diff --git a/src/org/oscim/layers/tile/TileRenderer.java b/src/org/oscim/layers/tile/TileRenderer.java index b42645c7..c2faccd8 100644 --- a/src/org/oscim/layers/tile/TileRenderer.java +++ b/src/org/oscim/layers/tile/TileRenderer.java @@ -21,11 +21,11 @@ import org.oscim.core.MapPosition; import org.oscim.core.Tile; import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer.Matrices; -import org.oscim.renderer.layer.BitmapRenderer; -import org.oscim.renderer.layer.Layer; -import org.oscim.renderer.layer.LineRenderer; -import org.oscim.renderer.layer.LineTexRenderer; -import org.oscim.renderer.layer.PolygonRenderer; +import org.oscim.renderer.sublayers.BitmapRenderer; +import org.oscim.renderer.sublayers.Layer; +import org.oscim.renderer.sublayers.LineRenderer; +import org.oscim.renderer.sublayers.LineTexRenderer; +import org.oscim.renderer.sublayers.PolygonRenderer; import org.oscim.utils.FastMath; import org.oscim.utils.Matrix4; import org.oscim.utils.quadtree.QuadTree; diff --git a/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java b/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java index 1da60ffa..7d026570 100644 --- a/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java +++ b/src/org/oscim/layers/tile/bitmap/BitmapTileLayer.java @@ -26,8 +26,8 @@ import org.oscim.layers.tile.MapTile; import org.oscim.layers.tile.TileLayer; import org.oscim.layers.tile.TileLoader; import org.oscim.layers.tile.TileManager; -import org.oscim.renderer.layer.BitmapLayer; -import org.oscim.renderer.layer.Layers; +import org.oscim.renderer.sublayers.BitmapLayer; +import org.oscim.renderer.sublayers.Layers; import org.oscim.view.MapView; import android.graphics.Bitmap; diff --git a/src/org/oscim/layers/tile/test/TestTileLayer.java b/src/org/oscim/layers/tile/test/TestTileLayer.java index 31055d89..ca90cc1d 100644 --- a/src/org/oscim/layers/tile/test/TestTileLayer.java +++ b/src/org/oscim/layers/tile/test/TestTileLayer.java @@ -24,8 +24,8 @@ import org.oscim.layers.tile.TileLayer; import org.oscim.layers.tile.TileLoader; import org.oscim.layers.tile.TileManager; import org.oscim.layers.tile.test.TestTileLayer.TestTileLoader; -import org.oscim.renderer.layer.Layers; -import org.oscim.renderer.layer.LineLayer; +import org.oscim.renderer.sublayers.Layers; +import org.oscim.renderer.sublayers.LineLayer; import org.oscim.theme.renderinstruction.Line; import org.oscim.view.MapView; diff --git a/src/org/oscim/layers/tile/vector/MapTileLoader.java b/src/org/oscim/layers/tile/vector/MapTileLoader.java index 44c94f0d..125fe2ba 100644 --- a/src/org/oscim/layers/tile/vector/MapTileLoader.java +++ b/src/org/oscim/layers/tile/vector/MapTileLoader.java @@ -30,12 +30,12 @@ import org.oscim.layers.tile.JobQueue; import org.oscim.layers.tile.MapTile; import org.oscim.layers.tile.TileLoader; import org.oscim.layers.tile.TileManager; -import org.oscim.renderer.layer.ExtrusionLayer; -import org.oscim.renderer.layer.Layers; -import org.oscim.renderer.layer.LineLayer; -import org.oscim.renderer.layer.LineTexLayer; -import org.oscim.renderer.layer.PolygonLayer; -import org.oscim.renderer.layer.TextItem; +import org.oscim.renderer.sublayers.ExtrusionLayer; +import org.oscim.renderer.sublayers.Layers; +import org.oscim.renderer.sublayers.LineLayer; +import org.oscim.renderer.sublayers.LineTexLayer; +import org.oscim.renderer.sublayers.PolygonLayer; +import org.oscim.renderer.sublayers.TextItem; import org.oscim.theme.IRenderCallback; import org.oscim.theme.IRenderTheme; import org.oscim.theme.renderinstruction.Area; diff --git a/src/org/oscim/layers/tile/vector/WayDecorator.java b/src/org/oscim/layers/tile/vector/WayDecorator.java index a872815f..94978a64 100644 --- a/src/org/oscim/layers/tile/vector/WayDecorator.java +++ b/src/org/oscim/layers/tile/vector/WayDecorator.java @@ -17,7 +17,7 @@ package org.oscim.layers.tile.vector; import org.oscim.core.Tile; import org.oscim.layers.tile.MapTile; -import org.oscim.renderer.layer.TextItem; +import org.oscim.renderer.sublayers.TextItem; import org.oscim.theme.renderinstruction.Text; import org.oscim.utils.GeometryUtils; import org.oscim.utils.LineClipper; diff --git a/src/org/oscim/renderer/GLRenderer.java b/src/org/oscim/renderer/GLRenderer.java index 6b734619..5eeb13bb 100644 --- a/src/org/oscim/renderer/GLRenderer.java +++ b/src/org/oscim/renderer/GLRenderer.java @@ -31,7 +31,7 @@ import javax.microedition.khronos.opengles.GL10; import org.oscim.core.MapPosition; import org.oscim.core.Tile; import org.oscim.layers.tile.MapTile; -import org.oscim.renderer.layer.Layers; +import org.oscim.renderer.sublayers.Layers; import org.oscim.theme.IRenderTheme; import org.oscim.utils.GlUtils; import org.oscim.utils.Matrix4; diff --git a/src/org/oscim/renderer/RenderLayer.java b/src/org/oscim/renderer/RenderLayer.java index 565d58f9..46db0267 100644 --- a/src/org/oscim/renderer/RenderLayer.java +++ b/src/org/oscim/renderer/RenderLayer.java @@ -22,13 +22,17 @@ import org.oscim.view.MapView; public abstract class RenderLayer { protected final MapView mMapView; - // keep the Position for which the Overlay is rendered + /** + * Use mMapPosition.copy(position) to keep the position for which + * the Overlay is _compiled_. NOTE: required by setMatrix utility + * functions to draw this layer fixed to the map + */ protected MapPosition mMapPosition; - // flag to set when data is ready for (re)compilation. + /** flag to set when data is ready for (re)compilation. */ public boolean newData; - // flag set by GLRenderer when data is compiled + /** flag to set when layer is ready for rendering */ public boolean isReady; public RenderLayer(MapView mapView) { @@ -36,54 +40,56 @@ public abstract class RenderLayer { mMapPosition = new MapPosition(); } - // /////////////// called from GLRender Thread //////////////////////// + /** /////////////// called in GLRender Thread /////////////////////// **/ /** - * Called first by GLRenderer: Set 'newData' true when 'compile()' should be - * called before next 'render()' + * 1. Called first by GLRenderer: + * Update the layer state here. Set 'this.newData = true' when + * 'compile()' should be called before next call to 'render()' * - * @param curPos TODO - * @param positionChanged - * true when MapPosition has changed - * @param matrices TODO + * @param position current MapPosition + * @param changed + * true when MapPosition has changed since last frame + * @param matrices contains the current view- and projection-matrices + * and 'mvp' matrix for temporary use. */ - public abstract void update(MapPosition curPos, boolean positionChanged, + public abstract void update(MapPosition position, boolean changed, Matrices matrices); /** - * 2: Compile everything for drawing - * Set 'isReady' true when things are ready for 'render()' + * 2. Compile vertex buffers and upload textures for drawing: + * Set 'this.isReady = true' when things are ready for 'render()' */ public abstract void compile(); /** - * 3: Draw layer + * 3. Draw layer: * - * @param pos - * Current MapPosition - * @param m - * Current render matrices + matrix for temporary use + * @param position current MapPosition + * @param matrices contains the current view- and projection-matrices. + * 'matrices.mvp' is for temporary use to build the model- + * view-projection to set as uniform. */ - public abstract void render(MapPosition pos, Matrices m); + public abstract void render(MapPosition position, Matrices matrices); /** - * Utility: set m.mvp matrix relative to the difference of current - * MapPosition - * and the last updated Overlay MapPosition + * Utility: Set matrices.mvp matrix relative to the difference of current + * MapPosition and the last updated Overlay MapPosition. + * Use this to 'stick' your layer to the map. * - * @param curPos + * @param position * current MapPosition - * @param m + * @param matrices * current Matrices * @param project - * apply view and projection, or just view otherwise + * if true apply view- and projection, or just view otherwise. */ - protected void setMatrix(MapPosition curPos, Matrices m, boolean project) { + protected void setMatrix(MapPosition position, Matrices matrices, boolean project) { MapPosition oPos = mMapPosition; - double tileScale = Tile.SIZE * curPos.scale; + double tileScale = Tile.SIZE * position.scale; - double x = oPos.x - curPos.x; - double y = oPos.y - curPos.y; + double x = oPos.x - position.x; + double y = oPos.y - position.y; // wrap around date-line // while (x < -1) @@ -91,21 +97,21 @@ public abstract class RenderLayer { // while (x > 2) // x -= 1.0; - m.mvp.setTransScale((float) (x * tileScale), (float) (y * tileScale), - (float) ((curPos.scale / oPos.scale) / GLRenderer.COORD_SCALE)); + matrices.mvp.setTransScale((float) (x * tileScale), (float) (y * tileScale), + (float) ((position.scale / oPos.scale) / GLRenderer.COORD_SCALE)); - m.mvp.multiplyMM(project ? m.viewproj : m.view, m.mvp); + matrices.mvp.multiplyMM(project ? matrices.viewproj : matrices.view, matrices.mvp); } /** - * Utility: set m.mvp matrix relative to the difference of current - * MapPosition - * and the last updated Overlay MapPosition and add m.viewproj + * Utility: Set matrices.mvp matrix relative to the difference of current + * MapPosition and the last updated Overlay MapPosition and add + * matrices.viewproj * - * @param curPos ... - * @param m ... + * @param position ... + * @param matrices ... */ - protected void setMatrix(MapPosition curPos, Matrices m) { - setMatrix(curPos, m, true); + protected void setMatrix(MapPosition position, Matrices matrices) { + setMatrix(position, matrices, true); } } diff --git a/src/org/oscim/renderer/overlays/BasicOverlay.java b/src/org/oscim/renderer/layers/BasicRenderLayer.java similarity index 80% rename from src/org/oscim/renderer/overlays/BasicOverlay.java rename to src/org/oscim/renderer/layers/BasicRenderLayer.java index a04b4231..bf19eb0e 100644 --- a/src/org/oscim/renderer/overlays/BasicOverlay.java +++ b/src/org/oscim/renderer/layers/BasicRenderLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.overlays; +package org.oscim.renderer.layers; import org.oscim.core.MapPosition; import org.oscim.renderer.BufferObject; @@ -20,34 +20,32 @@ import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.GLState; import org.oscim.renderer.RenderLayer; -import org.oscim.renderer.layer.BitmapRenderer; -import org.oscim.renderer.layer.Layer; -import org.oscim.renderer.layer.Layers; -import org.oscim.renderer.layer.LineRenderer; -import org.oscim.renderer.layer.LineTexRenderer; -import org.oscim.renderer.layer.PolygonRenderer; -import org.oscim.renderer.layer.TextureRenderer; +import org.oscim.renderer.sublayers.BitmapRenderer; +import org.oscim.renderer.sublayers.Layer; +import org.oscim.renderer.sublayers.Layers; +import org.oscim.renderer.sublayers.LineRenderer; +import org.oscim.renderer.sublayers.LineTexRenderer; +import org.oscim.renderer.sublayers.PolygonRenderer; +import org.oscim.renderer.sublayers.TextureRenderer; import org.oscim.utils.FastMath; import org.oscim.view.MapView; import android.opengl.GLES20; /** - * Base class to use the renderer.layer.Layers drawing 'API' + * Base class to use the renderer.sublayers for drawing */ -public abstract class BasicOverlay extends RenderLayer { +public abstract class BasicRenderLayer extends RenderLayer { public final Layers layers; - protected float[] mvp = new float[16]; - - public BasicOverlay(MapView mapView) { + public BasicRenderLayer(MapView mapView) { super(mapView); layers = new Layers(); } /** - * use synchronized when modifying layers + * Render all 'layers' */ @Override public synchronized void render(MapPosition curPos, Matrices m) { @@ -58,7 +56,7 @@ public abstract class BasicOverlay extends RenderLayer { GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, layers.vbo.id); GLState.test(false, false); GLState.blend(true); - int simple = pos.tilt == 0 ? 1 : 0; + int simple = (curPos.tilt < 1 ? 1 : 0); if (layers.baseLayers != null) { setMatrix(curPos, m, true); diff --git a/src/org/oscim/renderer/layers/BitmapRenderLayer.java b/src/org/oscim/renderer/layers/BitmapRenderLayer.java new file mode 100644 index 00000000..12d1c542 --- /dev/null +++ b/src/org/oscim/renderer/layers/BitmapRenderLayer.java @@ -0,0 +1,97 @@ +/* + * Copyright 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 . + */ +package org.oscim.renderer.layers; + +import org.oscim.core.MapPosition; +import org.oscim.renderer.GLRenderer.Matrices; +import org.oscim.renderer.sublayers.BitmapLayer; +import org.oscim.renderer.sublayers.BitmapRenderer; +import org.oscim.view.MapView; + +import android.graphics.Bitmap; + +/** + * RenderLayer to draw a custom Bitmap. + * NOTE: Only modify the Bitmap within a synchronized block! + * synchronized(bitmap){} + * Then call updateBitmap(). + */ +public class BitmapRenderLayer extends BasicRenderLayer { + + private Bitmap mBitmap; + private int mWidth; + private int mHeight; + private boolean initialized; + private boolean mUpdateBitmap; + + public BitmapRenderLayer(MapView mapView) { + super(mapView); + } + + /** + * @param bitmap + * with dimension being power of two + * @param srcWidth + * TODO width used + * @param srcHeight + * TODO height used + */ + public synchronized void setBitmap(Bitmap bitmap, + int srcWidth, int srcHeight, + int targetWidth, int targetHeight) { + mWidth = targetWidth; + mHeight = targetHeight; + mBitmap = bitmap; + initialized = false; + } + + public synchronized void updateBitmap() { + mUpdateBitmap = true; + } + + @Override + public synchronized void update(MapPosition pos, boolean changed, Matrices m) { + if (!initialized) { + layers.clear(); + + BitmapLayer l = new BitmapLayer(true); + l.setBitmap(mBitmap, mWidth, mHeight); + layers.textureLayers = l; + + newData = true; + } + + if (mUpdateBitmap) { + newData = true; + mUpdateBitmap = false; + } + } + + @Override + public synchronized void compile() { + if (mBitmap == null) + return; + + synchronized (mBitmap) { + super.compile(); + } + } + + @Override + public synchronized void render(MapPosition pos, Matrices m) { + m.useScreenCoordinates(false, 8); + BitmapRenderer.draw(layers.textureLayers, 1, m); + } +} diff --git a/src/org/oscim/renderer/overlays/CustomOverlay.java b/src/org/oscim/renderer/layers/CustomRenderLayer.java similarity index 96% rename from src/org/oscim/renderer/overlays/CustomOverlay.java rename to src/org/oscim/renderer/layers/CustomRenderLayer.java index 2dfe7f33..20684e5f 100644 --- a/src/org/oscim/renderer/overlays/CustomOverlay.java +++ b/src/org/oscim/renderer/layers/CustomRenderLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.overlays; +package org.oscim.renderer.layers; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -34,7 +34,7 @@ import android.opengl.GLES20; * https://github.com/dalinaum/opengl-es-book-samples/tree/master/Android * */ -public class CustomOverlay extends RenderLayer { +public class CustomRenderLayer extends RenderLayer { private int mProgramObject; private int hVertexPosition; @@ -49,7 +49,7 @@ public class CustomOverlay extends RenderLayer { }; private boolean mInitialized; - public CustomOverlay(MapView mapView) { + public CustomRenderLayer(MapView mapView) { super(mapView); } diff --git a/src/org/oscim/renderer/overlays/ExtrusionOverlay.java b/src/org/oscim/renderer/layers/ExtrusionRenderLayer.java similarity index 97% rename from src/org/oscim/renderer/overlays/ExtrusionOverlay.java rename to src/org/oscim/renderer/layers/ExtrusionRenderLayer.java index 7c7b6576..2327b15f 100644 --- a/src/org/oscim/renderer/overlays/ExtrusionOverlay.java +++ b/src/org/oscim/renderer/layers/ExtrusionRenderLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.overlays; +package org.oscim.renderer.layers; import org.oscim.core.MapPosition; import org.oscim.core.Tile; @@ -23,7 +23,7 @@ import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.GLState; import org.oscim.renderer.RenderLayer; -import org.oscim.renderer.layer.ExtrusionLayer; +import org.oscim.renderer.sublayers.ExtrusionLayer; import org.oscim.utils.GlUtils; import org.oscim.view.MapView; @@ -33,12 +33,12 @@ import android.util.Log; /** * @author Hannes Janetzek */ -public class ExtrusionOverlay extends RenderLayer { - private final static String TAG = ExtrusionOverlay.class.getName(); +public class ExtrusionRenderLayer extends RenderLayer { + private final static String TAG = ExtrusionRenderLayer.class.getName(); private final TileRenderLayer mTileLayer; - public ExtrusionOverlay(MapView mapView, org.oscim.layers.tile.TileRenderLayer tileRenderLayer) { + public ExtrusionRenderLayer(MapView mapView, org.oscim.layers.tile.TileRenderLayer tileRenderLayer) { super(mapView); mTileLayer = tileRenderLayer; } diff --git a/src/org/oscim/renderer/layers/GridRenderLayer.java b/src/org/oscim/renderer/layers/GridRenderLayer.java new file mode 100644 index 00000000..9009d1d0 --- /dev/null +++ b/src/org/oscim/renderer/layers/GridRenderLayer.java @@ -0,0 +1,137 @@ +/* + * 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 . + */ +package org.oscim.renderer.layers; + +import java.util.Locale; + +import org.oscim.core.GeometryBuffer; +import org.oscim.core.MapPosition; +import org.oscim.core.Tile; +import org.oscim.graphics.Color; +import org.oscim.graphics.Paint.Cap; +import org.oscim.renderer.GLRenderer.Matrices; +import org.oscim.renderer.sublayers.LineLayer; +import org.oscim.renderer.sublayers.TextItem; +import org.oscim.renderer.sublayers.TextLayer; +import org.oscim.theme.renderinstruction.Line; +import org.oscim.theme.renderinstruction.Text; +import org.oscim.view.MapView; + +public class GridRenderLayer extends BasicRenderLayer { + private final static String TILE_FORMAT = "%d/%d/%d"; + private final TextLayer mTextLayer; + private final Text mText; + + private final LineLayer mLineLayer; + + private final GeometryBuffer mLines; + + private int mCurX, mCurY, mCurZ; + + public GridRenderLayer(MapView mapView) { + super(mapView); + + int size = Tile.SIZE; + + // not needed to set but we know: + // 16 lines 'a' two points + mLines = new GeometryBuffer(2 * 16, 16); + + float pos = -size * 4; + + // 8 vertical lines + for (int i = 0; i < 8; i++) { + float x = pos + i * size; + mLines.startLine(); + mLines.addPoint(x, pos); + mLines.addPoint(x, pos + size * 8); + } + + // 8 horizontal lines + for (int j = 0; j < 8; j++) { + float y = pos + j * size; + mLines.startLine(); + mLines.addPoint(pos, y); + mLines.addPoint(pos + size * 8, y); + } + + mText = Text.createText(22, 0, Color.RED, 0, false); + + mTextLayer = layers.addTextLayer(new TextLayer()); + mLineLayer = layers.addLineLayer(0, + new Line(Color.BLUE, 1.5f, Cap.BUTT)); + } + + private void addLabels(int x, int y, int z) { + int s = Tile.SIZE; + + TextLayer tl = mTextLayer; + tl.clear(); + + for (int yy = -2; yy < 2; yy++) { + for (int xx = -2; xx < 2; xx++) { + + String label = String.format( + Locale.ROOT, TILE_FORMAT, + Integer.valueOf(x + xx), + Integer.valueOf(y + yy), + Integer.valueOf(z)); + + TextItem ti = TextItem.pool.get(); + ti.set(s * xx + s / 2, s * yy + s / 2, label, mText); + + tl.addText(ti); + } + } + + // render TextItems to a bitmap and prepare vertex buffer data. + tl.prepare(); + + // release TextItems + tl.clearLabels(); + } + + @Override + public void update(MapPosition pos, boolean changed, Matrices m) { + + // scale coordinates relative to current 'zoom-level' to + // get the position as the nearest tile coordinate + int z = 1 << pos.zoomLevel; + int x = (int) (pos.x * z); + int y = (int) (pos.y * z); + + // update layers when map moved by at least one tile + if (x == mCurX && y == mCurY && z == mCurZ) + return; + + mCurX = x; + mCurY = y; + mCurZ = z; + + MapPosition layerPos = mMapPosition; + layerPos.copy(pos); + layerPos.x = (double) x / z; + layerPos.y = (double) y / z; + layerPos.scale = z; + + addLabels(x, y, pos.zoomLevel); + + mLineLayer.clear(); + mLineLayer.addLine(mLines); + + // tell GLRender to compile new layer data. + this.newData = true; + } +} diff --git a/src/org/oscim/renderer/layers/LabelRenderLayer.java b/src/org/oscim/renderer/layers/LabelRenderLayer.java new file mode 100644 index 00000000..833e6008 --- /dev/null +++ b/src/org/oscim/renderer/layers/LabelRenderLayer.java @@ -0,0 +1,29 @@ +/* + * Copyright 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 . + */ +package org.oscim.renderer.layers; + +public class LabelRenderLayer { + + public LabelRenderLayer() { + + } + + @Override + protected void finalize() throws Throwable { + + super.finalize(); + } + +} diff --git a/src/org/oscim/renderer/overlays/TextOverlay.java b/src/org/oscim/renderer/layers/TextRenderLayer.java similarity index 92% rename from src/org/oscim/renderer/overlays/TextOverlay.java rename to src/org/oscim/renderer/layers/TextRenderLayer.java index ee134889..8fd55043 100644 --- a/src/org/oscim/renderer/overlays/TextOverlay.java +++ b/src/org/oscim/renderer/layers/TextRenderLayer.java @@ -13,7 +13,7 @@ * this program. If not, see . */ -package org.oscim.renderer.overlays; +package org.oscim.renderer.layers; // TODO // 1. rewrite :) @@ -31,7 +31,6 @@ package org.oscim.renderer.overlays; import org.oscim.core.MapPosition; import org.oscim.core.Tile; import org.oscim.graphics.Color; -import org.oscim.graphics.Paint.Cap; import org.oscim.layers.tile.MapTile; import org.oscim.layers.tile.TileRenderLayer; import org.oscim.layers.tile.TileSet; @@ -39,14 +38,14 @@ import org.oscim.renderer.BufferObject; import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.GLState; -import org.oscim.renderer.layer.Layer; -import org.oscim.renderer.layer.Layers; -import org.oscim.renderer.layer.LineLayer; -import org.oscim.renderer.layer.LineRenderer; -import org.oscim.renderer.layer.PolygonRenderer; -import org.oscim.renderer.layer.TextItem; -import org.oscim.renderer.layer.TextLayer; -import org.oscim.renderer.layer.TextureRenderer; +import org.oscim.renderer.sublayers.Layer; +import org.oscim.renderer.sublayers.Layers; +import org.oscim.renderer.sublayers.LineLayer; +import org.oscim.renderer.sublayers.LineRenderer; +import org.oscim.renderer.sublayers.PolygonRenderer; +import org.oscim.renderer.sublayers.TextItem; +import org.oscim.renderer.sublayers.TextLayer; +import org.oscim.renderer.sublayers.TextureRenderer; import org.oscim.theme.renderinstruction.Line; import org.oscim.utils.FastMath; import org.oscim.utils.OBB2D; @@ -59,8 +58,8 @@ import org.oscim.view.MapViewPosition; import android.opengl.GLES20; import android.os.SystemClock; -public class TextOverlay extends BasicOverlay { - private final static String TAG = TextOverlay.class.getName(); +public class TextRenderLayer extends BasicRenderLayer { + private final static String TAG = TextRenderLayer.class.getName(); private final static float MIN_CAPTION_DIST = 5; private final static float MIN_WAY_DIST = 3; @@ -198,7 +197,7 @@ public class TextOverlay extends BasicOverlay { private int mRelabelCnt; private final TileRenderLayer mTileLayer; - public TextOverlay(MapView mapView, TileRenderLayer baseLayer) { + public TextRenderLayer(MapView mapView, TileRenderLayer baseLayer) { super(mapView); mMapViewPosition = mapView.getMapViewPosition(); @@ -659,29 +658,19 @@ public class TextOverlay extends BasicOverlay { } private static void addDebugLayers(Layers dbg) { + int alpha = 0xaaffffff; + dbg.clear(); - LineLayer ll = dbg.getLineLayer(0); - ll.line = new Line((Color.BLUE & 0xaaffffff), 1, Cap.BUTT); - ll.width = 2; - ll = dbg.getLineLayer(3); - ll.line = new Line((Color.YELLOW & 0xaaffffff), 1, Cap.BUTT); - ll.width = 2; - ll = dbg.getLineLayer(1); - ll.line = new Line((Color.RED & 0xaaffffff), 1, Cap.BUTT); - ll.width = 2; - ll = dbg.getLineLayer(2); - ll.line = new Line((Color.GREEN & 0xaaffffff), 1, Cap.BUTT); - ll.width = 2; - ll = dbg.getLineLayer(4); - ll.line = new Line((Color.CYAN & 0xaaffffff), 1, Cap.BUTT); - ll.width = 2; - ll = dbg.getLineLayer(5); - ll.line = new Line((Color.MAGENTA & 0xaaffffff), 1, Cap.BUTT); - ll.width = 2; + dbg.addLineLayer(0, new Line((Color.BLUE & alpha), 2)); + dbg.addLineLayer(1, new Line((Color.RED & alpha), 2)); + dbg.addLineLayer(3, new Line((Color.YELLOW & alpha), 2)); + dbg.addLineLayer(2, new Line((Color.GREEN & alpha), 2)); + dbg.addLineLayer(4, new Line((Color.CYAN & alpha), 2)); + dbg.addLineLayer(5, new Line((Color.MAGENTA & alpha), 2)); } @Override - public synchronized void update(MapPosition curPos, boolean positionChanged, + public synchronized void update(MapPosition pos, boolean changed, Matrices matrices) { if (mNextLayer != null) { @@ -707,7 +696,7 @@ public class TextOverlay extends BasicOverlay { this.newData = true; - if (!positionChanged) + if (!changed) return; } diff --git a/src/org/oscim/renderer/overlays/AtlasTest.java b/src/org/oscim/renderer/layers/test/AtlasRenderLayer.java similarity index 84% rename from src/org/oscim/renderer/overlays/AtlasTest.java rename to src/org/oscim/renderer/layers/test/AtlasRenderLayer.java index 923b7e79..b1894440 100644 --- a/src/org/oscim/renderer/overlays/AtlasTest.java +++ b/src/org/oscim/renderer/layers/test/AtlasRenderLayer.java @@ -1,4 +1,4 @@ -package org.oscim.renderer.overlays; +package org.oscim.renderer.layers.test; import java.util.Arrays; @@ -6,21 +6,22 @@ import org.oscim.core.MapPosition; import org.oscim.graphics.Color; import org.oscim.graphics.Paint.Cap; import org.oscim.renderer.GLRenderer.Matrices; -import org.oscim.renderer.layer.LineLayer; -import org.oscim.renderer.layer.TextItem; -import org.oscim.renderer.layer.TextLayer; -import org.oscim.renderer.layer.TextureAtlas; -import org.oscim.renderer.layer.TextureAtlas.Rect; -import org.oscim.renderer.layer.TextureAtlas.Slot; +import org.oscim.renderer.layers.BasicRenderLayer; +import org.oscim.renderer.sublayers.LineLayer; +import org.oscim.renderer.sublayers.TextItem; +import org.oscim.renderer.sublayers.TextLayer; +import org.oscim.renderer.sublayers.TextureAtlas; +import org.oscim.renderer.sublayers.TextureAtlas.Rect; +import org.oscim.renderer.sublayers.TextureAtlas.Slot; import org.oscim.theme.renderinstruction.Line; import org.oscim.theme.renderinstruction.Text; import org.oscim.view.MapView; import android.util.Log; -public class AtlasTest extends BasicOverlay { +public class AtlasRenderLayer extends BasicRenderLayer { - public AtlasTest(MapView mapView) { + public AtlasRenderLayer(MapView mapView) { super(mapView); TextureAtlas mAtlas = TextureAtlas.create(2048, 2048, 1); diff --git a/src/org/oscim/renderer/layers/test/ModelRenderLayer.java b/src/org/oscim/renderer/layers/test/ModelRenderLayer.java new file mode 100644 index 00000000..d0ba0771 --- /dev/null +++ b/src/org/oscim/renderer/layers/test/ModelRenderLayer.java @@ -0,0 +1,144 @@ +/* + * Copyright 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 . + */ +package org.oscim.renderer.layers.test; + + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +import org.oscim.core.MapPosition; +import org.oscim.renderer.GLRenderer.Matrices; +import org.oscim.renderer.RenderLayer; +import org.oscim.view.MapView; +public class ModelRenderLayer extends RenderLayer{ + + public ModelRenderLayer(MapView mapView) { + super(mapView); + // TODO Auto-generated constructor stub + } + + @Override + public void update(MapPosition pos, boolean changed, Matrices m) { + // TODO Auto-generated method stub + + } + + @Override + public void compile() { + // TODO Auto-generated method stub + + } + + @Override + public void render(MapPosition pos, Matrices m) { + // TODO Auto-generated method stub + + } + + // based on edu.spsu.logo.SimpleRenderer (c) Jeff Chastine + private FloatBuffer vertexBuffer; // A buffer to hold the geometry/vertices + private FloatBuffer normalBuffer; // A buffer to hold the normals of each vertex + private FloatBuffer texCoordBuffer; // A buffer to hold the texture coordinates for each vertex + //private FloatBuffer lightBuffer; // A buffer to hold the position of a light + + private void initShapes() { + + float sin30 = (float)Math.sin(Math.PI/6.0); + float cos30 = (float)Math.cos(Math.PI/6.0); + + float hexagonCoords[] = { + 0.0f, 0.0f, 0.0f, // Hexagon face of SPSU logo + cos30, sin30, 0.0f, + 0.0f, 1.0f, 0.0f, + -cos30, sin30, 0.0f, + -cos30, -sin30, 0.0f, + 0.0f, -1.0f, 0.0f, + cos30, -sin30, 0.0f, + cos30, sin30, 0.0f + }; + + float hexagonNormals[] = { + 0.0f, 0.0f, 1.0f, // Normals for each vertex + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 1.0f + }; + + float hexagonTexCoords[] = { + 0.5f, 0.5f, // Texture coordinates for each vertex + -cos30/2.0f+0.5f, -sin30/2.0f+0.5f, + 0.5f, 0.0f, + cos30/2.0f+0.5f, -sin30/2.0f+0.5f, + cos30/2.0f+0.5f, sin30/2.0f+0.5f, + 0.5f, 1.0f, + -cos30/2.0f+0.5f, sin30/2.0f+0.5f, + -cos30/2.0f+0.5f, -sin30/2.0f+0.5f, + }; + + // Load all of that info into 3 buffers + ByteBuffer vbb = ByteBuffer.allocateDirect(hexagonCoords.length*4); + vbb.order (ByteOrder.nativeOrder()); + vertexBuffer = vbb.asFloatBuffer(); // make a buffer from a buffer + vertexBuffer.put(hexagonCoords); // add the coords to the float buffer + vertexBuffer.position(0); // set the reading pointer back to 0 + + ByteBuffer vbb2 = ByteBuffer.allocateDirect(hexagonNormals.length*4); + vbb2.order (ByteOrder.nativeOrder()); + normalBuffer = vbb2.asFloatBuffer(); // make a buffer from a buffer + normalBuffer.put(hexagonNormals); // add the coords to the float buffer + normalBuffer.position(0); // set the reading pointer back to 0 + + ByteBuffer vbb3 = ByteBuffer.allocateDirect(hexagonTexCoords.length*4); + vbb3.order (ByteOrder.nativeOrder()); + texCoordBuffer = vbb3.asFloatBuffer(); // make a buffer from a buffer + texCoordBuffer.put(hexagonTexCoords); // add the coords to the float buffer + texCoordBuffer.position(0); // set the reading pointer back to 0 + + } + + private final static String vertexShader = "" + + "uniform mat4 uMVPMatrix;" + + "uniform vec4 uLightPos;" + + "attribute vec4 vPosition;" + + "attribute vec4 vNormal;" + + "attribute vec2 aTextureCoord;" + + "varying vec2 vTextureCoord;" + + "varying vec4 color;" + + + + "void main() {" + //" vec4 normal = vNormal*uMVPMatrix;" + + + " vec3 light = normalize (uLightPos.xyz);" + + " vec3 normal = normalize (vNormal.xyz);" + + " vTextureCoord = aTextureCoord;" + + " color = vec4 (0.6, 0.8, 0.1, 1.0)*max(0.2, dot(normal, light));" + + " gl_Position = uMVPMatrix * vPosition;" + + "}"; + + private final static String fragmentShader = "" + + "precision mediump float;" + + "varying vec4 color;" + + "varying vec2 vTextureCoord;" + + "uniform sampler2D sTexture;" + + "void main() {" + + " gl_FragColor = color + texture2D(sTexture, vTextureCoord);" + + "}"; + +} diff --git a/src/org/oscim/renderer/overlays/TestOverlay.java b/src/org/oscim/renderer/layers/test/TestRenderLayer.java similarity index 78% rename from src/org/oscim/renderer/overlays/TestOverlay.java rename to src/org/oscim/renderer/layers/test/TestRenderLayer.java index c5b280dc..f5799fe6 100644 --- a/src/org/oscim/renderer/overlays/TestOverlay.java +++ b/src/org/oscim/renderer/layers/test/TestRenderLayer.java @@ -12,18 +12,15 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.overlays; +package org.oscim.renderer.layers.test; import org.oscim.core.MapPosition; import org.oscim.renderer.GLRenderer.Matrices; -import org.oscim.renderer.layer.LineTexLayer; -import org.oscim.renderer.layer.TextItem; -import org.oscim.theme.renderinstruction.Line; +import org.oscim.renderer.layers.BasicRenderLayer; +import org.oscim.renderer.sublayers.TextItem; import org.oscim.view.MapView; -import android.graphics.Color; - -public class TestOverlay extends BasicOverlay { +public class TestRenderLayer extends BasicRenderLayer { TextItem labels; @@ -31,40 +28,39 @@ public class TestOverlay extends BasicOverlay { private boolean first = true; - public TestOverlay(MapView mapView) { + public TestRenderLayer(MapView mapView) { super(mapView); // draw a rectangle //LineLayer ll = (LineLayer) layers.getLayer(1, Layer.LINE); //ll.line = new Line(Color.BLUE, 1.0f, Cap.BUTT); //ll.width = 2; - float[] points = { - -100, -100, - 100, -100, - 100, 100, - -100, 100, - -100, -100 - }; + // float[] points = { + // -100, -100, + // 100, -100, + // 100, 100, + // -100, 100, + // -100, -100 + // }; //short[] index = { (short) points.length }; //ll.addLine(points, index, true); - - LineTexLayer lt = layers.getLineTexLayer(2); - lt.line = new Line(Color.BLUE, 1.0f, 8); - lt.width = 8; - lt.addLine(points, null); - - float[] points2 = { - -200, -200, - 200, -200, - 200, 200, - -200, 200, - -200, -200 - }; - lt = layers.getLineTexLayer(3); - lt.line = new Line(Color.BLUE, 1.0f, 16); - lt.width = 8; - lt.addLine(points2, null); + // LineTexLayer lt = layers.getLineTexLayer(2); + // lt.line = new Line(Color.BLUE, 1.0f, 8); + // lt.width = 8; + // lt.addLine(points, null); + // + // float[] points2 = { + // -200, -200, + // 200, -200, + // 200, 200, + // -200, 200, + // -200, -200 + // }; + // lt = layers.getLineTexLayer(3); + // lt.line = new Line(Color.BLUE, 1.0f, 16); + // lt.width = 8; + // lt.addLine(points2, null); // // PolygonLayer pl = (PolygonLayer) layers.getLayer(0, Layer.POLYGON); diff --git a/src/org/oscim/renderer/overlays/GridOverlay.java b/src/org/oscim/renderer/overlays/GridOverlay.java deleted file mode 100644 index eb2bae1e..00000000 --- a/src/org/oscim/renderer/overlays/GridOverlay.java +++ /dev/null @@ -1,148 +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 . - */ -package org.oscim.renderer.overlays; - -import org.oscim.core.MapPosition; -import org.oscim.core.Tile; -import org.oscim.graphics.Color; -import org.oscim.graphics.Paint.Cap; -import org.oscim.renderer.GLRenderer.Matrices; -import org.oscim.renderer.layer.LineLayer; -import org.oscim.renderer.layer.TextItem; -import org.oscim.renderer.layer.TextLayer; -import org.oscim.theme.renderinstruction.Line; -import org.oscim.theme.renderinstruction.Text; -import org.oscim.view.MapView; - - -public class GridOverlay extends BasicOverlay { - - private final float[] mPoints; - private final short[] mIndex; - private final Text mText; - private final TextLayer mTextLayer; - private final LineLayer mLineLayer; - - public GridOverlay(MapView mapView) { - super(mapView); - - int size = Tile.SIZE; - float[] points = new float[64]; - short[] index = new short[16]; - - float pos = -size * 4; - - // vertical lines - for (int i = 0; i < 8; i++) { - index[i] = 4; - // x1,y1,x2,y2 - points[i * 4] = pos + i * size; - points[i * 4 + 1] = pos + 0; - points[i * 4 + 2] = pos + i * size; - points[i * 4 + 3] = pos + size * 8; - } - - // horizontal lines - for (int j = 8; j < 16; j++) { - index[j] = 4; - points[j * 4] = pos + 0; - points[j * 4 + 1] = pos + (j - 8) * size; - points[j * 4 + 2] = pos + size * 8; - points[j * 4 + 3] = pos + (j - 8) * size; - } - - mIndex = index; - mPoints = points; - - // mText = Text.createText(20, 3, Color.BLACK, Color.RED, false); - mText = Text.createText(22, 0, Color.RED, 0, false); - // mText = Text.createText(22, 0, Color.RED, 0, true); - - mTextLayer = new TextLayer(); - layers.textureLayers = mTextLayer; - - LineLayer ll = layers.getLineLayer(0); - ll.line = new Line(Color.BLUE, 1.0f, Cap.BUTT); - ll.width = 1.5f; - mLineLayer = ll; - } - - - private void addLabels(int x, int y, int z) { - int size = Tile.SIZE; - - TextLayer tl = mTextLayer; - - for (int i = -2; i < 2; i++) { - for (int j = -2; j < 2; j++) { - TextItem ti = TextItem.pool.get(); - ti.set(size * j + size / 2, size * i + size / 2, - (x + j) + " / " + (y + i) + " / " + z, mText); - - // TextItem ti = new TextItem(size * j + size / 2, size * i + - // size / 2, - // (x + j) + " / " + (y + i) + " / " + z, mText); - - // rotation, TODO could also be used for slide range - ti.x1 = 0; - ti.y1 = 1; // (short) (size / 2); - ti.x2 = 1; // (short) size; - ti.y2 = 1; // (short) (size / 2); - tl.addText(ti); - } - } - - tl.prepare(); - tl.clearLabels(); - } - - private int mCurX = -1; - private int mCurY = -1; - private int mCurZ = -1; - - @Override - public synchronized void update(MapPosition curPos, boolean changed, Matrices m) { - - int z = 1 << curPos.zoomLevel; - int x = (int) (curPos.x * z); - int y = (int) (curPos.y * z); - - // update layers when map moved by at least one tile - if (x != mCurX || y != mCurY || z != mCurZ) { - - MapPosition pos = mMapPosition; - - pos.copy(curPos); - pos.x = (double) x / z; - pos.y = (double) y / z; - pos.scale = z; - - mCurX = x; - mCurY = y; - mCurZ = z; - - mTextLayer.clear(); - mLineLayer.clear(); - - addLabels(x, y, curPos.zoomLevel); - - LineLayer ll = mLineLayer; - ll.verticesCnt = 0; - ll.addLine(mPoints, mIndex, false); - - newData = true; - } - } -} diff --git a/src/org/oscim/renderer/layer/BitmapLayer.java b/src/org/oscim/renderer/sublayers/BitmapLayer.java similarity index 98% rename from src/org/oscim/renderer/layer/BitmapLayer.java rename to src/org/oscim/renderer/sublayers/BitmapLayer.java index 42e7d59a..c0a387ec 100644 --- a/src/org/oscim/renderer/layer/BitmapLayer.java +++ b/src/org/oscim/renderer/sublayers/BitmapLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ShortBuffer; diff --git a/src/org/oscim/renderer/layer/BitmapRenderer.java b/src/org/oscim/renderer/sublayers/BitmapRenderer.java similarity index 96% rename from src/org/oscim/renderer/layer/BitmapRenderer.java rename to src/org/oscim/renderer/sublayers/BitmapRenderer.java index 92aa813f..19f33a6b 100644 --- a/src/org/oscim/renderer/layer/BitmapRenderer.java +++ b/src/org/oscim/renderer/sublayers/BitmapRenderer.java @@ -13,7 +13,7 @@ * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer.Matrices; @@ -22,11 +22,11 @@ import org.oscim.utils.GlUtils; import android.opengl.GLES20; -/** - * @author Hannes Janetzek - */ +// TODO merge with TextureRenderer + public final class BitmapRenderer { - private final static String TAG = BitmapRenderer.class.getName(); + + //private final static String TAG = BitmapRenderer.class.getName(); public final static boolean debug = true; private static int mTextureProgram; diff --git a/src/org/oscim/renderer/layer/ExtrusionLayer.java b/src/org/oscim/renderer/sublayers/ExtrusionLayer.java similarity index 99% rename from src/org/oscim/renderer/layer/ExtrusionLayer.java rename to src/org/oscim/renderer/sublayers/ExtrusionLayer.java index 0eb39db1..b1884dfb 100644 --- a/src/org/oscim/renderer/layer/ExtrusionLayer.java +++ b/src/org/oscim/renderer/sublayers/ExtrusionLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/src/org/oscim/renderer/layer/Layer.java b/src/org/oscim/renderer/sublayers/Layer.java similarity index 97% rename from src/org/oscim/renderer/layer/Layer.java rename to src/org/oscim/renderer/sublayers/Layer.java index d17b8843..33e928c6 100644 --- a/src/org/oscim/renderer/layer/Layer.java +++ b/src/org/oscim/renderer/sublayers/Layer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ShortBuffer; diff --git a/src/org/oscim/renderer/layer/Layers.java b/src/org/oscim/renderer/sublayers/Layers.java similarity index 92% rename from src/org/oscim/renderer/layer/Layers.java rename to src/org/oscim/renderer/sublayers/Layers.java index 5e1d3cfb..29b46c29 100644 --- a/src/org/oscim/renderer/layer/Layers.java +++ b/src/org/oscim/renderer/sublayers/Layers.java @@ -12,11 +12,12 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ShortBuffer; import org.oscim.renderer.BufferObject; +import org.oscim.theme.renderinstruction.Line; import android.util.Log; @@ -62,11 +63,25 @@ public class Layers { private Layer mCurLayer; + /** + * add the LineLayer for a level with a given Line style. Levels are + * ordered from bottom (0) to top + */ + public LineLayer addLineLayer(int level, Line style) { + LineLayer ll = (LineLayer) getLayer(level, Layer.LINE); + if (ll == null) + return null; + + ll.width = style.width; + ll.line = style; + + return ll; + } + /** * Get or add the LineLayer for a level. Levels are ordered from * bottom (0) to top */ - public LineLayer getLineLayer(int level) { return (LineLayer) getLayer(level, Layer.LINE); } @@ -87,6 +102,12 @@ public class Layers { return (LineTexLayer) getLayer(level, Layer.TEXLINE); } + public TextLayer addTextLayer(TextLayer textLayer) { + textLayer.next = textureLayers; + textureLayers = textLayer; + return textLayer; + } + private Layer getLayer(int level, byte type) { Layer l = baseLayers; Layer layer = null; @@ -294,4 +315,5 @@ public class Layers { // vbo = null; // } } + } diff --git a/src/org/oscim/renderer/layer/LineLayer.java b/src/org/oscim/renderer/sublayers/LineLayer.java similarity index 99% rename from src/org/oscim/renderer/layer/LineLayer.java rename to src/org/oscim/renderer/sublayers/LineLayer.java index 70c6fc89..98d5d666 100644 --- a/src/org/oscim/renderer/layer/LineLayer.java +++ b/src/org/oscim/renderer/sublayers/LineLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ShortBuffer; diff --git a/src/org/oscim/renderer/layer/LineRenderer.java b/src/org/oscim/renderer/sublayers/LineRenderer.java similarity index 96% rename from src/org/oscim/renderer/layer/LineRenderer.java rename to src/org/oscim/renderer/sublayers/LineRenderer.java index 813286b5..5abc0048 100644 --- a/src/org/oscim/renderer/layer/LineRenderer.java +++ b/src/org/oscim/renderer/sublayers/LineRenderer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import static android.opengl.GLES20.GL_SHORT; import static android.opengl.GLES20.GL_TRIANGLE_STRIP; @@ -288,8 +288,9 @@ public final class LineRenderer { + " float len = max((1.0 - u_mode) * abs(v_st.s), u_mode * texture2D(tex, v_st).a);" // interpolate alpha between: 0.0 < 1.0 - len < u_wscale // where wscale is 'filter width' / 'line width' and 0 <= len <= sqrt(2) - + " gl_FragColor = u_color * smoothstep(0.0, u_wscale, 1.0 - len);" - //+ " gl_FragColor = u_color * min(1.0, (1.0 - len) / u_wscale);" + //+ " gl_FragColor = u_color * smoothstep(0.0, u_wscale, 1.0 - len);" + //+ " gl_FragColor = mix(vec4(1.0,0.0,0.0,1.0), u_color, smoothstep(0.0, u_wscale, 1.0 - len));" + + " gl_FragColor = u_color * min(1.0, (1.0 - len) / u_wscale);" + "}"; private final static String lineFragmentShader = "" @@ -318,6 +319,7 @@ public final class LineRenderer { //+ " gl_FragColor = u_color * min(1.0, (1.0 - len) / (u_wscale + fuzz));" // can be faster according to nvidia docs 'Optimize OpenGL ES 2.0 Performace' + " gl_FragColor = u_color * clamp((1.0 - len) / (u_wscale + fuzz), 0.0, 1.0);" + //+ " gl_FragColor = mix(vec4(0.0,1.0,0.0,1.0), u_color, clamp((1.0 - len) / (u_wscale + fuzz), 0.0, 1.0));" + "}"; // private final static String lineVertexShader = "" diff --git a/src/org/oscim/renderer/layer/LineTexLayer.java b/src/org/oscim/renderer/sublayers/LineTexLayer.java similarity index 99% rename from src/org/oscim/renderer/layer/LineTexLayer.java rename to src/org/oscim/renderer/sublayers/LineTexLayer.java index 6560e575..f5863744 100644 --- a/src/org/oscim/renderer/layer/LineTexLayer.java +++ b/src/org/oscim/renderer/sublayers/LineTexLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ShortBuffer; diff --git a/src/org/oscim/renderer/layer/LineTexRenderer.java b/src/org/oscim/renderer/sublayers/LineTexRenderer.java similarity index 99% rename from src/org/oscim/renderer/layer/LineTexRenderer.java rename to src/org/oscim/renderer/sublayers/LineTexRenderer.java index e45c569e..8c6249a9 100644 --- a/src/org/oscim/renderer/layer/LineTexRenderer.java +++ b/src/org/oscim/renderer/sublayers/LineTexRenderer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ByteBuffer; import java.nio.ByteOrder; diff --git a/src/org/oscim/renderer/sublayers/MeshLayer.java b/src/org/oscim/renderer/sublayers/MeshLayer.java new file mode 100644 index 00000000..f9f78f86 --- /dev/null +++ b/src/org/oscim/renderer/sublayers/MeshLayer.java @@ -0,0 +1,40 @@ +/* + * Copyright 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 . + */ +package org.oscim.renderer.sublayers; + +import java.nio.ShortBuffer; + +import org.oscim.core.GeometryBuffer; + +public class MeshLayer extends Layer { + + public void addMesh(GeometryBuffer geom){ + + for (int i = 0, n = geom.points.length; i < n; i++){ + + } + } + + @Override + protected void compile(ShortBuffer sbuf) { + + } + + @Override + protected void clear() { + + } + +} diff --git a/src/org/oscim/renderer/sublayers/MeshRenderer.java b/src/org/oscim/renderer/sublayers/MeshRenderer.java new file mode 100644 index 00000000..13bc1825 --- /dev/null +++ b/src/org/oscim/renderer/sublayers/MeshRenderer.java @@ -0,0 +1,19 @@ +/* + * Copyright 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 . + */ +package org.oscim.renderer.sublayers; + +public class MeshRenderer { + +} diff --git a/src/org/oscim/renderer/layer/PolygonLayer.java b/src/org/oscim/renderer/sublayers/PolygonLayer.java similarity index 98% rename from src/org/oscim/renderer/layer/PolygonLayer.java rename to src/org/oscim/renderer/sublayers/PolygonLayer.java index 2749774e..7ad126fd 100644 --- a/src/org/oscim/renderer/layer/PolygonLayer.java +++ b/src/org/oscim/renderer/sublayers/PolygonLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ShortBuffer; diff --git a/src/org/oscim/renderer/layer/PolygonRenderer.java b/src/org/oscim/renderer/sublayers/PolygonRenderer.java similarity index 99% rename from src/org/oscim/renderer/layer/PolygonRenderer.java rename to src/org/oscim/renderer/sublayers/PolygonRenderer.java index cf070ebe..fb30c6d1 100644 --- a/src/org/oscim/renderer/layer/PolygonRenderer.java +++ b/src/org/oscim/renderer/sublayers/PolygonRenderer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import static android.opengl.GLES20.GL_ALWAYS; import static android.opengl.GLES20.GL_EQUAL; diff --git a/src/org/oscim/renderer/layer/SymbolItem.java b/src/org/oscim/renderer/sublayers/SymbolItem.java similarity index 97% rename from src/org/oscim/renderer/layer/SymbolItem.java rename to src/org/oscim/renderer/sublayers/SymbolItem.java index e25224bd..a588f30f 100644 --- a/src/org/oscim/renderer/layer/SymbolItem.java +++ b/src/org/oscim/renderer/sublayers/SymbolItem.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import org.oscim.utils.pool.Inlist; import org.oscim.utils.pool.SyncPool; diff --git a/src/org/oscim/renderer/layer/SymbolLayer.java b/src/org/oscim/renderer/sublayers/SymbolLayer.java similarity index 99% rename from src/org/oscim/renderer/layer/SymbolLayer.java rename to src/org/oscim/renderer/sublayers/SymbolLayer.java index 668117cf..06e842e3 100644 --- a/src/org/oscim/renderer/layer/SymbolLayer.java +++ b/src/org/oscim/renderer/sublayers/SymbolLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import android.graphics.Canvas; diff --git a/src/org/oscim/renderer/layer/TextItem.java b/src/org/oscim/renderer/sublayers/TextItem.java similarity index 97% rename from src/org/oscim/renderer/layer/TextItem.java rename to src/org/oscim/renderer/sublayers/TextItem.java index 7cf74566..ba913ee4 100644 --- a/src/org/oscim/renderer/layer/TextItem.java +++ b/src/org/oscim/renderer/sublayers/TextItem.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import org.oscim.theme.renderinstruction.Text; import org.oscim.utils.pool.Inlist; @@ -75,6 +75,10 @@ public class TextItem extends Inlist { this.y = y; this.string = string; this.text = text; + this.x1 = 0; + this.y1 = 0; + this.x2 = 1; + this.y2 = 0; this.width = text.paint.measureText(string); return this; } diff --git a/src/org/oscim/renderer/layer/TextLayer.java b/src/org/oscim/renderer/sublayers/TextLayer.java similarity index 96% rename from src/org/oscim/renderer/layer/TextLayer.java rename to src/org/oscim/renderer/sublayers/TextLayer.java index cb478c1d..b41e721c 100644 --- a/src/org/oscim/renderer/layer/TextLayer.java +++ b/src/org/oscim/renderer/sublayers/TextLayer.java @@ -12,12 +12,13 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import static org.oscim.renderer.GLRenderer.COORD_SCALE; -import static org.oscim.renderer.layer.TextureItem.TEXTURE_HEIGHT; -import static org.oscim.renderer.layer.TextureItem.TEXTURE_WIDTH; +import static org.oscim.renderer.sublayers.TextureItem.TEXTURE_HEIGHT; +import static org.oscim.renderer.sublayers.TextureItem.TEXTURE_WIDTH; import android.graphics.Canvas; + public final class TextLayer extends TextureLayer { //private static String TAG = TextureLayer.class.getName(); @@ -244,7 +245,8 @@ public final class TextLayer extends TextureLayer { numIndices += TextureRenderer.INDICES_PER_SPRITE; verticesCnt += 4; - if (it.next == null || (it.next.text != it.text) || (it.next.string != it.string)) { + if (it.next == null || (it.next.text != it.text) + || (it.next.string != it.string)) { it = it.next; break; } diff --git a/src/org/oscim/renderer/layer/TextureAtlas.java b/src/org/oscim/renderer/sublayers/TextureAtlas.java similarity index 99% rename from src/org/oscim/renderer/layer/TextureAtlas.java rename to src/org/oscim/renderer/sublayers/TextureAtlas.java index 323873a6..5ceffe03 100644 --- a/src/org/oscim/renderer/layer/TextureAtlas.java +++ b/src/org/oscim/renderer/sublayers/TextureAtlas.java @@ -57,7 +57,7 @@ * * ============================================================================ */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import org.oscim.utils.pool.Inlist; diff --git a/src/org/oscim/renderer/layer/TextureItem.java b/src/org/oscim/renderer/sublayers/TextureItem.java similarity index 99% rename from src/org/oscim/renderer/layer/TextureItem.java rename to src/org/oscim/renderer/sublayers/TextureItem.java index 6372b74b..3dcc2637 100644 --- a/src/org/oscim/renderer/layer/TextureItem.java +++ b/src/org/oscim/renderer/sublayers/TextureItem.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.util.ArrayList; diff --git a/src/org/oscim/renderer/layer/TextureLayer.java b/src/org/oscim/renderer/sublayers/TextureLayer.java similarity index 97% rename from src/org/oscim/renderer/layer/TextureLayer.java rename to src/org/oscim/renderer/sublayers/TextureLayer.java index 281693f6..584e1480 100644 --- a/src/org/oscim/renderer/layer/TextureLayer.java +++ b/src/org/oscim/renderer/sublayers/TextureLayer.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import java.nio.ShortBuffer; diff --git a/src/org/oscim/renderer/layer/TextureRenderer.java b/src/org/oscim/renderer/sublayers/TextureRenderer.java similarity index 96% rename from src/org/oscim/renderer/layer/TextureRenderer.java rename to src/org/oscim/renderer/sublayers/TextureRenderer.java index c368d796..3df8441b 100644 --- a/src/org/oscim/renderer/layer/TextureRenderer.java +++ b/src/org/oscim/renderer/sublayers/TextureRenderer.java @@ -13,11 +13,11 @@ * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import static org.oscim.renderer.GLRenderer.COORD_SCALE; -import static org.oscim.renderer.layer.TextureItem.TEXTURE_HEIGHT; -import static org.oscim.renderer.layer.TextureItem.TEXTURE_WIDTH; +import static org.oscim.renderer.sublayers.TextureItem.TEXTURE_HEIGHT; +import static org.oscim.renderer.sublayers.TextureItem.TEXTURE_WIDTH; import org.oscim.renderer.GLRenderer; import org.oscim.renderer.GLRenderer.Matrices; @@ -26,9 +26,6 @@ import org.oscim.utils.GlUtils; import android.opengl.GLES20; -/** - * @author Hannes Janetzek - */ public final class TextureRenderer { //private final static String TAG = TextureRenderer.class.getName(); public final static boolean debug = false; diff --git a/src/org/oscim/renderer/layer/VertexItem.java b/src/org/oscim/renderer/sublayers/VertexItem.java similarity index 84% rename from src/org/oscim/renderer/layer/VertexItem.java rename to src/org/oscim/renderer/sublayers/VertexItem.java index ade015da..5e64d436 100644 --- a/src/org/oscim/renderer/layer/VertexItem.java +++ b/src/org/oscim/renderer/sublayers/VertexItem.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see . */ -package org.oscim.renderer.layer; +package org.oscim.renderer.sublayers; import org.oscim.utils.pool.Inlist; import org.oscim.utils.pool.SyncPool; @@ -34,6 +34,16 @@ public class VertexItem extends Inlist { } }; + /** + * Add VertexItems back to pool. Make sure to not use the reference afterwards! + * i.e.: + * vertexItem.release(); + * vertexItem = null; + * */ + public void release(){ + VertexItem.pool.releaseAll(this); + } + public final short[] vertices = new short[SIZE]; public int used; diff --git a/src/org/oscim/theme/renderinstruction/Line.java b/src/org/oscim/theme/renderinstruction/Line.java index fa5936e0..e814e3b2 100644 --- a/src/org/oscim/theme/renderinstruction/Line.java +++ b/src/org/oscim/theme/renderinstruction/Line.java @@ -201,46 +201,16 @@ public final class Line extends RenderInstruction { this.min = min; } - public Line(int stroke, float width, Cap cap) { - this.level = 0; - this.blur = 0; - this.cap = cap; - this.outline = false; - this.style = ""; - this.width = width; - this.fixed = true; - this.fade = -1; - this.stipple = 0; - this.stippleColor = Color.BLACK; - this.stippleWidth = 0; - this.min = 0; - this.color = stroke; //GlUtils.colorToFloatP(stroke); + public Line(int stroke, float width) { + this(0, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, 0); } - public Line(int stroke, float width, int stipple) { - this.level = 0; - this.blur = 0; - this.cap = Cap.BUTT; - this.outline = false; - this.style = ""; - this.width = width; - this.fixed = true; - this.fade = -1; - this.stipple = stipple; - this.stippleColor = Color.BLACK; - this.stippleWidth = 0.6f; - this.min = 0; - color = stroke; //GlUtils.colorToFloatP(stroke); + public Line(int stroke, float width, Cap cap) { + this(0, "", stroke, width, cap, true, 0, 0, 0, -1, 0, false, 0); } @Override public void renderWay(IRenderCallback renderCallback) { renderCallback.renderWay(this, level); } - - // @Override - // public void scaleStrokeWidth(float scaleFactor) { - // paint.setStrokeWidth(strokeWidth * scaleFactor); - // } - }