From d409aa5b96c3f19eaf0727dc1c35cb34f42abf80 Mon Sep 17 00:00:00 2001 From: Emux Date: Sun, 11 Jun 2017 19:12:59 +0300 Subject: [PATCH] Location renderer custom color, closes #361 --- docs/Changelog.md | 2 +- vtm/resources/assets/shaders/location_1.glsl | 5 +++-- .../assets/shaders/location_1_reverse.glsl | 5 +++-- vtm/resources/assets/shaders/location_2.glsl | 5 +++-- .../org/oscim/renderer/LocationRenderer.java | 21 +++++++++++++++++++ 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index c9985622..043be9f1 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -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) diff --git a/vtm/resources/assets/shaders/location_1.glsl b/vtm/resources/assets/shaders/location_1.glsl index 10d4b5eb..9578bc81 100644 --- a/vtm/resources/assets/shaders/location_1.glsl +++ b/vtm/resources/assets/shaders/location_1.glsl @@ -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; } } diff --git a/vtm/resources/assets/shaders/location_1_reverse.glsl b/vtm/resources/assets/shaders/location_1_reverse.glsl index ac3a904e..ef3d1e62 100644 --- a/vtm/resources/assets/shaders/location_1_reverse.glsl +++ b/vtm/resources/assets/shaders/location_1_reverse.glsl @@ -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; } } diff --git a/vtm/resources/assets/shaders/location_2.glsl b/vtm/resources/assets/shaders/location_2.glsl index 44de49b6..1c84e2fe 100644 --- a/vtm/resources/assets/shaders/location_2.glsl +++ b/vtm/resources/assets/shaders/location_2.glsl @@ -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; } } diff --git a/vtm/src/org/oscim/renderer/LocationRenderer.java b/vtm/src/org/oscim/renderer/LocationRenderer.java index 6b38b703..d3e8f4ca 100644 --- a/vtm/src/org/oscim/renderer/LocationRenderer.java +++ b/vtm/src/org/oscim/renderer/LocationRenderer.java @@ -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;