tweak line drawing
This commit is contained in:
parent
e7c5831302
commit
4d663ca810
@ -46,7 +46,8 @@ import android.util.Log;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DatabaseRenderer implements MapGenerator, RenderCallback, IMapDatabaseCallback {
|
||||
public class DatabaseRenderer implements MapGenerator, RenderCallback,
|
||||
IMapDatabaseCallback {
|
||||
private static String TAG = DatabaseRenderer.class.getName();
|
||||
|
||||
private static final byte ZOOM_MAX = 22;
|
||||
@ -194,7 +195,8 @@ public class DatabaseRenderer implements MapGenerator, RenderCallback, IMapDatab
|
||||
private boolean prevClosed;
|
||||
|
||||
@Override
|
||||
public void renderWay(byte layer, Tag[] tags, float[] wayNodes, int[] wayLength, boolean changed) {
|
||||
public void renderWay(byte layer, Tag[] tags, float[] wayNodes, int[] wayLength,
|
||||
boolean changed) {
|
||||
|
||||
mProjected = false;
|
||||
mDrawingLayer = getValidLayer(layer) * mLevels;
|
||||
@ -220,17 +222,20 @@ public class DatabaseRenderer implements MapGenerator, RenderCallback, IMapDatab
|
||||
mWays = wayLength;
|
||||
|
||||
if (!firstMatch && prevClosed == closed && !changed) {
|
||||
DatabaseRenderer.renderTheme.matchWay(this, tags, mCurrentTile.zoomLevel, closed, false);
|
||||
DatabaseRenderer.renderTheme.matchWay(this, tags, mCurrentTile.zoomLevel,
|
||||
closed, false);
|
||||
} else {
|
||||
prevClosed = closed;
|
||||
DatabaseRenderer.renderTheme.matchWay(this, tags, mCurrentTile.zoomLevel, closed, true);
|
||||
DatabaseRenderer.renderTheme.matchWay(this, tags, mCurrentTile.zoomLevel,
|
||||
closed, true);
|
||||
}
|
||||
|
||||
firstMatch = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderAreaCaption(String caption, float verticalOffset, Paint paint, Paint stroke) {
|
||||
public void renderAreaCaption(String caption, float verticalOffset, Paint paint,
|
||||
Paint stroke) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@ -242,7 +247,8 @@ public class DatabaseRenderer implements MapGenerator, RenderCallback, IMapDatab
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderPointOfInterestCaption(String caption, float verticalOffset, Paint paint, Paint stroke) {
|
||||
public void renderPointOfInterestCaption(String caption, float verticalOffset,
|
||||
Paint paint, Paint stroke) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@ -265,7 +271,8 @@ public class DatabaseRenderer implements MapGenerator, RenderCallback, IMapDatab
|
||||
projectToTile(false);
|
||||
|
||||
LineLayer outlineLayer = null;
|
||||
LineLayer l = mLineLayers.getLayer(mDrawingLayer + line.level, line.color, false, line.fixed);
|
||||
LineLayer l = mLineLayers.getLayer(mDrawingLayer + line.level, line.color, false,
|
||||
line.fixed);
|
||||
|
||||
float w = line.strokeWidth;
|
||||
|
||||
@ -275,7 +282,8 @@ public class DatabaseRenderer implements MapGenerator, RenderCallback, IMapDatab
|
||||
if (line.outline != -1) {
|
||||
Line outline = DatabaseRenderer.renderTheme.getOutline(line.outline);
|
||||
if (outline != null) {
|
||||
outlineLayer = mLineLayers.getLayer(mDrawingLayer + outline.level, outline.color, true, false);
|
||||
outlineLayer = mLineLayers.getLayer(mDrawingLayer + outline.level,
|
||||
outline.color, true, false);
|
||||
outlineLayer.addOutline(l);
|
||||
}
|
||||
}
|
||||
@ -300,7 +308,8 @@ public class DatabaseRenderer implements MapGenerator, RenderCallback, IMapDatab
|
||||
if (!projectToTile(false))
|
||||
return;
|
||||
|
||||
PolygonLayer l = mPolyLayers.getLayer(mDrawingLayer + area.level, area.color, area.fade);
|
||||
PolygonLayer l = mPolyLayers.getLayer(mDrawingLayer + area.level, area.color,
|
||||
area.fade);
|
||||
|
||||
for (int i = 0, pos = 0, n = mWays.length; i < n; i++) {
|
||||
int length = mWays[i];
|
||||
@ -381,8 +390,10 @@ public class DatabaseRenderer implements MapGenerator, RenderCallback, IMapDatab
|
||||
// Log.d(TAG, "loaded " + mCurrentTile);
|
||||
|
||||
if (mapGeneratorJob.debugSettings.mDrawTileFrames) {
|
||||
float[] coords = { 0, 0, 0, Tile.TILE_SIZE, Tile.TILE_SIZE, Tile.TILE_SIZE, Tile.TILE_SIZE, 0, 0, 0 };
|
||||
LineLayer ll = mLineLayers.getLayer(Integer.MAX_VALUE, Color.BLACK, false, true);
|
||||
float[] coords = { 0, 0, 0, Tile.TILE_SIZE, Tile.TILE_SIZE, Tile.TILE_SIZE,
|
||||
Tile.TILE_SIZE, 0, 0, 0 };
|
||||
LineLayer ll = mLineLayers.getLayer(Integer.MAX_VALUE, Color.BLACK, false,
|
||||
true);
|
||||
ll.addLine(coords, 0, coords.length, 1.0f, false);
|
||||
}
|
||||
|
||||
|
||||
@ -624,16 +624,16 @@ public class MapRenderer implements org.mapsforge.android.MapRenderer {
|
||||
boolean drawOutlines = false;
|
||||
boolean drawFixed = false;
|
||||
|
||||
// stroke scale factor (0.85 to give some room for anti-aliasing)
|
||||
float wdiv = 0.85f / FloatMath.sqrt(mDrawScale / z);
|
||||
// stroke scale factor
|
||||
float wdiv = 1.0f / FloatMath.sqrt(mDrawScale / z);
|
||||
// linear scale for fixed lines
|
||||
float fdiv = 0.85f / (mDrawScale / z);
|
||||
float fdiv = 0.9f / (mDrawScale / z);
|
||||
|
||||
for (int i = 0, n = layers.length; i < n; i++) {
|
||||
LineLayer l = layers[i];
|
||||
|
||||
// set line width and mode
|
||||
if (i == 0 | l.isOutline != drawOutlines || l.isFixed != drawFixed) {
|
||||
if ((i == 0) || (l.isOutline != drawOutlines) || (l.isFixed != drawFixed)) {
|
||||
drawOutlines = l.isOutline;
|
||||
drawFixed = l.isFixed;
|
||||
if (drawFixed) {
|
||||
@ -644,7 +644,7 @@ public class MapRenderer implements org.mapsforge.android.MapRenderer {
|
||||
GLES20.glUniform1f(gLineWidthHandle, wdiv);
|
||||
} else {
|
||||
GLES20.glUniform1i(gLineModeHandle, 0);
|
||||
GLES20.glUniform1f(gLineWidthHandle, wdiv);
|
||||
GLES20.glUniform1f(gLineWidthHandle, wdiv * 0.95f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,26 +16,60 @@
|
||||
package org.mapsforge.android.glrenderer;
|
||||
|
||||
class Shaders {
|
||||
final static String gLineVertexShader = "" + "precision mediump float; \n" + "uniform mat4 u_center;"
|
||||
+ "uniform float u_width;" + "attribute vec4 a_position;" + "attribute vec2 a_st;" + "varying vec2 v_st;"
|
||||
+ "void main() {" + " gl_Position = u_center * a_position;" + " v_st = a_st;" + "}";
|
||||
final static String gLineVertexShader = ""
|
||||
+ "precision highp float; \n"
|
||||
+ "uniform mat4 u_center;"
|
||||
+ "uniform float u_width;"
|
||||
+ "attribute vec4 a_position;"
|
||||
+ "attribute vec2 a_st;"
|
||||
+ "varying vec2 v_st;"
|
||||
+ "void main() {"
|
||||
+ " gl_Position = u_center * a_position;"
|
||||
+ " v_st = a_st;" + "}";
|
||||
|
||||
final static String gLineFragmentShader = "" + "#extension GL_OES_standard_derivatives : enable\n"
|
||||
+ "precision mediump float;" + "uniform float u_width;" + "uniform int u_mode;" + "uniform vec4 u_color;"
|
||||
+ "const float zero = 0.0;" + "const int standard = 0;" + "const int fixed_width = 2;"
|
||||
+ "varying vec2 v_st;" + "void main() {" + " gl_FragColor = u_color;" + " float fuzz = fwidth(v_st.s);"
|
||||
+ " float len = abs(v_st.s) - u_width;" + " if (u_mode != fixed_width) {"
|
||||
+ " if (v_st.t != zero){ " + " fuzz = max(fuzz, fwidth(v_st.t));"
|
||||
+ " len = length(v_st) - u_width;" + " } " +
|
||||
// branching is not recommended...
|
||||
// " if (- fuzz > len) " +
|
||||
// " gl_FragColor = u_color;" +
|
||||
// " if (len < -fuzz)" +
|
||||
// " discard;" +
|
||||
// " else " +
|
||||
" if (len > -fuzz)" + " gl_FragColor *= smoothstep(fuzz , -fuzz , len);" + " } else { " +
|
||||
// just guesswork.. looks ok for fixed line width >= 0.5
|
||||
" if (len > -fuzz)" + " gl_FragColor *= smoothstep(fuzz*0.5, -fuzz, len);" + " }" + "}";
|
||||
final static String gLineFragmentShader = ""
|
||||
+ "#extension GL_OES_standard_derivatives : enable\n"
|
||||
+ "precision mediump float;"
|
||||
+ "uniform float u_width;"
|
||||
+ "uniform int u_mode;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "const float zero = 0.0;"
|
||||
+ "const int standard = 0;"
|
||||
+ "const int fixed_width = 2;"
|
||||
+ "const vec4 blank = vec4(1.0, 0.0, 0.0, 1.0);"
|
||||
+ "const vec4 blank2 = vec4(0.0, 1.0, 0.0, 1.0);"
|
||||
+ "varying vec2 v_st;"
|
||||
+ "void main() {"
|
||||
+ " if (u_mode != fixed_width) {"
|
||||
// + " gl_FragColor = u_color;"
|
||||
// + " float fuzz;"
|
||||
// + " float len;"
|
||||
+ " if (v_st.t == zero){ "
|
||||
// + " fuzz = - sqrt(dFdx(v_st.s) * dFdx(v_st.s) + dFdy(v_st.s) * dFdy(v_st.s));"
|
||||
+ " float fuzz = -fwidth(v_st.s) * 1.5;"
|
||||
+ " float len = abs(v_st.s) - u_width;"
|
||||
// + " if (len < fuzz)"
|
||||
+ " gl_FragColor = u_color * smoothstep(zero, fuzz, len);"
|
||||
+ " } else {"
|
||||
+ " float fuzz = -max(fwidth(v_st.s), fwidth(v_st.t)) * 1.5;"
|
||||
+ " float len = length(v_st) - u_width;"
|
||||
// + " if (len < fuzz)"
|
||||
+ " gl_FragColor = u_color * smoothstep(zero, fuzz, len);"
|
||||
+ " } "
|
||||
// + " if (len > zero)"
|
||||
// + " gl_FragColor = blank;"
|
||||
// + " discard;"
|
||||
// + " gl_FragColor = u_color;"
|
||||
// + " else if (len < fuzz)"
|
||||
// + " gl_FragColor = blank2;"
|
||||
// + " else "
|
||||
+ " } else { "
|
||||
+ " float fuzz = fwidth(v_st.s);"
|
||||
// + " gl_FragColor = u_color * smoothstep(fuzz, zero, abs(v_st.s) - u_width + fuzz);"
|
||||
// + " fuzz = - sqrt(dFdx(v_st.s) * dFdx(v_st.s) + dFdy(v_st.s) * dFdy(v_st.s)) * 1.5;"
|
||||
+ " gl_FragColor = u_color * smoothstep(fuzz*0.5, -fuzz, abs(v_st.s) - u_width);"
|
||||
+ " }"
|
||||
+ "}";
|
||||
|
||||
// final static String gLineFragmentShader = "" +
|
||||
// "#extension GL_OES_standard_derivatives : enable\n" +
|
||||
@ -48,16 +82,36 @@ class Shaders {
|
||||
// " gl_FragColor = u_color;" +
|
||||
// "}";
|
||||
|
||||
final static String gLineFragmentShaderSimple = "" + "precision mediump float;" + "uniform vec4 u_color;"
|
||||
+ "uniform float u_width;" + "varying vec2 v_st;" + "void main() {" + " vec4 color = u_color;"
|
||||
+ " float len;" + " if (v_st.t == 0.0) " + " len = abs(v_st.s);" + " else "
|
||||
+ " len = length(v_st);" + " if (len > 0.4) {"
|
||||
+ " color = u_color * (smoothstep(0.2, 1.0, (u_width + 0.3) - len));" + "}" + " gl_FragColor = color;"
|
||||
final static String gLineFragmentShaderSimple = ""
|
||||
+ "precision mediump float;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "uniform float u_width;"
|
||||
+ "varying vec2 v_st;"
|
||||
+ "void main() {"
|
||||
+ " vec4 color = u_color;"
|
||||
+ " float len;"
|
||||
+ " if (v_st.t == 0.0) "
|
||||
+ " len = abs(v_st.s);"
|
||||
+ " else "
|
||||
+ " len = length(v_st);"
|
||||
+ " if (len > 0.4) {"
|
||||
+ " color = u_color * (smoothstep(0.2, 1.0, (u_width + 0.3) - len));"
|
||||
+ "}"
|
||||
+ " gl_FragColor = color;"
|
||||
+ "}";
|
||||
|
||||
final static String gPolygonVertexShader = "" + "precision mediump float; \n" + "uniform mat4 u_center;\n"
|
||||
+ "attribute vec4 a_position;" + "void main() {" + " gl_Position = u_center * a_position;" + "}";
|
||||
final static String gPolygonVertexShader = ""
|
||||
+ "precision mediump float; \n"
|
||||
+ "uniform mat4 u_center;\n"
|
||||
+ "attribute vec4 a_position;"
|
||||
+ "void main() {"
|
||||
+ " gl_Position = u_center * a_position;"
|
||||
+ "}";
|
||||
|
||||
final static String gPolygonFragmentShader = "" + "precision mediump float;" + "uniform vec4 u_color;"
|
||||
+ "void main() {" + " gl_FragColor = u_color;" + "}";
|
||||
final static String gPolygonFragmentShader = ""
|
||||
+ "precision mediump float;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "void main() {"
|
||||
+ " gl_FragColor = u_color;"
|
||||
+ "}";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user