Location renderer custom color, closes #361

This commit is contained in:
Emux 2017-06-11 19:12:59 +03:00
parent 644c83ed69
commit d409aa5b96
5 changed files with 31 additions and 7 deletions

View File

@ -6,7 +6,7 @@
- Marker clustering [#312](https://github.com/mapsforge/vtm/issues/312)
- Osmagray theme [#300](https://github.com/mapsforge/vtm/issues/300)
- Symbol rotation [#294](https://github.com/mapsforge/vtm/issues/294)
- Location custom shaders & improvements [#317](https://github.com/mapsforge/vtm/issues/317) [#321](https://github.com/mapsforge/vtm/issues/321)
- Location renderer improvements [#317](https://github.com/mapsforge/vtm/issues/317) [#321](https://github.com/mapsforge/vtm/issues/321) [#361](https://github.com/mapsforge/vtm/issues/361)
- POT textures [#334](https://github.com/mapsforge/vtm/issues/334)
- OkHttp external cache [#135](https://github.com/mapsforge/vtm/issues/135)
- Texture atlas improvements [#301](https://github.com/mapsforge/vtm/pull/301) [#304](https://github.com/mapsforge/vtm/pull/304)

View File

@ -21,10 +21,11 @@ uniform float u_scale;
uniform float u_phase;
uniform vec2 u_dir;
uniform int u_mode;
uniform vec4 u_color;
void main() {
float len = 1.0 - length(v_tex);
if (u_mode == -1) {
gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len;
gl_FragColor = u_color * len;
} else {
// outer ring
float a = smoothstep(0.0, 2.0 / u_scale, len);
@ -40,6 +41,6 @@ void main() {
// - multiply by viewshed
// - add center point
a = d * (a - (b + c)) + c;
gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * a;
gl_FragColor = u_color * a;
}
}

View File

@ -21,10 +21,11 @@ uniform float u_scale;
uniform float u_phase;
uniform vec2 u_dir;
uniform int u_mode;
uniform vec4 u_color;
void main() {
float len = 1.0 - length(v_tex);
if (u_mode == -1) {
gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len;
gl_FragColor = u_color * len;
} else {
// outer ring
float a = smoothstep(0.0, 2.0 / u_scale, len);
@ -40,6 +41,6 @@ void main() {
// - multiply by viewshed
// - add center point
a = d * (a - (b + c)) + c;
gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * a;
gl_FragColor = u_color * a;
}
}

View File

@ -21,10 +21,11 @@ uniform float u_scale;
uniform float u_phase;
uniform vec2 u_dir;
uniform int u_mode;
uniform vec4 u_color;
void main() {
float len = 1.0 - length(v_tex);
if (u_mode == -1) {
gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len;
gl_FragColor = u_color * len;
} else {
// outer ring
float a = smoothstep(0.0, 2.0 / u_scale, len);
@ -40,6 +41,6 @@ void main() {
// - multiply by viewshed
// - add center point
a = max(d, (a - (b + c)) + c) + (u_mode == 2 ? c : 0);
gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * a;
gl_FragColor = u_color * a;
}
}

View File

@ -19,6 +19,7 @@
package org.oscim.renderer;
import org.oscim.backend.GL;
import org.oscim.backend.canvas.Color;
import org.oscim.core.Box;
import org.oscim.core.Point;
import org.oscim.core.Tile;
@ -35,6 +36,7 @@ public class LocationRenderer extends LayerRenderer {
private static final long INTERVAL = 2000;
private static final float CIRCLE_SIZE = 60;
private static final int COLOR = 0xff3333cc;
private static final int SHOW_ACCURACY_ZOOM = 16;
private final Map mMap;
@ -47,6 +49,7 @@ public class LocationRenderer extends LayerRenderer {
private int hScale;
private int hPhase;
private int hDirection;
private int uColor;
private int uMode;
private final Point mIndicatorPosition = new Point();
@ -62,6 +65,7 @@ public class LocationRenderer extends LayerRenderer {
private long mAnimStart;
private Callback mCallback;
private final float[] mColors = new float[4];
private final Point mLocation = new Point(Double.NaN, Double.NaN);
private double mRadius;
private int mShowAccuracyZoom = SHOW_ACCURACY_ZOOM;
@ -69,12 +73,26 @@ public class LocationRenderer extends LayerRenderer {
public LocationRenderer(Map map, Layer layer) {
mMap = map;
mLayer = layer;
float a = Color.aToFloat(COLOR);
mColors[0] = a * Color.rToFloat(COLOR);
mColors[1] = a * Color.gToFloat(COLOR);
mColors[2] = a * Color.bToFloat(COLOR);
mColors[3] = a;
}
public void setCallback(Callback callback) {
mCallback = callback;
}
public void setColor(int color) {
float a = Color.aToFloat(color);
mColors[0] = a * Color.rToFloat(color);
mColors[1] = a * Color.gToFloat(color);
mColors[2] = a * Color.bToFloat(color);
mColors[3] = a;
}
public void setLocation(double x, double y, double radius) {
mLocation.x = x;
mLocation.y = y;
@ -242,6 +260,8 @@ public class LocationRenderer extends LayerRenderer {
} else
gl.uniform1i(uMode, -1); // Outside screen
GLUtils.glUniform4fv(uColor, 1, mColors);
gl.drawArrays(GL.TRIANGLE_STRIP, 0, 4);
}
@ -256,6 +276,7 @@ public class LocationRenderer extends LayerRenderer {
hPhase = gl.getUniformLocation(program, "u_phase");
hScale = gl.getUniformLocation(program, "u_scale");
hDirection = gl.getUniformLocation(program, "u_dir");
uColor = gl.getUniformLocation(program, "u_color");
uMode = gl.getUniformLocation(program, "u_mode");
return true;