Circle map style #122
This commit is contained in:
parent
2821d8ddb8
commit
3a191fb513
76
vtm-playground/src/org/oscim/test/CircleTest.java
Normal file
76
vtm-playground/src/org/oscim/test/CircleTest.java
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* 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.test;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.GenericLayer;
|
||||
import org.oscim.renderer.BucketRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.renderer.bucket.CircleBucket;
|
||||
import org.oscim.theme.styles.CircleStyle;
|
||||
|
||||
public class CircleTest extends GdxMap {
|
||||
|
||||
private final GeometryBuffer geom = new GeometryBuffer(2, 1);
|
||||
private final Renderer renderer = new Renderer();
|
||||
|
||||
private void addCircle(float x, float y, CircleBucket cb) {
|
||||
geom.clear();
|
||||
geom.startPoints();
|
||||
geom.addPoint(x, y);
|
||||
cb.addCircle(geom);
|
||||
}
|
||||
|
||||
private class Renderer extends BucketRenderer {
|
||||
|
||||
Renderer() {
|
||||
mMapPosition.scale = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(GLViewport v) {
|
||||
if (mMapPosition.scale == 0)
|
||||
mMapPosition.copy(v.pos);
|
||||
|
||||
if (!isReady())
|
||||
compile();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
MapRenderer.setBackgroundColor(Color.BLACK);
|
||||
|
||||
mMap.setMapPosition(0, 0, 1 << 4);
|
||||
|
||||
CircleStyle cs = new CircleStyle(30, false, 0xff00ff00, 0xffffffff, 2, 0);
|
||||
CircleBucket cb = renderer.buckets.addCircleBucket(0, cs);
|
||||
addCircle(200, -200, cb);
|
||||
addCircle(-200, -200, cb);
|
||||
addCircle(-200, 200, cb);
|
||||
addCircle(200, 200, cb);
|
||||
|
||||
mMap.layers().add(new GenericLayer(mMap, renderer));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new CircleTest());
|
||||
}
|
||||
}
|
@ -2,15 +2,11 @@
|
||||
precision highp float;
|
||||
#endif
|
||||
uniform mat4 u_mvp;
|
||||
uniform float u_radius;
|
||||
uniform vec2 u_screen;
|
||||
uniform float u_scale;
|
||||
attribute vec2 a_pos;
|
||||
varying vec2 v_tex;
|
||||
|
||||
void
|
||||
main(){
|
||||
gl_Position = u_mvp * vec4(a_pos, 0.0, 1.0);
|
||||
v_tex = a_pos;
|
||||
void main() {
|
||||
gl_Position = u_mvp * vec4(a_pos, 0.0, 1.0);
|
||||
gl_PointSize = 2.0 * u_scale / gl_Position.z;
|
||||
}
|
||||
|
||||
$$
|
||||
@ -18,13 +14,10 @@ $$
|
||||
#ifdef GLES
|
||||
precision highp float;
|
||||
#endif
|
||||
varying vec2 v_tex;
|
||||
uniform float u_radius;
|
||||
uniform vec4 u_color;
|
||||
uniform vec2 u_screen;
|
||||
|
||||
void
|
||||
main(){
|
||||
float len = 1.0 - length(v_tex - u_screen);
|
||||
gl_FragColor = u_color * smoothstep(0.0, u_radius, len);
|
||||
void main() {
|
||||
vec2 cxy = 2.0 * gl_PointCoord - 1.0;
|
||||
float r = dot(cxy, cxy);
|
||||
float len = 1.0 - length(r);
|
||||
gl_FragColor = u_color * len;
|
||||
}
|
||||
|
@ -1,6 +1,22 @@
|
||||
/*
|
||||
* Copyright 2016 Andrey Novikov
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* 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.bucket;
|
||||
|
||||
import org.oscim.backend.GL;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.renderer.GLShader;
|
||||
import org.oscim.renderer.GLState;
|
||||
@ -14,7 +30,8 @@ import static org.oscim.backend.GLAdapter.gl;
|
||||
import static org.oscim.renderer.MapRenderer.COORD_SCALE;
|
||||
|
||||
public class CircleBucket extends RenderBucket {
|
||||
static final Logger log = LoggerFactory.getLogger(CircleBucket.class);
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CircleBucket.class);
|
||||
|
||||
public CircleStyle circle;
|
||||
|
||||
@ -38,24 +55,30 @@ public class CircleBucket extends RenderBucket {
|
||||
}
|
||||
|
||||
public static class Renderer {
|
||||
static CircleBucket.Renderer.Shader shader;
|
||||
static Shader shader;
|
||||
|
||||
static boolean init() {
|
||||
shader = new CircleBucket.Renderer.Shader("circle");
|
||||
shader = new Shader("circle");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class Shader extends GLShader {
|
||||
int uMVP, uColor, uRadius, uScreen, aPos;
|
||||
int uMVP, uColor, uScale, aPos;
|
||||
|
||||
Shader(String shaderFile) {
|
||||
if (!create(shaderFile))
|
||||
gl.enable(GL.VERTEX_PROGRAM_POINT_SIZE);
|
||||
|
||||
// OpenGL needs GLSL version 120
|
||||
String version = null;
|
||||
if (GLAdapter.GDX_DESKTOP_QUIRKS)
|
||||
version = "120";
|
||||
|
||||
if (!createVersioned(shaderFile, version))
|
||||
return;
|
||||
|
||||
uMVP = getUniform("u_mvp");
|
||||
uColor = getUniform("u_color");
|
||||
uRadius = getUniform("u_radius");
|
||||
uScreen = getUniform("u_screen");
|
||||
uScale = getUniform("u_scale");
|
||||
aPos = getAttrib("a_pos");
|
||||
}
|
||||
|
||||
@ -64,15 +87,13 @@ public class CircleBucket extends RenderBucket {
|
||||
GLState.enableVertexArrays(aPos, -1);
|
||||
|
||||
v.mvp.setAsUniform(uMVP);
|
||||
gl.uniform2f(uScreen, v.getWidth() / 2, v.getHeight() / 2);
|
||||
gl.lineWidth(2);
|
||||
}
|
||||
}
|
||||
|
||||
public static RenderBucket draw(RenderBucket b, GLViewport v) {
|
||||
GLState.blend(true);
|
||||
|
||||
CircleBucket.Renderer.Shader s = shader;
|
||||
Shader s = shader;
|
||||
|
||||
s.set(v);
|
||||
|
||||
@ -80,12 +101,15 @@ public class CircleBucket extends RenderBucket {
|
||||
CircleBucket cb = (CircleBucket) b;
|
||||
|
||||
GLUtils.setColor(s.uColor, cb.circle.fill, 1);
|
||||
gl.uniform1f(s.uRadius, cb.circle.radius);
|
||||
gl.uniform1f(s.uScale, cb.circle.radius);
|
||||
|
||||
gl.vertexAttribPointer(s.aPos, 2, GL.SHORT,
|
||||
false, 0, cb.vertexOffset);
|
||||
|
||||
gl.drawArrays(GL.TRIANGLE_STRIP, 0, 4);
|
||||
gl.drawElements(GL.POINTS,
|
||||
cb.numIndices,
|
||||
GL.UNSIGNED_SHORT,
|
||||
cb.indiceOffset);
|
||||
}
|
||||
|
||||
return b;
|
||||
|
@ -381,14 +381,6 @@ public class RenderBuckets extends TileData {
|
||||
}
|
||||
}
|
||||
|
||||
for (RenderBucket l = buckets; l != null; l = l.next) {
|
||||
if (l.type == CIRCLE) {
|
||||
l.compile(vboData, iboData);
|
||||
l.vertexOffset = pos;
|
||||
pos += l.numVertices;
|
||||
}
|
||||
}
|
||||
|
||||
offset[LINE] = vboData.position() * SHORT_BYTES;
|
||||
pos = 0;
|
||||
for (RenderBucket l = buckets; l != null; l = l.next) {
|
||||
|
@ -31,7 +31,7 @@ public final class CircleStyle extends RenderStyle<CircleStyle> {
|
||||
public final boolean scaleRadius;
|
||||
public final float strokeWidth;
|
||||
|
||||
public CircleStyle(Float radius, boolean scaleRadius, int fill, int stroke,
|
||||
public CircleStyle(float radius, boolean scaleRadius, int fill, int stroke,
|
||||
float strokeWidth, int level) {
|
||||
super();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user