move renderer.layer to renderer.sublayers and renderer.overlays to renderer.layers

This commit is contained in:
Hannes Janetzek 2013-05-06 04:36:24 +02:00
parent c682ae518c
commit 2ff67d078d
49 changed files with 726 additions and 440 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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<Item extends OverlayItem> extends Overlay
private int mSize;
class ItemOverlay extends BasicOverlay {
class ItemOverlay extends BasicRenderLayer {
private final SymbolLayer mSymbolLayer;
private final float[] mBox = new float[8];

View File

@ -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;
}

View File

@ -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<TextField, String> 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;
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.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);

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.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);
}

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layers;
public class LabelRenderLayer {
public LabelRenderLayer() {
}
@Override
protected void finalize() throws Throwable {
super.finalize();
}
}

View File

@ -13,7 +13,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

View File

@ -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);

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);"
+ "}";
}

View File

@ -12,18 +12,15 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.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);

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
}

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.nio.ShortBuffer;

View File

@ -13,7 +13,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.nio.ShortBuffer;

View File

@ -12,11 +12,12 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
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;
// }
}
}

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.nio.ShortBuffer;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 = ""

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.nio.ShortBuffer;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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() {
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.sublayers;
public class MeshRenderer {
}

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.nio.ShortBuffer;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import static android.opengl.GLES20.GL_ALWAYS;
import static android.opengl.GLES20.GL_EQUAL;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import org.oscim.utils.pool.Inlist;
import org.oscim.utils.pool.SyncPool;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import android.graphics.Canvas;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
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<TextItem> {
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;
}

View File

@ -12,12 +12,13 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
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;
}

View File

@ -57,7 +57,7 @@
*
* ============================================================================
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import org.oscim.utils.pool.Inlist;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.util.ArrayList;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
package org.oscim.renderer.sublayers;
import java.nio.ShortBuffer;

View File

@ -13,11 +13,11 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.renderer.layer;
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<VertexItem> {
}
};
/**
* 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;

View File

@ -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);
// }
}