Circle map style: use GL quads or GL points #122
This commit is contained in:
parent
4cd11462da
commit
b6dc72bbb6
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.test;
|
package org.oscim.test;
|
||||||
|
|
||||||
|
import org.oscim.backend.GLAdapter;
|
||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
import org.oscim.core.GeometryBuffer;
|
import org.oscim.core.GeometryBuffer;
|
||||||
import org.oscim.gdx.GdxMap;
|
import org.oscim.gdx.GdxMap;
|
||||||
@ -73,6 +74,9 @@ public class CircleTest extends GdxMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
// Draw circles with quads or points
|
||||||
|
GLAdapter.CIRCLE_QUADS = false;
|
||||||
|
|
||||||
GdxMapApp.init();
|
GdxMapApp.init();
|
||||||
GdxMapApp.run(new CircleTest());
|
GdxMapApp.run(new CircleTest());
|
||||||
}
|
}
|
||||||
|
22
vtm/resources/assets/shaders/circle_quad.glsl
Normal file
22
vtm/resources/assets/shaders/circle_quad.glsl
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifdef GLES
|
||||||
|
precision highp float;
|
||||||
|
#endif
|
||||||
|
uniform mat4 u_mvp;
|
||||||
|
attribute vec2 a_pos;
|
||||||
|
varying vec2 v_pos;
|
||||||
|
void main() {
|
||||||
|
gl_Position = u_mvp * vec4(a_pos, 0.0, 1.0);
|
||||||
|
v_pos = a_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
$$
|
||||||
|
|
||||||
|
#ifdef GLES
|
||||||
|
precision highp float;
|
||||||
|
#endif
|
||||||
|
uniform vec4 u_color;
|
||||||
|
uniform float u_scale;
|
||||||
|
varying vec2 v_pos;
|
||||||
|
void main() {
|
||||||
|
gl_FragColor = u_color;
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -35,6 +36,11 @@ public class GLAdapter {
|
|||||||
*/
|
*/
|
||||||
public static boolean NO_BUFFER_SUB_DATA = false;
|
public static boolean NO_BUFFER_SUB_DATA = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw circles with quads or points.
|
||||||
|
*/
|
||||||
|
public static boolean CIRCLE_QUADS = false;
|
||||||
|
|
||||||
public static void init(GL gl20) {
|
public static void init(GL gl20) {
|
||||||
gl = gl20;
|
gl = gl20;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class CircleBucket extends RenderBucket {
|
|||||||
public CircleStyle circle;
|
public CircleStyle circle;
|
||||||
|
|
||||||
public CircleBucket(int level) {
|
public CircleBucket(int level) {
|
||||||
super(RenderBucket.CIRCLE, true, false);
|
super(RenderBucket.CIRCLE, true, GLAdapter.CIRCLE_QUADS);
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,16 +49,43 @@ public class CircleBucket extends RenderBucket {
|
|||||||
float x = geom.getPointX(0);
|
float x = geom.getPointX(0);
|
||||||
float y = geom.getPointY(0);
|
float y = geom.getPointY(0);
|
||||||
|
|
||||||
vertexItems.add((short) (x * COORD_SCALE), (short) (y * COORD_SCALE));
|
if (GLAdapter.CIRCLE_QUADS) {
|
||||||
indiceItems.add((short) numVertices++);
|
// Create quad
|
||||||
numIndices++;
|
vertexItems.add((short) ((x + circle.radius) * COORD_SCALE), (short) ((y - circle.radius) * COORD_SCALE));
|
||||||
|
int ne = numVertices++;
|
||||||
|
vertexItems.add((short) ((x - circle.radius) * COORD_SCALE), (short) ((y - circle.radius) * COORD_SCALE));
|
||||||
|
int nw = numVertices++;
|
||||||
|
vertexItems.add((short) ((x - circle.radius) * COORD_SCALE), (short) ((y + circle.radius) * COORD_SCALE));
|
||||||
|
int sw = numVertices++;
|
||||||
|
vertexItems.add((short) ((x + circle.radius) * COORD_SCALE), (short) ((y + circle.radius) * COORD_SCALE));
|
||||||
|
int se = numVertices++;
|
||||||
|
|
||||||
|
indiceItems.add((short) ne);
|
||||||
|
numIndices++;
|
||||||
|
indiceItems.add((short) nw);
|
||||||
|
numIndices++;
|
||||||
|
indiceItems.add((short) sw);
|
||||||
|
numIndices++;
|
||||||
|
|
||||||
|
indiceItems.add((short) sw);
|
||||||
|
numIndices++;
|
||||||
|
indiceItems.add((short) se);
|
||||||
|
numIndices++;
|
||||||
|
indiceItems.add((short) ne);
|
||||||
|
numIndices++;
|
||||||
|
} else {
|
||||||
|
// Use point
|
||||||
|
vertexItems.add((short) (x * COORD_SCALE), (short) (y * COORD_SCALE));
|
||||||
|
indiceItems.add((short) numVertices++);
|
||||||
|
numIndices++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Renderer {
|
public static class Renderer {
|
||||||
static Shader shader;
|
static Shader shader;
|
||||||
|
|
||||||
static boolean init() {
|
static boolean init() {
|
||||||
shader = new Shader("circle");
|
shader = new Shader(GLAdapter.CIRCLE_QUADS ? "circle_quad" : "circle_point");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,12 +93,14 @@ public class CircleBucket extends RenderBucket {
|
|||||||
int uMVP, uColor, uScale, aPos;
|
int uMVP, uColor, uScale, aPos;
|
||||||
|
|
||||||
Shader(String shaderFile) {
|
Shader(String shaderFile) {
|
||||||
gl.enable(GL.VERTEX_PROGRAM_POINT_SIZE);
|
if (!GLAdapter.CIRCLE_QUADS)
|
||||||
|
gl.enable(GL.VERTEX_PROGRAM_POINT_SIZE);
|
||||||
|
|
||||||
// OpenGL needs GLSL version 120
|
|
||||||
String version = null;
|
String version = null;
|
||||||
if (GLAdapter.GDX_DESKTOP_QUIRKS)
|
if (!GLAdapter.CIRCLE_QUADS && GLAdapter.GDX_DESKTOP_QUIRKS) {
|
||||||
|
// OpenGL requires GLSL version 120 for gl_PointCoord
|
||||||
version = "120";
|
version = "120";
|
||||||
|
}
|
||||||
|
|
||||||
if (!createVersioned(shaderFile, version))
|
if (!createVersioned(shaderFile, version))
|
||||||
return;
|
return;
|
||||||
@ -106,10 +135,16 @@ public class CircleBucket extends RenderBucket {
|
|||||||
gl.vertexAttribPointer(s.aPos, 2, GL.SHORT,
|
gl.vertexAttribPointer(s.aPos, 2, GL.SHORT,
|
||||||
false, 0, cb.vertexOffset);
|
false, 0, cb.vertexOffset);
|
||||||
|
|
||||||
gl.drawElements(GL.POINTS,
|
if (GLAdapter.CIRCLE_QUADS)
|
||||||
cb.numIndices,
|
gl.drawElements(GL.TRIANGLES,
|
||||||
GL.UNSIGNED_SHORT,
|
cb.numIndices,
|
||||||
cb.indiceOffset);
|
GL.UNSIGNED_SHORT,
|
||||||
|
cb.indiceOffset);
|
||||||
|
else
|
||||||
|
gl.drawElements(GL.POINTS,
|
||||||
|
cb.numIndices,
|
||||||
|
GL.UNSIGNED_SHORT,
|
||||||
|
cb.indiceOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user